SQL query, IF ELSE issue - Help.
I am trying to migrate data from one table to another, however I am having problems trying to figure out a small issue in my Query.
I'm using Oracle 11g, SQL Developer 3.0
here is my old table
CREATE TABLE PROD.RELATED_OFFENDERS
CREATED_DATETIME DATE ,
LAST_UPD_DATETIME DATE ,
LAST_UPD_ID VARCHAR2 (30 BYTE) ,
CREATOR_ID VARCHAR2 (30 BYTE) ,
USSC_ID NUMBER (10) ,
REL_ORG_ID NUMBER (10) NOT NULL ,
REL_ORG_NAME VARCHAR2 (100 BYTE) ,
REL_IND_NAMES VARCHAR2 (100 BYTE) ,
REL_DOCKET_NUM VARCHAR2 (7 BYTE) ,
REL_LEVEL_AUTH NUMBER (2) ,
REL_LEVEL_AUTH_TEXT VARCHAR2 (240 BYTE) ,
SENT_TYPE_CODE NUMBER (2) ,
INDICATOR VARCHAR2 (1 BYTE)
ALTER TABLE PROD.RELATED_OFFENDERS
ADD CONSTRAINT RO_PK PRIMARY KEY ( REL_ORG_ID ) ;New table
CREATE TABLE USSC_CASES.CORP_RELATED_OFFENDERS
REL_ORG_ID NUMBER (10) NOT NULL ,
SENT_ID NUMBER (12) NOT NULL ,
DEF_TYPE_CODE NUMBER (1) ,
DEF_TYPE_NAME VARCHAR2 (100 BYTE) ,
REL_DOCKET_NUM VARCHAR2 (7 BYTE) ,
REL_LVL_AUTH NUMBER (1) ,
REL_LVL_AUTH_TEXT VARCHAR2 (240 BYTE)
ALTER TABLE USSC_CASES.CORP_RELATED_OFFENDERS
ADD CONSTRAINT CORP_REL_OFF_PK PRIMARY KEY ( REL_ORG_ID ) ;In the old table you will notice i have the following attributes:
REL_ORG_NAME VARCHAR2 (100 BYTE) ,
REL_IND_NAMES VARCHAR2 (100 BYTE) ,
In my new table I have both columns as one called DEF_TYPE_NAME VARCHAR2 (100 BYTE).
what I'm trying to do is use the INDICATOR column VALUE (old table) for each row and say the following in SQL code:
(if INDICATOR = 'I' then DEF_TYPE_NAME = the value of REL IND_NAMES
else if INDICATOR = 'O' then DEF_TYPE_NAME = the value of REL_ORG_NAME) AS DEF_TYPE_NAME
here is my query
INSERT INTO USSC_CASES.CORP_RELATED_OFFENDERS
SELECT
RO.REL_ORG_ID AS REL_ORG_ID,
S.SENT_ID AS SENT_ID,
DECODE(RO.INDICATOR, UPPER(TRIM('I')), 1, 2) AS DEF_TYPE_CODE,
AS DEF_TYPE_NAME, -- here is where I'm having issues.
RO.REL_DOCKET_NUM AS REL_DOCKET_NUM,
RO.REL_LVL_AUTH AS REL_LVL_AUTH,
RO.REL_LVL_AUTH_TEXT AS REL_LVL_AUTH_TEXT
FROM PROD.RELATED_OFFENDERS RO,
PROD.SENTENCES S
WHERE RO.USSC_ID = S.CORPSENT_USSC_ID
AND RO.SENT_TYPE_CODE = S.SENT_TYPE_CODE
AND RO.SENT_TYPE_CODE = 1
ORDER BY REL_ORG_ID;Thanks in advance for your help.
INSERT INTO USSC_CASES.CORP_RELATED_OFFENDERS
SELECT RO.REL_ORG_ID AS REL_ORG_ID,
S.SENT_ID AS SENT_ID,
CASE RO.INDICATOR
WHEN 'I' THEN REL_IND_NAMES
WHEN 'O' THEN REL_ORG_NAME
END AS DEF_TYPE_NAME,
RO.REL_DOCKET_NUM AS REL_DOCKET_NUM,
RO.REL_LVL_AUTH AS REL_LVL_AUTH,
RO.REL_LVL_AUTH_TEXT AS REL_LVL_AUTH_TEXT
FROM PROD.RELATED_OFFENDERS RO,
PROD.SENTENCES S
WHERE RO.USSC_ID = S.CORPSENT_USSC_ID
AND RO.SENT_TYPE_CODE = S.SENT_TYPE_CODE
AND RO.SENT_TYPE_CODE = 1
ORDER BY REL_ORG_ID;SY.
Similar Messages
-
SQL Query Sorting Order issue - Help needed
Hi All,
I am using the following query in my project to display the records in the grid.
/* Formatted on 04-09-2013 PM 8:01:51 (QP5 v5.149.1003.31008) */
SELECT eol,
status_msg,
relation,
building_name,
device_id id,
CEIL (SYSDATE - updated_date) duration,
lab_id,
aisle_id,
aisle_location_id,
ip_address,
port,
slot_num,
hostname,
pid,
description,
sl_num,
eitms_code,
status,
dnd_flag,
aisle,
aisle_location,
spname,
os_version,
user_id,
TO_CHAR (updated_date, 'YYYY-MM-DD HH24:MI:SS') updated_date,
isterm_svr,
net_type,
DEVICE_GROUP_REF,
cmd_id_ref,
LISTAGG (TESTBED_ID, ',') WITHIN GROUP (ORDER BY TESTBED_ID)
AS testbeds_id_ref,
LISTAGG (NAME, ',') WITHIN GROUP (ORDER BY TESTBED_ID)
AS testbeds_names,
spname || '-' || ip_address || '-' || port AS child_asset_group
FROM DEVICE_TESTBED_VW
WHERE lab_id IN
('7099849',
'10769617',
'4258712',
'10513562',
'10515074',
'5882676',
'8330925')
GROUP BY eol,
status_msg,
relation,
device_id,
lab_id,
aisle_id,
aisle_location_id,
ip_address,
port,
slot_num,
hostname,
pid,
description,
sl_num,
eitms_code,
status,
dnd_flag,
aisle,
aisle_location,
spname,
os_version,
user_id,
updated_date,
isterm_svr,
net_type,
DEVICE_GROUP_REF,
cmd_id_ref,
building_name
ORDER BY building_name ASC,
LOWER (child_asset_group) ASC,
LOWER (relation) DESC
The problem is , if any one sorting with any column , the order is not correct
In this below code , i have done sorting by port . But the result data order is not correct .
/* Formatted on 04-09-2013 PM 8:07:02 (QP5 v5.149.1003.31008) */
SELECT eol,
status_msg,
relation,
building_name,
device_id id,
CEIL (SYSDATE - updated_date) duration,
lab_id,
aisle_id,
aisle_location_id,
ip_address,
port,
slot_num,
hostname,
pid,
description,
sl_num,
eitms_code,
status,
dnd_flag,
aisle,
aisle_location,
spname,
os_version,
user_id,
TO_CHAR (updated_date, 'YYYY-MM-DD HH24:MI:SS') updated_date,
isterm_svr,
net_type,
DEVICE_GROUP_REF,
cmd_id_ref,
LISTAGG (TESTBED_ID, ',') WITHIN GROUP (ORDER BY TESTBED_ID)
AS testbeds_id_ref,
LISTAGG (NAME, ',') WITHIN GROUP (ORDER BY TESTBED_ID)
AS testbeds_names,
spname || '-' || ip_address || '-' || port AS child_asset_group
FROM DEVICE_TESTBED_VW
WHERE lab_id IN
('7099849',
'10769617',
'4258712',
'10513562',
'10515074',
'5882676',
'8330925')
GROUP BY eol,
status_msg,
relation,
device_id,
lab_id,
aisle_id,
aisle_location_id,
ip_address,
port,
slot_num,
hostname,
pid,
description,
sl_num,
eitms_code,
status,
dnd_flag,
aisle,
aisle_location,
spname,
os_version,
user_id,
updated_date,
isterm_svr,
net_type,
DEVICE_GROUP_REF,
cmd_id_ref,
building_name
ORDER BY PORT ASC
Can some one help me to fix this issue?Hi,
Sorry, it's not clear what you want.
Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved, so that the people who want to help you can re-create the problem and test their ideas.
Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
Simplify the problem as much as possible. For example, if you really need to GROUP BY 28 columns, post a problem where you need to GROUP BY only 2 or 3 columns. (Just explain that you really have 28, so people will give solutions that are sure to work for all 28).)
Always say which version of Oracle you're using (for example, 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002 -
How do tune sql query? Can somebody help me in this? Atleast prescribe book
how do tune sql query? Can somebody help me in this? Atleast prescribe a reference book.
I am not able understand How to analyze tkproof output.Check out asktom.oracle.com
Lot's of threads on interpreting tkprof output - no simple easy solution here.
You need to understand what is happening and THINK. Then you can be a good engineer.
As for good books...
Tom Kyte's books are really, really good.
http://www.amazon.com/Effective-Oracle-Design-Osborne-ORACLE/dp/0072230657/ref=sr_1_3?ie=UTF8&s=books&qid=1266783471&sr=8-3
http://www.amazon.com/Expert-Oracle-Database-Architecture-Programming/dp/1590595300/ref=sr_1_1?ie=UTF8&s=books&qid=1266783471&sr=8-1
Good luck! -
SQL query...pls help ASAP
Actor (Aname: varchar(40), Ano: varchar(6)) Ano is pk
Movie (Mname: varchar(40),mno: varchar(8)) Mno is pk
PlayIn (Ano, Mno, Pay: Integer) Ano and Mno are fk referencing Acotr and Movie respectively.
Actor(Aname, Ano)
A Bingo, A1
B Castro, A2
C Katie, A3
S Hommy, A4
J Tammy, A5
K loren, A6
Movie(Mname, Mno)
Gladiator, M1
Cast, M2
Dog, M3
Jilters, M4
PlayIn(Ano,Mno,Pay)
A1 M1 800
A1 M2 1500
A2 M2 78
A2 M3 1750
A2 M4 2301
A3 M2 904
A3 M3 629
A4 M2 565
A4 M3 5695
A4 M4 1255
A5 M1 989
A5 M4 238
A6 M2 137
A6 M3 236
A6 M4 545
QUESTION: write SQL query to find the names of actors who earned less than 'B Castro' in each movie that 'B Castro' played in.thanks so so much.....
another question:
for each movie, list the movie number, the average
pay and the total number of actors in the movie.....Rather than just asking homework questions and expecting everyone else to do your work for you, why don't you at least have a go at it yourself and post the query that you've tried, then we'll tell you where you are going wrong. You won't learn anything if we just write it for you.
Also, your use of "pls help ASAP" in the subject title is not polite.
This forum is manned by volunteers who have their own jobs and offer their help free of charge.
Everyone who posts an issue on here would love to have it answered as soon as possible, but nobody has the right to assume that their issue is any more important, urgent or requires a quicker answer than anybody elses.
If you need urgent help then you should pay someone to do the work for you. -
Problem with sql;query tag! Please help ...
Dear all,
I have the following SQL statement submitted by a sql;query tag:
<c:out value='${namestring}'/> // <-- namestring is printed out as ABC-% here.
<sql:query var="resultset">
SELECT sales
FROM SALESTABLE
WHERE name LIKE <c:out value='${namestring}'/> //<-- appearently namestring is not ABC-% anymore!!!
</sql:query>
Everything is fine except the satement "WHERE name LIKE ?". The namestring passed in is supposed to be in the form 'ABC-%'. It indeed prints out as 'ABC-%' before the <sql:query/> tag.
Appearnetly, when it is passed to the statement "WHERE name LIKE ?", it becomes something else because it returns no data.
Note that when I hardcode 'ABC-%' to the WHERE statement, however, I do get a lot of data back.
I also tried to to use <sql:param/> tag to tackle it:
<sql:query var="resultset">
SELECT sales
FROM SALESTABLE
WHERE name LIKE ?
<sql:param value='${namestring}' />
</sql:query>
But still got no data. Is '%" considered as special characters that needs to be treated in a special way? What else do I need to do in order to pass in 'ABC-%' to the statement???
By the way, is there a way to print out the generated SQL statement to see how all the variables are evaluated?
Any help or suggestions will be highly appreciated. Thanks.
Robert.Try to escape the special character '%' using '\%'.
-
SQL Query : Order By issue with HUGE Table
Hello friends,
I have been through a terrible issue with order by. I would appreciate your help. Please let me know, your input for my case:
=> if i run select query it returns result quick in some milliseconds. (sql dev. fetches 50 rows at a time)
=> if i run select query with where condition and column (say A) in where condition is even indexed and i have order by and that order by column (say B) is also indexed.
Now, here is the issue:
1. if no. of rows with that where condition can filter yielding small result set then order by works fine .. 1-5 sec which is good.
2.*if no. of rows with that where condition can filter yielding Large result set, say more than 50,000 then with order by then the wait time is exponential.... i have even waited 10+ mins to get the result back for 120,000 records.*
Is order by takes that long for 100K records ... i think something else if wrong... your pointer will really be helpful... i am very new to sql and even newer for large table case.
I am using SQL Developer Version 2.1.1.64
and Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
Thank you so much.
Edited by: 896719 on Jan 11, 2013 8:38 AMYes you are correct, but my concentration was on order by thing, so it will do full scan of table so i was putting that ... and was also wondering if millions of record in table should not be a issue...???
Any way for the explain plan , when just a value in the where changes there is the huge difference i want to point out too as below:
SELECT
FROM
EES_EVT EES_EVT where APLC_EVT_CD= 'ABC' ORDER BY CRE_DTTM DESC
execution time : 0.047 sec
Plan hash value: 290548126
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 27 | 14688 | 25 (4)| 00:00:01 |
| 1 | SORT ORDER BY | | 27 | 14688 | 25 (4)| 00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| EES_EVT | 27 | 14688 | 24 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | XIE1EES_EVT | 27 | | 4 (0)| 00:00:01 |
Predicate Information (identified by operation id):
3 - access("APLC_EVT_CD"='ABC')
Note
- SQL plan baseline "SYS_SQL_PLAN_6d41e6b91925c463" used for this statement
=============================================================================================
SELECT
FROM
EES_EVT EES_EVT where APLC_EVT_CD= 'XYZ' ORDER BY CRE_DTTM DESC
execution : 898.672 sec.
Plan hash value: 290548126
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 121K| 62M| | 102K (1)| 00:11:02 |
| 1 | SORT ORDER BY | | 121K| 62M| 72M| 102K (1)| 00:11:02 |
| 2 | TABLE ACCESS BY INDEX ROWID| EES_EVT | 121K| 62M| | 88028 (1)| 00:09:27 |
|* 3 | INDEX RANGE SCAN | XIE1EES_EVT | 121K| | | 689 (1)| 00:00:05 |
Predicate Information (identified by operation id):
3 - access("APLC_EVT_CD"='XYZ')
Note
- SQL plan baseline "SYS_SQL_PLAN_ef5709641925c463" used for this statementAlso Note this table contains 74328 MB data in it.
Thanks -
Need SQL query using View - Please help
Hi,
I have similar requirement like below.
I have two tables DEPT and EMP and some departments may not have employees. I have created below view, which displays all DEPT records, even though there are no emplyees.
CREATE OR REPLACE VIEW dept_emp_vw AS
SELECT deptno, empid, 0 AS selected
FROM dept d, emp e
WHERE d.deptno = e.deptnno (+);
Ex.
DEPTNO EMPID SELECTED
10 101 0
10 102 0
20 103 0
30 103 0
40 104 0
50 <null> 0
Application will pass "empid" to the view (for ex. empid = 103) and I want result like below.
Ex.
DEPTNO EMPID SELECTED
10 101 0
10 102 0
20 103 1
30 103 1
40 104 0
50 <null> 0
Can you please let me know the query using "dept_emp_vw" view. We have Oracle 11g Release 2.
Thanks a lot for the help.Not possible using normal SQL - as SQL is not a procedure language and does not support variable declaration and use (e.g. passing empid as a variable and using it both as a predicate and as a condition in the SQL projection).
That said - SQL can be "+parameterised+". An approach that is ugly and contrary to the basic design and use of SQL. But it can support the (very weird) view definition of yours.
E.g.
SQL> create or replace procedure SetVariable( name varchar2, value varchar2 ) is
2 begin
3 DBMS_SESSION.set_context( 'MyVariables', name, value );
4 end;
5 /
Procedure created.
SQL>
SQL>
SQL> create or replace context MyVariables using SetVariable;
Context created.
SQL>
SQL> create or replace view my_funky_weird_view as
2 select
3 e.empno,
4 e.ename,
5 e.job,
6 case e.empno
7 when to_number(sys_context( 'MyVariables', 'empid' )) then
8 0
9 else
10 1
11 end as "SELECTED"
12 from emp e
13 /
View created.
SQL>
SQL> exec SetVariable( 'empid', 7499 )
PL/SQL procedure successfully completed.
SQL>
SQL> select * from session_context where namespace = 'MYVARIABLES';
NAMESPACE ATTRIBUTE VALUE
MYVARIABLES EMPID 7499
SQL>
SQL> select * from my_funky_weird_view order by selected;
EMPNO ENAME JOB SELECTED
7499 ALLEN SALESMAN 0
7521 WARD SALESMAN 1
7566 JONES MANAGER 1
7654 MARTIN SALESMAN 1
7698 BLAKE MANAGER 1
7934 MILLER CLERK 1
7788 SCOTT ANALYST 1
7839 KING PRESIDENT 1
7844 TURNER SALESMAN 1
7876 ADAMS CLERK 1
7900 JAMES CLERK 1
7902 FORD ANALYST 1
7369 SMITH CLERK 1
7782 CLARK MANAGER 1
14 rows selected.
SQL>But I will N\OT recommend doing it this way. It is not natural SQL as PL/SQL is needed to "+inject+" name-value pairs into the context for the SQL view to use. It is ugly. It is not standard. It cannot scale. It is complex to use. Etc.
Yes, there are instances when this approach is exactly what one needs - when for example dealing with a trusted context and using the contents for implementing a security layer. But in the above case - I would rather want to see the actual business requirement first, as I think you're barking up the wrong tree with the view solution you have imagined. -
SQL Query Group By Issues - Urgent
I currently have an issue writing a pl\sql report, I can get part of the way to the results I want but the group by clause is causing problems, because I have to add more columns to the group by, dispersing the figures further, I have tried it with coalesce for each of the task types but I still get the same results, I am getting close to the results I need but not quite there yet. I would really appreciate it if someone could take at look at this for me as it is an urgent requirement.
The report is based on the tables similar to the following:
TASKS, ORGANISATIONS, POSITIONS
A position is a member of an organisation.
A task has a position assigned to it.
The SQL for the tables and to insert the data that would produce the report is detailed below:
CREATE TABLE TASKS
( TASK_ID NUMBER NOT NULL ENABLE,
TASK_TYPE VARCHAR2 (15 BYTE) NOT NULL ENABLE,
STATUS VARCHAR2 (15 BYTE) NOT NULL ENABLE,
POS_ID NUMBER NOT NULL ENABLE,
CONSTRAINT TASKS_PK PRIMARY KEY (TASK_ID));
CREATE TABLE ORGANISATIONS
( ORG_ID NUMBER NOT NULL ENABLE,
ORG_NAME VARCHAR2 (15 BYTE) NOT NULL ENABLE,
CONSTRAINT ORGANISATIONS_PK PRIMARY KEY (ORG_ID));
CREATE TABLE POSITIONS
( POS_ID NUMBER NOT NULL ENABLE,
POS_NAME VARCHAR2 (25 BYTE) NOT NULL ENABLE,
ORG_ID NUMBER NOT NULL ENABLE,
CONSTRAINT POSITIONS_PK PRIMARY KEY (POS_ID));
INSERT INTO ORGANISATIONS (ORG_ID, ORG_NAME) VALUES (1,'ABC');
INSERT INTO ORGANISATIONS (ORG_ID, ORG_NAME) VALUES (2,'DEF');
INSERT INTO ORGANISATIONS (ORG_ID, ORG_NAME) VALUES (3,'EFG');
INSERT INTO POSITIONS (POS_ID, POS_NAME, ORG_ID) VALUES (1,'ABC-1', 1);
INSERT INTO POSITIONS (POS_ID, POS_NAME, ORG_ID) VALUES (3,'ABC-2', 1);
INSERT INTO POSITIONS (POS_ID, POS_NAME, ORG_ID) VALUES (2,'ABC-3', 1);
INSERT INTO POSITIONS (POS_ID, POS_NAME, ORG_ID) VALUES (5,'DEF-2', 2);
INSERT INTO POSITIONS (POS_ID, POS_NAME, ORG_ID) VALUES (4,'DEF-1', 2);
INSERT INTO POSITIONS (POS_ID, POS_NAME, ORG_ID) VALUES (7,'EFG-1', 3);
INSERT INTO TASKS (TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (12,'TASK_TYPE_3','LIVE',3);
INSERT INTO TASKS (TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (11,'TASK_TYPE_2','LIVE',3);
INSERT INTO TASKS (TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (10,'TASK_TYPE_2','LIVE',2);
INSERT INTO TASKS (TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (9,'TASK_TYPE_2','LIVE',2);
INSERT INTO TASKS (TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (8,'TASK_TYPE_1','LIVE',3);
INSERT INTO TASKS (TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (7,'TASK_TYPE_1','LIVE',3);
INSERT INTO TASKS (TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (6,'TASK_TYPE_1','LIVE',3);
INSERT INTO TASKS (TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (5,'TASK_TYPE_1','LIVE',3);
INSERT INTO TASKS (TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (4,'TASK_TYPE_1','LIVE',2);
INSERT INTO TASKS (TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (3,'TASK_TYPE_3','LIVE',1);
INSERT INTO TASKS (TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (2,'TASK_TYPE_1','LIVE',1);
INSERT INTO TASKS (TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (1,'TASK_TYPE_1','LIVE',1);
INSERT INTO TASKS (TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (13,'TASK_TYPE_3','LIVE',3);
The report should detail the following information based on the information in the tables:
1st Column
Organisation
ABC
DEF
EFG
2nd Column
No. of Positions in Organsiation
3
2
1
With total of the number of people in all of the organisation 6
3rd Column
Number of tasks assigned to the organisation of task type1
2
1
4
4th Column
Number of tasks assigned to the organisation of task type 2
0
2
1
5th Column
Number of tasks assigned to the organisation of task type 3
1
0
2
Total no of tasks assigned to the Organisation
3
3
7
Message was edited by:
Suzy_r_82
Message was edited by:
Suzy_r_82Hi,
Apologies, my insert statements where incorrect, if you try the data below instead it should give you output I was expecting
INSERT INTO TASKS( TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (1,'TASK_TYPE_1', 'LIVE',1);
INSERT INTO TASKS( TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (2,'TASK_TYPE_1', 'LIVE',2);
INSERT INTO TASKS( TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (3,'TASK_TYPE_1', 'LIVE',5);
INSERT INTO TASKS( TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (4,'TASK_TYPE_1', 'LIVE',7);
INSERT INTO TASKS( TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (5,'TASK_TYPE_1', 'LIVE',7);
INSERT INTO TASKS( TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (6,'TASK_TYPE_1', 'LIVE',7);
INSERT INTO TASKS( TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (7,'TASK_TYPE_1', 'LIVE',7);
INSERT INTO TASKS( TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (8,'TASK_TYPE_2', 'LIVE',4);
INSERT INTO TASKS( TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (9,'TASK_TYPE_2', 'LIVE',5);
INSERT INTO TASKS( TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (10,'TASK_TYPE_3', 'LIVE',1);
INSERT INTO TASKS( TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (11,'TASK_TYPE_3', 'LIVE',7);
INSERT INTO TASKS( TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (12,'TASK_TYPE_2', 'LIVE',7);
INSERT INTO TASKS( TASK_ID, TASK_TYPE, STATUS, POS_ID) VALUES (13,'TASK_TYPE_3', 'LIVE',7);
The results I would like are
ORG No. of Pos No of Task No of Task No of Task Total no
In Org Type1 for Type2 for Type3 for of Tasks
Org Org Org for Org
ABC 3 2 0 1 3
DEF 2 1 2 0 3
EFG 1 4 1 2 7
Total 6The results I get are multiple lines for each organisation, I would like to rollup these lines so I can have one line per organisation.
Hope this helps a bit more, I appreciate the help, let me know if you need more information
Thanks
Suzy -
SQL query slow when issued by app, fast when issued mnaually
Hi there,
I have a more general question about a specific Oracle behaviour.
I update a feature from within an application. The application doesn't respond and I finally have to terminate it. I checked Oracle whether a query is running long using the following statement:
select s.username,s.sid,s.serial#,s.last_call_et/60 mins_running,q.sql_text from v$session s
join v$sqltext_with_newlines q
on s.sql_address = q.address
where status='ACTIVE'
and type <>'BACKGROUND'
and last_call_et> 60
order by sid,serial#,q.piece
The result of the above query is:
WITH CONNECTION AS ( SELECT * FROM WW_CONN C WHERE (C.FID_FROM I
N (SELECT FID FROM WW_LINE WHERE FID_ATTR=:B1 ) AND C.F_CLASS_ID
FROM =22) OR (C.FIDTO IN (SELECT FID FROM WW_LINE WHERE FID_AT
TR=:B1 ) AND C.F_CLASS_ID_TO =22) ) SELECT MIN(P.FID_ATTR) AS FI
D_FROM FROM CONNECTION C, WW_POINT P WHERE (P.FID = C.FID_FROM A
ND C.F_CLASS_ID_FROM = 32 AND C.FLOW = 1) OR (P.FID = C.FID_TO A
ND C.F_CLASS_ID_TO = 32 AND C.FLOW = 2)
I have a different tool which shows me the binding parameter values. So I know that the value for :B1 is 5011 - the id of the feature being updated. This query runs for 20 mins and longer before it eventually stops. The update process involves multiple sql statements - so this one is not doing the update but is part of the process.
Here is the bit I do not understand: when I run the query in SQL Developer with value 5011 for :B1 it takes 0.5 secs to return a result.
Why is it, that the sql statement takes so long when issued by the application but takes less than a second when I run it manually?
I sent a dump of the data to the application vendor who is not able to reproduce the issue in their environment. Could someone explain to me what happens here or give me some keywords for further research?
We are using 11gR2, 64bit.
Many thanks,
RobHi Rob,
at least you should see some differences in the statistics for the different child cursor (the one for the execution in the application should show at least a higher value for ELAPSED_TIME). I would use something like the following query to check the information for the child cursors:
select sql_id
, PLAN_HASH_VALUE
, CHILD_NUMBER
, EXECUTIONS
, ELAPSED_TIME
, USER_IO_WAIT_TIME
, CONCURRENCY_WAIT_TIME
, DISK_READS
, BUFFER_GETS
, ROWS_PROCESSED
from v$sql
where sql_id = your_sql_idRegards
Martin -
SQL Query Having performance issues
I need help on rewriting this query, I am having performance issues with the way it is now. I create a temporary table and query against it. Any help will be appreciated. Thanks, Antonio
Here it is:
create global temporary table pr_php_elig_tmp
on commit preserve rows as
SELECT UNIQUE A.SAK_PROV, A.CDE_SERVICE_LOC, a.sak_short
FROM T_PR_PHP_ELIG A,
T_PR_TYPE C
WHERE C.SAK_PROV = A.SAK_PROV
AND C.CDE_SERVICE_LOC = A.CDE_SERVICE_LOC
AND C.CDE_PROV_TYPE not in ('01', '03', '08', '24', '27', '31')
AND A.SAK_PROV_PGM not in (11, 13)
AND A.DTE_END >= :il_current_date
AND A.DTE_EFFECTIVE <= :il_prev_18_months
AND NOT EXISTS (
SELECT 'X'
FROM T_PR_GRP_MBR T
WHERE T.SAK_PROV = A.SAK_PROV
AND T.CDE_SVC_LOC_MBR = A.CDE_SERVICE_LOC)
AND NOT EXISTS (
select a.sak_prov, a.cde_service_loc
from t_pmp_svc_loc d
where a.sak_prov = d.sak_prov
and a.cde_service_loc = d.cde_service_loc
and d.dte_end >= :il_current_date)
ORDER BY A.SAK_PROV, A.CDE_SERVICE_LOC;
select * from pr_php_elig_tmp
minus
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_deny_dntl_dtl temp01
WHERE temp01.sak_prov_perf = a.sak_prov
and temp01.cde_svc_loc_perf = a.cde_service_loc
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp01.DTE_FIRST_SVC) >= :il_prev_18_months
OR NVL(MAX(temp01.DTE_FIRST_SVC),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_deny_dntl_hdr temp02
WHERE ( (temp02.prov_billing = a.sak_prov
and temp02.cde_service_loc = a.cde_service_loc)
OR (temp02.sak_prov_perf = a.sak_prov
and temp02.cde_perf_svc_loc = a.cde_service_loc)
OR (temp02.sak_prov_referring = a.sak_prov
and temp02.cde_svc_loc_ref_1 = a.cde_service_loc)
OR (temp02.sak_prov_referring_2 = a.sak_prov
and temp02.cde_svc_loc_ref_2 = a.cde_service_loc)
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp02.DTE_FINAL) >= :il_prev_18_months
OR NVL(MAX(temp02.DTE_FINAL),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_deny_phrm_hdr temp03
WHERE ( (temp03.prov_billing = a.sak_prov and
temp03.cde_service_loc = a.cde_service_loc)
OR (temp03.sak_prov_rendering = a.sak_prov and
temp03.cde_svc_loc_rend = a.cde_service_loc)
OR (temp03.sak_presc_prov = a.sak_prov and
temp03.cde_svc_loc_presc = a.cde_service_loc)
OR temp03.id_prov_prescrb = to_char(a.sak_prov) || a.cde_service_loc
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp03.DTE_FINAL) >= :il_prev_18_months
OR NVL(MAX(temp03.DTE_FINAL),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_deny_phys_dtl temp04
WHERE ( (temp04.sak_prov_perf = a.sak_prov
and temp04.cde_svc_loc_rend = a.cde_service_loc)
OR (temp04.sak_prov_referring = a.sak_prov
and temp04.cde_svc_loc_ref_1 = a.cde_service_loc)
OR (temp04.sak_prov_referring_2 = a.sak_prov
and temp04.cde_svc_loc_ref_2 = a.cde_service_loc)
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp04.DTE_LAST_SVC) >= :il_prev_18_months
OR NVL(MAX(temp04.DTE_LAST_SVC),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_deny_phys_hdr temp05
WHERE ( (temp05.prov_billing = a.sak_prov
and temp05.cde_service_loc = a.cde_service_loc)
OR (temp05.sak_prov_perf = a.sak_prov
and temp05.cde_perf_svc_loc = a.cde_service_loc)
OR (temp05.sak_prov_referring = a.sak_prov
and temp05.cde_svc_loc_ref_1 = a.cde_service_loc)
OR (temp05.sak_prov_referring_2 = a.sak_prov
and temp05.cde_svc_loc_ref_2 = a.cde_service_loc)
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp05.DTE_FINAL) >= :il_prev_18_months
OR NVL(MAX(temp05.DTE_FINAL),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_deny_ub92_dtl temp06
WHERE ( (temp06.sak_pr_other = a.sak_prov
and temp06.cde_scv_loc_other = a.cde_service_loc)
OR (temp06.sak_pr_other_2 = a.sak_prov
and temp06.cde_svc_loc_other_2 = a.cde_service_loc)
OR (temp06.sak_pr_attend = a.sak_prov
and temp06.cde_svc_loc_attend = a.cde_service_loc)
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp06.DTE_LAST_SVC) >= :il_prev_18_months
OR NVL(MAX(temp06.DTE_LAST_SVC),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_deny_ub92_hdr temp07
WHERE ( (temp07.prov_billing = a.sak_prov
and temp07.cde_service_loc = a.cde_service_loc)
OR (temp07.sak_pr_facility = a.sak_prov
and temp07.cde_svc_loc_fa = a.cde_service_loc)
OR (temp07.sak_pr_other = a.sak_prov
and temp07.cde_svc_loc_other = a.cde_service_loc)
OR (temp07.sak_pr_other_2 = a.sak_prov
and temp07.cde_svc_loc_other_2 = a.cde_service_loc)
OR (temp07.sak_pr_attend = a.sak_prov
and temp07.cde_svc_loc_attend = a.cde_service_loc)
OR temp07.id_prov_attend = to_char(a.sak_prov) || a.cde_service_loc
OR temp07.id_prov_other = to_char(a.sak_prov) || a.cde_service_loc
OR temp07.id_prov_other_2 = to_char(a.sak_prov) || a.cde_service_loc
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp07.DTE_FINAL) >= :il_prev_18_months
OR NVL(MAX(temp07.DTE_FINAL),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_pd_dntl_dtl temp08
WHERE temp08.sak_prov_perf = a.sak_prov
and temp08.cde_svc_loc_perf = a.cde_service_loc
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp08.DTE_FIRST_SVC) >= :il_prev_18_months
OR NVL(MAX(temp08.DTE_FIRST_SVC),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_pd_dntl_hdr temp09
WHERE ( (temp09.prov_billing = a.sak_prov
and temp09.cde_service_loc = a.cde_service_loc)
OR (temp09.sak_prov_perf = a.sak_prov
and temp09.cde_perf_svc_loc = a.cde_service_loc)
OR (temp09.sak_prov_referring = a.sak_prov
and temp09.cde_svc_loc_ref_1 = a.cde_service_loc)
OR (temp09.sak_prov_referring_2 = a.sak_prov
and temp09.cde_svc_loc_ref_2 = a.cde_service_loc)
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp09.DTE_FINAL) >= :il_prev_18_months
OR NVL(MAX(temp09.DTE_FINAL),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_pd_pharm_hdr temp10
WHERE ( (temp10.prov_billing = a.sak_prov
and temp10.cde_service_loc = a.cde_service_loc)
OR (temp10.sak_prov_rend = a.sak_prov
and temp10.cde_svc_loc_rend = a.cde_service_loc)
OR (temp10.sak_presc_prov = a.sak_prov
and temp10.cde_svc_loc_presc = a.cde_service_loc)
OR temp10.id_prov_prescrb = to_char(a.sak_prov) || a.cde_service_loc
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp10.DTE_FINAL) >= :il_prev_18_months
OR NVL(MAX(temp10.DTE_FINAL),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_pd_phys_dtl temp11
WHERE ( (temp11.sak_prov_perf = a.sak_prov
and temp11.cde_svc_loc_rend = a.cde_service_loc)
OR (temp11.sak_prov_referring = a.sak_prov
and temp11.cde_svc_loc_ref_1 = a.cde_service_loc)
OR (temp11.sak_prov_referring_2 = a.sak_prov
and temp11.cde_svc_loc_ref_2 = a.cde_service_loc)
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp11.DTE_LAST_SVC) >= :il_prev_18_months
OR NVL(MAX(temp11.DTE_LAST_SVC),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_pd_phys_hdr temp12
WHERE ( (temp12.prov_billing = a.sak_prov
and temp12.cde_service_loc = a.cde_service_loc)
OR (temp12.sak_prov_perf = a.sak_prov
and temp12.cde_perf_svc_loc = a.cde_service_loc)
OR (temp12.sak_prov_referring = a.sak_prov
and temp12.cde_svc_loc_ref_1 = a.cde_service_loc)
OR (temp12.sak_prov_referring_2 = a.sak_prov
and temp12.cde_svc_loc_ref_2 = a.cde_service_loc)
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp12.DTE_FINAL) >= :il_prev_18_months
OR NVL(MAX(temp12.DTE_FINAL),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_pd_ub92_dtl temp13
WHERE ( (temp13.sak_pr_other = a.sak_prov
and temp13.cde_scv_loc_other = a.cde_service_loc)
OR (temp13.sak_pr_other_2 = a.sak_prov
and temp13.cde_svc_loc_other_2 = a.cde_service_loc)
OR (temp13.sak_pr_attend = a.sak_prov
and temp13.cde_svc_loc_attend = a.cde_service_loc)
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp13.DTE_LAST_SVC) >= :il_prev_18_months
OR NVL(MAX(temp13.DTE_LAST_SVC),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_pd_ub92_hdr temp14
WHERE ( (temp14.prov_billing = a.sak_prov
and temp14.cde_service_loc = a.cde_service_loc)
OR (temp14.sak_pr_facility = a.sak_prov
and temp14.cde_svc_loc_fa = a.cde_service_loc)
OR (temp14.sak_pr_other_2 = a.sak_prov
and temp14.cde_svc_loc_other_2 = a.cde_service_loc)
OR (temp14.sak_pr_attend = a.sak_prov
and temp14.cde_svc_loc_attend = a.cde_service_loc)
OR (temp14.sak_pr_other = a.sak_prov
and temp14.cde_svc_loc_other = a.cde_service_loc)
OR temp14.id_prov_attend = to_char(a.sak_prov) || a.cde_service_loc
OR temp14.id_prov_other = to_char(a.sak_prov) || a.cde_service_loc
OR temp14.id_prov_other_2 = to_char(a.sak_prov) || a.cde_service_loc
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp14.DTE_FINAL) >= :il_prev_18_months
OR NVL(MAX(temp14.DTE_FINAL),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim00.t_susp_dental_dtl temp15
WHERE temp15.sak_prov_perf = a.sak_prov
and temp15.cde_svc_loc_perf = a.cde_service_loc
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp15.DTE_FIRST_SVC) >= :il_prev_18_months
OR NVL(MAX(temp15.DTE_FIRST_SVC),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim00.t_susp_dental_hdr temp16
WHERE ( (temp16.sak_prov_perf = a.sak_prov
and temp16.cde_perf_svc_loc = a.cde_service_loc)
OR (temp16.sak_prov_referring = a.sak_prov
and temp16.cde_svc_loc_ref_1 = a.cde_service_loc)
OR (temp16.sak_prov_referring_2 = a.sak_prov
and temp16.cde_svc_loc_ref_2 = a.cde_service_loc)
OR (temp16.prov_billing = a.sak_prov
and temp16.cde_service_loc = a.cde_service_loc)
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING ((MAX(temp16.DTE_LAST_SVC) >= :il_prev_18_months
OR NVL(MAX(temp16.DTE_LAST_SVC),0) = 0)
and (MAX(temp16.DTE_BILLED) >= :il_prev_18_months
OR NVL(MAX(temp16.DTE_BILLED),0) = 0) )
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim00.t_susp_phrm_hdr temp17
WHERE ( (temp17.prov_billing = a.sak_prov
and temp17.cde_service_loc = a.cde_service_loc)
OR (temp17.sak_prov_rend = a.sak_prov
and temp17.cde_svc_loc_rend = a.cde_service_loc)
OR (temp17.sak_presc_prov = a.sak_prov
and temp17.cde_svc_loc_presc = a.cde_service_loc)
OR temp17.id_prov_prescrb = to_char(a.sak_prov) || a.cde_service_loc
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp17.DTE_BILLED) >= :il_prev_18_months
OR NVL(MAX(temp17.DTE_BILLED),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim00.t_susp_phys_dtl temp18
WHERE ( (temp18.sak_prov_perf = a.sak_prov
and temp18.cde_svc_loc_rend = a.cde_service_loc)
OR (temp18.sak_prov_referring = a.sak_prov
and temp18.cde_svc_loc_ref_1 = a.cde_service_loc)
OR (temp18.sak_prov_referring_2 = a.sak_prov
and temp18.cde_svc_loc_ref_2 = a.cde_service_loc)
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp18.DTE_LAST_SVC) >= :il_prev_18_months
OR NVL(MAX(temp18.DTE_LAST_SVC),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim00.t_susp_phys_hdr temp19
WHERE ( (temp19.prov_billing = a.sak_prov
and temp19.cde_service_loc = a.cde_service_loc)
OR (temp19.sak_prov_perf = a.sak_prov
and temp19.cde_perf_svc_loc = a.cde_service_loc)
OR (temp19.sak_prov_referring = a.sak_prov
and temp19.cde_svc_loc_ref_1 = a.cde_service_loc)
OR (temp19.sak_prov_referring_2 = a.sak_prov
and temp19.cde_svc_loc_ref_2 = a.cde_service_loc)
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING ((MAX(temp19.DTE_LAST_SVC) >= :il_prev_18_months
OR NVL(MAX(temp19.DTE_LAST_SVC),0) = 0)
and (MAX(temp19.DTE_BILLED) >= :il_prev_18_months
OR NVL(MAX(temp19.DTE_BILLED),0) = 0) )
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim00.t_susp_ub92_dtl temp20
WHERE ( (temp20.sak_pr_other = a.sak_prov
and temp20.cde_scv_loc_other = a.cde_service_loc)
OR (temp20.sak_pr_other_2 = a.sak_prov
and temp20.cde_svc_loc_other_2 = a.cde_service_loc)
OR (temp20.sak_pr_attend = a.sak_prov
and temp20.cde_svc_loc_attend = a.cde_service_loc)
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp20.DTE_LAST_SVC) >= :il_prev_18_months
OR NVL(MAX(temp20.DTE_LAST_SVC),0) = 0
union
select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim00.t_susp_ub92_hdr temp22
WHERE ( (temp22.prov_billing = a.sak_prov
and temp22.cde_service_loc = a.cde_service_loc)
OR (temp22.sak_pr_facility = a.sak_prov
and temp22.cde_svc_loc_fa = a.cde_service_loc)
OR (temp22.sak_pr_other_2 = a.sak_prov
and temp22.cde_svc_loc_other_2 = a.cde_service_loc)
OR (temp22.sak_pr_attend = a.sak_prov
and temp22.cde_svc_loc_attend = a.cde_service_loc)
OR (temp22.sak_pr_other = a.sak_prov
and temp22.cde_svc_loc_other = a.cde_service_loc)
OR temp22.id_prov_attend = to_char(a.sak_prov) || a.cde_service_loc
OR temp22.id_prov_other = to_char(a.sak_prov) || a.cde_service_loc
OR temp22.id_prov_other_2 = to_char(a.sak_prov) || a.cde_service_loc
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX(temp22.DTE_BILLED) >= :il_prev_18_months
OR NVL(MAX(temp22.DTE_BILLED),0) = 0
);Perhaps an approach like this would work better. No promises, but it's worth a try.
SELECT *
FROM pr_php_elig_tmp a
WHERE NOT EXISTS (
SELECT a.sak_prov,
a.cde_service_loc,
a.sak_short
FROM aim01.t_deny_dntl_dtl temp01
WHERE temp01.sak_prov_perf = a.sak_prov
AND temp01.cde_svc_loc_perf = a.cde_service_loc
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX (temp01.dte_first_svc) >= :il_prev_18_months
OR NVL (MAX (temp01.dte_first_svc), 0) = 0)
AND NOT EXISTS (
SELECT a.sak_prov,
a.cde_service_loc,
a.sak_short
FROM aim01.t_deny_dntl_hdr temp02
WHERE ( ( temp02.prov_billing = a.sak_prov
AND temp02.cde_service_loc = a.cde_service_loc)
OR ( temp02.sak_prov_perf = a.sak_prov
AND temp02.cde_perf_svc_loc = a.cde_service_loc)
OR ( temp02.sak_prov_referring = a.sak_prov
AND temp02.cde_svc_loc_ref_1 = a.cde_service_loc)
OR ( temp02.sak_prov_referring_2 = a.sak_prov
AND temp02.cde_svc_loc_ref_2 = a.cde_service_loc))
GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
HAVING MAX (temp02.dte_final) >= :il_prev_18_months
OR NVL (MAX (temp02.dte_final), 0) = 0) -
Sql Query Tuning. Please help me to tune this query
Hi All ,
I have this problematic Sql . It is taking huge time to execute. It contains a view CIDV, which i think is the bottleneck.
I have pasted the query below. I will be pasting TKPROF and explain plan for the same. Please advice me to tune this query.
SELECT GCC.SEGMENT1 || '.' || GCC.SEGMENT2 || '.' || GCC.SEGMENT3 || '.' ||
GCC.SEGMENT4 || '.' || GCC.SEGMENT5 || '.' || GCC.SEGMENT6 || '.' ||
GCC.SEGMENT7 || '.' || GCC.SEGMENT8 || '.' || GCC.SEGMENT9 OFFSET_ACCOUNT,
OOD.ORGANIZATION_CODE,
CIDV.SUBINVENTORY_CODE OFFSET_SUBINV,
MIL.SEGMENT1 || '.' || MIL.SEGMENT2 || '.' || MIL.SEGMENT3 || '.' ||
MIL.SEGMENT4 || '.' || MIL.SEGMENT5 OFFSET_LOCATOR,
CIDV.LAST_UPDATE_LOGIN
FROM APPS.CST_INV_DISTRIBUTION_V CIDV,
APPS.GL_CODE_COMBINATIONS GCC,
APPS.MTL_ITEM_LOCATIONS MIL,
APPS.ORG_ORGANIZATION_DEFINITIONS OOD
WHERE CIDV.TRANSACTION_ID = :B2
AND CIDV.PRIMARY_QUANTITY = (-1) * :B1
AND CIDV.REFERENCE_ACCOUNT = GCC.CODE_COMBINATION_ID
AND OOD.ORGANIZATION_ID = CIDV.ORGANIZATION_ID
AND MIL.INVENTORY_LOCATION_ID = CIDV.LOCATOR_ID
AND GCC.ACCOUNT_TYPE = 'A'****************
TKPROF
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 68337 10.32 10.32 0 0 0 0
Fetch 68337 229.75 936.36 58819 6743323 1121 68232
total 136675 240.07 946.69 58819 6743323 1121 68232
Misses in library cache during parse: 1
Misses in library cache during execute: 1
Optimizer mode: ALL_ROWS
Parsing user id: 203 (recursive depth: 1)
Number of plan statistics captured: 1
Rows (1st) Rows (avg) Rows (max) Row Source Operation
1 1 1 MERGE JOIN CARTESIAN (cr=102 pr=15 pw=0 time=193608 us cost=56 size=219 card=1)
1 1 1 NESTED LOOPS (cr=100 pr=15 pw=0 time=193483 us cost=53 size=219 card=1)
1 1 1 NESTED LOOPS (cr=99 pr=15 pw=0 time=193407 us cost=52 size=215 card=1)
1 1 1 NESTED LOOPS (cr=96 pr=15 pw=0 time=193378 us cost=51 size=190 card=1)
1 1 1 NESTED LOOPS (cr=93 pr=15 pw=0 time=193284 us cost=49 size=162 card=1)
1 1 1 NESTED LOOPS (cr=89 pr=14 pw=0 time=185515 us cost=46 size=138 card=1)
1 1 1 NESTED LOOPS (cr=85 pr=12 pw=0 time=157975 us cost=44 size=81 card=1)
1 1 1 NESTED LOOPS (cr=83 pr=12 pw=0 time=157925 us cost=43 size=73 card=1)
1 1 1 NESTED LOOPS (cr=81 pr=12 pw=0 time=157641 us cost=43 size=132 card=2)
1 1 1 VIEW CST_INV_DISTRIBUTION_V (cr=78 pr=12 pw=0 time=156386 us cost=41 size=118 card=2)
1 1 1 UNION-ALL (cr=78 pr=12 pw=0 time=156378 us)
0 0 0 NESTED LOOPS OUTER (cr=44 pr=9 pw=0 time=124997 us cost=20 size=291 card=1)
0 0 0 NESTED LOOPS (cr=44 pr=9 pw=0 time=124993 us cost=18 size=255 card=1)
0 0 0 NESTED LOOPS (cr=44 pr=9 pw=0 time=124990 us cost=18 size=251 card=1)
33 33 33 MERGE JOIN CARTESIAN (cr=25 pr=6 pw=0 time=98544 us cost=14 size=192 card=1)
1 1 1 NESTED LOOPS OUTER (cr=22 pr=5 pw=0 time=85754 us cost=12 size=156 card=1)
1 1 1 NESTED LOOPS (cr=19 pr=4 pw=0 time=79830 us cost=10 size=120 card=1)
1 1 1 NESTED LOOPS OUTER (cr=17 pr=4 pw=0 time=79813 us cost=9 size=113 card=1)
1 1 1 NESTED LOOPS (cr=15 pr=4 pw=0 time=79752 us cost=8 size=106 card=1)
1 1 1 NESTED LOOPS (cr=11 pr=2 pw=0 time=43120 us cost=6 size=93 card=1)
1 1 1 NESTED LOOPS (cr=7 pr=2 pw=0 time=43087 us cost=4 size=83 card=1)
1 1 1 NESTED LOOPS (cr=6 pr=2 pw=0 time=43072 us cost=4 size=80 card=1)
1 1 1 TABLE ACCESS BY INDEX ROWID MTL_MATERIAL_TRANSACTIONS (cr=5 pr=2 pw=0 time=43042 us cost=4 size=76 card=1)
1 1 1 INDEX UNIQUE SCAN MTL_MATERIAL_TRANSACTIONS_U1 (cr=4 pr=2 pw=0 time=43011 us cost=3 size=0 card=1)(object id 12484094)
1 1 1 INDEX UNIQUE SCAN MTL_TRANSACTION_TYPES_U1 (cr=1 pr=0 pw=0 time=20 us cost=0 size=764 card=191)(object id 9983)
1 1 1 INDEX UNIQUE SCAN MTL_TXN_SOURCE_TYPES_U1 (cr=1 pr=0 pw=0 time=7 us cost=0 size=54 card=18)(object id 9987)
1 1 1 INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_B_U1 (cr=4 pr=0 pw=0 time=27 us cost=2 size=736324450 card=73632445)(object id 12484155)
1 1 1 INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_TL_U1 (cr=4 pr=2 pw=0 time=36626 us cost=2 size=957481070 card=73652390)(object id 12484137)
1 1 1 TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=2 pr=0 pw=0 time=42 us cost=1 size=3290 card=470)
1 1 1 INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 pr=0 pw=0 time=28 us cost=0 size=0 card=1)(object id 9847)
1 1 1 TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=2 pr=0 pw=0 time=12 us cost=1 size=3290 card=470)
1 1 1 INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 pr=0 pw=0 time=7 us cost=0 size=0 card=1)(object id 9847)
0 0 0 INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=3 pr=1 pw=0 time=5915 us cost=2 size=36 card=1)(object id 705891)
33 33 33 BUFFER SORT (cr=3 pr=1 pw=0 time=12713 us cost=12 size=36 card=1)
33 33 33 INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=3 pr=1 pw=0 time=12582 us cost=2 size=36 card=1)(object id 705891)
0 0 0 TABLE ACCESS BY INDEX ROWID MTL_TRANSACTION_ACCOUNTS (cr=19 pr=3 pw=0 time=26591 us cost=4 size=59 card=1)
66 66 66 INDEX RANGE SCAN MTL_TRANSACTION_ACCOUNTS_N1 (cr=18 pr=2 pw=0 time=13607 us cost=3 size=0 card=3)(object id 12484127)
0 0 0 INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=0 pr=0 pw=0 time=0 us cost=0 size=4 card=1)(object id 9847)
0 0 0 INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=0 pr=0 pw=0 time=0 us cost=2 size=36 card=1)(object id 705891)
1 1 1 NESTED LOOPS (cr=34 pr=3 pw=0 time=31269 us cost=21 size=288 card=1)
1 1 1 NESTED LOOPS (cr=30 pr=3 pw=0 time=31161 us cost=19 size=275 card=1)
1 1 1 NESTED LOOPS (cr=26 pr=3 pw=0 time=31105 us cost=17 size=265 card=1)
1 1 1 NESTED LOOPS (cr=25 pr=3 pw=0 time=31082 us cost=17 size=261 card=1)
1 1 1 NESTED LOOPS OUTER (cr=23 pr=3 pw=0 time=31027 us cost=16 size=254 card=1)
1 1 1 NESTED LOOPS (cr=21 pr=3 pw=0 time=30980 us cost=15 size=247 card=1)
1 1 1 NESTED LOOPS (cr=20 pr=3 pw=0 time=30957 us cost=15 size=243 card=1)
1 1 1 NESTED LOOPS OUTER (cr=19 pr=3 pw=0 time=30926 us cost=15 size=240 card=1)
1 1 1 NESTED LOOPS (cr=16 pr=3 pw=0 time=30389 us cost=13 size=204 card=1)
1 1 1 NESTED LOOPS (cr=11 pr=0 pw=0 time=665 us cost=9 size=131 card=1)
1 1 1 NESTED LOOPS OUTER (cr=8 pr=0 pw=0 time=306 us cost=7 size=95 card=1)
1 1 1 TABLE ACCESS BY INDEX ROWID MTL_TRANSACTION_ACCOUNTS (cr=5 pr=0 pw=0 time=37 us cost=5 size=59 card=1)
2 2 2 INDEX RANGE SCAN MTL_TRANSACTION_ACCOUNTS_N1 (cr=4 pr=0 pw=0 time=17 us cost=4 size=0 card=3)(object id 12484127)
1 1 1 INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=3 pr=0 pw=0 time=216 us cost=2 size=36 card=1)(object id 705891)
1 1 1 INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=3 pr=0 pw=0 time=352 us cost=2 size=36 card=1)(object id 705891)
1 1 1 TABLE ACCESS BY INDEX ROWID MTL_MATERIAL_TRANSACTIONS (cr=5 pr=3 pw=0 time=29716 us cost=4 size=73 card=1)
1 1 1 INDEX RANGE SCAN MTL_MATERIAL_TRANSACTIONS_N23 (cr=4 pr=3 pw=0 time=29588 us cost=3 size=0 card=1)(object id 12484133)
0 0 0 INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=3 pr=0 pw=0 time=520 us cost=2 size=36 card=1)(object id 705891)
1 1 1 INDEX UNIQUE SCAN MTL_TXN_SOURCE_TYPES_U1 (cr=1 pr=0 pw=0 time=22 us cost=0 size=3 card=1)(object id 9987)
1 1 1 INDEX UNIQUE SCAN MTL_TRANSACTION_TYPES_U1 (cr=1 pr=0 pw=0 time=16 us cost=0 size=4 card=1)(object id 9983)
1 1 1 TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=2 pr=0 pw=0 time=34 us cost=1 size=7 card=1)
1 1 1 INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 pr=0 pw=0 time=19 us cost=0 size=0 card=1)(object id 9847)
1 1 1 TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=2 pr=0 pw=0 time=44 us cost=1 size=7 card=1)
1 1 1 INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 pr=0 pw=0 time=14 us cost=0 size=0 card=1)(object id 9847)
1 1 1 INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 pr=0 pw=0 time=13 us cost=0 size=4 card=1)(object id 9847)
1 1 1 INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_B_U1 (cr=4 pr=0 pw=0 time=49 us cost=2 size=10 card=1)(object id 12484155)
1 1 1 INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_TL_U1 (cr=4 pr=0 pw=0 time=96 us cost=2 size=13 card=1)(object id 12484137)
1 1 1 TABLE ACCESS BY INDEX ROWID HR_ALL_ORGANIZATION_UNITS (cr=3 pr=0 pw=0 time=1246 us cost=1 size=7 card=1)
1 1 1 INDEX UNIQUE SCAN HR_ORGANIZATION_UNITS_PK (cr=2 pr=0 pw=0 time=24 us cost=0 size=0 card=1)(object id 250158)
1 1 1 INDEX UNIQUE SCAN HR_ALL_ORGANIZATION_UNTS_TL_PK (cr=2 pr=0 pw=0 time=275 us cost=0 size=7 card=1)(object id 689101)
1 1 1 TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=2 pr=0 pw=0 time=38 us cost=1 size=8 card=1)
1 1 1 INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 pr=0 pw=0 time=15 us cost=0 size=0 card=1)(object id 9847)
1 1 1 TABLE ACCESS BY INDEX ROWID GL_CODE_COMBINATIONS (cr=4 pr=2 pw=0 time=27531 us cost=2 size=57 card=1)
1 1 1 INDEX UNIQUE SCAN GL_CODE_COMBINATIONS_U1 (cr=3 pr=1 pw=0 time=19925 us cost=1 size=0 card=1)(object id 51426)
1 1 1 TABLE ACCESS BY INDEX ROWID MTL_ITEM_LOCATIONS (cr=4 pr=1 pw=0 time=7758 us cost=3 size=24 card=1)
1 1 1 INDEX RANGE SCAN MTL_ITEM_LOCATIONS_U1 (cr=3 pr=0 pw=0 time=51 us cost=2 size=0 card=1)(object id 9761)
1 1 1 TABLE ACCESS BY INDEX ROWID HR_ORGANIZATION_INFORMATION (cr=3 pr=0 pw=0 time=85 us cost=2 size=28 card=1)
1 1 1 INDEX RANGE SCAN HR_ORGANIZATION_INFORMATIO_FK2 (cr=2 pr=0 pw=0 time=29 us cost=1 size=0 card=2)(object id 5379798)
1 1 1 TABLE ACCESS BY INDEX ROWID HR_ORGANIZATION_INFORMATION (cr=3 pr=0 pw=0 time=25 us cost=1 size=25 card=1)
1 1 1 INDEX RANGE SCAN HR_ORGANIZATION_INFORMATIO_FK2 (cr=2 pr=0 pw=0 time=11 us cost=1 size=0 card=1)(object id 5379798)
1 1 1 INDEX FULL SCAN GL_SETS_OF_BOOKS_U2 (cr=1 pr=0 pw=0 time=69 us cost=1 size=4 card=1)(object id 1380842)
1 1 1 BUFFER SORT (cr=2 pr=0 pw=0 time=110 us cost=55 size=0 card=1)
1 1 1 TABLE ACCESS FULL FND_PRODUCT_GROUPS (cr=2 pr=0 pw=0 time=59 us cost=3 size=0 card=1)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
library cache lock 2 0.00 0.00
library cache pin 2 0.00 0.00
Disk file operations I/O 249 0.00 0.00
db file sequential read 58819 2.61 714.28
gc cr grant 2-way 5198 0.16 4.52
gc current grant busy 1 0.00 0.00
KJC: Wait for msg sends to complete 517 0.00 0.05
library cache: mutex X 433 0.01 0.04
gc cr grant congested 28 0.08 0.18
latch: ges resource hash list 5 0.00 0.00
gc current block 2-way 513 0.11 0.61
gc current block congested 2 0.00 0.00
latch: gc element 16 0.00 0.01
latch: cache buffers chains 4 0.00 0.00
latch: object queue header operation 3 0.00 0.00
********************************************************************************Explain Plan for the query
SELECT STATEMENT, GOAL = ALL_ROWS Cost=56 Cardinality=1 Bytes=219
MERGE JOIN CARTESIAN Cost=56 Cardinality=1 Bytes=219
NESTED LOOPS Cost=53 Cardinality=1 Bytes=219
NESTED LOOPS Cost=52 Cardinality=1 Bytes=215
NESTED LOOPS Cost=51 Cardinality=1 Bytes=190
NESTED LOOPS Cost=49 Cardinality=1 Bytes=162
NESTED LOOPS Cost=46 Cardinality=1 Bytes=138
NESTED LOOPS Cost=44 Cardinality=1 Bytes=81
NESTED LOOPS Cost=43 Cardinality=1 Bytes=73
NESTED LOOPS Cost=43 Cardinality=2 Bytes=132
VIEW Object owner=APPS Object name=CST_INV_DISTRIBUTION_V Cost=41 Cardinality=2 Bytes=118
UNION-ALL
NESTED LOOPS OUTER Cost=20 Cardinality=1 Bytes=291
NESTED LOOPS Cost=18 Cardinality=1 Bytes=255
NESTED LOOPS Cost=18 Cardinality=1 Bytes=251
MERGE JOIN CARTESIAN Cost=14 Cardinality=1 Bytes=192
NESTED LOOPS OUTER Cost=12 Cardinality=1 Bytes=156
NESTED LOOPS Cost=10 Cardinality=1 Bytes=120
NESTED LOOPS OUTER Cost=9 Cardinality=1 Bytes=113
NESTED LOOPS Cost=8 Cardinality=1 Bytes=106
NESTED LOOPS Cost=6 Cardinality=1 Bytes=93
NESTED LOOPS Cost=4 Cardinality=1 Bytes=83
NESTED LOOPS Cost=4 Cardinality=1 Bytes=80
TABLE ACCESS BY INDEX ROWID Object owner=INV Object name=MTL_MATERIAL_TRANSACTIONS Cost=4 Cardinality=1 Bytes=76
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_MATERIAL_TRANSACTIONS_U1 Cost=3 Cardinality=1
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_TRANSACTION_TYPES_U1 Cost=0 Cardinality=191 Bytes=764
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_TXN_SOURCE_TYPES_U1 Cost=0 Cardinality=18 Bytes=54
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_SYSTEM_ITEMS_B_U1 Cost=2 Cardinality=73632445 Bytes=736324450
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_SYSTEM_ITEMS_TL_U1 Cost=2 Cardinality=73652390 Bytes=957481070
TABLE ACCESS BY INDEX ROWID Object owner=INV Object name=MTL_PARAMETERS Cost=1 Cardinality=470 Bytes=3290
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_PARAMETERS_U1 Cost=0 Cardinality=1
TABLE ACCESS BY INDEX ROWID Object owner=INV Object name=MTL_PARAMETERS Cost=1 Cardinality=470 Bytes=3290
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_PARAMETERS_U1 Cost=0 Cardinality=1
INDEX RANGE SCAN Object owner=APPLSYS Object name=FND_LOOKUP_VALUES_U1 Cost=2 Cardinality=1 Bytes=36
BUFFER SORT Cost=12 Cardinality=1 Bytes=36
INDEX RANGE SCAN Object owner=APPLSYS Object name=FND_LOOKUP_VALUES_U1 Cost=2 Cardinality=1 Bytes=36
TABLE ACCESS BY INDEX ROWID Object owner=INV Object name=MTL_TRANSACTION_ACCOUNTS Cost=4 Cardinality=1 Bytes=59
INDEX RANGE SCAN Object owner=INV Object name=MTL_TRANSACTION_ACCOUNTS_N1 Cost=3 Cardinality=3
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_PARAMETERS_U1 Cost=0 Cardinality=1 Bytes=4
INDEX RANGE SCAN Object owner=APPLSYS Object name=FND_LOOKUP_VALUES_U1 Cost=2 Cardinality=1 Bytes=36
NESTED LOOPS Cost=21 Cardinality=1 Bytes=288
NESTED LOOPS Cost=19 Cardinality=1 Bytes=275
NESTED LOOPS Cost=17 Cardinality=1 Bytes=265
NESTED LOOPS Cost=17 Cardinality=1 Bytes=261
NESTED LOOPS OUTER Cost=16 Cardinality=1 Bytes=254
NESTED LOOPS Cost=15 Cardinality=1 Bytes=247
NESTED LOOPS Cost=15 Cardinality=1 Bytes=243
NESTED LOOPS OUTER Cost=15 Cardinality=1 Bytes=240
NESTED LOOPS Cost=13 Cardinality=1 Bytes=204
NESTED LOOPS Cost=9 Cardinality=1 Bytes=131
NESTED LOOPS OUTER Cost=7 Cardinality=1 Bytes=95
TABLE ACCESS BY INDEX ROWID Object owner=INV Object name=MTL_TRANSACTION_ACCOUNTS Cost=5 Cardinality=1 Bytes=59
INDEX RANGE SCAN Object owner=INV Object name=MTL_TRANSACTION_ACCOUNTS_N1 Cost=4 Cardinality=3
INDEX RANGE SCAN Object owner=APPLSYS Object name=FND_LOOKUP_VALUES_U1 Cost=2 Cardinality=1 Bytes=36
INDEX RANGE SCAN Object owner=APPLSYS Object name=FND_LOOKUP_VALUES_U1 Cost=2 Cardinality=1 Bytes=36
TABLE ACCESS BY INDEX ROWID Object owner=INV Object name=MTL_MATERIAL_TRANSACTIONS Cost=4 Cardinality=1 Bytes=73
INDEX RANGE SCAN Object owner=INV Object name=MTL_MATERIAL_TRANSACTIONS_N23 Cost=3 Cardinality=1
INDEX RANGE SCAN Object owner=APPLSYS Object name=FND_LOOKUP_VALUES_U1 Cost=2 Cardinality=1 Bytes=36
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_TXN_SOURCE_TYPES_U1 Cost=0 Cardinality=1 Bytes=3
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_TRANSACTION_TYPES_U1 Cost=0 Cardinality=1 Bytes=4
TABLE ACCESS BY INDEX ROWID Object owner=INV Object name=MTL_PARAMETERS Cost=1 Cardinality=1 Bytes=7
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_PARAMETERS_U1 Cost=0 Cardinality=1
TABLE ACCESS BY INDEX ROWID Object owner=INV Object name=MTL_PARAMETERS Cost=1 Cardinality=1 Bytes=7
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_PARAMETERS_U1 Cost=0 Cardinality=1
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_PARAMETERS_U1 Cost=0 Cardinality=1 Bytes=4
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_SYSTEM_ITEMS_B_U1 Cost=2 Cardinality=1 Bytes=10
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_SYSTEM_ITEMS_TL_U1 Cost=2 Cardinality=1 Bytes=13
TABLE ACCESS BY INDEX ROWID Object owner=HR Object name=HR_ALL_ORGANIZATION_UNITS Cost=1 Cardinality=1 Bytes=7
INDEX UNIQUE SCAN Object owner=HR Object name=HR_ORGANIZATION_UNITS_PK Cost=0 Cardinality=1
INDEX UNIQUE SCAN Object owner=HR Object name=HR_ALL_ORGANIZATION_UNTS_TL_PK Cost=0 Cardinality=1 Bytes=7
TABLE ACCESS BY INDEX ROWID Object owner=INV Object name=MTL_PARAMETERS Cost=1 Cardinality=1 Bytes=8
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_PARAMETERS_U1 Cost=0 Cardinality=1
TABLE ACCESS BY INDEX ROWID Object owner=GL Object name=GL_CODE_COMBINATIONS Cost=2 Cardinality=1 Bytes=57
INDEX UNIQUE SCAN Object owner=GL Object name=GL_CODE_COMBINATIONS_U1 Cost=1 Cardinality=1
TABLE ACCESS BY INDEX ROWID Object owner=INV Object name=MTL_ITEM_LOCATIONS Cost=3 Cardinality=1 Bytes=24
INDEX RANGE SCAN Object owner=INV Object name=MTL_ITEM_LOCATIONS_U1 Cost=2 Cardinality=1
TABLE ACCESS BY INDEX ROWID Object owner=HR Object name=HR_ORGANIZATION_INFORMATION Cost=2 Cardinality=1 Bytes=28
INDEX RANGE SCAN Object owner=HR Object name=HR_ORGANIZATION_INFORMATIO_FK2 Cost=1 Cardinality=2
TABLE ACCESS BY INDEX ROWID Object owner=HR Object name=HR_ORGANIZATION_INFORMATION Cost=1 Cardinality=1 Bytes=25
INDEX RANGE SCAN Object owner=HR Object name=HR_ORGANIZATION_INFORMATIO_FK2 Cost=1 Cardinality=1
INDEX FULL SCAN Object owner=GL Object name=GL_SETS_OF_BOOKS_U2 Cost=1 Cardinality=1 Bytes=4
BUFFER SORT Cost=55 Cardinality=1
TABLE ACCESS FULL Object owner=APPLSYS Object name=FND_PRODUCT_GROUPS Cost=3 Cardinality=1 -
SQL Query Urgent..pls help
Dear Experts,
Table.
C_id Purity
1 100
2 100
10 100
11 100
12 100
Ranking Regions by Size You have to list all regions in the table, and you have to list them according to their size.
you need to list all regions of two or more containers with a purity of 100, and you need to sort that list by the number of containers in each region.
The output should be something like this:
RegBeg RegEnd RegionSize
10 12 3
1 2 2
Kindly help me,
BasavLooks like a homework assignment.
Perhaps you can explain to your tutor how the tabbibitosan method works...
SQL> ed
Wrote file afiedt.buf
1 with t as (select 1 as C_id, 100 as Purity from dual union all
2 select 2, 100 from dual union all
3 select 4, 100 from dual union all
4 select 5, 100 from dual union all
5 select 6, 50 from dual union all
6 select 7, 100 from dual union all
7 select 10, 100 from dual union all
8 select 11, 100 from dual union all
9 select 12, 100 from dual)
10 --
11 -- use tabbibitosan method to group data
12 select min(c_id) as min_c_id
13 ,max(c_id) as max_c_id
14 ,count(*) as grp_size
15 from t
16 where purity = 100
17 group by c_id-rownum
18 having count(*) > 1
19* order by 3 desc, 1
SQL> /
MIN_C_ID MAX_C_ID GRP_SIZE
10 12 3
1 2 2
4 5 2... if you can understand it. ;) -
A Oracle sql query is needed, please help me out
Hi,
I have a table similar to scott.emp table and i should get first three recently joined employees salaries according to their joined date from each deptno
output should like this:
deptno firstempsalary secondemplsal thirdemploysalary
10 xxx xxx xxxx
20 xx xx
30 xx xxx xxxx
40 xx
50 xx xxxx xxx
60 xx xx
70 xx
it means that 70 dept having only one employee and 20 dept having only two employees and 10 dept having more than three employees but we should get only three recently joined employees salaries from 10 dept.
Hope this is clear .. please give me a query to get this info ..
oracle is 10g version
great thanks in advance.select deptno,
max(case jd_rank when 1 then salary end) firstempsal,
max(case jd_rank when 2 then salary end) secondempsal,
max(case jd_rank when 3 then salary end) thirdempsal
from
(select salary, deptno, row_number() over(partition by deptno order by join_date desc) jd_rank from emp)
group by deptno
Problem here is what to do when employees have the same join date? This example will arbitrarily choose their order and if, for example, three employees share the same (most recent) join date then they will arbitrarily be classed as "first", "second" and "third". If four employees join at the same time, one of them will be ignored at random!
Edited by: user10548434 on 03-Dec-2008 06:27 -
XMLdb: SQL query/XPATH/RDF issue
Hello -
a small question about the extraction of data from a XML document using XPATH.
I have modified a local copy of a XML schema (foxml1-0.xsd) in order to add the xdb namespace and a "defaultTable" attribute to be able to store the object in a table called MAPDO
<xsd:element name="digitalObject" xdb:defaultTable="MAPDO">
Then I've registered this XML schema using the statement:
BEGIN
DBMS_XMLSchema.registerSchema(
schemaurl=>'http://www.fedora.info/definitions/1/0/foxml1-0.xsd',
schemadoc=>bfilename('XMLDIR','foxml1-0.xsd'),
CSID=>nls_charset_id('AL32UTF8'));
END;
After that, when I describe the table I get this:
SQL> desc mapdo;
Nom NULL ? Type
TABLE of SYS.XMLTYPE(XMLSchema
"http://www.fedora.info/definitions/1/0/foxml1-0.
xsd" Element "digitalObject") STORAGE Object-relational TYPE
"digitalObject730_T
The next step: I have inserted one XML record in the table.
=> No error. The record is valid.
It contains data from differents namespaces (foxml, rdf, oai_dc...)
my problem:
I can get the values for XML elements from the namespace "foxml" (the main one)
but not from the others. (you can see the XML record at the end of the message)
SELECT
extract(object_value,'/digitalObject/@PID') as PID,
extract(object_value,'/digitalObject/datastream[position()=2]/@ID') as
sObjProp,
extract(object_value,'/digitalObject/datastream[position()=2]/datastreamVersion/
@LABEL') as sLabel,
extract(object_value,'/digitalObject/datastream[position()=2]/datastreamVersion/
@CREATED') as sCreated
FROM mapdo e;
The fields PID, sObjProp and sLabel are well retrieved
But... about RDF data (see the xml record below), it describes links between objects in my database.
<foxml:xmlContent>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rel="info:fedora/fedora-system:def/relations-external#">
<rdf:Description rdf:about="info:fedora/boreal:1437">
<rel:isMemberOf
rdf:resource="info:fedora/boreal:1414"/>
</rdf:Description>
</rdf:RDF>
</foxml:xmlContent>
How can I extract data from rdf:RDF elements ?
SELECT
extract(object_value,'/digitalObject/datastream[position()=2]/datastreamVersion/
xmlContent/RDF/Description') as sLink
FROM mapdo e;
It doesn't work. I get a NULL record.
What's the solution ?
Thank you
Benoit Erken
XML record:
<?xml version="1.0" encoding="UTF-8"?>
<foxml:digitalObject xmlns:foxml="info:fedora/fedora-system:def/foxml#"
xmlns:fedoraxsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:audit="info:fedora/fedora-system:def/audit#"
fedoraxsi:schemaLocation="info:fedora/fedora-system:def/foxml#
http://www.fedora.info/definitions/1/0/foxml1-0.xsd" PID="boreal:1437">
<foxml:objectProperties>
<foxml:property NAME="http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
VALUE="FedoraObject"/>
<foxml:property NAME="info:fedora/fedora-system:def/model#state"
VALUE="Active"/>
<foxml:property NAME="info:fedora/fedora-system:def/model#label"
VALUE="Thèses"/>
<foxml:property NAME="info:fedora/fedora-system:def/model#createdDate"
VALUE="2007-05-22T11:35:13.004Z"/>
<foxml:property
NAME="info:fedora/fedora-system:def/view#lastModifiedDate"
VALUE="2007-05-22T11:35:18.412Z"/>
<foxml:property NAME="info:fedora/fedora-system:def/model#contentModel"
VALUE="com.vtls.vital.redrocket.collection"/>
</foxml:objectProperties>
<foxml:datastream ID="AUDIT" STATE="A" CONTROL_GROUP="X"
VERSIONABLE="false">
<foxml:datastreamVersion ID="AUDIT.0" LABEL="Fedora Object Audit Trail"
CREATED="2007-05-22T11:35:13.004Z" MIMETYPE="text/xml"
FORMAT_URI="info:fedora/fedora-system:format/xml.fedora.audit">
<foxml:xmlContent>
<audit:auditTrail
xmlns:audit="info:fedora/fedora-system:def/audit#">
<audit:record ID="AUDREC1">
<audit:process type="Fedora API-M"/>
<audit:action>modifyDatastreamByValue</audit:action>
<audit:componentID>DC</audit:componentID>
<audit:responsibility>fedoraAdmin</audit:responsibility>
<audit:date>2007-05-22T11:35:16.921Z</audit:date>
<audit:justification/>
</audit:record>
<audit:record ID="AUDREC2">
<audit:process type="Fedora API-M"/>
<audit:action>addDatastream</audit:action>
<audit:componentID>RELS-EXT</audit:componentID>
<audit:responsibility>fedoraAdmin</audit:responsibility>
<audit:date>2007-05-22T11:35:18.412Z</audit:date>
<audit:justification/>
</audit:record>
</audit:auditTrail>
</foxml:xmlContent>
</foxml:datastreamVersion>
</foxml:datastream>
<foxml:datastream ID="RELS-EXT" STATE="A" CONTROL_GROUP="X"
VERSIONABLE="true">
<foxml:datastreamVersion ID="RELS-EXT.0" LABEL="Relationship Metadata"
CREATED="2007-05-22T11:35:18.412Z" MIMETYPE="text/xml" SIZE="0">
<foxml:xmlContent>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rel="info:fedora/fedora-system:def/relations-external#">
<rdf:Description rdf:about="info:fedora/boreal:1437">
<rel:isMemberOf
rdf:resource="info:fedora/boreal:1414"/>
</rdf:Description>
</rdf:RDF>
</foxml:xmlContent>
</foxml:datastreamVersion>
</foxml:datastream>
<foxml:datastream ID="DC" STATE="A" CONTROL_GROUP="X" VERSIONABLE="true">
<foxml:datastreamVersion ID="DC1.0" LABEL="Dublin Core Metadata"
CREATED="2007-05-22T11:35:13.004Z" MIMETYPE="text/xml" SIZE="243">
<foxml:xmlContent>
<oai_dc:dc
xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title>Thèses</dc:title>
<dc:identifier>boreal:1437</dc:identifier>
</oai_dc:dc>
</foxml:xmlContent>
</foxml:datastreamVersion>
<foxml:datastreamVersion ID="DC.1" LABEL="Dublin Core Metadata"
CREATED="2007-05-22T11:35:16.921Z" MIMETYPE="text/xml" SIZE="321">
<foxml:xmlContent>
<oai_dc:dc xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/">
<dc:identifier>boreal:1437</dc:identifier>
<dc:title>Thèses</dc:title>
<dc:description>FUNDP - MED : Département d'Histologie
- Embryologie - Thèses</dc:description>
</oai_dc:dc>
</foxml:xmlContent>
</foxml:datastreamVersion>
</foxml:datastream>
</foxml:digitalObject>Forget this question.
I have found more info here
Re: XMLQuery (XQuery) with namespace -
SQL query with PHP variable help
Hi,
Using Dreamweaver Developer Toolbox, I added a Horizontal
recordset to get two columns across for the city. Next to this is a
number value of how many records are in the particular city.
But I have gone wrong somewhere, as I get the same value for
all my 102 cities.
I have two records in the 'jobs' table and it shows '2' in
the repeat region for all 102 cities.
Can anyone point me in the right direction?
Thank you.Many 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
Maybe you are looking for
-
USB hub and internet sharing stop working after sleep
Hi, I have a relatively new Bluestork USB hub I purchased to connect multiple USB devices I have at the same time. It used to work correctly under Leopard, but now it stops working each time the computer wakes up from sleep. I have to restart the com
-
PreProcess Event Handler setting default password
Greetings. We developed a custom preprocess event handler and is working fine, but I want to set a default password for a new user using the sentence orchestration.addParameter("Password","defaultpassword") However I got the message : <Error> <oracle
-
Basic mis-understanding about Airport?
I cannot find a question like this, though I am sure they are there. I have a base-station which works as advertised. I wish to extend my range, by using the Airport Express. I programmed the express to join an existing network. In another room, I ha
-
Limit user role to edit just specific web sites
Hi, can I limit a user role in a way, that this user can edit only chosen web sites and not all? And can I even let user only edit certain region on specific sites? Like editing content but not headings? UPDATE: I found that this can be done by using
-
Displaying image on canvas as background for joystick display
i am displating my joystick on canvas sucessfully and now i want to add a background image to it for better display please guide in detail. thanks in advance .. ahsan