Create a materialized view for a connect by sql - oracle

There is a log-time SQL which need to be performance-tuing. However I can not change the SQL, because it is generated by IDM(one application
developed by Oracle) automatically. The customer know it will be a
long time if they ask for the new edition of IDM which contain new
and fasted SQL. So I am required to boost the response time without
change the original SQL.
I give a solution of materialized view, however there are some
problems when I test for it.
The SQL is :
select * from scott.usr
where act_key in (select act_key
from scott.ACT act
START WITH act_key in ('267' )
connect by nocycle
prior act_key = parent_key)
For table ACT, there are two columns: act_key and parent_key, which is
foreign key relationship. My puzzle is , there is a input parameter 267, which is not fixed.
if I create a materialized view like the following:
sql> select act_key from scott.ACT act
connect by nocycle prior act_key = parent_key;
The query rewrite will not happen. Any input is appreciated.
Regards
santa

Related

Can't get Oracle SQL Developer to display specific values from object table

I've started learning SQL and playing with Oracle SQL Developer v22. For some reason I'm not able to retrieve value from an object table by using SELECT VALUE(A). It only gives my user ID.object_name as in the below screenshot. Any tips why?
SELECT VALUE(A) FROM table A;
If I use SELECT * FROM table; all is fine.
SELECT * FROM table A;
I've tried printing using dmbs_output, same problem.
Tried with other object tables, same behaviour.
Please share your table DDL and DML for a more accurate answer, but setting this preference should do what you're looking for
'Display Struct Value in Grid'
I talk about that here
Disclaimer: I work for Oracle and am the product manager for SQL Developer.

how to get select statement query which was used to create table in oracle

I created a table in oracle like
CREATE TABLE suppliers AS (SELECT * FROM companies WHERE id > 1000);
I would like to know the complete select statement which was used to create this table.
I have already tried get_ddl but it is not giving the select statement. Can you please let me know how to get the select statement?
If you're lucky one of these statements will show the DDL used to generate the table:
select *
from gv$sql
where lower(sql_fulltext) like '%create table suppliers%';
select *
from dba_hist_sqltext
where lower(sql_text) like '%create table%';
I used the word lucky because GV$SQL will usually only have results for a few hours or days, until the data is purged from the shared pool. DBA_HIST_SQLTEXT will only help if you have AWR enabled, the statement was run in the last X days that AWR is configured to hold data (the default is 8), the statement was run after the last snapshot collection (by default it happens every hour), and the statement ran long enough for AWR to think it's worth saving.
And for each table Oracle does not always store the full SQL. For security reasons, DDL statements are often truncated in the data dictionary. Don't be surprised if the text suddenly cuts off after the first N characters.
And depending on how the SQL is called the case and space may be different. Use lower and lots of wildcards to increase the chance of finding the statement.
TRY THIS:
select distinct table_name
from
all_tab_columns where column_name in
(
select column_name from
all_tab_columns
where table_name ='SUPPLIERS'
)
you can find table which created from table

Oracle performance drop in massive table copy

Situation:
I'm using Oracle 11g R2 to work on two database users.
User U0 = original database with hundreds of tables
User U1 = copy of U0 to be used for simulating U0
To maintain U1, I run a script as below on U1 when simulation starts.
truncate table T1;
truncate table T2;
...
insert into T1 (select * from U0.T1)
insert into T2 (select * from U0.T2)
...
Problem: It had no problem for few days, but got slower after weeks.
Also it sometimes stop inserting records in tables, and in this case it always stops at same table. However I don't think that the table size is the problem since it has less than 20,000 records only.
I guess that this is due to resource problem in DBMS side, disk or memory, but have no idea how to resolve it. I could find a similar question as below without exact procedure to work around storage problem. Maybe this can be simple one to DBAs but unfortunately I'm not qualified for that.
Oracle performance issue with massive inserts and truncates (AWR attached)
Edit: following Jon Heller's comment, I've got query results as follows.
dba_resumable : no records.
gv$sql : 5~6 records queried but insert statement is not included.
Most notable one is "select TIME_WAITED_MICRO from V$SYSTEM_EVENT where event = 'Shared IO Pool Memory'". I guess it is due to insufficient memory.
report_sql_monitor : every sql_id returns "SQL Monitoring Report" without additional information.
Edit2: Please forget about edit above. Insert statement appeared in gv$sql query and SQL monitor result is as attached picture.
Edit3: This time SQL monitor returned Activity detail for the same insert statement.

