Recursive sql-query?
got a question about doing a recursive sql-query:
i've table containing the employee's number pnr and the superior's number vnr, who's also an employee.
my task is to get all numbers of the direct and indirect superior of a certain employee(e.g. pnr=123), meaning the result set should contain the superior's number, the superior's superior's number etc. until the superior's number is NULL.
is it possible to do that in a simple sql query?
starting:
select vnr
from staff
where pnr = 123
i don't want to write a loop using java and jdbc.
thanks in advance.
got a question about doing a recursive sql-query:
i've table containing the employee's number pnr and the superior's number vnr, who's also an employee.
my task is to get all numbers of the direct and indirect superior of a certain employee(e.g. pnr=123), meaning the result set should contain the superior's number, the superior's superior's number etc. until the superior's number is NULL.
is it possible to do that in a simple sql query?
starting:
select vnr
from staff
where pnr = 123Try to use
select pnr
from staff
CONNECT BY prior vnr=pnr
START WITH pnr=123;
i don't want to write a loop using java and jdbc.
thanks in advance.
Similar Messages
-
SQL query with Bind variable with slower execution plan
I have a 'normal' sql select-insert statement (not using bind variable) and it yields the following execution plan:-
Execution Plan
0 INSERT STATEMENT Optimizer=CHOOSE (Cost=7 Card=1 Bytes=148)
1 0 HASH JOIN (Cost=7 Card=1 Bytes=148)
2 1 TABLE ACCESS (BY INDEX ROWID) OF 'TABLEA' (Cost=4 Card=1 Bytes=100)
3 2 INDEX (RANGE SCAN) OF 'TABLEA_IDX_2' (NON-UNIQUE) (Cost=3 Card=1)
4 1 INDEX (FAST FULL SCAN) OF 'TABLEB_IDX_003' (NON-UNIQUE)
(Cost=2 Card=135 Bytes=6480)
Statistics
0 recursive calls
18 db block gets
15558 consistent gets
47 physical reads
9896 redo size
423 bytes sent via SQL*Net to client
1095 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
55 rows processed
I have the same query but instead running using bind variable (I test it with both oracle form and SQL*plus), it takes considerably longer with a different execution plan:-
Execution Plan
0 INSERT STATEMENT Optimizer=CHOOSE (Cost=407 Card=1 Bytes=148)
1 0 TABLE ACCESS (BY INDEX ROWID) OF 'TABLEA' (Cost=3 Card=1 Bytes=100)
2 1 NESTED LOOPS (Cost=407 Card=1 Bytes=148)
3 2 INDEX (FAST FULL SCAN) OF TABLEB_IDX_003' (NON-UNIQUE) (Cost=2 Card=135 Bytes=6480)
4 2 INDEX (RANGE SCAN) OF 'TABLEA_IDX_2' (NON-UNIQUE) (Cost=2 Card=1)
Statistics
0 recursive calls
12 db block gets
3003199 consistent gets
54 physical reads
9448 redo size
423 bytes sent via SQL*Net to client
1258 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
55 rows processed
TABLEA has around 3million record while TABLEB has 300 records. Is there anyway I can improve the speed of the sql query with bind variable? I have DBA Access to the database
Regards
IvanMany thanks for your reply.
I have run the statistic already for the both tableA and tableB as well all the indexes associated with both table (using dbms_stats, I am on 9i db ) but not the indexed columns.
for table I use:-
begin
dbms_stats.gather_table_stats(ownname=> 'IVAN', tabname=> 'TABLEA', partname=> NULL);
end;
for index I use:-
begin
dbms_stats.gather_index_stats(ownname=> 'IVAN', indname=> 'TABLEB_IDX_003', partname=> NULL);
end;
Is it possible to show me a sample of how to collect statisc for INDEX columns stats?
regards
Ivan -
ORA-00604: error occurred at recursive SQL level 1 ORA-01882: timezone
Hi
I'm trying to config my base_domain for SOA11g but i'm getting the following error when connecting to my Oracle XE DB to configure SOA,
please help thanks
Software installed
OS: Windows 7 64bit
DB: Oracle XE 10g
Oracle SOA 11.1.1.4.0
Oracle RCU 11.1.1.4.0
Oracle wls1034_generic
Error Detials
Component Schema=SOA Infrastructure
Driver=oracle.jdbc.xa.client.OracleXADataSource
URL=jdbc:oracle:thin:@127.0.0.1:1521/XE
User=DEV_SOAINFRA
Password=********
SQL Test=select 1 from schema_version_registry where owner=(select user from dual) and mr_type='SOAINFRA' and version='11.1.1.4.0'
ORA-00604: error occurred at recursive SQL level 1
ORA-01882: timezone region not found
CFGFWK-60850: Test Failed!
Component Schema=User Messaging Service
Driver=oracle.jdbc.OracleDriver
URL=jdbc:oracle:thin:@127.0.0.1:1521/XE
User=DEV_ORASDPM
Password=********
SQL Test=select 1 from schema_version_registry where owner=(select user from dual) and mr_type='ORASDPM' and version='11.1.1.2.0'
ORA-00604: error occurred at recursive SQL level 1
ORA-01882: timezone region not found
CFGFWK-60850: Test Failed!
Component Schema=OWSM MDS Schema
Driver=oracle.jdbc.OracleDriver
URL=jdbc:oracle:thin:@127.0.0.1:1521/XE
User=DEV_MDS
Password=********
SQL Test=select 1 from schema_version_registry where
owner=(select user from dual) and mr_type='MDS' and
version='11.1.1.4.0'
ORA-00604: error occurred at recursive SQL level 1
ORA-01882: timezone region not found
CFGFWK-60850: Test Failed!
Component Schema=SOA MDS Schema
Driver=oracle.jdbc.OracleDriver
URL=jdbc:oracle:thin:@127.0.0.1:1521/XE
User=DEV_MDS
Password=********
SQL Test=select 1 from schema_version_registry where owner=(select user from dual) and mr_type='MDS' and version='11.1.1.4.0'
ORA-00604: error occurred at recursive SQL level 1
ORA-01882: timezone region not found
CFGFWK-60850: Test Failed!
Component Schema=OSB JMS Reporting Provider
Driver=org.apache.derby.jdbc.ClientDriver
URL=jdbc:derby://127.0.0.1:1521/XE;create=true;ServerName=127.0.0.1;databaseName=XE
User=DEV_SOAINFRA
Password=********
SQL Test=SELECT 1 FROM SYS.SYSTABLES
Insufficient data while reading from the network - expected a minimum of 6 bytes and received only 0 bytes. The connection has been terminated.
CFGFWK-60850: Test Failed!Hi,
Please check the timezone set in your server where Weblogic is installed. Also ensure the timezone on which your weblogic is running, the same is present in in database by querying V$TIMEZONE_NAMES table. If it is not present then please change the timezone of the server. then try to execute the steps what you are doing, it will not throw any error.
if this helps please mark.
Thanks,
Kishore -
ORA-00604: error occurred at recursive SQL level 1 (Call to a Oracle View)
I have created a view that refers to a package function within the sql select.
Like
E.x
CREATE OR REPLACE VIEW VW_TAX
as select
test_pkg.fn_get_gl_value(acct_id) desired_col1,
test_pkg.fn_get_gl_desc_value(acct_id) desired_col2
From tables a, b
a.col= b.col
The sample function( fn_get_gl_value) is embedded into a package (test_pkg).
Function fn_get_gl_value:
It earlier referred to table A1, B1, C1 and this query took really long, Therefore I used object type tables and stored the values required once within the package when it is invoked. Later I used the Tables A1, B1 and C1(table Cast from the type Table Loaded in Package Memory)
The query was fast and fine, but now when I try to re-use the view
select * from VW_TAX
where acct_id = '02846'
It fails with this message
09:32:35 Error: ORA-00604: error occurred at recursive SQL level 1
ORA-01000: maximum open cursors exceeded
Note: The database is Oracle8i Enterprise Edition Release 8.1.7.4.0.
Maximum cursors database is 500
Please let me know if there is any known solution,
Appreciate all your help
Thanks
RPSeems like your OPEN_CURSORS init.ora parameter is set too low.
See Metalink Note:1012266.6 for details.
ORA-01000: "maximum open cursors exceeded"
Cause: A host language program attempted to open too many cursors.
The initialization parameter OPEN_CURSORS determines the
maximum number of cursors per user.
Action: Modify the program to use fewer cursors. If this error occurs
often, shut down Oracle, increase the value of OPEN_CURSORS,
and then restart Oracle. -
Ora-00604:error occurred at recursive SQL level 1 and Ora-04023
hi all
i am using oracle linux 5.5 and oracle Database 11g R2 while shutingdown the database i am getting
the following errors.
SQL> shutdown immediate;
Ora-00604:error occurred at recursive SQL level 1
Ora-04023: object select count(*) from reg$SQL>plz can anyone help me out?Couple of questions related to this issue:
1.Is there anything in alert log. Post last 50 lines from alert log.
2.Is there any trace / log generated by Oracle ?
3.What is Memory_Target parameter value ?
4.What is value of statistics_level parameter ?
5.Did you perform any failed upgradation ?
6.Are there any invalid objects in database ?
Generally ORA-00604 is related to insufficient size of shared pool. Now, i am googling how to get a proper value of shared pool size ? I got that there is a view v$shared_pool_advice which will tell me the answer of this question. Ok, it means now question is how do i get the proper value of shared pool from v$shared_pool_advice; i mean how do i interpret this v$shared_pool_advice view ?
No problem docs are there to answer this question : (How i got this link ? Open a new page---http://tahiti.oracle.com---selected 11.2 docs--in the left hand sided there is a search text box i entered v$shared_pool_advice and i got couple of links)
http://download.oracle.com/docs/cd/E11882_01/server.112/e17110/dynviews_3037.htm#REFRN30239
I will read these links and now i will query this and DBA_HIST_SHARED_POOL_ADVICE views, interpret the values. Ok, but what about my original question i.e. ORA-00604 and 4023 ? If i am at this stage, understood all the values, it means now i can understand the meaning / sense of resizing of shared pool.
ALTER SYSTEM SET statistics_level=TYPICAL SCOPE=SPFILE;
You can monitor V$SGA_RESIZE_OPS to identify the range of values that Oracle is automatically resizing the DB_CACHE_SIZE and SHARED_POOL_SIZE components to. Then, pick an appropriate minimum value based on the range. There's no "magic formula". But V$SGA_RESIZE_OPS shows the sizes that Oracle has been automatically been resizing the SGA components to. The Buffer Cache Advisory section of the AWR report or V$DB_CACHE_ADVICE, V$SHARED_POOL_ADVICE, V$SGA_TARGET_ADVICE and DBA_HIST_SGA_TARGET_ADVICE are views that provide advisory information as well. Hemant @ SGA_MAX_SIZE and SGA_TARGET how to set minimum for pools
So, these are the baby steps if i ever gets ORA-00604 and ORA-04023 on my test database. Do all these and feel free to post the next doubt, i am sure you will get the correct answer.
Regards
Girish Sharma -
ORA-00604: error occurred at recursive SQL level 1 + ORA-04031
Hi,
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Solaris: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
os version : SunOS oratest 5.10 Generic_127127-11 sun4u sparc SUNW,Sun-Fire-V210
SQL> show parameter sga_target
NAME TYPE VALUE
sga_target big integer 892M
SQL> show parameter shared_pool_size
NAME TYPE VALUE
shared_pool_size big integer 112M
when i do normal query i am getting ora-04031 error and 10g server is Automatic Shared Memory Management since i set sga_target and server as to do automatically readjusts the sizes of memory pools, if that is the case why it throwing ora-04031 error;
below errors showing before bounce the database
SQL> show parameter size
ORA-04031: unable to allocate 3840 bytes of shared memory ("shared
pool","unknown object","sga heap(1,0)","kglsim object batch")
SQL> select * from tab
2 ;
select * from tab
ERROR at line 1:
ORA-04031: unable to allocate 3840 bytes of shared memory ("shared
pool","select * from tab
","sga heap(1,0)","kglsim object batch")
alert log file:
Errors in file /oracle/admin/appsdb/bdump/appsdb_smon_19154.trc:
ORA-00604: error occurred at recursive SQL level 1
ORA-04031: unable to allocate 3840 bytes of shared memory ("shared pool","unknown object","sga heap(1,0)","kglsim object batc
h")
Thanks
PrakashEdited by: prakashdba on Jan 10, 2009 12:31 AM
Edited by: prakashdba on Jan 10, 2009 4:10 AMAnd your version number is?
And your patch level is?
And your hardware and operating system are?
What did you find when you looked this up at metalink?
Did you follow the advice in the metalink Knowledge Base docs? -
ORA-00604: error occurred at recursive SQL level 1 (10G)
I was adding a default schema setting to a user id, saved the role and got the above error. ID hidden. All the roles below had default already added but had not caused error and some had been in place since Oracle9i
SQL> REVOKE "ROL_HOBSONS_SCHEMA_VIEWS" FROM <USER ID>
Revoke complete.
SQL> GRANT "ROL_HOBSONS_SCHEMA_VIEWS" TO <USER ID>
Grant complete.
SQL> ALTER USER <USER ID>
DEFAULT ROLE "DBA", "ROL_IRIS_CONVERSION", "ROL_UKFRSRPT_VIEW", "ROL_UKFRS_TRANS", "ROL_UKFRS_VIEW", "ROL_UKHRS_RPT", "ROL_UKSISRPT_FAMSBR", "ROL_UKFRS_RPT2", "ROL_CM_IT_CPE", "ROL_UKSISRPT_ VIEW", "CONNECT", "ROL_HOBSONS_SCHEMA_VIEWS", "RESOURCE", "ROL_NEW_UKSIS_VIEWS_IN_TEST", "ROL_HOBSONS_SCHEMA_VIEWS"
ALTER USER <USER ID>
DEFAULT ROLE "DBA", "ROL_IRIS_CONVERSION", "ROL_UKFRSRPT_VIEW", "ROL_UKFRS_TRANS", "ROL_UKFRS_VIEW", "ROL_UKHRS_RPT", "ROL_UKSISRPT_FAMSBR", "ROL_UKFRS_RPT2", "ROL_CM_IT_CPE", "ROL_UKSISRPT_ VIEW", "CONNECT", "ROL_HOBSONS_SCHEMA_VIEWS", "RESOURCE", "ROL_NEW_UKSIS_VIEWS_IN_TEST", "ROL_HOBSONS_SCHEMA_VIEWS"
Error at line 4
ORA-00604: error occurred at recursive SQL level 1
ORA-00001: unique constraint (SYS.I_DEFROLE1) violated
The original change was made by a dba using current Oracle OEM. I accessed using TOAD10 to update another user with a default check mark. Upon trying to save, I got the above error. The updated access remained even though it gave an error and the user reported being able to get to her data. However, any changes to the role with adding or removing admin or default will display the error.
Any ideas?
thanks JohnHi,
Oracle makes an entry in SYS.DEFROLE$ table for a pair of user and default role.
You are getting the error as some of the roles you are now assigning are already default roles for this user and hence UK violation.
You can make use of *"sys.KU$_DEFROLE_LIST_VIEW"* to find already existing records. (see ex below)
SQL> select * from sys.KU$_DEFROLE_LIST_VIEW;
USER_ID USER_NAME ROLE ROLE_ID
69 SRICKMAN DBA 4
69 SRICKMAN ORACLE_DBA 156Find already existing entries for your user, remove those roles from your query and try again.
Regards,
Ullhas -
ORA-00604: error occurred at recursive SQL level 1 ORA-01003: no statement
Hi ,
we pass Query to ref cursor using with clause and it works fine on oracle Sql but raise an error when called from
ADO.net
for example
create or replace package body abc_details
as
proedure initial (p_refcursor out sys_refcursor)
is
begin
v_sql='with a as (select ..
, b as (select * from table(emppkg.empdetails))
open p_refcursor for v_sql;
end;
with oracle 10g it works fine on Sql prompt and fetches the results but when called from ado.net it
intermitantly fetches and error "ORA-00604: error occurred at recursive SQL level 1 ORA-01003: no statement "
Please suggest
Thanks in advance.wild guess here,
but emppkg.empdetails type look's like a pl/sql type,
while it should be a sql type.
Amiel -
SQL Query to find Receipt No.s which are not matched to AP Invoices
Hi
Please help me to frame a query to find list of Receipt No.s which are not matched with AP Invoices.
Please refer to the below query .
SELECT
poh.segment1 "PO No.",
aps.vendor_name "Supplier Name",
pol.item_description "Item Description",
rcvh.receipt_num "GRV No.s",
rcvl.quantity_received "Quantity",
pol.unit_price "Rate/Unit",
rcvtl.tax_name||' - '||initcap(rcvtl.tax_type) "Tax",
(rcvl.quantity_received * pol.unit_price) + nvl(rcvtl.tax_amount,0) "Amount"
FROM
po_headers_all poh,
po_lines_all pol,
po_distributions_all pod,
ap_suppliers aps,
rcv_shipment_headers rcvh,
rcv_shipment_lines rcvl,
rcv_transactions rcvt,
jai_rcv_line_taxes rcvtl
WHERE
poh.po_header_id = pol.po_header_id
AND poh.po_header_id = pod.po_header_id
AND pol.po_line_id = pod.po_line_id
AND aps.vendor_id = poh.vendor_id
AND aps.vendor_id = rcvh.vendor_id
AND rcvh.shipment_header_id = rcvl.shipment_header_id
AND poh.po_header_id = rcvl.po_header_id
AND pol.po_line_id = rcvl.po_line_id
AND rcvh.shipment_header_id = rcvt.shipment_header_id
AND rcvl.shipment_line_id = rcvt.shipment_line_id
AND poh.po_header_id = rcvt.po_header_id
AND pol.po_line_id = rcvt.po_line_id
AND aps.vendor_id = rcvt.vendor_id
AND rcvh.shipment_header_id = rcvtl.shipment_header_id
AND rcvl.shipment_line_id = rcvtl.shipment_line_id
AND rcvt.transaction_id = rcvtl.transaction_id
AND aps.vendor_id = rcvtl.vendor_id
AND rcvt.transaction_type = 'RECEIVE'
AND poh.authorization_status = 'APPROVED'
AND poh.segment1 = '210001079'
I have'nt included the Invoice Tables in the above query.
Please help me in that area.
This is bit urgent.
Please help me.
Regards
Nakul VenkatramanI am using ORACLE 11gR2 If you're licensed for Diangnostics pack then you might want to look at the AWR tables, e.g. DBA_HIST_SQLSTAT and cross-reference with DBA_HIST_SNAPSHOT.
By this will i get the top 5 consumed queries of DEV user in the whole session or its just the top 5 queries at that particular time. The "executions" columns in this query, does it mean that the no. of. times the query has executed... This will get you a random 5 queries that were first parsed by DEV. Depending on your application code/structure, it may well be that all code (except for system-recursive sql) executed by DEV is parsed by DEV, and all code parsed by DEV is executed by DEV but this isn't true for all.
In terms of top N queries, you need to ORDER BY and then restrict by ROWNUM at an outer level to the ROWNUM otherwise the ROWNUM filter is applied before the ORDER BY.
i.e.
SELECT *
FROM
(SELECT ...
FROM ...
WHERE
ORDER BY...)
WHERE ROWNUM <= ....
The "executions" columns in this query, does it mean that the no. of. times the query has executedYes.
http://download.oracle.com/docs/cd/E11882_01/server.112/e25513/dynviews_3064.htm#REFRN30259
Edited by: Dom Brooks on Oct 24, 2011 9:45 AM -
I am executing one sql query with order by clause.
how to check sort is happing in memory or disk ?
what are all the init parameter affect in order by clauseThere are a couple of ways.
1. Query the V$MYSTAT view before and after your query and take the delta of the statistics. A query to retrieve sort information could be the following:
SELECT name,value FROM V$mystat m JOIN v$statname USING (statistic#) where name like 'sorts%';2. In SQL*Plus Set AUTOTRACE TO STATISTICS and run your query. The sort information will be at the bottom.
Sample:
SQL > set autotrace off;
SQL > SELECT name,value FROM V$mystat m JOIN v$statname USING (statistic#) where name like 'sorts%';
NAME VALUE
sorts (memory) 12
sorts (disk) 0
sorts (rows) 42
SQL > SET AUTOTRACE TRACEONLY STATISTICS
SQL > SELECT * FROM (SELECT OBJECT_NAME FROM ALL_OBJECTS WHERE ROWNUM <= 100) ORDER BY OBJECT_NAME;
100 rows selected.
Statistics
674 recursive calls
0 db block gets
245 consistent gets
0 physical reads
0 redo size
2257 bytes sent via SQL*Net to client
462 bytes received via SQL*Net from client
8 SQL*Net roundtrips to/from client
31 sorts (memory)
0 sorts (disk)
100 rows processed
SQL > SET AUTOTRACE OFF;
SQL > SELECT name,value FROM V$mystat m JOIN v$statname USING (statistic#) where name like 'sorts%';
NAME VALUE
sorts (memory) 43
sorts (disk) 0
sorts (rows) 173HTH! -
SQL query to fetch approximately 9000 rows
Hi,
I am using the following SQL query in a java class. Using JDBC to connect to an Oracle database using JRUN app server connection pooling.
SELECT PT.ACCOUNT_NUMBER,PAYMENT_REF_ID, TO_CHAR (PT.DATE_CREATED, 'MM/DD/YYYY'),
PT.AMOUNT_PAID, DECODE(STATUS_VALUE,'Cancelled','Canceled',STATUS_VALUE)
FROM EPAY_PAYMENT_TRANSACTIONS PT, EPAY_STATUS_LOOKUP SL
WHERE
PT.CLIENT_NAME = 'someclientname'
AND TO_CHAR(DATE_PAYMENT_SCHEDULED,'MM/DD/YYYY') = '08/28/2006'
AND PT.PAYMENT_STATUS = SL.STATUS_CODE
ORDER BY PT.DATE_CREATED DESC
EPAY_PAYMENT_TRANSACTIONS is a huge table consisting of thousands of rows. There are 4 indexes defined on this table but not on the columns used in the join condition of the query.
EPAY_STATUS_LOOKUP is a much smaller table mainly used for lookup consisting of some 100 rows.
The above query fetches approx 9000 records and takes a very long time to execute. Is there any way it can be optimized or we can change some attributes on the tables involved for speeding up the query?
Thanks in advance,
Nisha.So the task is to avoid FTS on EPAY_PAYMENT_TRANSACTIONSWell, maybe...
But I believe that we have yet to hear more details about data distribution, execution plans and so on.
Because it all depends...
Consider simple testcase:
SQL> select * from v$version where rownum = 1;
BANNER
Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production
SQL> -- Create "small" table
SQL>
SQL> create table build_t as
2 select rownum x,
3 rpad('*', 200, '*') padding
4 from dual
5 connect by level <= 100;
Table created.
SQL> -- Create "large" table - initially, add 9000 rows which satisfy join criteria
SQL>
SQL> create table probe_t as
2 select mod(rownum - 1, 100) + 1 x,
3 dbms_random.value y,
4 rpad('*', 200, '*') padding
5 from dual
6 connect by level <= 9000;
Table created.
SQL> -- Now, add some extra rows to large table - "thousands of rows"
SQL>
SQL> insert into probe_t
2 select rownum + 100,
3 0,
4 rpad('*', 200, '*') padding
5 from dual
6 connect by level <= 100000;
100000 rows created.
SQL> exec dbms_stats.gather_table_stats(user, 'BUILD_T')
PL/SQL procedure successfully completed.
SQL> exec dbms_stats.gather_table_stats(user, 'PROBE_T')
PL/SQL procedure successfully completed.
SQL> -- Ok, let's measure ...
SQL>
SQL> set autot traceonly
SQL>
SQL> select a.*, b.*
2 from build_t a,
3 probe_t b
4 where a.x = b.x
5 order by b.y;
9000 rows selected.
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=1387 Card=109 Bytes=45017)
1 0 SORT (ORDER BY) (Cost=1387 Card=109 Bytes=45017)
2 1 HASH JOIN (Cost=1386 Card=109 Bytes=45017)
3 2 TABLE ACCESS (FULL) OF 'BUILD_T' (Cost=5 Card=100 Bytes=20400)
4 2 TABLE ACCESS (FULL) OF 'PROBE_T' (Cost=1355 Card=109000 Bytes=22781000)
Statistics
0 recursive calls
0 db block gets
3280 consistent gets
0 physical reads
0 redo size
360756 bytes sent via SQL*Net to client
7096 bytes received via SQL*Net from client
601 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
9000 rows processedOn my server, this query finished in less that second and took 3280 LIO to complete.
Now, which index did you mean to build? I guess it's and index on join column, isn't it?
If so - let's build it and measure again:
SQL> create index idx_probe_t on probe_t(x);
Index created.
SQL> select /*+ ORDERED USE_NL(a b) */
2 a.*, b.*
3 from build_t a,
4 probe_t b
5 where a.x = b.x
6 order by b.y;
9000 rows selected.
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=211 Card=109 Bytes=45017)
1 0 SORT (ORDER BY) (Cost=211 Card=109 Bytes=45017)
2 1 TABLE ACCESS (BY INDEX ROWID) OF 'PROBE_T' (Cost=3 Card=1 Bytes=209)
3 2 NESTED LOOPS (Cost=210 Card=109 Bytes=45017)
4 3 TABLE ACCESS (FULL) OF 'BUILD_T' (Cost=5 Card=100 Bytes=20400)
5 3 INDEX (RANGE SCAN) OF 'IDX_PROBE_T' (NON-UNIQUE) (Cost=2 Card=1)
Statistics
0 recursive calls
0 db block gets
9124 consistent gets
21 physical reads
0 redo size
360756 bytes sent via SQL*Net to client
7096 bytes received via SQL*Net from client
601 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
9000 rows processedLook at this - 9124 consistent gets, almost three times larger than in case of hash join.
Full table scan is not something to be avoided at all cost.
Indexing - sometimes it is good,
sometimes it's just useless,
sometimes it only makes things worse...
It all depends on underlying data distribution. That's why I asked user527580 to tell us more.
Kind regards. -
Dynamic SQL within a SQL Query ?
is there any possibility to do like this ?
SELECT table_name, XXXXXXXX('SELECT Count(*) FROM '||table_name) tot_rows
FROM dba_tables
WHERE owner = 'SCOTT';or any other trick to run dynamic SQL within the SQL Query?
Hoping....that it should be.
Regards,
OrapdevOne small disadvantage: it is executing 202 SQL statements: 3 "user SQL statements" (the one above and the 2 "select count(*)..."), and 199 internal ones ...How did you get to those numbers?
I just traced this statement and found completely different results:
TKPROF: Release 10.2.0.3.0 - Production on Tue Jul 10 12:12:10 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Trace file: diesl10r2_ora_5440.trc
Sort options: default
count = number of times OCI procedure was executed
cpu = cpu time in seconds executing
elapsed = elapsed time in seconds executing
disk = number of physical reads of buffers from disk
query = number of buffers gotten for consistent read
current = number of buffers gotten in current mode (usually for update)
rows = number of rows processed by the fetch or execute call
declare cursor NlsParamsCursor is SELECT * FROM
nls_session_parameters;begin SELECT Nvl(Lengthb(Chr(65536)),
Nvl(Lengthb(Chr(256)), 1)) INTO :CharLength FROM dual; for NlsRecord in
NlsParamsCursor loop if NlsRecord.parameter = 'NLS_DATE_LANGUAGE' then
:NlsDateLanguage := NlsRecord.value; elsif NlsRecord.parameter =
'NLS_DATE_FORMAT' then :NlsDateFormat := NlsRecord.value; elsif
NlsRecord.parameter = 'NLS_NUMERIC_CHARACTERS' then
:NlsNumericCharacters := NlsRecord.value; elsif NlsRecord.parameter =
'NLS_TIMESTAMP_FORMAT' then :NlsTimeStampFormat := NlsRecord.value;
elsif NlsRecord.parameter = 'NLS_TIMESTAMP_TZ_FORMAT' then
:NlsTimeStampTZFormat := NlsRecord.value; end if; end loop;end;
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 1
Fetch 0 0.00 0.00 0 0 0 0
total 2 0.00 0.00 0 0 0 1
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 50
SELECT NVL(LENGTHB(CHR(65536)), NVL(LENGTHB(CHR(256)), 1))
FROM
DUAL
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.01 0.00 0 0 0 0
Fetch 1 0.00 0.00 0 0 0 1
total 3 0.01 0.00 0 0 0 1
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 50 (recursive depth: 1)
Rows Row Source Operation
1 FAST DUAL (cr=0 pr=0 pw=0 time=7 us)
SELECT *
FROM
NLS_SESSION_PARAMETERS
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1 0.00 0.00 0 0 0 17
total 3 0.00 0.00 0 0 0 17
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 50 (recursive depth: 1)
Rows Row Source Operation
17 FIXED TABLE FULL X$NLS_PARAMETERS (cr=0 pr=0 pw=0 time=124 us)
select PARAMETER,VALUE
from
nls_session_parameters where PARAMETER in('NLS_NUMERIC_CHARACTERS',
'NLS_DATE_FORMAT','NLS_CURRENCY')
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1 0.00 0.00 0 0 0 3
total 3 0.00 0.00 0 0 0 3
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 50
Rows Row Source Operation
3 FIXED TABLE FULL X$NLS_PARAMETERS (cr=0 pr=0 pw=0 time=57 us)
select to_char(9,'9C')
from
dual
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1 0.00 0.00 0 0 0 1
total 3 0.00 0.00 0 0 0 1
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 50
Rows Row Source Operation
1 FAST DUAL (cr=0 pr=0 pw=0 time=2 us)
SELECT table_name,
DBMS_XMLGEN.getxmltype ('select count(*) c from ' || table_name).EXTRACT
('//text').getstringval
() tot
FROM dba_tables
WHERE table_name IN ('EMP', 'DEPT') AND owner = 'SCOTT'
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1 0.01 0.02 0 48 0 2
total 3 0.01 0.02 0 48 0 2
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 50
Rows Row Source Operation
2 HASH JOIN (cr=42 pr=0 pw=0 time=2952 us)
2 MERGE JOIN CARTESIAN (cr=42 pr=0 pw=0 time=1206 us)
2 NESTED LOOPS OUTER (cr=42 pr=0 pw=0 time=478 us)
2 NESTED LOOPS OUTER (cr=36 pr=0 pw=0 time=421 us)
2 NESTED LOOPS OUTER (cr=30 pr=0 pw=0 time=379 us)
2 NESTED LOOPS OUTER (cr=30 pr=0 pw=0 time=365 us)
2 NESTED LOOPS (cr=22 pr=0 pw=0 time=312 us)
2 NESTED LOOPS (cr=16 pr=0 pw=0 time=272 us)
2 NESTED LOOPS (cr=8 pr=0 pw=0 time=172 us)
1 TABLE ACCESS BY INDEX ROWID USER$ (cr=2 pr=0 pw=0 time=56 us)
1 INDEX UNIQUE SCAN I_USER1 (cr=1 pr=0 pw=0 time=30 us)(object id 44)
2 INLIST ITERATOR (cr=6 pr=0 pw=0 time=111 us)
2 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=6 pr=0 pw=0 time=87 us)
2 INDEX RANGE SCAN I_OBJ2 (cr=4 pr=0 pw=0 time=54 us)(object id 37)
2 TABLE ACCESS CLUSTER TAB$ (cr=8 pr=0 pw=0 time=98 us)
2 INDEX UNIQUE SCAN I_OBJ# (cr=4 pr=0 pw=0 time=26 us)(object id 3)
2 TABLE ACCESS CLUSTER TS$ (cr=6 pr=0 pw=0 time=39 us)
2 INDEX UNIQUE SCAN I_TS# (cr=2 pr=0 pw=0 time=13 us)(object id 7)
2 TABLE ACCESS CLUSTER SEG$ (cr=8 pr=0 pw=0 time=37 us)
2 INDEX UNIQUE SCAN I_FILE#_BLOCK# (cr=4 pr=0 pw=0 time=21 us)(object id 9)
0 INDEX UNIQUE SCAN I_OBJ1 (cr=0 pr=0 pw=0 time=4 us)(object id 36)
2 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=6 pr=0 pw=0 time=33 us)
2 INDEX UNIQUE SCAN I_OBJ1 (cr=4 pr=0 pw=0 time=23 us)(object id 36)
2 TABLE ACCESS CLUSTER USER$ (cr=6 pr=0 pw=0 time=28 us)
2 INDEX UNIQUE SCAN I_USER# (cr=2 pr=0 pw=0 time=12 us)(object id 11)
2 BUFFER SORT (cr=0 pr=0 pw=0 time=716 us)
1 FIXED TABLE FULL X$KSPPI (cr=0 pr=0 pw=0 time=661 us)
1436 FIXED TABLE FULL X$KSPPCV (cr=0 pr=0 pw=0 time=1449 us)
select count(*) c
from
EMP
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 2 0.00 0.00 0 1 0 1
total 4 0.00 0.00 0 1 0 1
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 50 (recursive depth: 1)
Rows Row Source Operation
1 SORT AGGREGATE (cr=1 pr=0 pw=0 time=96 us)
14 INDEX FULL SCAN EMP_IDX (cr=1 pr=0 pw=0 time=46 us)(object id 61191)
select metadata
from
kopm$ where name='DB_FDO'
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1 0.00 0.00 0 2 0 1
total 3 0.00 0.00 0 2 0 1
Misses in library cache during parse: 0
Optimizer mode: CHOOSE
Parsing user id: SYS (recursive depth: 1)
Rows Row Source Operation
1 TABLE ACCESS BY INDEX ROWID KOPM$ (cr=2 pr=0 pw=0 time=42 us)
1 INDEX UNIQUE SCAN I_KOPM1 (cr=1 pr=0 pw=0 time=22 us)(object id 365)
select count(*) c
from
DEPT
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 2 0.00 0.00 0 1 0 1
total 4 0.00 0.00 0 1 0 1
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 50 (recursive depth: 1)
ALTER SESSION SET sql_trace=FALSE
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
total 2 0.00 0.00 0 0 0 0
Misses in library cache during parse: 0
Parsing user id: 50
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 5 0.00 0.00 0 0 0 0
Execute 5 0.00 0.00 0 0 0 1
Fetch 3 0.01 0.02 0 48 0 6
total 13 0.01 0.03 0 48 0 7
Misses in library cache during parse: 0
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 5 0.00 0.00 0 0 0 0
Execute 5 0.01 0.00 0 0 0 0
Fetch 7 0.00 0.00 0 4 0 21
total 17 0.01 0.00 0 4 0 21
Misses in library cache during parse: 0
9 user SQL statements in session.
1 internal SQL statements in session.
10 SQL statements in session.
Trace file: diesl10r2_ora_5440.trc
Trace file compatibility: 10.01.00
Sort options: default
1 session in tracefile.
9 user SQL statements in trace file.
1 internal SQL statements in trace file.
10 SQL statements in trace file.
10 unique SQL statements in trace file.
132 lines in trace file.
0 elapsed seconds in trace file.I only see a ratio of 1:9 for user- to internal SQL statements?
michaels> select * from v$version
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production -
How to write SQL query to flatten the hierarchy
Hi,
I have person table which has recursive hierarchy and I wish to flatten it upto 5 levels.
I am using Oracle10g and I have written following query to flatten the hierarchy
SELECT
ID,
level lvl,
REGEXP_SUBSTR (SYS_CONNECT_BY_PATH (fname||' '||lname, '/'), '[^/]+', 1, 1) AS level_1,
REGEXP_SUBSTR (SYS_CONNECT_BY_PATH (fname||' '||lname, '/'), '[^/]+', 1, 2) AS level_2,
REGEXP_SUBSTR (SYS_CONNECT_BY_PATH (fname||' '||lname, '/'), '[^/]+', 1, 3) AS level_3,
REGEXP_SUBSTR (SYS_CONNECT_BY_PATH (fname||' '||lname, '/'), '[^/]+', 1, 4) AS level_4,
REGEXP_SUBSTR (SYS_CONNECT_BY_PATH (fname||' '||lname, '/'), '[^/]+', 1, 5) AS level_5
FROM cmt_person
CONNECT BY manager_id = PRIOR id
and level<=5
The person table have more than a million records.
Here I am getting the correct output but this query is taking a lot of time to run.
I am looking at a SQL query without use of connect by to get the required output.
To recreate the issue, you can use this query in HR schema of Oracle and use Employees table.
Any help would be greatly appreciated.
Thanks,
RaghvendraI tried to rewrite the query without using regular expression and connect by. Here is the code:
SELECT
cmt_person.id ,
cmt_person.fname as mgr1,
case when cmt_person2.manager_id=cmt_person.id then (cmt_person2.fname ) end as mgr2,
case when cmt_person3.manager_id=cmt_person2.id then (cmt_person3.fname ) end as mgr3,
case when cmt_person4.manager_id=cmt_person3.id then cmt_person4.fname end as mgr4,
case when cmt_person5.manager_id=cmt_person4.id then cmt_person5.fname end as mgr5
FROM
cmt_person,
cmt_person cmt_person2,
cmt_person cmt_person3,
cmt_person cmt_person4,
cmt_person cmt_person5
WHERE
cmt_person2.manager_id(+)=cmt_person.id and
cmt_person3.manager_id(+)=cmt_person2.id and
cmt_person4.manager_id(+)=cmt_person3.id and
cmt_person5.manager_id(+)=cmt_person4.id
order by 2,3,4
I got following output:
emplo000000000200100 Bobby Khasha Rahul Rajesh
emplo000000000200099 Bobby Khasha Rahul Ajay
emplo000000000200101 Bobby Khasha Rahul Swati
emplo000000000200320 Bobby Khasha Rahul Jinesh
emplo000000000201231 Bobby Khasha Test123
emplo000000000201230 Bobby Khasha User1_Domain
emplo000000000201227 Bobby Khasha User1_World
emplo000000000200104 Bobby Khasha Yitzik Natalia
emplo000000000200103 Bobby Khasha Yitzik Andrew
total 9 rows
But this is partially correct output. I want output like this:
emplo000000000200097 Bobby
emplo000000000200087 Bobby Khasha
emplo000000000200102 Bobby Khasha Yitzik
emplo000000000200103 Bobby Khasha Yitzik Andrew
emplo000000000200104 Bobby Khasha Yitzik Natalia
emplo000000000201227 Bobby Khasha User1_World
emplo000000000201231 Bobby Khasha Test123
emplo000000000201230 Bobby Khasha User1_Domain
emplo000000000200098 Bobby Khasha Rahul
emplo000000000200099 Bobby Khasha Rahul Ajay
emplo000000000200100 Bobby Khasha Rahul Rajesh
emplo000000000200320 Bobby Khasha Rahul Jinesh
emplo000000000200101 Bobby Khasha Rahul Swati
total 13 rows
Do you know what I should do to get this output.
Thanks,
Raghvendra -
Recursive, hierachical query problem
Hi!
I have a hierachical SQL query using "connect by" that result in the following dataset (simplified to get down to the point):
ID | Parent | IsData
A | | N
A1 | A | N
A2 | A | N
X1 | A2 | Y
B | | N
B1 | B | N
X2 | B1 | Y
B2 | B | N
C | | N
C1 | C | N There are data entries (X1 and X2) and structural (An, Bn, Cn) entries. Some nodes of the structure tree have data entries as childs, some do not.
What I need is a third column that says "this node has a data node below recursively" as shown below:
ID | Parent | IsData | HasRecursiveDataChilds
A | | N | Y
A1 | A | N | N
A2 | A | N | Y
X1 | A2 | Y | Y/N (doesn't matter)
B | | N | Y
B1 | B | N | Y
X2 | B1 | Y | Y/N (doesn't matter)
B2 | B | N | N
C | | N | N
C1 | C | N | N I currently do this on the client side, after I got all the data, which involves interating through the complete dataset at least once (if you know the data well). Since the data has to be accessed from another (web) app, I want to move the logic to the server.
I'm wondering if this can be done with a simple SQL statement without using PL/SQL to iterate through the result set "manually". I can use the 10g feature set. Performance is not utterly important, so wild sub-sub-subqueries would be ok.
Thanks for your help,
MarcusOk, this is a bit of a fudge..
SQL> ed
Wrote file afiedt.buf
1 with t as (select 'A' as ID, null as parent, 'N' as IsData from dual union all
2 select 'A1','A','N' from dual union all
3 select 'A2','A','N' from dual union all
4 select 'X1','A2','Y' from dual union all
5 select 'B', null, 'N' from dual union all
6 select 'B1','B','N' from dual union all
7 select 'X2','B1','Y' from dual union all
8 select 'B2','B','N' from dual union all
9 select 'C',null,'N' from dual union all
10 select 'C1','C','N' from dual)
11 -- END OF TEST DATA
12 select lpad(' ',(level-1)*2,' ')||id as id, parent, isdata
13 ,NVL((select max(t2.isdata)
14 from t t2
15 connect by parent = prior id
16 start with parent = t.id),'N') as recursivechilddata
17 from t
18 connect by parent = prior id
19* start with parent is null
SQL> /
ID PARENT ISDATA RECURSIVECHILDDATA
A N Y
A1 A N N
A2 A N Y
X1 A2 Y N
B N Y
B1 B N Y
X2 B1 Y N
B2 B N N
C N N
C1 C N N
10 rows selected.
SQL>Edited by: BluShadow on Apr 9, 2009 10:59 AM
removed redundant code -
Error occurred at recursive SQL level 1
Hi,
When I create the Oracle tables, I hit the following error:
ORA-00604: error occurred at recursive SQL level 1
ORA-01654: unable to extend index SYS.I_OBJ1 by 12 in tablespace SYSTEM
Any idea of how to solve the problem?
Regards
EvanWith this query you can see how much space is still free in your tablespaces
select tablespace_name, sum(bytes)/1024/1024 from sys.dba_free_space
group by tablespace_name
To enlarge your tablespace you can add an extra datafile
alter tablespace <name> add datafile '<filename>' size <number>M
Coen
Maybe you are looking for
-
Query ON ORACLE AND OAS UPGRADE PLAN
Currently we are running Oracle Server 7.3.4 Under Unix (SunOS5.7) with access to a Sybase 12.5.0.1 via Oracle-Sybase Transparent Gateway 4.1.1.0.0. For the web services, we use OAS 4.0.8.1. Our web applications are based on Javascript and Oracle PL/
-
SQLParseException occurred while composing Offline Database View definition
While importing view definitions from CASE120 to offline database for some views I am getting following error. ERROR: An SQLParseException occurred while composing Offline Database View definitions: Error(s) parsing SQL: Unexpected token near *!* in
-
Dynamic partner link for http binding
Hi all, I'm writing BPEL code to call a web service with dynamic partner link. I'm succesful in soap binding but fail in http binding, it does not run with new given address. Could you please help me to solve this problem? Is the trouble coming from
-
Hi, I use ODI 10.1.3.4.0 and in a new project I have to invoke Web service(department) (Web RESTFUL service). I would like to know if it is possible via the command OdiInvokeWebService. Should the opposite occur, what is the best solution? Thank
-
How do I post an FYI I want to share some information about html5 video I discovered
This is not a question it is a solution. Before I could not get Firefox 14.0.1 to display .ogg videos even with the proper memi type set on the Apache Web Server 2.0 Here is the solution Do not put meta tag with Content-Type set to content="text/html