Make this query more elegant?
can anybody tell me how to make this subquery more elegant?
select 1 lfdidx from dual union
select 2 lfdidx from dual union
select 49 lfdidx from dual union
select 50 lfdidx from dual
Thanks in advance
Sergey, thanks, that's what I hoped for.
http://www.sqlsnippets.com/en/topic-11821.html has some additional info concerning this.
Regards, Thomas
Similar Messages
-
How to make this query more efficient
Hi, i have query to find out the count of records based on certain conditions like below.
SELECT count(*)
FROM new_orders WHERE card_number IS NOT NULL
AND exp_date IS NOT NULL
AND card_id in ( select card_id from old_orders );
There are millions of records in both the tables. , so it is taking long time to run. Is there any solution to optimize this query.....thanks for help. Bcjyou might want to give this a try.
SELECT count(*)
FROM new_orders no
WHERE no.card_number IS NOT NULL
AND no.exp_date IS NOT NULL
AND exists (select 'x'
from old_orders oo
where oo.card_id = no.card_id);it would also help if you can post the information needed as suggested by rob. -
Could you please help me make this query less complicated
could you please help me make this query less complicated
select t1.R_OBJECT_ID
from dm_relation_sp a, ddt_resolution_sp t1
where a.parent_id = '0900000283560456' -----------ID
and a.child_id = t1.R_OBJECT_ID
union all
select t3.R_OBJECT_ID
from ddt_resolution_sp t3
where t3.R_OBJECT_ID in (select t2.child_id
from dm_relation_sp t2
where t2.parent_id in (select a.child_id
from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
where a.parent_id = '0900000283560456' -----------ID
and a.child_id = t1.R_OBJECT_ID))
union all
select t4.R_OBJECT_ID
from ddt_resolution_sp t4
where t4.R_OBJECT_ID in(
select t3.child_id from dm_relation_sp t3
where t3.parent_id in (
select t2.child_id
from asud_fsk.dm_relation_sp t2
where t2.parent_id in (select a.child_id
from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
where a.parent_id = '0900000283560456' -----------ID
and a.child_id = t1.R_OBJECT_ID))
and t3.relation_name = 'RESOLUTION_RELATION')
union all
select t5.R_OBJECT_ID
from ddt_resolution_sp t5
where t5.R_OBJECT_ID in
(select t4.child_id
from dm_relation_sp t4
where t4.parent_id in(
select t3.child_id from dm_relation_sp t3
where t3.parent_id in (
select t2.child_id
from asud_fsk.dm_relation_sp t2
where t2.parent_id in (select a.child_id
from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
where a.parent_id = '0900000283560456' -----------ID
and a.child_id = t1.R_OBJECT_ID))
and t3.relation_name = 'RESOLUTION_RELATION')
and t4.relation_name = 'RESOLUTION_RELATION')
Edited by: user13025450 on 29.04.2010 16:23Hi,
Welcome to the forum! You'll find that there are many qualified people (such as Tubby) willing to help you. Will you do what you can to help them? In order to simplify the query you posted,someone will first have to understand what it does, what the tables that it uses are like, and what tools you have to work with (that is, what version of Oracle, and any other software you are using). To actually test their ideas, people will need versions of your tables.
Many people, if they spent enough time, might be able to figure out roughly what you are doing, make some tables themselves and test a solution. You can help with all of that. I assume you already know what the appliction is, and what this particular query is supposed to do: you don't have to figure out any of that, you just have to say it. You know what all your tables are, what the datatypes of all the columns are, and what kinds of data are in the tables: you don't have to guess at any of that.
Describe what you're doing. Think about it: how do we know that
SELECT NULL
FROM dual;doesn't do what you want?
Post CREATE TABLE and INSERT statements for a little sample data.
Post the results that this query is supposed to produce from those results. (Is it producing the right output now? Then it should be easy to post the correct results.)
Describe, as well as you can, how the present query is doing it.
Format your existing code, so it's easy to see what the different branches of the UNION are, and what the main clauses are in each one.
When posting formatted text (code or results) type these 6 characters
\(all small letters, inside curly brackets) before and after each formatted section, to keep this site from compressing the spaces.
Say what versions of Oracle (e.g. 10.2.0.3.0) and any other relevant software you are using.
I know it's a lot of work, but it really helps. You can do it as well (probably better) than anyone else, and if you're unwilling to do it, why should anyone else be willing? -
hi,
i have 2 tables emp1 & emp2
emp1 consist
empno month amt
001 201002 200
001 201003 100
emp2 consist
empno month amt
001 201001 100
001 201002 200
001 201003 100
i want to make a query on emp1 table where i want to show amt according to month ,if data is not available in emp1 table then only then it should take data from emp2 table ,if emp2 has that month data o/w 0.
my output should be like this
empno month amt
001 201001 100
001 201002 200
001 201003 100
regardsMay be....
SQL> WITH emp1 AS (SELECT '001' empno,'201002' mon,200 amt FROM DUAL UNION ALL
2 SELECT '001' empno,'201003' mon,100 amt FROM DUAL
3 )
4 ,emp2 AS ( SELECT '001' empno,'201001' mon,100 amt FROM DUAL UNION ALL
5 SELECT '001' empno,'201002' mon,200 amt FROM DUAL UNION ALL
6 SELECT '001' empno,'201003' mon,100 amt FROM DUAL
7 )
8 SELECT coalesce(e1.empno,e2.empno) empno,
9 coalesce(e1.mon,e2.mon) mon,
10 coalesce(e1.amt,e2.amt)amt
11 FROM emp1 e1 FULL OUTER JOIN emp2 e2
12 ON e1.empno =e2.empno
13 AND e1.mon=e2.mon
14 ORDER BY 2 ;
EMP MON AMT
001 201001 100
001 201002 200
001 201003 100 -
Can we make this query shorter....?
hi there
Can any body help me in reducing the number of lines in this query ! I am using union to concat 3 queries. Select fields in every query are same and in where condition also most of the joins are same in every query. but in where clause only two conditions are different. Can we make this 3 queries into one becoze entire select statement fields are same and most of the where conditions are same !
Below is the query:
SELECT
au1.bu_id,
au1.first_nam,
au1.last_nam,
c.id,
c.first_nam_d,
c.last_nam_d,
c.birth_dte_d,
c.ssn_num_d,
se.id schd_event_id,
seu.dsc,
ssc.dsc,
sea.access_typ,
sea.ATTENDEE_TYP
FROM
CLIENT c,
APP_USER au1,
SCHD_STAT_CD ssc,
schd_event_url seu,
schd_evnt se,
SCHD_evnt_stat ses,
SCHD_EVNT_ATTENDEE sea,
CLIENT_APPT ca
WHERE
c.id = ca.client_id_k AND
au1.bu_id = se.APP_USER_BU_ID_PRIME_K AND
ssc.code = ses.SCHD_STAT_CD_CODE_K AND
seu.code = se.SCHD_EVNT_URL_CODE_K AND
se.id = ses.SCHD_EVNT_ID_K AND
se.id = sea.SCHD_EVNT_ID_K(+) AND
se.id = ca.SCHD_EVNT_ID_K AND
sea.ATTENDEE_TYP(+) = 'WORKER' AND
ses.create_ts = (select max(create_ts) FROM SCHD_evnt_stat ses1 WHERE ses1.SCHD_EVNT_ID_K = ses.SCHD_EVNT_ID_K)
UNION
SELECT
au1.bu_id,
au1.first_nam,
au1.last_nam,
c.id,
c.first_nam_d,
c.last_nam_d,
c.birth_dte_d,
c.ssn_num_d,
se.id schd_event_id,
seu.dsc,
ssc.dsc,
FROM
CLIENT c,
APP_USER au1,
SCHD_STAT_CD ssc,
schd_event_url seu,
schd_evnt se,
SCHD_evnt_stat ses,
SCHD_EVNT_ATTENDEE sea,
CLIENT_APPT ca
WHERE
c.id = ca.client_id_k AND
au1.bu_id = se.APP_USER_BU_ID_PRIME_K AND
ssc.code = ses.SCHD_STAT_CD_CODE_K AND
seu.code = se.SCHD_EVNT_URL_CODE_K AND
se.id = ses.SCHD_EVNT_ID_K AND
se.id = sea.SCHD_EVNT_ID_K AND
se.id = ca.SCHD_EVNT_ID_K AND
sea.ATTENDEE_TYP = 'ROLE' AND
ses.create_ts = (select max(create_ts) FROM SCHD_evnt_stat ses1 WHERE ses1.SCHD_EVNT_ID_K = ses.SCHD_EVNT_ID_K)
UNION
SELECT
au1.bu_id,
au1.first_nam,
au1.last_nam,
c.id,
c.first_nam_d,
c.last_nam_d,
c.birth_dte_d,
c.ssn_num_d,
se.id schd_event_id,
seu.dsc,
ssc.dsc,
sea.access_typ,
sea.ATTENDEE_TYP
FROM
CLIENT c,
APP_USER au1,
SCHD_STAT_CD ssc,
schd_event_url seu,
schd_evnt se,
SCHD_evnt_stat ses,
SCHD_EVNT_ATTENDEE sea,
CLIENT_APPT ca
WHERE
c.id = ca.client_id_k AND
au1.APP_ROLE_NAM_DESKTOP_K = sea.ATTENDEE_ID_K AND
ssc.code = ses.SCHD_STAT_CD_CODE_K AND
seu.code = se.SCHD_EVNT_URL_CODE_K AND
se.id = ses.SCHD_EVNT_ID_K AND
se.id = sea.SCHD_EVNT_ID_K AND
se.id = ca.SCHD_EVNT_ID_K AND
sea.ATTENDEE_TYP = 'ROLE' AND
ses.create_ts = (select max(create_ts) FROM SCHD_evnt_stat ses1 WHERE ses1.SCHD_EVNT_ID_K = ses.SCHD_EVNT_ID_K)
Thanks in advance
prasanth a.s.Hi,
it is difficult to change this query without the possibility to test it in a worksheet. But try the following query.
I think it should be the same result as your 3 queries.
SELECT au1.bu_id,
au1.first_nam,
au1.last_nam,
c.id,
c.first_nam_d,
c.last_nam_d,
c.birth_dte_d,
c.ssn_num_d,
se.id schd_event_id,
seu.dsc,ssc.dsc,
decode(sea.access_typ,NULL,' ',sea.access_typ) AS sea.access_typ,
decode(sea.ATTENDEE_TYP,NULL,' ',sea.ATTENDEE_TYP) AS sea.ATTENDEE_TYP
FROM CLIENT c,
APP_USER au1,
SCHD_STAT_CD ssc,
schd_event_url seu,
schd_evnt se,
SCHD_evnt_stat ses,
SCHD_EVNT_ATTENDEE sea,
CLIENT_APPT ca
WHERE c.id = ca.client_id_k
AND au1.bu_id = se.APP_USER_BU_ID_PRIME_K
AND ssc.code = ses.SCHD_STAT_CD_CODE_K
AND seu.code = se.SCHD_EVNT_URL_CODE_K
AND se.id = ses.SCHD_EVNT_ID_K
AND se.id = ca.SCHD_EVNT_ID_K
AND ses.create_ts = (select max(create_ts)
FROM SCHD_evnt_stat ses1
WHERE ses1.SCHD_EVNT_ID_K = ses.SCHD_EVNT_ID_K)
AND
(sea.ATTENDEE_TYP(+) = 'WORKER' AND se.id = sea.SCHD_EVNT_ID_K(+)) --clause of the 1st query
OR
(sea.ATTENDEE_TYP = 'ROLE' AND se.id = sea.SCHD_EVNT_ID_K) --clause of the 2nd query
OR
(sea.ATTENDEE_TYP = 'ROLE' AND se.id = sea.SCHD_EVNT_ID_K AND au1.APP_ROLE_NAM_DESKTOP_K = sea.ATTENDEE_ID_K) --clause of the 3rd query
); -
How to make this query go faster
Hi ,
I have the following query :
select a.* from
tbl1 a , tbl2 b
where a.id = b.id
substr(b.id , 3, 2) <> 'XX'
and b.date1 is not null
and b.date1 >= sysdate - 90 ;
tbl1 - 21 million rows
tbl2 - 2 millions
i specify this hints /*+ INDEX(idxa_1 , idxa_2) INDEX(ixdb_1)
where idxa_1 --> b.lotid
idxa_2 --> b.date1
idxb_1 --> a.lotid
IF i DO NOT include b.date1 is not null and b.date1 >= sysdate - 90 ,
from explain plan i could see it using a FAST FULL SCAN which really returns very fast
HOWEVER if i include b.date1 is not null and b.date1 >= sysdate - 90
, from explain plain it uses row index and then there's a range scan and its slow
how can i improve the performance of this query ?
pls advise
tks & rdgsDon't create the temporary table.
Create a function based index on table two
substr(id , 3, 2)Make sure you have gathered statistics on the tables.
Remove the hint.
select a.* from
tbl1 a , tbl2 b
where a.id = b.id
and substr(b.id , 3, 2) <> 'XX'
and b.date1 >= sysdate - 90;If you still have performance problems, post the formatted explain plan from sqlplus.
Read the Performance Tuning Guide.
Unfortunately this is not urs advice. -
To make the query more efficient (create table wiht select command)
Hi,
I have written this query to create another table, but it takes approx two hours while both tables are indexed with 891353, 769023, i have used the following query.
create table source1 as select a.idx, a.source from tt a where a.idx not in (select b.idx from ttt b)
thanksTry this one if you're on oracle 8i or older
create table source1 as
select a.idx, a.source
from tt a
where not exists (select null from ttt b where a.idx = b.idx) -
Make this query into for all entries
Hello Experts,
please change this query into for all entries to increase performance
loop at itab1.
SELECT single b~vtext INTO itab2
FROM vbkd AS a
INNER JOIN tvkggt AS b
ON akdkg1 = bkdkgr
WHERE a~vbeln EQ itab1-vbeln_vauf
AND a~posnr EQ itab1-posnr_vauf.
endloop.
Thank you so much for all the replies.as I write again and again, then performance is mainly increased but correct index usage
SELECT single b~vtext
INTO itab2
FROM vbkd AS a
INNER JOIN tvkggt AS b
ON ..... spras ???
bkdkgr = akdkg1
WHERE a~vbeln EQ itab1-vbeln_vauf
AND a~posnr EQ itab1-posnr_vauf.
You access vbkd with the primary key vbeln and posnr
and then you switch to tvkggt where you need spras and kdgr for the primary key
With spras you statement is incorrect you get one text it is unclear in which language,
it might be that there is onyl one, but still you *** it to the statement to use the index.
spras = sy-langu might be o.k.
I.e.
IF NOT ( itab1 is initial ).
SELECT single b~vtext
INTO itab2
FROM vbkd AS a
INNER JOIN tvkggt AS b
ON b~spras = sy_langu
b~kdkgr = a~kdkg1
FOR ALL ENTRIES in itab1
WHERE a~vbeln EQ itab1-vbeln_vauf
AND a~posnr EQ itab1-posnr_vauf.
ENDIF.
Siegfried -
How can i make this query run for a form
This query works fine for a sql report
SELECT *
FROM STUDENTS
WHERE given_name||' '||family_name = :P101_USERNAME
AND password = :P101_PASSWORD;
But i want it to do the same thing for a form but i dont have the option like i do for the report where i can just apply the condition to the process.
Anyone any ideas how i could do this so that when i go to the form this information is already there based on the username and password from the previous page?Assuming that page 101 is your login form, just lookup the primary key of the student based on the values presented in the login page fields, then set and pass this value to the form page.
So you would create a process that runs near the very end of the the login processes on page 101, something like this:
declare
l_student_id students.student_id%TYPE;
begin
select student_id into l_student_id from students where given_name||' '||family_name = :P101_USERNAME and password = :P101_PASSWORD;
-- then set the value of your form page primary key field
:P1_STUDENT_ID := l_student_id;
end;I've done something similar and it works fine for me, although I haven't looked at it recently.
Earl -
How do make this query ?
CREATE TABLE CLIENT (
CLIENTID NUMBER PRIMARY KEY,
NAME VARCHAR2(40)
CREATE TABLE SALESMAN (
SALESMANID NUMBER PRIMARY KEY,
NAME VARCHAR2(40),
ALL_CLIENTS NUMBER -- ACCESS ALL CLIENTS IF VALUE IS 1
CREATE TABLE CLIENTSALESMAN (
SALESMANID NUMBER,
CLIENTID NUMBER
INSERT INTO CLIENT VALUES(1,'Bob');
INSERT INTO CLIENT VALUES(2,'Jhon');
INSERT INTO CLIENT VALUES(3,'Robert');
INSERT INTO CLIENT VALUES(4,'Clarck');
INSERT INTO SALESMAN VALUES (1,'Christina',0);
INSERT INTO SALESMAN VALUES (2,'Doug',1); -- access all clients
INSERT INTO CLIENTSALESMAN VALUES (1,1);
INSERT INTO CLIENTSALESMAN VALUES (1,2);
How do you return all the clients of a salesman ? same that SALESMAN.ALL = 1 OR SALESMAN.ALL = 0.
the salesman.all is 1 then he access all clients no need insert in CLIENTSALESMAN. If SALESMAN.ALL = 0 he
access clientsalesman.
Does somebody some suggestion how i make this ?
thanks !1 select *
2 from (select a.name SALESMAN, b.name CLIENT
3 from salesman a, client b, clientsalesman
4 where a.SALESMANID = c.SALESMANID
5 and b.CLIENTID = c.CLIENTID
6 union
7 select a.name SALESMAN, b.name CLIENT
8 from salesman a, client b
9 where a.ALL_CLIENTS = 1)
10* where salesman = '&1'
SQL> /
Enter value for 1: Christina
old 10: where salesman = '&1'
new 10: where salesman = 'Christina'
Christina Bob
Christina Jhon
SQL> /
Enter value for 1: Doug
old 10: where salesman = '&1'
new 10: where salesman = 'Doug'
Doug Bob
Doug Clarck
Doug Jhon
Doug RobertNicolas. -
What can I do to make this query run faster
Hi All,
The below query is taking a long time. Is there any thing that I can do to shorten its time.
SELECT C.FOLIO_NO, C.CO_TRANS_NO TRANS_NO, to_char(C.CREATED_DATE, 'dd/mm/yyyy') DOC_DATE, DECODE(PP.NAME, NULL, D.EMP_NAME, PP.NAME) LODGED_BY, decode(sf_fetch_datechange(c.co_trans_no, C.CO_TRANS_ID), Null, '-', sf_fetch_datechange(c.co_trans_no, C.CO_TRANS_ID)) DATE_CHANGE, P.RECEIPT_NO, decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id) TRANS_ID,(case when decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id)='AR20' then 1 when decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id)='AR03' then 2 end) TRANS_TYPE FROM CO_TRANS_MASTER C, PAYMENT_DETAIL P, PEOPLE_PROFILE PP, SC_AGENT_EMP D, M_CAA_TRANS E where '1' <> TRIM(UPPER('S0750070Z')) and (C.CO_TRANS_ID in TRIM(UPPER('AR20')) OR C.CO_TRANS_ID in TRIM(UPPER('AR03'))OR c.co_trans_id IN TRIM (UPPER ('A020')))and C.CO_TRANS_NO = P.TRANS_NO and (C.VOID_IND = 'N' or C.VOID_IND is Null) and C.CREATED_BY = PP.PP_ID(+) and C.PROF_NO = D.PROF_NO(+) and C.CREATED_BY = D.EMP_ID (+) and TRIM(UPPER(C.CO_NO)) = TRIM(UPPER('200101586W')) and c.co_trans_id = e.trans_id (+) order by FOLIO_NO;
SQL>
SQL> show parameter user_dump_dest
NAME TYPE VALUE
user_dump_dest string /u01/app/oracle/diag/rdbms/ebi
zfile/EBIZFILE1/trace
SQL> show parameter optimizer
NAME TYPE VALUE
optimizer_capture_sql_plan_baselines boolean FALSE
optimizer_dynamic_sampling integer 2
optimizer_features_enable string 11.2.0.2
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
optimizer_mode string ALL_ROWS
optimizer_secure_view_merging boolean TRUE
optimizer_use_invisible_indexes boolean FALSE
optimizer_use_pending_statistics boolean FALSE
optimizer_use_sql_plan_baselines boolean TRUE
SQL> show parameter db_file_multi
NAME TYPE VALUE
db_file_multiblock_read_count integer 128
SQL> show parameter db_block_size
NAME TYPE VALUE
db_block_size integer 8192
SQL> show parameter cursor_sharing
NAME TYPE VALUE
cursor_sharing string EXACT
SQL>
SQL> column sname format a20
SQL> column pname format a20
SQL> column pval2 format a20
SQL>
SQL> select
2 sname, pname, pval1, pval2
3 from
4 sys.aux_stats$;
SNAME PNAME PVAL1 PVAL2
SYSSTATS_INFO STATUS COMPLETED
SYSSTATS_INFO DSTART 09-11-2010 14:25
SYSSTATS_INFO DSTOP 09-11-2010 14:25
SYSSTATS_INFO FLAGS 1
SYSSTATS_MAIN CPUSPEEDNW 739.734748
SYSSTATS_MAIN IOSEEKTIM 10
SYSSTATS_MAIN IOTFRSPEED 4096
SYSSTATS_MAIN SREADTIM
SYSSTATS_MAIN MREADTIM
SYSSTATS_MAIN CPUSPEED
SYSSTATS_MAIN MBRC
SYSSTATS_MAIN MAXTHR
SYSSTATS_MAIN SLAVETHR
13 rows selected.
Elapsed: 00:00:00.06
SQL>
SQL> explain plan for
2 SELECT C.FOLIO_NO, C.CO_TRANS_NO TRANS_NO, to_char(C.CREATED_DATE, 'dd/mm/yyyy') DOC_DATE, DECODE(PP.NAME, NULL, D.EMP_NAME, PP.NAME) LODGED_BY, decode(sf_fetch_datechange(c.co_trans_no, C.CO_TRANS_ID), Null, '-', sf_fetch_datechange(c.co_trans_no, C.CO_TRANS_ID)) DATE_CHANGE, P.RECEIPT_NO, decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id) TRANS_ID,(case when decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id)='AR20' then 1 when decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id)='AR03' then 2 end) TRANS_TYPE FROM CO_TRANS_MASTER C, PAYMENT_DETAIL P, PEOPLE_PROFILE PP, SC_AGENT_EMP D, M_CAA_TRANS E where '1' <> TRIM(UPPER('S0750070Z')) and (C.CO_TRANS_ID in TRIM(UPPER('AR20')) OR C.CO_TRANS_ID in TRIM(UPPER('AR03'))OR c.co_trans_id IN TRIM (UPPER ('A020')))and C.CO_TRANS_NO = P.TRANS_NO and (C.VOID_IND = 'N' or C.VOID_IND is Null) and C.CREATED_BY = PP.PP_ID(+) and C.PROF_NO = D.PROF_NO(+) and C.CREATED_BY = D.EMP_ID (+) and TRIM(UPPER(C.CO_NO)) = TRIM(UPPER('200101586W')) and c.co_trans_id = e.trans_id (+) order by FOLIO_NO;
Explained.
Elapsed: 00:00:00.09
SQL>
SQL> set pagesize 1000;
SQL> set linesize 170;
SQL> @/u01/app/oracle/product/11.2.0/rdbms/admin/utlxpls.sql
SQL> Rem
SQL> Rem $Header: utlxpls.sql 26-feb-2002.19:49:37 bdagevil Exp $
SQL> Rem
SQL> Rem utlxpls.sql
SQL> Rem
SQL> Rem Copyright (c) 1998, 2002, Oracle Corporation. All rights reserved.
SQL> Rem
SQL> Rem NAME
SQL> Rem utlxpls.sql - UTiLity eXPLain Serial plans
SQL> Rem
SQL> Rem DESCRIPTION
SQL> Rem script utility to display the explain plan of the last explain plan
SQL> Rem command. Do not display information related to Parallel Query
SQL> Rem
SQL> Rem NOTES
SQL> Rem Assume that the PLAN_TABLE table has been created. The script
SQL> Rem utlxplan.sql should be used to create that table
SQL> Rem
SQL> Rem With SQL*plus, it is recomended to set linesize and pagesize before
SQL> Rem running this script. For example:
SQL> Rem set linesize 100
SQL> Rem set pagesize 0
SQL> Rem
SQL> Rem MODIFIED (MM/DD/YY)
SQL> Rem bdagevil 02/26/02 - cast arguments
SQL> Rem bdagevil 01/23/02 - rewrite with new dbms_xplan package
SQL> Rem bdagevil 04/05/01 - include CPU cost
SQL> Rem bdagevil 02/27/01 - increase Name column
SQL> Rem jihuang 06/14/00 - change order by to order siblings by.
SQL> Rem jihuang 05/10/00 - include plan info for recursive SQL in LE row source
SQL> Rem bdagevil 01/05/00 - add order-by to make it deterministic
SQL> Rem kquinn 06/28/99 - 901272: Add missing semicolon
SQL> Rem bdagevil 05/07/98 - Explain plan script for serial plans
SQL> Rem bdagevil 05/07/98 - Created
SQL> Rem
SQL>
SQL> set markup html preformat on
SQL>
SQL> Rem
SQL> Rem Use the display table function from the dbms_xplan package to display the last
SQL> Rem explain plan. Force serial option for backward compatibility
SQL> Rem
SQL> select plan_table_output from table(dbms_xplan.display('plan_table',null,'serial'));
PLAN_TABLE_OUTPUT
Plan hash value: 2520189693
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 592 | 85248 | 16573 (1)| 00:03:19 |
| 1 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | 20 | 2 (0)| 00:00:01 |
|* 2 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | 1 (0)| 00:00:01 |
| 3 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | 20 | 2 (0)| 00:00:01 |
|* 4 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | 1 (0)| 00:00:01 |
| 5 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | 20 | 2 (0)| 00:00:01 |
|* 6 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | 1 (0)| 00:00:01 |
| 7 | SORT ORDER BY | | 592 | 85248 | 16573 (1)| 00:03:19 |
| 8 | NESTED LOOPS | | | | | |
| 9 | NESTED LOOPS | | 592 | 85248 | 16572 (1)| 00:03:19 |
| 10 | NESTED LOOPS OUTER | | 477 | 54855 | 15329 (1)| 00:03:04 |
| 11 | NESTED LOOPS OUTER | | 477 | 41499 | 14374 (1)| 00:02:53 |
| 12 | INLIST ITERATOR | | | | | |
|* 13 | TABLE ACCESS BY INDEX ROWID| CO_TRANS_MASTER | 477 | 22896 | 14367 (1)| 00:02:53 |
|* 14 | INDEX RANGE SCAN | IDX_CO_TRANS_ID | 67751 | | 150 (1)| 00:00:02 |
| 15 | TABLE ACCESS BY INDEX ROWID | SC_AGENT_EMP | 1 | 39 | 1 (0)| 00:00:01 |
|* 16 | INDEX UNIQUE SCAN | PK_SC_AGENT_EMP | 1 | | 0 (0)| 00:00:01 |
| 17 | TABLE ACCESS BY INDEX ROWID | PEOPLE_PROFILE | 1 | 28 | 2 (0)| 00:00:01 |
|* 18 | INDEX UNIQUE SCAN | SYS_C0063100 | 1 | | 1 (0)| 00:00:01 |
|* 19 | INDEX RANGE SCAN | IDX_PAY_DETAIL_TRANS_NO | 1 | | 2 (0)| 00:00:01 |
| 20 | TABLE ACCESS BY INDEX ROWID | PAYMENT_DETAIL | 1 | 29 | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("F"."CO_TRANS_NO"=:B1)
4 - access("F"."CO_TRANS_NO"=:B1)
6 - access("F"."CO_TRANS_NO"=:B1)
13 - filter(TRIM(UPPER("SYS_ALIAS_3"."CO_NO"))='200101586W' AND ("SYS_ALIAS_3"."VOID_IND" IS NULL
OR "SYS_ALIAS_3"."VOID_IND"='N'))
14 - access("SYS_ALIAS_3"."CO_TRANS_ID"='A020' OR "SYS_ALIAS_3"."CO_TRANS_ID"='AR03' OR
"SYS_ALIAS_3"."CO_TRANS_ID"='AR20')
16 - access("SYS_ALIAS_3"."PROF_NO"="D"."PROF_NO"(+) AND
"SYS_ALIAS_3"."CREATED_BY"="D"."EMP_ID"(+))
18 - access("SYS_ALIAS_3"."CREATED_BY"="PP"."PP_ID"(+))
19 - access("SYS_ALIAS_3"."CO_TRANS_NO"="P"."TRANS_NO")
42 rows selected.
Elapsed: 00:00:00.53
SQL>
SQL>
SQL>
SQL> rollback;
Rollback complete.
Elapsed: 00:00:00.01
SQL>
SQL> rem Set the ARRAYSIZE according to your application
SQL> set autotrace traceonly arraysize 100
SQL>
SQL> alter session set tracefile_identifier = 'mytrace1';
Session altered.
Elapsed: 00:00:00.00
SQL>
SQL> rem if you're using bind variables
SQL> rem define them here
SQL>
SQL> rem variable b_var1 number
SQL> rem variable b_var2 varchar2(20)
SQL>
SQL> rem and initialize them
SQL>
SQL> rem exec :b_var1 := 1
SQL> rem exec :b_var2 := 'DIAG'
SQL> set pagesize 1000;
SQL> set linesize 170;
SQL> alter session set events '10046 trace name context forever, level 8';
Session altered.
Elapsed: 00:00:00.01
SQL> SELECT C.FOLIO_NO, C.CO_TRANS_NO TRANS_NO, to_char(C.CREATED_DATE, 'dd/mm/yyyy') DOC_DATE, DECODE(PP.NAME, NULL, D.EMP_NAME, PP.NAME) LODGED_BY, decode(sf_fetch_datechange(c.co_trans_no, C.CO_TRANS_ID), Null, '-', sf_fetch_datechange(c.co_trans_no, C.CO_TRANS_ID)) DATE_CHANGE, P.RECEIPT_NO, decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id) TRANS_ID,(case when decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id)='AR20' then 1 when decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id)='AR03' then 2 end) TRANS_TYPE FROM CO_TRANS_MASTER C, PAYMENT_DETAIL P, PEOPLE_PROFILE PP, SC_AGENT_EMP D, M_CAA_TRANS E where '1' <> TRIM(UPPER('S0750070Z')) and (C.CO_TRANS_ID in TRIM(UPPER('AR20')) OR C.CO_TRANS_ID in TRIM(UPPER('AR03'))OR c.co_trans_id IN TRIM (UPPER ('A020')))and C.CO_TRANS_NO = P.TRANS_NO and (C.VOID_IND = 'N' or C.VOID_IND is Null) and C.CREATED_BY = PP.PP_ID(+) and C.PROF_NO = D.PROF_NO(+) and C.CREATED_BY = D.EMP_ID (+) and TRIM(UPPER(C.CO_NO)) = TRIM(UPPER('200101586W')) and c.co_trans_id = e.trans_id (+) order by FOLIO_NO;
10 rows selected.
Elapsed: 00:03:42.27
Execution Plan
Plan hash value: 2520189693
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 592 | 85248 | 16573 (1)| 00:03:19 |
| 1 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | 20 | 2 (0)| 00:00:01 |
|* 2 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | 1 (0)| 00:00:01 |
| 3 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | 20 | 2 (0)| 00:00:01 |
|* 4 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | 1 (0)| 00:00:01 |
| 5 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | 20 | 2 (0)| 00:00:01 |
|* 6 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | 1 (0)| 00:00:01 |
| 7 | SORT ORDER BY | | 592 | 85248 | 16573 (1)| 00:03:19 |
| 8 | NESTED LOOPS | | | | | |
| 9 | NESTED LOOPS | | 592 | 85248 | 16572 (1)| 00:03:19 |
| 10 | NESTED LOOPS OUTER | | 477 | 54855 | 15329 (1)| 00:03:04 |
| 11 | NESTED LOOPS OUTER | | 477 | 41499 | 14374 (1)| 00:02:53 |
| 12 | INLIST ITERATOR | | | | | |
|* 13 | TABLE ACCESS BY INDEX ROWID| CO_TRANS_MASTER | 477 | 22896 | 14367 (1)| 00:02:53 |
|* 14 | INDEX RANGE SCAN | IDX_CO_TRANS_ID | 67751 | | 150 (1)| 00:00:02 |
| 15 | TABLE ACCESS BY INDEX ROWID | SC_AGENT_EMP | 1 | 39 | 1 (0)| 00:00:01 |
|* 16 | INDEX UNIQUE SCAN | PK_SC_AGENT_EMP | 1 | | 0 (0)| 00:00:01 |
| 17 | TABLE ACCESS BY INDEX ROWID | PEOPLE_PROFILE | 1 | 28 | 2 (0)| 00:00:01 |
|* 18 | INDEX UNIQUE SCAN | SYS_C0063100 | 1 | | 1 (0)| 00:00:01 |
|* 19 | INDEX RANGE SCAN | IDX_PAY_DETAIL_TRANS_NO | 1 | | 2 (0)| 00:00:01 |
| 20 | TABLE ACCESS BY INDEX ROWID | PAYMENT_DETAIL | 1 | 29 | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("F"."CO_TRANS_NO"=:B1)
4 - access("F"."CO_TRANS_NO"=:B1)
6 - access("F"."CO_TRANS_NO"=:B1)
13 - filter(TRIM(UPPER("SYS_ALIAS_3"."CO_NO"))='200101586W' AND ("SYS_ALIAS_3"."VOID_IND" IS NULL
OR "SYS_ALIAS_3"."VOID_IND"='N'))
14 - access("SYS_ALIAS_3"."CO_TRANS_ID"='A020' OR "SYS_ALIAS_3"."CO_TRANS_ID"='AR03' OR
"SYS_ALIAS_3"."CO_TRANS_ID"='AR20')
16 - access("SYS_ALIAS_3"."PROF_NO"="D"."PROF_NO"(+) AND
"SYS_ALIAS_3"."CREATED_BY"="D"."EMP_ID"(+))
18 - access("SYS_ALIAS_3"."CREATED_BY"="PP"."PP_ID"(+))
19 - access("SYS_ALIAS_3"."CO_TRANS_NO"="P"."TRANS_NO")
Statistics
51 recursive calls
0 db block gets
651812 consistent gets
92202 physical reads
0 redo size
1594 bytes sent via SQL*Net to client
524 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
10 rows processed
SQL>
SQL> disconnect
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL> Thanks in advance!Hi Raj,
I have given the output below as you requested....
QL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
PLAN_TABLE_OUTPUT
SQL_ID 0taz7ckjm41yv, child number 1
SELECT C.FOLIO_NO, C.CO_TRANS_NO TRANS_NO, to_char(C.CREATED_DATE,
'dd/mm/yyyy') DOC_DATE, DECODE(PP.NAME, NULL, D.EMP_NAME, PP.NAME)
LODGED_BY, decode(sf_fetch_datechange(c.co_trans_no, C.CO_TRANS_ID),
Null, '-', sf_fetch_datechange(c.co_trans_no, C.CO_TRANS_ID))
DATE_CHANGE, P.RECEIPT_NO, decode(c.co_trans_id,'A020',(select
nvl(base_trans_id,co_trans_id) from co_form5a_trans f where
f.co_trans_no=c.co_trans_no),c.co_trans_id) TRANS_ID,(case when
decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from
co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id)='AR2
0' then 1 when decode(c.co_trans_id,'A020',(select
nvl(base_trans_id,co_trans_id) from co_form5a_trans f where
f.co_trans_no=c.co_trans_no),c.co_trans_id)='AR03' then 2 end)
TRANS_TYPE FROM CO_TRANS_MASTER C, PAYMENT_DETAIL P, PEOPLE_PROFILE PP,
SC_AGENT_EMP D, M_CAA_TRANS E where '1' <> TRIM(UPPER('S0750070Z')) and
(C.CO_TRANS_ID in TRIM(UPPER('AR20')) OR C.CO_TRANS_ID in
TRIM(UPPER('AR03'))OR c.co
Plan hash value: 4175354585
| Id | Operation | Name | E-Rows | OMem | 1Mem | Used-Mem |
| 0 | SELECT STATEMENT | | | | | |
| 1 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | | | |
|* 2 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | | |
| 3 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | | | |
|* 4 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | | |
| 5 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | | | |
|* 6 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | | |
| 7 | SORT ORDER BY | | 12 | 2048 | 2048 | 2048 (0)|
| 8 | NESTED LOOPS | | | | | |
| 9 | NESTED LOOPS | | 12 | | | |
| 10 | NESTED LOOPS OUTER | | 10 | | | |
| 11 | NESTED LOOPS OUTER | | 10 | | | |
|* 12 | TABLE ACCESS FULL | CO_TRANS_MASTER | 10 | | | |
| 13 | TABLE ACCESS BY INDEX ROWID| SC_AGENT_EMP | 1 | | | |
|* 14 | INDEX UNIQUE SCAN | PK_SC_AGENT_EMP | 1 | | | |
| 15 | TABLE ACCESS BY INDEX ROWID | PEOPLE_PROFILE | 1 | | | |
|* 16 | INDEX UNIQUE SCAN | SYS_C0063100 | 1 | | | |
|* 17 | INDEX RANGE SCAN | IDX_PAY_DETAIL_TRANS_NO | 1 | | | |
| 18 | TABLE ACCESS BY INDEX ROWID | PAYMENT_DETAIL | 1 | | | |
Predicate Information (identified by operation id):
2 - access("F"."CO_TRANS_NO"=:B1)
4 - access("F"."CO_TRANS_NO"=:B1)
6 - access("F"."CO_TRANS_NO"=:B1)
12 - filter((INTERNAL_FUNCTION("SYS_ALIAS_3"."CO_TRANS_ID") AND
TRIM(UPPER("SYS_ALIAS_3"."CO_NO"))='200101586W' AND ("SYS_ALIAS_3"."VOID_IND" IS NULL OR
"SYS_ALIAS_3"."VOID_IND"='N')))
14 - access("SYS_ALIAS_3"."PROF_NO"="D"."PROF_NO" AND "SYS_ALIAS_3"."CREATED_BY"="D"."EMP_ID")
16 - access("SYS_ALIAS_3"."CREATED_BY"="PP"."PP_ID")
17 - access("SYS_ALIAS_3"."CO_TRANS_NO"="P"."TRANS_NO")
Note
- cardinality feedback used for this statement
- Warning: basic plan statistics not available. These are only collected when:
* hint 'gather_plan_statistics' is used for the statement or
* parameter 'statistics_level' is set to 'ALL', at session or system level
65 rows selected. -
Would Anyone Mind Giving A Few Tips To Make This Script More Robust?
Hello. I haven't done any scripting before but I've written this script to run as a post-recording process in Audio Hijack Pro:
on process(theArgs)
-- This part of the script will disable any timers that are set to repeat exactly 7 days (±1 minute) after the recording started
-- Dates have the format "Monday 1 January 2007 12:00:00"
tell application "Audio Hijack Pro"
set allSessions to every session
repeat with eachSession in allSessions
set allTimers to every timer in eachSession
repeat with eachTimer in allTimers
try -- The try protects against empty values of "next run date"
set nextDate to word 1 of ((next run date of eachTimer) as string)
set nextDay to word 2 of ((next run date of eachTimer) as string)
set nextMonth to word 3 of ((next run date of eachTimer) as string)
set nextYear to word 4 of ((next run date of eachTimer) as string)
set nextHour to word 5 of ((next run date of eachTimer) as string)
set nextMin to word 6 of ((next run date of eachTimer) as string) as number
set weekOn to ((current date) + (60 * 60 * 24 * 7) - (duration of eachTimer)) -- This calculates the date in 7 days, less the duration of the timer
set weekOnDate to word 1 of (weekOn as string)
set weekOnDay to word 2 of (weekOn as string)
set weekOnMonth to word 3 of (weekOn as string)
set weekOnYear to word 4 of (weekOn as string)
set weekOnHour to word 5 of (weekOn as string)
set weekOnMin to word 6 of (weekOn as string) as number
if nextDate is equal to weekOnDate and nextDay is equal to weekOnDay and nextMonth is equal to weekOnMonth and nextYear is equal to weekOnYear and nextHour is equal to weekOnHour and nextMin is greater than (weekOnMin - 60) and nextMin is less than (weekOnMin + 60) then
set enabled of eachTimer to false
end if
end try
end repeat
end repeat
end tell
-- The script then goes on to import the recordings into iTunes (as wavs), set tags and copy the wavs up to the server
if class of theArgs is not list then -- This is a standard Audio Hijack Pro routine
set theArgs to {theArgs}
end if
set recordedFiles to {} -- This will protect against theArgs being changed by Audio Hijack Pro whilst this script is still running
set recordedFiles to theArgs
set convertedFileList to {} -- This will keep track of the paths to the imported files
tell application "iTunes"
set current encoder to encoder "WAV Encoder"
copy (convert recordedFiles) to trackList -- Do the conversion
if class of trackList is not list then
set trackList to {trackList}
end if
repeat with eachTrack in trackList -- Set the tags
set artist of eachTrack to "Theatre Archive"
set album of eachTrack to word 1 of ((name of eachTrack) as string)
set convertedFileList to convertedFileList & (location of eachTrack as alias)
end repeat
end tell
tell application "Finder"
repeat with eachFile in convertedFileList
-- This section (down to HERE) is a subroutine to delay the file copy until iTunes has finished creating the files
set currentSize to size of (info for eachFile)
delay 1
set latestSize to size of (info for eachFile)
repeat until currentSize is equal to latestSize -- Keep checking the size every second to see if it's stopped changing
set currentSize to size of (info for eachFile)
delay 1
set latestSize to size of (info for eachFile)
end repeat
-- ...HERE
duplicate eachFile to "Server HD:" as alias -- Copy the files up to the server
end repeat
end tell
end process
The idea is that it disables the repeating timer that created the recording (as I don't necessarily want it to repeat every week), converts the recording to wav in iTunes and then copies the wav up to our server. If I run it too many times in quick succession some files don't get converted, and then some wavs don't get copied to the server. I'd like to know a way of getting it to tell me why not!
Thanks for any advice you can give.
RichSince you specifically ask if people can make it 'more robust', it would help if you indicated which areas, if any, were of particular concern.
For example, does the script frequently fail in one particular area?
That would help narrow it down significantly. There's little point in people deeply analyzing code that works just fine.
If, on the other hand, you're looking for optimizations, there are several that come to mind.
Firstly, you're making repeated coercions of a date to a string in order to compare them. String comparisons for dates are inherently dangerous for many reasons.
For one, different users might have different settings for their date format.
Both "Monday May 28th 2007 1:02:03am" and "28th May 2007 1:02:03am" are valid coercions of a date to a string, depending on the user's preferences.
You might expect the former format whereas the current system settings use the latter so now 'word 1" returns "28th" rather than "Monday" as you expect.
The problem is exascerbated by the fact that since you're coercing to strings you're now using alphabetical sorting, not numeric sorting. This is critical because in an alpha sort "3rd" comes AFTER "20th" because the character '3' comes after the character '2'. However I'm guessing you'd want events on the 3rd of the month to be sorted before events on the 20th.
So the solution here is to throw away the entire block of code that does the date-to-string coercions. If my reading of the code and the expected values is correct it can all be reduced from:
<pre class=command>set nextDate to word 1 of ((next run date of eachTimer) as string)
set nextDay to word 2 of ((next run date of eachTimer) as string)
set nextMonth to word 3 of ((next run date of eachTimer) as string)
set nextYear to word 4 of ((next run date of eachTimer) as string)
set nextHour to word 5 of ((next run date of eachTimer) as string)
set nextMin to word 6 of ((next run date of eachTimer) as string) as number
set weekOn to ((current date) + (60 * 60 * 24 * 7) - (duration of eachTimer)) -- This calculates the date in 7 days, less the duration of the timer
set weekOnDate to word 1 of (weekOn as string)
set weekOnDay to word 2 of (weekOn as string)
set weekOnMonth to word 3 of (weekOn as string)
set weekOnYear to word 4 of (weekOn as string)
set weekOnHour to word 5 of (weekOn as string)
set weekOnMin to word 6 of (weekOn as string) as number
if nextDate is equal to weekOnDate and nextDay is equal to weekOnDay and nextMonth is equal to weekOnMonth and nextYear is equal to weekOnYear and nextHour is equal to weekOnHour and nextMin is greater than (weekOnMin - 60) and nextMin is less than (weekOnMin + 60) then
set enabled of eachTimer to false
end if</pre>
to:
<pre class=command>set nextDate next run date of eachTimer
set weekOn to ((current date) + (60 * 60 * 24 * 7) - (duration of eachTimer)) -- This calculates the date in 7 days, less the duration of the timer
if nextDate is greater than (weekOn - 60) and nextDate is less than (weekOn + 60) then
set enabled of eachTimer to false
end if</pre>
The next area of concern is your copying of the files to the server. I don't understand why you have all the delays and file size comparisons.
Given a list of aliases convertedFileList, you can simply:
<pre class=command>tell application "Finder"
duplicate convertedFileList to "Server HD" as alias
end tell</pre>
The Finder will copy all the files in one go and you don't need the repeat loop or the delays. -
Plz help to make this query......very urgent
I ve two tables <br>
<br>
First one is <b>grn_dtl</b> containing following fields <br> <br> <br>
<u><b>
item_code ent_dt qty doc_no </u></b><br>
11001318 09/09/2003 5 56300501 <br>
11001318 11/09/2004 9 56300502 <br>
11001318 12/05/2005 2 56300503 <br>
11001319 22/06/2004 0 56300504 <br>
11001320 09/06/2005 0 56300505 <br>
11001320 11/08/2004 8 56300506 <br>
11001320 30/05/2005 4 56300507 <br>
11001320 21/06/2003 1 56300508 <br>
11001321 25/09/2004 1 56300509 <br>
11001321 15/07/2004 1 56300510 <br>
11001321 01/08/2004 2 56300511 <br>
11001322 02/06/2004 1 56300512 <br>
11001322 22/06/2004 2 56300513 <br>
11001323 12/09/2004 1 56300514 <br>
11001323 08/05/2004 4 56300515 <br>
11001323 17/08/2004 5 56300516 <br>
11001323 28/06/2004 2 56300517 <br>
<br><br>
second one is <b>item_mst</B> containing following fields <br>
<br>
<u><b>
item_code description leadtim kanbandate</u></b><br>
11001318 aaaaaaaaaaa 15 22/04/2004<br>
11001319 aaaaaaaaaaa 15 02/12/2004<br>
11001320 aaaaaaaaaaa 15 14/07/2005<br>
11001321 aaaaaaaaaaa 15 23/02/2004<br>
11001322 aaaaaaaaaaa 15 05/10/2004<br>
11001323 aaaaaaaaaaa 15 17/05/2004<br>
11001324 aaaaaaaaaaa 15 27/12/2004<br>
11001325 aaaaaaaaaaa 15 07/08/2004<br>
<br><br><br><b>
From the above two tables I want the combine SQL query which will display item_code its description ,kanbandate from item_mst table and will also display the minimum ent_dt of each corresponding item_code alongwith the qty and doc_no.the item_code should not be repeated .<br>
I want to run the query from sql query analyzer</b><br><br>
the result should be like this<br><br>
<b></u>item_code desc ent_dt qty doc_no</b></u>
<br>
11001318 aaaaaaaaaaa 09/09/2003 5 56300501<br>
11001319 aaaaaaaaaaa 22/06/2004 0 56300504<br>
11001320 aaaaaaaaaaa 21/06/2003 1 56300508<br>
11001321 aaaaaaaaaaa 15/07/2004 1 56300510<br>
11001322 aaaaaaaaaaa 02/06/2004 1 56300513<br>
11001323 aaaaaaaaaaa 08/05/2004 4 56300515<br>
<br>
<br>
plz help me out ASAP
null
Message was edited by:
aanchal_2008can you try this,
SELECT DISTINCT im.item_code,
im.descR,
gd.ent_dt,
gd.qty,
gd.doc_no
FROM item_mst im,
grn_dtl gd
WHERE im.item_code = gd.item_code (+)
AND NOT EXISTS (
SELECT 'later detail'
FROM grn_dtl gd2
WHERE gd2.item_code = gd.item_code
AND gd2.ent_dt > gd.ent_dt)
ITEM_CODE DESCR ENT_DT QTY DOC_NO
11001318 aaaaaaaaaaa 2/12/2005 6 563005
11001319 aaaaaaaaaaa 6/22/2004 0 563005
11001320 aaaaaaaaaaa 6/9/2005 0 563005
11001321 aaaaaaaaaaa 12/5/2005 5 563005
11001322 aaaaaaaaaaa 6/22/2004 2 563005
11001323 aaaaaaaaaaa 9/12/2004 1 563005
11001324 aaaaaa
11001325 aaaaaa
8 rows selected -
How do I make this query?
I'm working with a table that has over 400,000 records. The columns are as follows:
Species_Code, Breed_Code, Premium_Coverage, Age.
Species_code is either a,c,r,or f. There are associated breed codes for each specie code.
The Premium_coverage is based on species_code and breed_code no matter what the age is. The problem is that for all ages, you have the same premium which makes the table longer than it should be. Which query can I write to have one base_premium for all species_code and breed_code?Use an aggregate function like MIN, MAX, or AVG and GROUP BY:
SELECT species_code, breed_code, MIN (premium_coverage)
FROM your_table
GROUP BY species_code, breed_code -
WITH
MEMBER [FYDay].[DateHierarchy].[CurrentDay] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[PreviousDay] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .PREVMEMBER }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay1] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(1) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay2] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(2) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay3] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(3) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay4] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(4) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay5] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(5) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay6] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(6) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay7] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(7) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[PTD] AS AGGREGATE(PERIODSTODATE([FYDay].[DateHierarchy].[FPERIOD],
[FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014]
), [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[WTD] AS AGGREGATE(PERIODSTODATE([FYDay].[DateHierarchy].[FWEEK],
[FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014]
), [Measures].CURRENTMEMBER)
SELECT
[FYDay].[DateHierarchy].[WTD],
[FYDay].[DateHierarchy].[PTD],
[FYDay].[DateHierarchy].[PreviousDay],
[FYDay].[DateHierarchy].[CurrentDay],
[FYDay].[DateHierarchy].[CurrentDay1],
[FYDay].[DateHierarchy].[CurrentDay2],
[FYDay].[DateHierarchy].[CurrentDay3],
[FYDay].[DateHierarchy].[CurrentDay4],
[FYDay].[DateHierarchy].[CurrentDay5],
[FYDay].[DateHierarchy].[CurrentDay6],
[FYDay].[DateHierarchy].[CurrentDay7]
} ON COLUMNS,
[Measures].[Store Budget],
[MEASURES].[SNAPSHOTSOLDAMOUNT],
[MEASURES].[SHIPPEDAMOUNT],
[MEASURES].[SHIPPED VS SOLD],
[Measures].[% To Budget]
{[STOREMASTER].[SERVICINGDC].[SERVICINGDC].ALLMEMBERS}
)} ON ROWS
from ( select {[STOREMASTER].[SERVICINGDC].&[Houston]} on columns
FROM [Model]Hi Ramparasad,
In your query, you add a measures and dimension on Row axis which is not supported in query designer in SSRS. Please use the query below.
WITH
MEMBER [FYDay].[DateHierarchy].[CurrentDay] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[PreviousDay] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .PREVMEMBER }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay1] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(1) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay2] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(2) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay3] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(3) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay4] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(4) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay5] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(5) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay6] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(6) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay7] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(7) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[PTD] AS AGGREGATE(PERIODSTODATE([FYDay].[DateHierarchy].[FPERIOD],
[FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014]
), [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[WTD] AS AGGREGATE(PERIODSTODATE([FYDay].[DateHierarchy].[FWEEK],
[FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014]
), [Measures].CURRENTMEMBER)
SELECT
[Measures].[Store Budget],
[MEASURES].[SNAPSHOTSOLDAMOUNT],
[MEASURES].[SHIPPEDAMOUNT],
[MEASURES].[SHIPPED VS SOLD],
[Measures].[% To Budget]
}ON COLUMNS,
{ [FYDay].[DateHierarchy].[WTD],
[FYDay].[DateHierarchy].[PTD],
[FYDay].[DateHierarchy].[PreviousDay],
[FYDay].[DateHierarchy].[CurrentDay],
[FYDay].[DateHierarchy].[CurrentDay1],
[FYDay].[DateHierarchy].[CurrentDay2],
[FYDay].[DateHierarchy].[CurrentDay3],
[FYDay].[DateHierarchy].[CurrentDay4],
[FYDay].[DateHierarchy].[CurrentDay5],
[FYDay].[DateHierarchy].[CurrentDay6],
[FYDay].[DateHierarchy].[CurrentDay7]
{[STOREMASTER].[SERVICINGDC].[SERVICINGDC].ALLMEMBERS}
} ON ROWS
from ( select {[STOREMASTER].[SERVICINGDC].&[Houston]} on columns
FROM [Model]
Regards,
Charlie Liao
TechNet Community Support
Maybe you are looking for
-
Email Sales Order Confirmation to "Created By" -
Hi Experts I have a requirement where we need to email the Order confirmation output to the person who has created the sales order. So lets say i am creating a sales order and my user id is 9999. (SY-UNAME). Now as we have implemented HR module and o
-
10.5.8 won't detect any external hard drives
I want to update my 10.5.8 Macbook Pro which I bought in 2008. It runs incredibly slow, and I want to reformat it before updating with Snow Leopard. The problem is that my computer won't detect any external disc drives, so I can't back up my import
-
Org Structure creation for different countries
Hi, Pls guide me as of how to proceed with the scenario.Client has Organization structure in 2 countries,that is India and srilanka. 1/ While configuring in the system for creating Org structure should i change the MOLG value(in SU3)accordingly for e
-
Calling the PAI of a screen dynamically
Hi Experts, I have two screens say 9000 and 9001. If the user enters a certain command in screen 9000 I am supposed to call screen 9001 for some secondary information. After the user enters the info in screen 9001 i am supposed to return back to the
-
Trial Serial Number Does Not Work
I downloaded the trial version of Aperture to try on my new MacBook (this is my first Mac). I received a serial number in an email but when I enter the number during the installation process I was told that the serial number is not valid. How do I in