Why does an Oracle Union create a duplicate in SSIS?

In PLSQL I run:
truncate table MyOracleTableName;
commit work;
insert into MyOracleTablename
select a,b,c,trunc(sysdate) as datadate
from AnotherOracleTableName
where there is a ton of nasty criteria
union
select a,b,c,trunc(sysdate) as datadate from AnotherOracleTableName
where there is a ton of different nasty criteria;
commit work;
In PLSQL Developer this inserts one row.
When I run the SQL (without the semi colons and the commit work statements) in SSIS, I get a primary key violation from MyOracleTableName.
I have validated that the truncate from SSIS is committed in Oracle.
When I run the SQL above in PLSQL Developer and replace the union with union all, I see a second row and the insert fails for a PK violation. As it should with a union all allowing the duplicate.
This is currently part of an SSIS 2005 package using MSDAORA where it works just fine. I am now re-writing in SSIS 2008 using Native OLE DB providor for Oracle.
I cannot use MSDAORA in my new environment. Is this a driver issue and is there a work around other than breaking these into multiple statements where the second inserts only what is not already in MyOracleTableName?
Regards.
I figured out the problem after dinner.
The Primary key constraint is a composite key on columns A and B. The Union de-dups on columns a,b,c and the date. In Oracle the trunc(sysdate) returns mm/dd/yyyy. In SSIS the trunc(sysdate) is being parsed out to the second or milisecond. This results in two unique rows (to SQL Server and Microsoft) due to the timestamp, and then attempts to insert duplicate rows where columns a,b, and c are duplicated.
The solution is this:
truncate table MyOracleTableName;
commit work;
insert into MyOracleTablename
select a.*,
trunc(sysdate) as datadate
from(
select a,b,c
from AnotherOracleTableName
where there is a ton of nasty criteria
union
select a,b,c from AnotherOracleTableName
where there is a ton of different nasty criteria) a
commit work;
This allows the union to kill the duplicate and runs the trunc(sysdate) once thereby presenting the single row to my primary key constraint.
Thank you.

Join between a sqlsever table and an oracle table

I have been using SQL Server 2008 for a short time now and have never used Oracle before. I am able to access an Oracle table through SQL Server with the syntax
select * from [OracleDB1]..[OracleDB1].[Zips]
(where OracleDB1 is the oracle database and Zips is the table I require)
Is it possible to join a SQL Server table with this one in a Table-valued Function? Just using a normal join as I would with SQL Server tables gives an Invalid object name error on the Oracle table.
Can this be done directly (or at all) or is it possible to do this some other way such as table variables?
example query:
select * from dbo.Table1 t INNER JOIN [OracleDB1]..[OracleDB1].[Zips] z where t.zip = z.zip
I was performing the join wrong since I missed the ON clause. I was able to get it to work by declaring a temptable and joining on that.
declare #tempTable table{
ZIP nvarchar(5),
COUNTY nvarchar(10)
}
insert #tempTable select ZIP, COUNTY, from [OracleDB1]..[OracleDB1].[ZIPS]
select * from dbo.Table1 t INNER JOIN #tempTable z on t.ZIP = v.ZIP where t.AdmissionOn >= '08-08-2011' AND t.AdmissionOn <= ''09-08-2011'
This also worked in line as I had in the original question once I added the ON clause but the table variable suits my needs better since it only has to access the Oracle table once and not each comparison.

Resources