Require help on the Query related to where condition
Hi All,
i am a java developer and was required to write a query for some of my operations to get the data from oracle database.
i am stuck at one point. please help me.
i have table with 3 columns.
ID | Name | Value
1 | ser | x
1 | Bus | a
1 | pol | b
2 | ser | x
2 | Bus | a
2 | pol | c
3 | ser | y
3 | Bus | a
3 | pol | b
4 | ser | y
4 | Bus | d
4 | pol | e
i have written query like below.
Select ID from table where Name in ('ser','Bus','pol') and Value in ('x','a','b');
i am getting out put as ID = 1,2,3
but i should get the output as ID=1
i should get the ID which satisfies all the given attributes and values.
i cannot use the AND for each Name and Value here as i the no.of values inName or Value field may increase and that will be dynamically passed from my java class.
Immediate help is appreciated.
thanks a lot
Something like this will deal with multiple values and treat the name value pairs together...
SQL> ed
Wrote file afiedt.buf
1 with t as (select 1 as ID, 'ser' as Name, 'x' as Value from dual union all
2 select 1, 'Bus', 'a' from dual union all
3 select 1, 'pol', 'b' from dual union all
4 select 2, 'ser', 'x' from dual union all
5 select 2, 'Bus', 'a' from dual union all
6 select 2, 'pol', 'c' from dual union all
7 select 3, 'ser', 'y' from dual union all
8 select 3, 'Bus', 'a' from dual union all
9 select 3, 'pol', 'b' from dual union all
10 select 4, 'ser', 'y' from dual union all
11 select 4, 'Bus', 'd' from dual union all
12 select 4, 'pol', 'e' from dual)
13 --
14 -- end of test data
15 --
16 ,i as (select 'ser|x,Bus|a,pol|b' as r from dual)
17 --
18 -- end of input
19 --
20 ,split as (select regexp_substr(r,'[^,]+',1,rn) as pair
21 from i
22 cross join (select rownum rn
23 from dual
24 connect by rownum <= (select length(regexp_replace(r,'[^,]'))+1 from i))
25 )
26 select id
27 from t, split
28 where name = regexp_substr(pair,'[^|]+',1,1)
29 and value = regexp_substr(pair,'[^|]+',1,2)
30 group by id
31* having count(*) = (select count(*) from split)
SQL> /
ID
1It's then just a case of providing the input in the correct format.
Similar Messages
-
I need help with the query
Here is what I need
For a particular comm record if there is no Salary record where comm:Date = Salary:Date, then
• Find maximum dated Salary record as of comm:Date.
• Clone this record and set Salary:Date = comm:Date
• Set Salary:rate = comm:rate
Like wise for a particular Salary record If there is no comm record where Salary:Date = comm:Date then
• Find maximum effective dated comm record as of Salary:Date
• Apply Rate 2 amount from this maximum effective dated record to Salary record i.e. Set Salary:rate = comm:rate
Example
Salary Table :
ID Sal_Date Rate Hours
1 07/01/2011 400.00 40
2 02/15/2011 200.00 40
3 01/01/2011 160.00 40
Sal_comm Table:
Sal_Date comm_Rate
1 07/01/2011 10.00
4 03/01/2011 7.50
3 01/01/2011 4.00
I need to merge comm_Rate column in Salary table, since there is no salary record as off 03/01/2011, I need to find the maximum dated salary record as of 03/01/2011
i.e. the record dated 02/15/2011. Now I need to clone that salary record, set the SAL_date as 03/01/2011 and update Rate2 amount. So the record set will be like:
Sal_Date:
id sal_Date Rate Hours comm_Rate
1 07/01/2011 400.00 40 10.00
4 03/01/2011 200.00 40 7.50
2 02/15/2011 200.00 40 4.00
3 01/01/2011 160.00 40 4.00So you need all used dates as the "driving" dataset. And you need the according data for each of these.
WITH salary_table as
(select 1 id,to_date('07/01/2011','MM/DD/YYYY')sal_date,400 rate,40 hours from dual union all
select 2 id,to_date('02/15/2011','MM/DD/YYYY')sal_date,200 rate,40 hours from dual union all
select 3 id,to_date('01/01/2011','MM/DD/YYYY')sal_date,160 rate,40 hours from dual),
sal_comm as
(select 1 id,to_date('07/01/2011','MM/DD/YYYY')sal_date,10 comm_Rate from dual union all
select 4 id,to_date('03/01/2011','MM/DD/YYYY')sal_date,7.5 comm_Rate from dual union all
select 3 id,to_date('01/01/2011','MM/DD/YYYY')sal_date,4 comm_Rate from dual)
select to_char(all_dates.sal_date,'MM/DD/YYYY') sal_date,sal.rate,sal.hours,com.comm_rate
from (select sal_date from salary_table
union
select sal_date from sal_comm) all_dates
inner join (select s1.*,lead(sal_date-1,1,to_date('31/12/9999','DD/MM/YYYY')) over (order by sal_date) next_sal_date
from salary_table s1) sal
on (all_dates.sal_date between sal.sal_date and sal.next_sal_date)
inner join (select s1.*,lead(sal_date-1,1,to_date('31/12/9999','DD/MM/YYYY')) over (order by sal_date) next_sal_date
from sal_comm s1) com
on (all_dates.sal_date between com.sal_date and com.next_sal_date)
order by all_dates.sal_date desc;
SAL_DATE RATE HOURS COMM_RATE
07/01/2011 400 40 10
03/01/2011 200 40 7.5
02/15/2011 200 40 4
01/01/2011 160 40 4
-
Please Help for the Query
Hi frds please help me for the below query.What I want to do is to pull out the data from below table :-
date ticker indicator
03/13/2008 3IINFOTECH -8
03/18/2008 3IINFOTECH -4
03/25/2008 3IINFOTECH -5
03/27/2008 3IINFOTECH -3
as such :-
date ticker indicator
03/13/2008 3IINFOTECH -8
03/25/2008 3IINFOTECH -5
03/27/2008 3IINFOTECH -3
Here I want to find the Trend i.e either asc or desc order from the lowest indicator.
In the above sample data -8, -4, -5, -3 out of which I want the asc order data -8, -5, -3 and exclude -4 data.Because the asc order -8, -5, -3 will not follow.
So I want the data
date ticker indicator
03/13/2008 3IINFOTECH -8
03/25/2008 3IINFOTECH -5
03/27/2008 3IINFOTECH -3SQL> CREATE TABLE BORRAME(FECHA DATE, INDICA VARCHAR2(100));
Tabla creada.
SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/13/2008','MM/DD/YYYY'), '3IINFOTECH -8');
1 fila creada.
SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/18/2008','MM/DD/YYYY'), '3IINFOTECH -4');
1 fila creada.
SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/25/2008','MM/DD/YYYY'), '3IINFOTECH -5');
1 fila creada.
SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/27/2008','MM/DD/YYYY'), '3IINFOTECH -3');
1 fila creada.
SQL> COMMIT;
Validación terminada.
SQL>
SQL> SELECT FECHA, INDICA
2 FROM BORRAME
3 WHERE SUBSTR(INDICA,INSTR(INDICA,'-',1)+1,LENGTH(INDICA)) <> '4'
4 ORDER BY SUBSTR(INDICA,INSTR(INDICA,'-',1)+1,LENGTH(INDICA)) DESC;
FECHA
INDICA
13/03/08
3IINFOTECH -8
25/03/08
3IINFOTECH -5
27/03/08
3IINFOTECH -3
-
A filter to be applied on the F4 help in the query
Hi
I have a requirement wherein the user wants a filter to be applied on the F4 help in the query (for e.g. company code) for a specific area(for this e.g. real estate). Can I do this as now it brings all the company codes that exist
Thanks
BhimaHi,
It might be done. If your specific area is a compounding attribute to company code then restrict your area and co_code by variables (user entry). After you enter area into variable, F4 help for a co_code variable will show only codes from the entered area.
Best regards,
Eugene -
I want to move my iweb domain files to another computer, I read the directions in help but the file isn't where it says it is, can anyone direct me?
Where are you looking?
Here:
User>Library>Application Support>iWeb
Keep in mind that your Library folder is hidden by default in Mountain Lion.
To find it, hold down the option key and choose the Go menu in the Finder.
You might also want to try posting your question over in the iWeb area.
https://discussions.apple.com/community/ilife/iweb
Matt
Message was edited by: Matthew Morgan -
Infoobject F4 help in the Query takes lot of time and hangs
Hi All,
I have 0Material in the query and the F4 help for selection takes lot of time and hangs after some time.
The 0Material has 2 million records the Infoobject properties for Bex are as below:
Selection:No selection restriction
Query Def. Filter Value Selection: Values in Master Data Table
Query Execution Filter Val.Selectn:Only Posted Values for Navigation
We tried to alter some of the Properties but we have the same issue.
Suggest other options that can be be looked into to get the F4 help in the Query .
Thanks,
Mikehi Mike,
check if helps
Note 817335 - Performance in F4 Help
Note 748623 - Input help (F4) has a very long runtime - recommendations
Note 581802 - Variable dialog boxes: performance of the F4 help
search oss note for f4 performance ...... -
Dynamic select query with dynamic where condition
Hi all,
I want to use the dynamic select query with dynamic where condition. For that I used the below code but I am getting dump when using this code.
Please advice, if there is any other way to achieve this requirement.
Thanks,
Sanket Sethi
Code***************
PARAMETERS: p_tabnam TYPE tabname,
p_selfl1 TYPE edpline,
p_value TYPE edpline,
p_where1 TYPE edpline .
DATA: lt_where TYPE TABLE OF edpline,
lt_sel_list TYPE TABLE OF edpline,
l_wa_name TYPE string,
ls_where TYPE edpline,
l_having TYPE string,
dref TYPE REF TO data,
itab_type TYPE REF TO cl_abap_tabledescr,
struct_type TYPE REF TO cl_abap_structdescr,
elem_type TYPE REF TO cl_abap_elemdescr,
comp_tab TYPE cl_abap_structdescr=>component_table,
comp_fld TYPE cl_abap_structdescr=>component.
TYPES: f_count TYPE i.
FIELD-SYMBOLS : <lt_outtab> TYPE ANY TABLE,
* <ls_outtab> TYPE ANY,
<l_fld> TYPE ANY.
struct_type ?= cl_abap_typedescr=>describe_by_name( p_tabnam ).
elem_type ?= cl_abap_elemdescr=>describe_by_name( 'F_COUNT' ).
comp_tab = struct_type->get_components( ).
comp_fld-name = 'F_COUNT'.
comp_fld-type = elem_type.
APPEND comp_fld TO comp_tab.
struct_type = cl_abap_structdescr=>create( comp_tab ).
itab_type = cl_abap_tabledescr=>create( struct_type ).
l_wa_name = 'l_WA'.
CREATE DATA dref TYPE HANDLE itab_type.
ASSIGN dref->* TO <lt_outtab>.
*CREATE DATA dref TYPE HANDLE struct_type.
*ASSIGN dref->* TO <ls_outtab>.
* Creation of the selection fields
APPEND p_selfl1 TO lt_sel_list.
APPEND 'COUNT(*) AS F_COUNT' TO lt_sel_list.
** Creation of the "where" clause
*CONCATENATE p_selfl1 '= '' p_value ''.'
* INTO ls_where
* SEPARATED BY space.
*APPEND ls_where TO lt_where.
* Creation of the "where" clause
APPEND p_where1 TO lt_where.
* Creation of the "having" clause
l_having = 'count(*) >= 1'.
* THE dynamic select
SELECT (lt_sel_list)
FROM (p_tabnam)
INTO CORRESPONDING FIELDS OF TABLE <lt_outtab>.
* WHERE (lt_where).Hi Sanket,
The above given logic of mine works for you, put the code in the If condition and try-
just like below:
IF NOT P_EBELN IS INITIAL.
lt_where = '& = ''&'' '.
REPLACE '&' WITH p_ebeln INTO lt_where.
REPLACE '&' WITH field_value INTO lt_where.
SELECT (lt_sel_list) INTO CORRESPONDING FIELDS OF TABLE <lt_outtab>
FROM (p_tabnam)
WHERE (lt_where).
ENDIF.
thanks\
Mahesh -
Help required in optimizing the query response time
Hi,
I am working on a application which uses a jdbc thin client. My requirement is to select all the table rows in one table and use the column values to select data in another table in another database.
The first table can have maximum of 6 million rows but the second table rows will be around 9000.
My first query is returning within 30-40 milliseconds when the table is having 200000 rows. But when I am iterating the result set and query the second table the query is taking around 4 millisecond for each query.
the second query selection criteria is to find the value in the range .
for example my_table ( varchar2 column1, varchar2 start_range, varchar2 end_range);
My first query returns a result which then will be used to select using the following query
select column1 from my_table where start_range < my_value and end_range> my_value;
I have created an index on start_range and end_range. this query is taking around 4 millisseconds which I think is too much.
I am using a preparedStatement for the second query loop.
Can some one suggest me how I can improve the query response time?
Regards,
ShyamTry the code below.
Pre-requistee: you should know how to pass ARRAY objects to oracle and receive resultsets from java. There are 1000s of samples available on net.
I have written a sample db code for the same interraction.
Procedure get_list takes a array input from java and returns the record set back to java. You can change the tablenames and the creteria.
Good luck.
DROP TYPE idlist;
CREATE OR REPLACE TYPE idlist AS TABLE OF NUMBER;
CREATE OR REPLACE PACKAGE mypkg1
AS
PROCEDURE get_list (myval_list idlist, orefcur OUT sys_refcursor);
END mypkg1;
CREATE OR REPLACE PACKAGE BODY mypkg1
AS
PROCEDURE get_list (myval_list idlist, orefcur OUT sys_refcursor)
AS
ctr NUMBER;
BEGIN
DBMS_OUTPUT.put_line (myval_list.COUNT);
FOR x IN (SELECT object_name, object_id, myvalue
FROM user_objects a,
(SELECT myval_list (ROWNUM + 1) myvalue
FROM TABLE (myval_list)) b
WHERE a.object_id < b.myvalue)
LOOP
DBMS_OUTPUT.put_line ( x.object_name
|| ' - '
|| x.object_id
|| ' - '
|| x.myvalue
END LOOP;
END;
END mypkg1;
[pre]
Testing the code above. Make sure dbms output is ON.
[pre]
DECLARE
a idlist;
refc sys_refcursor;
c number;
BEGIN
SELECT x.nu
BULK COLLECT INTO a
FROM (SELECT 5000 nu
FROM DUAL) x;
mypkg1.get_list (a, refc);
END;
[pre]
Vishal V. -
hi folks,
Help me to build the query here.
Tables BKPF - fields belnr, blart
BSEG - fields kunnr,wrbtr, zuonr
I need to get the data into a single internal table whose strucutre consists of fields kunnr, blart,wrbtr and zuonr
the common field between the two tables is belnr and the query should be run based on 'zuonr' field
i.e
select ......................... where bseg-zuonr = p_advnum(paramter field where I get the data)
Question how to establish relation between two tables in asingle query without the use of 'JOIN' statements because BSEG is a cluster table and i cannot do that.
Thanks in advance.
SanthoshHere's one way, but that hit to BSEG may take a while if you don't have an index for that field.
data: xbkpf type bkpf.
data: ibseg type table of bkpf with header line.
data: begin of itab occurs 0,
kunnr type bseg-kunnr,
blart type bkpf-blart,
wrbtr type bseg-wrbtr,
zuonr type bseg-zuonr,
end of itab.
parameters: p_advnum type bseg-zuonr.
select * into corresponding fields of table ibseg
from bseg
where zuonr = p_advnum.
loop at ibseg.
move-corresponding ibseg to itab.
clear xbkpf.
select single * from bkpf into xbkpf
where belnr = ibseg-belnr.
itab-blart = ibseg-blart.
append itab.
endloop.
Regards,
Rich Heilman -
Help: Setting the multipart/related start parameter
I am wanting to set the "start" parameter on my ContentType header for
a multipart related message. Something like below.
DATA
ContentType: multipart/related; boundary=_XXX; start="<somecid@domain>"
I can set the content type to "multipart/related" by calling
MimeMultipart.setSubType(), but I cannot figure out how to set the
"start" parameter.
Anyone know.
Thanks,
ChrisDoes the SMTP server accept the mail for delivery of does it reject it?
If it doesn't reject it, is the issue with the format of the mime message, or possibly with whatever mail reader you are using.
It the SMTP server does reject the message I suppose the next question is what exactly is the "SMTP" server you are using?
IMHO you should not need to add anything to the mime multipart headers if using any RFC compliant SMTP server or reader. No-where in RFCs 2045,2046,2049,2822 etc can I find anything that relates to this "start" parameter.
If the SMTP server is a "proper" SMTP server it should not give two hoots about the mime multipart/mime body parts of the message as it "should" only be interested in the headers required to deliver the email. The mime multi/body part headers are generally not used to deliver. They are used by a Mime compliant mail reader to format and display the message.
We use Javamail to send regular "Newsletters" via a numbers of SMTP mail serviers running on IBM AS/400s, Sendmail on Unix, Lotus Notes servers and and others and have no problems.
If you want to send me your code to run on our systems to see if it really is your SMTP server or your message format that is giving trouble I can probably help. I can't open up a server for you as we have rather strict policies on who can do what with our servers. You can of course use our normal SMTP server to send a test email to me!!
Rgds,
SH -
Hi All....
Required help for one more query.
I have a table with data like this:
Cust_id Transaction_no
111 1
111 2
111 3
111 4
111 5
111 6
222 7
222 8
333 9
333 10
333 11
333 12
I wrote the following query :
select cust_id, ntile(3) over (order by cust_id) "Bucket" from trans_detls
The output is like this :
Cust_id Bucket
111 1
111 1
111 1
111 1
111 2
111 2
222 2
222 2
333 3
333 3
333 3
333 3
The problem is that I dont want the cust_id to overlap in buckets. That is one cust_id should be present in only one bucket.
Is this possible?
Thanks in advance.
AmeyaOr Something like..
SQL> select * from test;
ID NO
111 1
111 2
111 3
111 4
111 5
111 6
222 7
222 8
333 9
333 10
333 11
333 12
12 rows selected.
SQL> select id, ntile(3) over (order by rn) "Bucket"
2 from(
3 select id,row_number() over(partition by id order by no) rn
4 from test);
ID Bucket
111 1
222 1
333 1
111 1
222 2
333 2
111 2
333 2
111 3
333 3
111 3
111 3
12 rows selected. -
Hi all..
I required some help in writing a query..
My table is like this
Cust_id Cust_type Del_status Incharge
111 Gold HD
222 Gold
333 Gold HD
444 Gold
123 Gold HD
456 Gold
789 Gold HD
987 Gold
555 Silver HD
666 Silver HD
777 Silver
888 Silver
I want a query to generate this output
Cust_id Cust_type Del_status Incharge
111 Gold HD 1
222 Gold 1
333 Gold HD 1
444 Gold 1
555 Silver HD 1
777 Silver 1
123 Gold HD 2
456 Gold 2
789 Gold HD 2
987 Gold 2
666 Silver HD 2
888 Silver 2
The query basically allocates the customers to incharges... based on cust_type and del_status.
there are 3 categories, Gold Customers, Silver Customers and HD customers..
It should divide this three equally amongst the 2 incharges...
Also this is just a sample data... actually table consists of around 3Lac customers and 12 incharges
Sorry if its a incorrect post..
Thanks in advance..Is there a way to find the value for ntile(2) dynamically?
I tried something like
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.8.0 - Production
SQL> with mytable as (select 111 cust_id, 'Gold' cust_type, 'HD' del_status from dual UNION ALL
2 select 222 cust_id, 'Gold' cust_type, null del_status from dual UNION ALL
3 select 333 cust_id, 'Gold' cust_type, 'HD' del_status from dual UNION ALL
4 select 444 cust_id, 'Gold' cust_type, null del_status from dual UNION ALL
5 select 123 cust_id, 'Gold' cust_type, 'HD' del_status from dual UNION ALL
6 select 456 cust_id, 'Gold' cust_type, null del_status from dual UNION ALL
7 select 789 cust_id, 'Gold' cust_type, 'HD' del_status from dual UNION ALL
8 select 897 cust_id, 'Gold' cust_type, null del_status from dual UNION ALL
9 select 555 cust_id, 'Silver' cust_type, 'HD' del_status from dual UNION ALL
10 select 666 cust_id, 'Silver' cust_type, 'HD' del_status from dual UNION ALL
11 select 777 cust_id, 'Silver' cust_type, null del_status from dual UNION ALL
12 select 888 cust_id, 'Silver' cust_type, null del_status from dual UNION ALL
13 select 1001 cust_id, 'Copper' cust_type, null del_status from dual UNION ALL
14 select 1002 cust_id, 'Copper' cust_type, 'HD' del_status from dual UNION ALL
15 select 1003 cust_id, 'Copper' cust_type, null del_status from dual
16 )
17 select t1.cust_id
18 , t1.cust_type
19 , t1.del_status
20 --, ntile(3) over (partition by nvl(t1.del_status,t1.cust_type) order by t1.cust_id)
21 , ntile((select count(distinct nvl(t2.del_status,t2.cust_type))-1 from mytable t2)) over (parti
tion by nvl(del_status,cust_type) order by cust_id)
22 incharge
23 from mytable t1
24 order by incharge, t1.cust_type, t1.cust_id
25 /
, ntile((select count(distinct nvl(t2.del_status,t2.cust_type))-1 from mytable t2)) over (partition
ERROR at line 21:
ORA-30488: argument should be a function of expressions in PARTITION BY
SQL> The number of incharges could change during the time.
Message was edited by:
Sven Weller -
Hi ,
Below query is taking more time (4mins) for 41 rows returning and there is no full table scan .Can some one help to rewrite the query.
SELECT
esma.candidate AS candidate_additional_sample,
ccr.raw_mark,
ccr.split_session_year AS year,
ccr.split_session_month AS month,
ccr.paper_code,
ccr.assessment_school AS school_code,
get_cand_session_number(ccr.split_session_year,ccr.split_session_month,ccr.candidate) AS candidate_session_number,
ccr.candidate AS candidate_code,
c.firstname AS candidate_firstname,
c.lastname AS candidate_lastname,
ema.moderator_code,
ema.examiner_code,
csr.self_taught
FROM
ibis.candidate_component_reg ccr
INNER JOIN ibis.candidate_examiner_allocation cea
ON ccr.split_session_year= cea.year
AND ccr.split_session_month=cea.month
AND ccr.assessment_school=cea.assessment_school
AND ccr.paper_code= cea.paper_code
AND ccr.candidate = cea.candidate
INNER JOIN ibis.examination_paper ep
ON ccr.split_session_year= ep.year
AND ccr.split_session_month=ep.month
AND ccr.paper_code=ep.paper_code
INNER JOIN ibis.examiner_moderator_allocation ema
ON ema.year =cea.year
AND ema.month =cea.month
AND ema.no_lang_code=ep.no_lang_code
AND ema.examiner_code=cea.examiner_code
AND ema.year =ccr.split_session_year
AND ema.month =ccr.split_session_month
INNER JOIN ibis.candidate_subject_registration csr
ON ccr.split_session_year=csr.year
AND ccr.split_session_month=csr.month
AND ccr.main_school=csr.main_school
AND ccr.candidate=csr.candidate
AND ccr.subject=csr.subject
AND ccr.subject_option=csr.subject_option
AND ccr.lvl=csr.lvl
AND ccr.language=csr.language
INNER JOIN ibis.candidate c
ON ccr.candidate=c.candidate
LEFT OUTER JOIN ibis.exam_sample_mark_additional esma
ON ccr.split_session_year = esma.year
AND ccr.split_session_month = esma.month
AND ep.no_lang_code = esma.nolang_code
AND ccr.candidate = esma.candidate
WHERE
ccr.split_session_year=:v_year
AND ccr.split_session_month=:v_month
AND ccr.subject=:v_subject
AND ccr.subject_option=nvl(:v_subject_option,ccr.subject_option)
AND ccr.language=nvl(:v_language, ccr.language)
AND ccr.component=:v_component
AND ccr.lvl=:v_lvl
AND ccr.raw_mark IS NOT NULL
AND cea.examiner_code = :v_examiner_code
AND ((ccr.sampled='Y'
AND csr.self_taught='N'
AND EXISTS (SELECT 1 FROM ibis.subject_component sc
WHERE sc.assessment_method_id = 11
AND sc.assessment_type='INTERNAL'
AND ccr.split_session_year=sc.year
AND ccr.split_session_month=sc.month
AND ccr.paper_code=sc.paper_code
AND ccr.subject=sc.subject
AND ccr.subject_option=sc.subject_option
AND ccr.lvl=sc.lvl
AND ccr.language=sc.language
AND ccr.component=sc.component)
AND NOT EXISTS (SELECT 1 FROM ibis.cw_portfolio_template cpt
WHERE ccr.split_session_year = cpt.year
AND ccr.split_session_month = cpt.month
AND ccr.subject = cpt.subject
AND ccr.subject_option = cpt.subject_option
AND ccr.component = cpt.component
AND cpt.combined = 'Y')
AND NOT EXISTS (SELECT 1 FROM ibis.school_sample_mark ssm
WHERE ssm.year= ccr.split_session_year
AND ssm.month = ccr.split_session_month
AND ssm.paper_code = ccr.paper_code
AND ssm.candidate =ccr.candidate
AND ssm.examiner_sample = 'Y'))
OR (ccr.sampled='N'
AND csr.self_taught='Y'
AND EXISTS (SELECT 1 FROM ibis.subject_component sc
WHERE sc.assessment_method_id = 11
AND ccr.split_session_year=sc.year
AND ccr.split_session_month=sc.month
AND ccr.paper_code=sc.paper_code
AND ccr.subject=sc.subject
AND ccr.subject_option=sc.subject_option
AND ccr.lvl=sc.lvl
AND ccr.language=sc.language
AND ccr.component=sc.component)
AND NOT EXISTS (SELECT 1 FROM ibis.cw_portfolio_template cpt
WHERE ccr.split_session_year = cpt.year
AND ccr.split_session_month = cpt.month
AND ccr.subject = cpt.subject
AND ccr.subject_option = cpt.subject_option
AND ccr.component = cpt.component
AND cpt.combined = 'Y'))
OR (ccr.sampled='N'
AND EXISTS (SELECT 1 FROM ibis.subject_component sc
WHERE sc.assessment_method_id = 11
AND ccr.split_session_year=sc.year
AND ccr.split_session_month=sc.month
AND ccr.paper_code=sc.paper_code
AND ccr.subject=sc.subject
AND ccr.subject_option=sc.subject_option
AND ccr.lvl=sc.lvl
AND ccr.language=sc.language
AND ccr.component=sc.component)
AND EXISTS (SELECT 1 FROM ibis.cw_portfolio_template cpt
WHERE ccr.split_session_year = cpt.year
AND ccr.split_session_month = cpt.month
AND ccr.subject = cpt.subject
AND ccr.subject_option = cpt.subject_option
AND ccr.component = cpt.component
AND cpt.combined = 'Y')));
explain plan
line 1: SQLPLUS Command Skipped: set linesize 130
line 2: SQLPLUS Command Skipped: set pagesize 0
PLAN_TABLE_OUTPUT
Plan hash value: 2594643366
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 2 | 1036 | 34 (3)| 00:00:01 |
|* 1 | FILTER | | | | | |
|* 2 | HASH JOIN OUTER | | 2 | 1036 | 34 (3)| 00:00:01 |
| 3 | VIEW | | 2 | 974 | 32 (0)| 00:00:01 |
| 4 | CONCATENATION | | | | | |
|* 5 | FILTER | | | | | |
|* 6 | TABLE ACCESS BY INDEX ROWID | CANDIDATE_SUBJECT_REGISTRATION | 1 | 58 | 3 (0)| 00:00:01 |
| 7 | NESTED LOOPS | | 1 | 485 | 16 (0)| 00:00:01 |
| 8 | NESTED LOOPS | | 1 | 427 | 13 (0)| 00:00:01 |
| 9 | NESTED LOOPS | | 1 | 357 | 11 (0)| 00:00:01 |
| 10 | NESTED LOOPS | | 1 | 129 | 8 (0)| 00:00:01 |
| 11 | NESTED LOOPS | | 1 | 80 | 5 (0)| 00:00:01 |
|* 12 | INDEX RANGE SCAN | PK_EXAMINER_MODERATOR_ALLOC | 1 | 39 | 3 (0)| 00:00:01 |
|* 13 | INDEX RANGE SCAN | RFL_EP1 | 1 | 41 | 2 (0)| 00:00:01 |
| 14 | TABLE ACCESS BY INDEX ROWID| CANDIDATE_EXAMINER_ALLOCATION | 1 | 49 | 3 (0)| 00:00:01 |
|* 15 | INDEX RANGE SCAN | CANDIDATE_ALLOCATION_EXAMINER | 1 | | 2 (0)| 00:00:01 |
|* 16 | TABLE ACCESS BY INDEX ROWID | CANDIDATE_COMPONENT_REG | 1 | 228 | 3 (0)| 00:00:01 |
|* 17 | INDEX RANGE SCAN | SPLIT_SESSION_CANDIDATE | 1 | | 2 (0)| 00:00:01 |
| 18 | TABLE ACCESS BY INDEX ROWID | CANDIDATE | 1 | 70 | 2 (0)| 00:00:01 |
|* 19 | INDEX UNIQUE SCAN | CANDIDATE_PK | 1 | | 1 (0)| 00:00:01 |
|* 20 | INDEX RANGE SCAN | Y_M_CAND_SUBJ_LVL_OPTION | 1 | | 2 (0)| 00:00:01 |
|* 21 | FILTER | | | | | |
|* 22 | TABLE ACCESS BY INDEX ROWID | CANDIDATE_SUBJECT_REGISTRATION | 1 | 58 | 3 (0)| 00:00:01 |
| 23 | NESTED LOOPS | | 1 | 485 | 16 (0)| 00:00:01 |
| 24 | NESTED LOOPS | | 1 | 427 | 13 (0)| 00:00:01 |
| 25 | NESTED LOOPS | | 1 | 357 | 11 (0)| 00:00:01 |
| 26 | NESTED LOOPS | | 1 | 129 | 8 (0)| 00:00:01 |
| 27 | NESTED LOOPS | | 1 | 80 | 5 (0)| 00:00:01 |
|* 28 | INDEX RANGE SCAN | PK_EXAMINER_MODERATOR_ALLOC | 1 | 39 | 3 (0)| 00:00:01 |
|* 29 | INDEX RANGE SCAN | RFL_EP1 | 1 | 41 | 2 (0)| 00:00:01 |
| 30 | TABLE ACCESS BY INDEX ROWID| CANDIDATE_EXAMINER_ALLOCATION | 1 | 49 | 3 (0)| 00:00:01 |
|* 31 | INDEX RANGE SCAN | CANDIDATE_ALLOCATION_EXAMINER | 1 | | 2 (0)| 00:00:01 |
|* 32 | TABLE ACCESS BY INDEX ROWID | CANDIDATE_COMPONENT_REG | 1 | 228 | 3 (0)| 00:00:01 |
|* 33 | INDEX RANGE SCAN | SPLIT_SESSION_CANDIDATE | 1 | | 2 (0)| 00:00:01 |
| 34 | TABLE ACCESS BY INDEX ROWID | CANDIDATE | 1 | 70 | 2 (0)| 00:00:01 |
|* 35 | INDEX UNIQUE SCAN | CANDIDATE_PK | 1 | | 1 (0)| 00:00:01 |
|* 36 | INDEX RANGE SCAN | Y_M_CAND_SUBJ_LVL_OPTION | 1 | | 2 (0)| 00:00:01 |
|* 37 | INDEX RANGE SCAN | EXAM_SAMP_MARK_ADD_IOT_PK | 36 | 1116 | 1 (0)| 00:00:01 |
|* 38 | TABLE ACCESS BY INDEX ROWID | CW_PORTFOLIO_TEMPLATE | 1 | 46 | 4 (0)| 00:00:01 |
|* 39 | INDEX RANGE SCAN | YEAR_MON_PORTFOLIO_TEMPLATE | 1 | | 3 (0)| 00:00:01 |
|* 40 | TABLE ACCESS BY INDEX ROWID | SCHOOL_SAMPLE_MARK | 1 | 34 | 4 (0)| 00:00:01 |
|* 41 | INDEX RANGE SCAN | CAND_PAPER_YEAR_MONTH | 1 | | 3 (0)| 00:00:01 |
|* 42 | TABLE ACCESS BY INDEX ROWID | SUBJECT_COMPONENT | 1 | 96 | 4 (0)| 00:00:01 |
|* 43 | INDEX RANGE SCAN | SUBJECT_COMPONENT_PK | 1 | | 3 (0)| 00:00:01 |
|* 44 | TABLE ACCESS BY INDEX ROWID | CW_PORTFOLIO_TEMPLATE | 1 | 46 | 4 (0)| 00:00:01 |
|* 45 | INDEX RANGE SCAN | YEAR_MON_PORTFOLIO_TEMPLATE | 1 | | 3 (0)| 00:00:01 |
|* 46 | TABLE ACCESS BY INDEX ROWID | SUBJECT_COMPONENT | 1 | 87 | 4 (0)| 00:00:01 |
|* 47 | INDEX RANGE SCAN | SUBJECT_COMPONENT_PK | 1 | | 3 (0)| 00:00:01 |
|* 48 | TABLE ACCESS BY INDEX ROWID | SUBJECT_COMPONENT | 1 | 87 | 4 (0)| 00:00:01 |
|* 49 | INDEX RANGE SCAN | SUBJECT_COMPONENT_PK | 1 | | 3 (0)| 00:00:01 |
|* 50 | TABLE ACCESS BY INDEX ROWID | CW_PORTFOLIO_TEMPLATE | 1 | 46 | 4 (0)| 00:00:01 |
|* 51 | INDEX RANGE SCAN | YEAR_MON_PORTFOLIO_TEMPLATE | 1 | | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter("from$_subquery$_011"."SAMPLED"='Y' AND "from$_subquery$_011"."SELF_TAUGHT"='N' AND NOT EXISTS
(SELECT /*+ */ 0 FROM "IBIS"."CW_PORTFOLIO_TEMPLATE" "CPT" WHERE "CPT"."COMPONENT"=:B1 AND
"CPT"."SUBJECT_OPTION"=:B2 AND "CPT"."SUBJECT"=:B3 AND "CPT"."MONTH"=:B4 AND "CPT"."YEAR"=:B5 AND
"CPT"."COMBINED"='Y') AND NOT EXISTS (SELECT /*+ */ 0 FROM "IBIS"."SCHOOL_SAMPLE_MARK" "SSM" WHERE
"SSM"."MONTH"=:B6 AND "SSM"."YEAR"=:B7 AND "SSM"."PAPER_CODE"=:B8 AND "SSM"."CANDIDATE"=:B9 AND
"SSM"."EXAMINER_SAMPLE"='Y') AND EXISTS (SELECT /*+ */ 0 FROM "IBIS"."SUBJECT_COMPONENT" "SC" WHERE
"SC"."COMPONENT"=:B10 AND "SC"."SUBJECT_OPTION"=:B11 AND "SC"."LANGUAGE"=:B12 AND "SC"."LVL"=:B13 AND
"SC"."SUBJECT"=:B14 AND "SC"."MONTH"=:B15 AND "SC"."YEAR"=:B16 AND "SC"."PAPER_CODE"=:B17 AND
"SC"."ASSESSMENT_METHOD_ID"=11 AND "SC"."ASSESSMENT_TYPE"='INTERNAL') OR "from$_subquery$_011"."SAMPLED"='N'
AND "from$_subquery$_011"."SELF_TAUGHT"='Y' AND NOT EXISTS (SELECT /*+ */ 0 FROM
"IBIS"."CW_PORTFOLIO_TEMPLATE" "CPT" WHERE "CPT"."COMPONENT"=:B18 AND "CPT"."SUBJECT_OPTION"=:B19 AND
"CPT"."SUBJECT"=:B20 AND "CPT"."MONTH"=:B21 AND "CPT"."YEAR"=:B22 AND "CPT"."COMBINED"='Y') AND EXISTS (SELECT
/*+ */ 0 FROM "IBIS"."SUBJECT_COMPONENT" "SC" WHERE "SC"."COMPONENT"=:B23 AND "SC"."SUBJECT_OPTION"=:B24 ANDEdited byCan you please post the following scripts:
1. Tables structure (with all indexes & constraints)
2. Tables data
3. SQL trace file
possibly everything that one can need to regenerate the scenario on his own DB...
OR
spend some time with Oracle Docs on Performance Tuning and then resolve it yourself.
Regards,
Ankit Rathi
http://theoraclelog.blogspot.in -
How to write the select query with complex where condition
Hi all,
Can u help me in writing following select query.
select * from zu1cd_corr where time_stamp between firstday and lastday .
In the above query time_stamp contains the date and time.
where as firstday and lastday contains the dates.
I need to compare the date in the time_stamp with the firstday and lastday.
But time_stamp contains the time also and it is char of 14 characters length.Hi,
If that is the case u can do as advait specified....
if the firstday and secondday are select-options then declare two more variables having 14 character length and then concatenate '000000' to firstday variable and '240000' to last day variable and then write ur query.
CLEAR : lv_firstday,
lv_lastday.
concatenate firstday '000000' to lv_firstday.
concatenate lastday '240000' to lv_lastday.
ranges : r_Date for zu1cd_corr-time_stamp.
r_date-sign = 'I'.
r_date-option = 'BT'.
r_Date-low = lv_firstday.
r_Date-high = lv_lastday.
append r_date.
select * from zu1cd_corr into table it_zu1cd_corr where time_stamp in r_Date.
I hope it helps.
Regards,
Nagaraj -
Need urgent help with the query - Beginer
Hello - I need help with a query to populate data in a table.Here is the scenario.
Source1
MnthID BranchCod CustID SegCode FXStatus ProfStatus Profit
200712 B1 C1 20 Y Y 100
Source2
MnthID BranchCod CustID ProdCode ProdIndex
200712 B1 C1 12 1
200712 B1 C2 12 0
Destination
MnthID BranchCod SegCode ProdCode CountSegCust CountProdCust ProfitProdCust
Condition and Calculations:
1)Source1 customer are base customers.If Source2 has customers who is not in source1 then that customer's record should not be fetched.
2)SegCode, FX Status, ProfStatus is one variable in destination table. [ SegCode = SegCode+ FXStatus (if FXStatus = Y)+ ProfStatus (if FXStatus = Y) ]
3)CountSegCust = CountCustID Groupby MnthID,BranchCod,SegCode Only.
4)CountProdCust = CountCustID Groupby MnthID,BranchCod,SegCode,ProdCode (when ProdIndex = 1)
5)ProfitProdCust = Sum of Profit of Customers Groupby MnthID,BranchCod,SegCode,ProdCode (when ProdIndex = 1)
Apologies for bad formatting.
Thanks in advance!!A total guess indeed.
It's not clear whether some aggregation can be done (summing counts of grouped data might cause some customers being counted more than once)
insert into destination
select mnthid,branchcod,segcode,prodcode,countsegcust,countprodcust,profitprodcust
from (select s1.mnthid,
s1.branchcod,
s1.segcode || case s1.fxstatus when 'Y' then s1.fxstatus || s1.profstatus end segcode,
s2.prodcode,
count(s1.custid) over (partition by s1.mnthid,
s1.branchcod,
s1.segcode || case s1.fxstatus when 'Y' then s1.fxstatus || s1.profstatus end
order by null
) countsegcust,
count(case proindex when 1
then custid
end
) over (partition by s1.mnthid,
s1.branchcod,
s1.segcode || case s1.fxstatus when 'Y' then s1.fxstatus || s1.profstatus end
s2.prodcode
order by null
) countprodcust,
sum(case proindex when 1
then profit
end
) over (partition by s1.mnthid,
s1.branchcod,
s1.segcode || case s1.fxstatus when 'Y' then s1.fxstatus || s1.profstatus end
s2.prodcode
order by null
) profitprodcust,
row_number() over (partition by s1.mnthid,
s1.branchcod,
s1.segcode || case s1.fxstatus when 'Y' then s1.fxstatus || s1.profstatus end
s2.prodcode
order by null
) the_row
from source1 s1,source2 s2
where s1.mnthid = s2.mnthid
and s1.branchcod = s2.branchcod
and s1.custid = s2.custid
where the_row = 1Regards
Etbin
Maybe you are looking for
-
Is it possible to set up a Playlist of suggested tracks for another person to buy?
I am interested in sharing a list of songs with my students as suggested songs to purchase. I typically have to go to each album and send a link to that album. Is it possible to put a list together and somehow suggest that as a group of songs at on
-
Break Points while remote debugging not working in Eclipse
I have set up my tomcat to listen for debugger connections on the default pot 8000. Now when I set break points in the code, it does not show the execution stop at that particular line. Now why would that be? Am I missing somethiing? I have built the
-
My administrator account was set to standard?
So I just got a brand new macbook pro about 4 months ago. It was working perfectly, until last night everything froze and stopped responding, so I restarted my computer. But when it restarted it took forever to reboot and when it finally did it just
-
Problem with custom UINavigationItem
Hello, when I pass animated:NO to UINavigationController pushViewController, my custom navigation item (setup in my nib) doesn't show up. I'm trying to do a flip animation as follows: MyController* ctrl = [[MyController alloc] initWithNibName:@"MyNib
-
Problems reading reviews in App Store
Hi, Whenever I go to the app store and either click on the review title or the "More" button to read the review in full, I get the following error message: "The item you've requested is not currently available in the UK Store" Surely reviews should n