Help with APP_USER in SQL query
HelloI would like to extract a detail of the user in a form of language element DML based on the logged in user and the standard authentication scheme.
I make this request in the element:
select ANALYST_FIRST_NAME ||' '|| ANALYST_LAST_NAME d, ANALYST_ID r from QTMT_ANALYST where EMAIL = :APP_USER
The user in the session is equal to the value of the EMAIL. In fact, the value in the session is a capital letter, and the other in the database is tiny. I think that's irrelevant anyway.The query do not of any value. Could you please let me know what I did wrong?
APEX: 4.2
Item Source type: query SQL (single return value)
Thank you and best regards,
Vladimir
To be on the safe side you should uppercase both sides of the equation. It could be that the user name is entered in lowercase.
But if you think that your request is correct, test it by using a literal rather than the user name.
select ANALYST_FIRST_NAME ||' '|| ANALYST_LAST_NAME d
from QTMT_ANALYST
where upper(EMAIL) = upper(:APP_USER);
for testing purposes, use something like this:
select ANALYST_FIRST_NAME ||' '|| ANALYST_LAST_NAME d
from QTMT_ANALYST
where upper(EMAIL) = upper('[email protected]');
Published by: Sven w. October 23, 2012 13:30
APEX: 4.2
Item Source type: SQL Query ( return a single value )
I just noticed that you use an element that has this as the SQL source. This only works if the sql returns a row and a column only. That's why I removed the second column in your query.
Published by: Sven w. October 23, 2012 13:33
Tags: Database
Similar Questions
-
Help with an advanced SQL query
I have a table with standard lengths of material. (tblStdLength)
In another table are the lengths in stock to matter. (tblOnStock)
I would like to match these two tables on the amount of the stock of standard lengths, you stock in the table.
If the length is greater than the nearest standard length, the trail of the excess up to the closest standradlangd if there is a X 'CUP field.
However, I have encountered a problem and cannot solve this...
Ex:
Material cable23 have 4 standard lengths in the tblStdLength Table:
{code}
Material StdLength
----------------------------------------------------
Cable23 | 2000
Cable23 | 4000
Cable23 | 6000
Cable23 | 8000
Cable23 materials have the following lengths in stock in the tblOnStock Table:
Factor important length TotalQty Cup
-----------------------------------------------------------------------------------------------------------------------------
Cable23 | 1 | 383. 383.
Cable23 | 1 | 424. 424.
Cable23 | 1 | 998. 998.
Cable23 | 1 | 1000 | 1000 |
Cable23 | 3 | 4000 | 12000 | X
Cable23 | 1 | 4234. 4234. X
{code}
In this mode, the lengths of 12000 + 4000 must include in the calculation of the total stock of standard lengths.
The answer should be 16000.
4000, he gets to 4234. It has X on the field of 'Cut', then it round down to the nearest Stud.
How can I be better? I hope that I have explained so you understand...Hello
Did you mean this
with tblStd as ( select Material , stdlength , lead(stdlength) over (partition by material order by stdlength) hstdlength from tblStdlength ) select t.Material , sum(floor(s.totalqty/t.stdlength)*t.stdlength) tot_quantity from tblStd t, tblonstock s where t.material=s.material and s.length >= t.stdlength and (s.length< t.hstdlength or t.hstdlength is null) and (s.cut = 'X' or s.length=t.stdlength) group by t.material
Concerning
Anurag -
performance issue with the Oracle SQL query
Dears
Good evening
I am new to begin to use Oracle SQL, I have a sql query which takes longer to run in production.
Each table in the query contains 1.2 million records and DBA suggested using the "Oracle - tips. I don't have good knowledge on this subject and the difficulties to implement this advice for imrpovise performance. In the product the jobs Informatica are failed and stuck with this problem of query performance.
I ask this forum for an emergency for me to solve this problem by using "advice". kindly help me.
SELECT
CASE.ID,
CASE. DTYPE,
CASE. Version
CASE. EXTERNAL_REF,
CASE. CREATION_TS,
RQ. TYPE
Of
PAS_CASE CASE,
AS_REQUEST RQ,
CN PAS_CONTEXT
where rq.case_id = case.id
AND rq.id = cn.request_id
and rq. DTYPE = "MAINREQUEST."
and rq. TYPE in
(
'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.
'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.)
and CN. STATUS ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')
AND CAST (CN. CREATION_TS AS DATE) > = TO_DATE ('2014-05-06 00:00:00 ',' ' YYYY-MM-DD HH24:MI:SS)
AND
CAST (CN. CREATION_TS AS DATE) < TO_DATE ('2014-05-06 23:59:59 ',' ' YYYY-MM-DD HH24:MI:SS)-2nd request
SELECT
RA.ID,
RHEUMATOID ARTHRITIS. Version
RHEUMATOID ARTHRITIS. REQUEST_ID,
RA.NAME,
RHEUMATOID ARTHRITIS. VALUE,
RHEUMATOID ARTHRITIS. LOB_ID,
RHEUMATOID ARTHRITIS. DTYPE,
RHEUMATOID ARTHRITIS. CREATION_TS,
TASK. MAIN_REQ_TYPE
PAS_REQUESTATTRIBUTE RA
Join
(
Select tsk.ID, tsk. TYPE, main_req_type main_req.
of tsk PAS_REQUEST
Join
(
Select cn.id as context_id, rq. TYPE main_req_type
of PAS_REQUEST rq
Cn PAS_CONTEXT
where rq.id = cn.request_id
and rq. DTYPE = "MAINREQUEST."
and rq. TYPE in
(
'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.
'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.
)
and cn. STATUS ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')
and CAST (cn. END_TS AS DATE) > = TO_DATE ('2014-05-06 00:00:00 ',' ' YYYY-MM-DD HH24:MI:SS)
and CAST (cn. END_TS AS DATE) < = TO_DATE ('2014-05-06 23:59:59 ',' ' YYYY-MM-DD HH24:MI:SS)
and cn.ID between the 20141999999999999 AND 20141800000000000
and rq.ID between the 20141999999999999 AND 20141800000000000) main_req
On tsk.parent_context_id = main_req.context_id
and tsk. DTYPE in ('ANALYSIS_TASK', 'DECISION_TASK')
and tsk.ID between $$ LOW_ID1 AND $$ HIGH_ID1
) task
on the RA REQUEST_ID = task.ID
and RA.ID between $$ LOW_ID1 AND $$ HIGH_ID1
UNIONSELECT
RA.ID,
RHEUMATOID ARTHRITIS. Version
RHEUMATOID ARTHRITIS. REQUEST_ID,
RA.NAME,
RHEUMATOID ARTHRITIS. VALUE,
RHEUMATOID ARTHRITIS. LOB_ID,
RHEUMATOID ARTHRITIS. DTYPE,
RHEUMATOID ARTHRITIS. CREATION_TS,
MAIN_REQ. TYPE
PAS_REQUESTATTRIBUTE RA
Join
(
Select rq.id, rq.type
of PAS_REQUEST rq
Cn PAS_CONTEXT
where rq.id = cn.request_id
and rq. DTYPE = "MAINREQUEST."
and rq. TYPE in
(
'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.
'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.
)
and cn. STATUS ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')
and CAST (cn. END_TS AS DATE) > = TO_DATE ('2014-05-06 00:00:00 ',' ' YYYY-MM-DD HH24:MI:SS)
and CAST (cn. END_TS AS DATE) < = TO_DATE ('2014-05-06 23:59:59 ',' ' YYYY-MM-DD HH24:MI:SS)
and cn.ID between the 20141999999999999 AND 20141800000000000
and rq.ID between the 20141999999999999 AND 20141800000000000
) main_req
on the RA REQUEST_ID = main_req.ID-3rd request
SELECT
RB.ID,
RB. DTYPE,
RB. Version
RB. TYPE,
RB. CREATION_TS,
RB. TASK_ID,
RB. Color
RB. GLOBAL_RESULT,
TASK. MAIN_REQ_TYPE
Of
PAS_RESULTBLOCK RB
Join
(
Select tsk.ID, tsk. TYPE, main_req_type main_req.
of tsk PAS_REQUEST
Join
(
Select cn.id as context_id, rq. TYPE main_req_type
of PAS_REQUEST rq
Cn PAS_CONTEXT
where rq.id = cn.request_id
and rq. DTYPE = "MAINREQUEST."
and rq. TYPE in
(
'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.
'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.
)
and cn. STATUS ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')
and CAST (cn. END_TS AS DATE) > = TO_DATE ('2014-05-06 00:00:00 ',' ' YYYY-MM-DD HH24:MI:SS)
and CAST (cn. END_TS AS DATE) < = TO_DATE ('2014-05-06 23:59:59 ',' ' YYYY-MM-DD HH24:MI:SS)
and cn.ID between the 20141999999999999 AND 20141800000000000
and rq.ID between the 20141999999999999 AND 20141800000000000
) main_req
On tsk.parent_context_id = main_req.context_id
and tsk. DTYPE in ('ANALYSIS_TASK', 'DECISION_TASK')
and tsk.ID between $$ LOW_ID1 AND $$ HIGH_ID1
) task
We rb.task_id = task.ID
and rb.ID between $$ LOW_ID1 AND $$ HIGH_ID1
and RB. TYPE is not null
and RB. TYPE IN
(
'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.
'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.
)
UNION
SELECT
RB.ID,
RB. DTYPE,
RB. Version
RB. TYPE,
RB. CREATION_TS,
RB. TASK_ID,
RB. Color
RB. GLOBAL_RESULT,
TASK. MAIN_REQ_TYPE
Of
PAS_RESULTBLOCK RB
Join
(
Select tsk.ID, tsk. TYPE, main_req_type main_req.
of tsk PAS_REQUEST
Join
(
Select cn.id as context_id, rq. TYPE main_req_type
of PAS_REQUEST rq
Cn PAS_CONTEXT
where rq.id = cn.request_id
and rq. DTYPE = "MAINREQUEST."
and rq. TYPE in
(
'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.
'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.
)
and cn. STATUS ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')
and CAST (cn. END_TS AS DATE) > = TO_DATE ('2014-05-06 00:00:00 ',' ' YYYY-MM-DD HH24:MI:SS)
and CAST (cn. END_TS AS DATE) < = TO_DATE ('2014-05-06 23:59:59 ',' ' YYYY-MM-DD HH24:MI:SS)
and cn.ID between the 20141999999999999 AND 20141800000000000
and rq.ID between the 20141999999999999 AND 20141800000000000
) main_req
On tsk.parent_context_id = main_req.context_id
and tsk. DTYPE in ('ANALYSIS_TASK', 'DECISION_TASK')
and tsk.ID between $$ LOW_ID1 AND $$ HIGH_ID1
) task
We rb.task_id = task.ID
and rb.ID between $$ LOW_ID1 AND $$ HIGH_ID1
and RB. TYPE is nullSELECT
RB.ID,
RB. DTYPE,
RB. Version
RB. TYPE,
RB. CREATION_TS,
RB. TASK_ID,
RB. Color
RB. GLOBAL_RESULT,
TASK. MAIN_REQ_TYPE
Of
PAS_RESULTBLOCK RB
Join
(
Select tsk.ID, tsk. TYPE, main_req_type main_req.
of tsk PAS_REQUEST
Join
(
Select cn.id as context_id, rq. TYPE main_req_type
of PAS_REQUEST rq
Cn PAS_CONTEXT
where rq.id = cn.request_id
and rq. DTYPE = "MAINREQUEST."
and rq. TYPE in
(
'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.
'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.
)
and cn. STATUS ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')
and CAST (cn. END_TS AS DATE) > = TO_DATE ('2014-05-06 00:00:00 ',' ' YYYY-MM-DD HH24:MI:SS)
and CAST (cn. END_TS AS DATE) < = TO_DATE ('2014-05-06 23:59:59 ',' ' YYYY-MM-DD HH24:MI:SS)
and cn.ID between the 20141999999999999 AND 20141800000000000
and rq.ID between the 20141999999999999 AND 20141800000000000
) main_req
On tsk.parent_context_id = main_req.context_id
and tsk. DTYPE in ('ANALYSIS_TASK', 'DECISION_TASK')
and tsk.ID between $$ LOW_ID1 AND $$ HIGH_ID1
) task
We rb.task_id = task.ID
and rb.ID between $$ LOW_ID1 AND $$ HIGH_ID1
and RB. TYPE is not null
and RB. TYPE IN
(
'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.
'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.
)
UNION
SELECT
RB.ID,
RB. DTYPE,
RB. Version
RB. TYPE,
RB. CREATION_TS,
RB. TASK_ID,
RB. Color
RB. GLOBAL_RESULT,
TASK. MAIN_REQ_TYPE
Of
PAS_RESULTBLOCK RB
Join
(
Select tsk.ID, tsk. TYPE, main_req_type main_req.
of tsk PAS_REQUEST
Join
(
Select cn.id as context_id, rq. TYPE main_req_type
of PAS_REQUEST rq
Cn PAS_CONTEXT
where rq.id = cn.request_id
and rq. DTYPE = "MAINREQUEST."
and rq. TYPE in
(
'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.
'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.
)
and cn. STATUS ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')
and CAST (cn. END_TS AS DATE) > = TO_DATE ('2014-05-06 00:00:00 ',' ' YYYY-MM-DD HH24:MI:SS)
and CAST (cn. END_TS AS DATE) < = TO_DATE ('2014-05-06 23:59:59 ',' ' YYYY-MM-DD HH24:MI:SS)
and cn.ID between the 20141999999999999 AND 20141800000000000
and rq.ID between the 20141999999999999 AND 20141800000000000
) main_req
On tsk.parent_context_id = main_req.context_id
and tsk. DTYPE in ('ANALYSIS_TASK', 'DECISION_TASK')
and tsk.ID between $$ LOW_ID1 AND $$ HIGH_ID1
) task
We rb.task_id = task.ID
and rb.ID between $$ LOW_ID1 AND $$ HIGH_ID1
and RB. TYPE is null
-4th query
SELECT
RI.ID,
UII DTYPE,
UII Version
UII RESULTBLOCK_ID,
RI.NAME,
UII VALUE,
UII UNIT,
UII Color
UII LOB_ID,
UII CREATION_TS,
UII SEQUENCE,
UII DETAILLEVEL,
RES_BLK. MAIN_REQ_TYPE
Of
RI PAS_RESULTITEM
Join
(
Select
rb.ID, rb. TYPE rb_type, task. TYPE as the task_type, task. pas_resultblock rb main_req_type
Join
(
Select tsk.ID, tsk. TYPE, main_req_type main_req.
of tsk PAS_REQUEST
Join
(
Select cn.id as context_id, rq. TYPE main_req_type
of PAS_REQUEST rq
Cn PAS_CONTEXT
where rq.id = cn.request_id
and rq. DTYPE = "MAINREQUEST."
and rq. TYPE in
(
'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.
'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.
)
and cn. STATUS ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')
and CAST (cn. END_TS AS DATE) > = TO_DATE ('2014-05-06 00:00:00 ',' ' YYYY-MM-DD HH24:MI:SS)
and CAST (cn. END_TS AS DATE) < = TO_DATE ('2014-05-06 23:59:59 ',' ' YYYY-MM-DD HH24:MI:SS)
and cn.ID between the 20141999999999999 AND 20141800000000000
and rq.ID between the 20141999999999999 AND 20141800000000000
) main_req
On tsk.parent_context_id = main_req.context_id
and tsk. DTYPE in ('ANALYSIS_TASK', 'DECISION_TASK')
and tsk.ID between the 20141999999999999 AND 20141800000000000
) task
We rb.task_id = task.ID
and rb.ID between the 20141999999999999 AND 20141800000000000
and RB. TYPE IN
(
'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.
'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.
)
) res_blk
On ri.resultblock_id = res_blk.ID
where IN RI.NAME
(
'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.
'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.
)
and RI.ID between the 20141999999999999 AND 20141800000000000
and RI.NAME is not null
UNIONSelect
RI.ID,
UII DTYPE,
UII Version
UII RESULTBLOCK_ID,
RI.NAME,
UII VALUE,
UII UNIT,
UII Color
UII LOB_ID,
UII CREATION_TS,
UII SEQUENCE,
UII DETAILLEVEL,
RES_BLK. MAIN_REQ_TYPE
of pas_resultitem ri
Join
(
Select
rb.ID, rb. TYPE rb_type, task. TYPE as the task_type, task. pas_resultblock rb main_req_type
Join
(
Select tsk.ID, tsk. TYPE, main_req_type main_req.
of tsk PAS_REQUEST
Join
(
Select cn.id as context_id, rq. TYPE main_req_type
of PAS_REQUEST rq
Cn PAS_CONTEXT
where rq.id = cn.request_id
and rq. DTYPE = "MAINREQUEST."
and rq. TYPE in
(
'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.
'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.
)
and cn. STATUS ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')
and CAST (cn. END_TS AS DATE) > = TO_DATE ('2014-05-06 00:00:00 ',' ' YYYY-MM-DD HH24:MI:SS)
and CAST (cn. END_TS AS DATE) < = TO_DATE ('2014-05-06 23:59:59 ',' ' YYYY-MM-DD HH24:MI:SS)
and cn.ID between the 20141999999999999 AND 20141800000000000
and rq.ID between the 20141999999999999 AND 20141800000000000
) main_req
On tsk.parent_context_id = main_req.context_id
and tsk. DTYPE in ('ANALYSIS_TASK', 'DECISION_TASK')
and tsk.ID between the 20141999999999999 AND 20141800000000000
) task
We rb.task_id = task.ID
and rb.ID between the 20141999999999999 AND 20141800000000000
) res_blk
On ri.resultblock_id = res_blk.ID
where RI.ID between 20141800000000000 20141999999999999 AND
and RI.NAME is null-REQUEST OF 5HT
SELECT
TSK.ID,
TSK. Version
TSK. DTYPE,
TSK. CASE_ID,
TSK. TYPE,
TSK. CORRELATION_ID,
TSK. INITIATOR,
TSK. EXECUTOR,
TSK. CATEGORY,
TSK. PARENT_CONTEXT_ID,
TSK. CREATION_TS,
MAIN_REQ. MAIN_REQ_TYPE
Of
TSK PAS_REQUEST
Join
(
Select cn.id as context_id, rq. TYPE main_req_type
of PAS_REQUEST rq
Cn PAS_CONTEXT
where rq.id = cn.request_id
and rq. DTYPE = "MAINREQUEST."
and rq. TYPE in
(
'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.
'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.
)
and cn. STATUS ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')
and CAST (cn. END_TS AS DATE) > = TO_DATE ('2014-05-06 00:00:00 ',' ' YYYY-MM-DD HH24:MI:SS)
and CAST (cn. END_TS AS DATE) < = TO_DATE ('2014-05-06 23:59:59 ',' ' YYYY-MM-DD HH24:MI:SS)
and cn.ID between the 20141999999999999 AND 20141800000000000
and rq.ID between the 20141999999999999 AND 20141800000000000
) main_req
On tsk.parent_context_id = main_req.context_id
and tsk. DTYPE in ('ANALYSIS_TASK', 'DECISION_TASK')
and tsk.ID between $$ LOW_ID1 AND $$ HIGH_ID1
UNION
Select
MREQ.ID,
MREQ. Version
MREQ. DTYPE,
MREQ. CASE_ID,
MREQ. TYPE,
MREQ. CORRELATION_ID,
MREQ. INITIATOR,
MREQ. EXECUTOR,
MREQ. CATEGORY,
MREQ. PARENT_CONTEXT_ID,
MREQ. CREATION_TS,
MREQ. TYPE
of PAS_REQUEST mreq
Cn PAS_CONTEXT
where mreq.id = cn.request_id
and mreq. DTYPE = "MAINREQUEST."
and mreq. TYPE in
(
'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.
'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.
)
and cn. STATUS ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')
and CAST (cn. END_TS AS DATE) > = TO_DATE ('2014-05-06 00:00:00 ',' ' YYYY-MM-DD HH24:MI:SS)
and CAST (cn. END_TS AS DATE) < = TO_DATE ('2014-05-06 23:59:59 ',' ' YYYY-MM-DD HH24:MI:SS)
and cn.ID between the 20141999999999999 AND 20141800000000000
and mreq.ID between the 20141999999999999 AND 20141800000000000
Tips will be may not be necessary (proportional to the cardinalities need)
Select pc.id, pc.dtype, pc.version, pc.external_ref, pc.creation_ts, rq.type
from pas_case
as_request rq,
CN pas_context
where rq.case_id = pc.id
and rq.id = cn.request_id
and rq.dtype = 'MAINREQUEST. '
and rq.type in ('bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution', ' bgc.tbf.repair.vap',
'bgc.dar.e2etest ',' bgc.dar.e2etest.intermediate.execution', ' bgc.cbm ',.
'bgc.dar.e2etest.preparation ','bgc.chc.polling '.
)
and cn.status in ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')
and cn.creation_ts > = to_timestamp ('2014-05-06 00:00:00 ',' yyyy-mm-dd hh24:mi:ss')
and cn.creation_ts<= to_timestamp('2014-05-06="" 23:59:59.999999','yyyy-mm-dd="">=>
-2nd request
with
main_request as
(select / * + materialize * /)
CN.ID as context_id, rq.type as main_req_type
of pas_request rq
Join
CN pas_context
On rq.id = cn.request_id
and rq.dtype = 'MAINREQUEST. '
and rq.type in ('bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution', ' bgc.chc.polling',
'bgc.tbf.repair.vap ',' bgc.dar.e2etest', ' bgc.dar.e2etest.intermediate.execution ',.
'bgc.cbm ','bgc.dar.e2etest.preparation '.
)
and cn.status in ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')
and cn.end_ts > = to_timestamp ('2014-05-06 00:00:00 ',' yyyy-mm-dd hh24:mi:ss')
and cn.end_ts<= to_timestamp('2014-05-06="" 23:59:59.999999','yyyy-mm-dd="">=>
and cn.id between 20141800000000000 and 20141999999999999
and rq.id between 20141800000000000 and 20141999999999999
)
Select ra.id, ra.version, ra.request_id, ra.name, ra.value, ra.lob_id, ra.dtype, ra.creation_ts, task.main_req_type
of pas_requestattribute ra
Join
(select tsk.id, tsk.type, main_req.main_req_type
from pas_request tsk
Join
main_request main_req
On tsk.parent_context_id = main_req.context_id
and tsk.dtype in ('ANALYSIS_TASK', 'DECISION_TASK')
and tsk.id between $$ low_id1 and $$ high_id1
) task
We ra.request_id = task.id
and ra.id between $$ low_id1 and $$ high_id1
Union
Select ra.id, ra.version, ra.request_id, ra.name, ra.value, ra.lob_id, ra.dtype, ra.creation_ts, main_req.type
of pas_requestattribute ra
Join
main_request main_req
On ra.request_id = main_req.context_id
-3rd request
Select rb.id, rb.dtype, rb.version, rb.type, rb.creation_ts, rb.task_id, rb.color, rb.global_result, task.main_req_type
of pas_resultblock rb
Join
(select tsk.id, tsk.type, main_req.main_req_type
from pas_request tsk
Join
(select cn.id as context_id, rq.type as main_req_type
of pas_request rq
Join
CN pas_context
On rq.id = cn.request_id
and rq.dtype = 'MAINREQUEST. '
and rq.type in ('bgc.dar.vap.resolution.advice ','bgc.dar.e2etest.execution ',
'bgc.tbf.repair.vap ','bgc.dar.e2etest ',.
'bgc.dar.e2etest.intermediate.execution ','bgc.cbm ',.
'bgc.dar.e2etest.preparation ','bgc.chc.polling '.
)
and cn.status in ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')
and cn.end_ts > = to_timestamp ('2014-05-06 00:00:00 ',' yyyy-mm-dd hh24:mi:ss')
and cn.end_ts<= to_timestamp('2014-05-06="" 23:59:59.999999','yyyy-mm-dd="">=>
and cn.id between 20141800000000000 and 20141999999999999
and rq.id between 20141800000000000 and 20141999999999999
) main_req
On tsk.parent_context_id = main_req.context_id
and tsk.dtype in ('ANALYSIS_TASK', 'DECISION_TASK')
and tsk.id between $$ low_id1 and $$ high_id1
) task
We rb.task_id = task.id
and rb.id between $$ low_id1 and $$ high_id1
where the type is null
or (type is not null
type in ('bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ', ' bgc.tbf.repair.vap',
'bgc.dar.e2etest ',' bgc.dar.e2etest.intermediate.execution', ' bgc.cbm ',.
'bgc.dar.e2etest.preparation ','bgc.chc.polling '.
)
)
-4th query
Select ri.id, ri.dtype, ri.version, ri.resultblock_id, ri.name, ri.value, ri.unit, ri.color, ri.lob_id.
RI.creation_ts, RI. Sequence, RI. DetailLevel, res_blk.main_req_type
of pas_resultitem ri
Join
(select rb.id, rb.type as rb_type, task.type as task_type, task.main_req_type)
of pas_resultblock rb
Join
(select main_req_type, tsk.id, tsk.type, main_req.)
from pas_request tsk
Join
(select cn.id as context_id, rq.type as main_req_type
of pas_request rq
Join
CN pas_context
On rq.id = cn.request_id
and rq.dtype = 'MAINREQUEST. '
and rq.type in ('bgc.dar.vap.resolution.advice ','bgc.dar.e2etest.execution ',
'bgc.tbf.repair.vap ','bgc.dar.e2etest ',.
'bgc.dar.e2etest.intermediate.execution ','bgc.cbm ',.
'bgc.dar.e2etest.preparation ','bgc.chc.polling '.
)
and cn.status in ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')
and cn.end_ts > = to_timestamp ('2014-05-06 00:00:00 ',' yyyy-mm-dd hh24:mi:ss')
and cn.end_ts<= to_timestamp('2014-05-06="" 23:59:59.999999','yyyy-mm-dd="">=>
and cn.id between 20141800000000000 and 20141999999999999
and rq.id between 20141800000000000 and 20141999999999999
) main_req
On tsk.parent_context_id = main_req.context_id
and tsk.dtype in ('ANALYSIS_TASK', 'DECISION_TASK')
and tsk.id between 20141800000000000 and 20141999999999999
) task
We rb.task_id = task.id
and rb.id between 20141800000000000 and 20141999999999999
and rb.type in ('bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution', ' bgc.tbf.repair.vap',
'bgc.dar.e2etest ',' bgc.dar.e2etest.intermediate.execution', ' bgc.cbm ',.
'bgc.dar.e2etest.preparation ','bgc.chc.polling '.
)
) res_blk
On ri.resultblock_id = res_blk.id
and ri.id between 20141800000000000 and 20141999999999999
where ri.name is null
or (ri.name is not null
and ri.name in ('bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution', ' bgc.tbf.repair.vap',
'bgc.dar.e2etest ',' bgc.dar.e2etest.intermediate.execution', ' bgc.cbm ',.
'bgc.dar.e2etest.preparation ','bgc.chc.polling '.
)
)
-5th application
with
main_request as
(select / * + materialize * / )
mreq.ID, mreq.version, mreq.dtype, mreq.case_id, mreq.type, mreq.correlation_id, mreq. Initiator, mreq. Executor,
mreq. Category, mreq.parent_context_id, mreq.creation_ts, mreq.type
of pas_request mreq
Join
CN pas_context
On mreq.id = cn.request_id
and mreq.dtype = 'MAINREQUEST. '
and mreq.type in ('bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution', ' bgc.tbf.repair.vap',
'bgc.dar.e2etest ',' bgc.dar.e2etest.intermediate.execution', ' bgc.cbm ',.
'bgc.dar.e2etest.preparation ','bgc.chc.polling '.
)
and cn.status in ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')
and cn.end_ts > = to_timestamp ('2014-05-06 00:00:00 ',' yyyy-mm-dd hh24:mi:ss')
and cn.end_ts<= to_timestamp('2014-05-06="" 23:59:59.999999','yyyy-mm-dd="">=>
and cn.id between 20141800000000000 and 20141999999999999
and mreq.id between 20141800000000000 and 20141999999999999
)
Select tsk.id, tsk.version, tsk.dtype, tsk.case_id, tsk.type, tsk.correlation_id, tsk.initiator, tsk.executor,
TSK. Category, tsk.parent_context_id, tsk.creation_ts, main_req.main_req_type
from pas_request tsk
Join
main_request main_req
On tsk.parent_context_id = main_req.id
and tsk.dtype in ('ANALYSIS_TASK', 'DECISION_TASK')
and tsk.id between $$ low_id1 and $$ high_id1
Union
SELECT id, version, dtype, case_id, type, correlation_id, initiator, executor,
category, type parent_context_id, creation_ts
of main_request
Concerning
Etbin
-
Help with some PL/SQL triggers
Hello, I'm totally new using PL/SQL, so I need your help with two triggers.
For example
1 compare two dates and check that there are different, you must send an error message
2. when I insert a new record, a trigger must get data from other tables and Add (on a new record)
Maybe not the answers, perhaps the way forward!
Thks!Insert values into a new record of existing data tables
This thing that you can do with simple sql statements as
insert into table_name1 select column_name from table_name2;
For example: -.
create table test(id number(10)); Table created. insert into test select empno from emp; 14 row(s) inserted. select * from test; ID 7839 7698 7782 7566 7788 7902 7369 7499 7521 7654
Thank you
Mezaber
-
Need help to write a SQL query complex
I have the source tabe as below
-> SOURCE_TABLE
I want to load as target table belowNAME CUST_ID SVC_ST_DT SVC_END_DT TOM 1 31/08/2009 23/03/2011 DOCK 2 01/01/2004 31/05/2010 HARRY 3 28/02/2007 31/12/2009
-> TARGET_TABLE
Is it possible to write a SQL query that returns the data in the same way above the target table.NAME CUST_ID SVC_ST_DT SVC_END_DT TOM 1 31/08/2009 31/12/2009 TOM 1 01/01/2010 31/12/2010 TOM 1 01/01/2011 23/03/2011 DOCK 2 01/01/2004 31/12/2004 DOCK 2 01/01/2005 31/12/2005 DOCK 2 01/01/2006 31/12/2006 DOCK 2 01/01/2007 31/12/2007 DOCK 2 01/01/2008 31/12/2008 DOCK 2 01/01/2009 31/12/2009 DOCK 2 01/01/2010 31/05/2010 HARRY 3 28/02/2007 31/12/2007 HARRY 3 01/01/2008 31/12/2008 HARRY 3 01/01/2009 31/12/2009
Published by: AChatterjee on April 30, 2012 07:14
Published by: AChatterjee on April 30, 2012 07:14Or like this...
SQL> ed Wrote file afiedt.buf 1 with t as (select 'TOM' as NAME, 1 as CUST_ID, date '2009-08-31' as SVC_ST_DT, date '2011-03-23' as SVC_END_DT from dual union all 2 select 'DOCK', 2, date '2004-01-01', date '2010-05-31' from dual union all 3 select 'HARRY', 3, date '2007-02-28', date '2009-12-31' from dual) 4 -- 5 -- end of test data 6 -- 7 select name, cust_id, svc_st_dt, svc_end_dt 8 from ( 9 select name 10 ,cust_id 11 ,greatest(svc_st_dt, add_months(trunc(svc_st_dt,'YYYY'),yr*12)) as svc_st_dt 12 ,least(svc_end_dt, add_months(trunc(svc_st_dt,'YYYY'),(yr+1)*12)-1) as svc_end_dt 13 from t 14 cross join (select rownum-1 as yr 15 from dual 16 connect by rownum <= (select extract(year from max(svc_end_dt)) - extract(year from min(svc_st_dt)) + 1 from t) 17 ) 18 ) 19 where svc_st_dt <= svc_end_dt 20* order by 2, 3 SQL> / NAME CUST_ID SVC_ST_DT SVC_END_DT ----- ---------- -------------------- -------------------- TOM 1 31-AUG-2009 00:00:00 31-DEC-2009 00:00:00 TOM 1 01-JAN-2010 00:00:00 31-DEC-2010 00:00:00 TOM 1 01-JAN-2011 00:00:00 23-MAR-2011 00:00:00 DOCK 2 01-JAN-2004 00:00:00 31-DEC-2004 00:00:00 DOCK 2 01-JAN-2005 00:00:00 31-DEC-2005 00:00:00 DOCK 2 01-JAN-2006 00:00:00 31-DEC-2006 00:00:00 DOCK 2 01-JAN-2007 00:00:00 31-DEC-2007 00:00:00 DOCK 2 01-JAN-2008 00:00:00 31-DEC-2008 00:00:00 DOCK 2 01-JAN-2009 00:00:00 31-DEC-2009 00:00:00 DOCK 2 01-JAN-2010 00:00:00 31-MAY-2010 00:00:00 HARRY 3 28-FEB-2007 00:00:00 31-DEC-2007 00:00:00 HARRY 3 01-JAN-2008 00:00:00 31-DEC-2008 00:00:00 HARRY 3 01-JAN-2009 00:00:00 31-DEC-2009 00:00:00 13 rows selected.
-
Need help to build the SQL query
Hi all
I struggle to create the select statement.
This is my expected outcome:
Insert into tmp (aa, bb, cc, dd)
values('CUST1','10100001',2,'10-Jan-2013');
Insert into tmp (aa, bb, cc, dd)
values('CUST1','10100002',4,'11-Jan-2013');
Insert into tmp (aa, bb, cc, dd)
values('CUST2','10200001',2,'19-Jan-2013');
Insert into tmp (aa, bb, cc, dd)
values('CUST2','10200002',6,'28-Jan-2013');
Insert into tmp (aa, bb, cc, dd)
values('CUST2','10200003',1,'28-Mar-2013');
My result is:
AA COUNT (1) MAX (DD) by cc dd AA AA
CUST1 2 10100002 4 11 January 2013
CUST2 3 10200003 1 28 MARCH 2013
Can someone help with the select statement?
Thank you and best regards,
Iwan
Just change it to the column:
SELECT
AA
COUNT (aa)
, MAX (bb) keep (last dense_rank command by JJ)
, MAX (cc) keep (last dense_rank command by JJ)
MAX (dd)
OF THE TMP
GROUP BY aa
ORDER BY aa
Note that by default sort order is ascending with the last NULL values.
If in case your line-date-max will contain null value in the bb or cc columns those will be returned.
Post edited by: Correction of chris227
Post edited by: chris227 added note
-
Need help to write the SQL query
Hello
Please help me to write a query. My requirement is as below.
Hello
I have a table say XYZ in the following format.
product_id local min_order_quntity
========================================
1 en 10
1 ch 10
2 en 20
2 ch 20
3 en 30
3 ch 30
4 en 40
4 NC 10
Now I want to find the product_id where min_order_quantity is different for cn and locale
now I want the result of the following
product_id local min_order_quantity
=============================================
4 en 40
4 ch 10
This is different for local in and cn for product_id 4 min_order_quantity
min_order_quantity should be the same for both the locale(en,ch) for any product_id.
I want to find the product_id where min_order_quantity is different for ch and fr local
Thank you..Hello
This query should do the job
select * from xyz t1 where exists ( select 1 from xyz t2 where t2.product_id = t1.product_id and t2.locale != t1.locale and t2.min_order_quantity != t1.min_order_quantity );
See you soon
-
Help setting up a SQL query with poor performance
Hi all
Database version: 10.2.0.5
I'm working on a new report to view the top users by the number of calls. The table is truncated and filled again every month with records for the previous month; It contains approximately 400 000 records.
I created a view with the columns needed for the report; also, the two functions of view calls to determine if a phone number is assigned to multiple staffs or several departments.
It's full again table every month:
CREATE TABLE "VOIP"."MONTHLY_BILLING_DETAILS" ( "ID" NUMBER NOT NULL ENABLE, "CDRRECORDTYPE" NUMBER, "G_CALLMANAGERID" NUMBER, "G_CALLID" NUMBER, "O_LEGCALLIDENTIFIER" NUMBER, "DATETIMEORIGINATION" NUMBER, "O_NODEID" NUMBER, "O_SPAN" NUMBER, "O_IPADDR" NUMBER, "CALLINGPARTYNUMBER" VARCHAR2(50 BYTE) NOT NULL ENABLE, "CALLINGPARTY_USERID" VARCHAR2(128 BYTE), "O_CAUSE_LOCATION" NUMBER, "O_CAUSE_VALUE" NUMBER, "O_PRECEDENCELEVEL" NUMBER, "O_MEDIATRANSPORTADDR_IP" NUMBER, "O_MEDIATRANSPORTADDR_PORT" NUMBER, "O_MCAP_PAYLOADCAPABILITY" NUMBER, "O_MCAP_MAXFRAMESPERPACKET" NUMBER, "O_MCAP_G723BITRATE" NUMBER, "O_VCAP_CODEC" NUMBER, "O_VCAP_BANDWIDTH" NUMBER, "O_VCAP_RESOLUTION" NUMBER, "O_VIDEOTRANSPORTADDR_IP" NUMBER, "O_VIDEOTRANSPORTADDR_PORT" NUMBER, "O_RSVPAUDIOSTAT" VARCHAR2(64 BYTE), "O_RSVPVIDEOSTAT" VARCHAR2(64 BYTE), "DESTLEGIDENTIFIER" NUMBER, "DESTNODEID" NUMBER, "DESTSPAN" NUMBER, "DESTIPADDR" NUMBER, "ORIGINALCALLEDPARTYNUMBER" VARCHAR2(50 BYTE), "FINALC_PARTYNUMBER" VARCHAR2(50 BYTE), "FINALC_PARTY_USERID" VARCHAR2(128 BYTE), "DESTCAUSE_LOCATION" NUMBER, "DESTCAUSE_VALUE" NUMBER, "DESTPRECEDENCELEVEL" NUMBER, "DESTMEDIATRANSPORTADDR_IP" NUMBER, "DESTMEDIATRANSPORTADDR_PORT" NUMBER, "DESTMCAP_PAYLOADCAPABILITY" NUMBER, "DESTMCAP_MAXFRAMESPERPACKET" NUMBER, "DESTMCAP_G723BITRATE" NUMBER, "DV_CAP_CODEC" NUMBER, "DV_CAP_BANDWIDTH" NUMBER, "DV_CAP_RESOLUTION" NUMBER, "DV_TRANSPORTADDR_IP" NUMBER, "DV_TRANSPORTADDR_PORT" NUMBER, "DESTRSVPAUDIOSTAT" VARCHAR2(64 BYTE), "DESTRSVPVIDEOSTAT" VARCHAR2(64 BYTE), "DATETIMECONNECT" NUMBER, "DATETIMEDISCONNECT" NUMBER, "LASTREDIRECTDN" VARCHAR2(50 BYTE), "PKID" VARCHAR2(4000 BYTE), "O_INALCALLEDPARTYNUM_PARTITION" VARCHAR2(50 BYTE), "CALLINGPARTYNUM_PARTITION" VARCHAR2(50 BYTE), "FINALC_PARTYNUM_PARTITION" VARCHAR2(50 BYTE), "LASTREDIRECTDNPARTITION" VARCHAR2(50 BYTE), "DURATION" NUMBER, "O_DEVICENAME" VARCHAR2(129 BYTE), "DESTDEVICENAME" VARCHAR2(129 BYTE), "O_CALLTERMINATION_BEHALF" NUMBER, "DESTCALLTERMINATION_BEHALF" NUMBER, "O_CALLEDPARTYREDIRECT_BEHALF" NUMBER, "LASTREDIRECTREDIRECT_BEHALF" NUMBER, "O_CALLEDPARTYREDIRECTREASON" NUMBER, "LASTREDIRECTREDIRECTREASON" NUMBER, "DESTCONVERSATIONID" NUMBER, "G_CALLID_CLUSTERID" VARCHAR2(50 BYTE), "JOIN_BEHALF" NUMBER, "COMMENTS" VARCHAR2(2048 BYTE), "AUTHCODEDESCRIPTION" VARCHAR2(50 BYTE), "AUTHORIZATIONLEVEL" NUMBER, "CLIENTMATTERCODE" VARCHAR2(32 BYTE), "O_DTMFMETHOD" NUMBER, "DESTDTMFMETHOD" NUMBER, "CALLSECUREDSTATUS" NUMBER, "O_CONVERSATIONID" NUMBER, "O_MCAP_BANDWIDTH" NUMBER, "DESTMCAP_BANDWIDTH" NUMBER, "AUTHORIZATIONCODEVALUE" VARCHAR2(32 BYTE), "OUTPULSEDCALLINGPARTYNUMBER" VARCHAR2(50 BYTE), "OUTPULSEDCALLEDPARTYNUMBER" VARCHAR2(50 BYTE), "O_IPV4V6ADDR" VARCHAR2(64 BYTE), "DESTIPV4V6ADDR" VARCHAR2(64 BYTE), "O_VCAP_CODEC_CHAN2" NUMBER, "O_VCAP_BANDWIDTH_CHAN2" NUMBER, "O_VCAP_RESOLUTION_CHAN2" NUMBER, "O_V_TRANSPORTADDR_IP_CHAN2" NUMBER, "O_V_TRANSPORTADDR_PORT_CHAN2" NUMBER, "O_V_OCHANNEL_ROLE_CHAN2" NUMBER, "DV_CAP_CODEC_CHAN2" NUMBER, "DV_CAP_BANDWIDTH_CHAN2" NUMBER, "DV_CAP_RESOLUTION_CHAN2" NUMBER, "DV_TRANSPORTADDR_IP_CHAN2" NUMBER, "DV_TRANSPORTADDR_PORT_CHAN2" NUMBER, "DV_CHANNEL_ROLE_CHAN2" NUMBER, "DATE_CREATED" DATE, "DATETIME_CONNECT" DATE, "DATETIME_DISCONNECT" DATE, "USERID_EMAIL_ADDRESS" VARCHAR2(100 BYTE), "FROM_FULL_TELEPHONE" VARCHAR2(20 BYTE), "TO_FULL_TELEPHONE" VARCHAR2(20 BYTE), "FROM_EXCHANGE" VARCHAR2(7 BYTE), "TO_EXCHANGE" VARCHAR2(20 BYTE), "FROM_CITY" VARCHAR2(200 BYTE), "FROM_STATE" VARCHAR2(2 BYTE), "TO_CITY" VARCHAR2(200 BYTE), "TO_STATE" VARCHAR2(2 BYTE), "CALL_TYPE" VARCHAR2(10 BYTE), CONSTRAINT "MONTHLY_BILLING_PK" PRIMARY KEY ("ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 3145728 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VOIPDATA" ENABLE ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 75497472 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VOIPDATA" ; CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX1" ON "VOIP"."MONTHLY_BILLING_DETAILS" (TRUNC("DATETIME_CONNECT")) PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 4194304 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VOIPDATA" ; CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX10" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("CALL_TYPE") PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 4194304 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VOIPDATA" ; CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX2" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("FROM_EXCHANGE") PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 3145728 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VOIPDATA" ; CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX3" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("FROM_FULL_TELEPHONE", TRUNC("DATETIME_CONNECT")) PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VOIPDATA" ; CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX4" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("DATETIME_CONNECT", NVL("FROM_FULL_TELEPHONE","CALLINGPARTYNUMBER")) PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 5242880 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VOIPDATA" ; CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX5" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("DATETIME_CONNECT", NVL("TO_FULL_TELEPHONE","ORIGINALCALLEDPARTYNUMBER")) PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 5242880 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VOIPDATA" ; CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX6" ON "VOIP"."MONTHLY_BILLING_DETAILS" (TO_CHAR("DATETIME_CONNECT",'fmMONTH YYYY')) PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 4194304 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VOIPDATA" ; CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX7" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("TO_EXCHANGE") PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 3145728 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VOIPDATA" ; CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX8" ON "VOIP"."MONTHLY_BILLING_DETAILS" (NVL("FROM_FULL_TELEPHONE","CALLINGPARTYNUMBER")) PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 4194304 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VOIPDATA" ; CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX9" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("DATETIME_CONNECT") PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 3145728 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VOIPDATA" ;
These are the functions to determine if a phone number is assigned to multiple staffs or departments:
FUNCTION GET_EMPLOYEE_NAME (P_FROM_FULL_TELEPHONE IN VARCHAR2) RETURN VARCHAR2 AS L_NAME EMPLOYEES.NAME%TYPE; BEGIN SELECT NAME INTO L_NAME FROM EMPLOYEES WHERE WORK_PHONE_1_FORMAT = P_FROM_FULL_TELEPHONE; RETURN L_NAME; EXCEPTION WHEN TOO_MANY_ROWS THEN L_NAME := 'Multiple Employees'; RETURN L_NAME; WHEN NO_DATA_FOUND THEN L_NAME := 'No Employee Assigned'; RETURN L_NAME; WHEN OTHERS THEN NULL; END;
FUNCTION GET_DEPARTMENT_NAME (P_FROM_FULL_TELEPHONE IN VARCHAR2) RETURN VARCHAR2 AS L_DEPT_DESCR EMPLOYEES.DEPT_DESCR%TYPE; BEGIN SELECT DEPT_DESCR INTO L_DEPT_DESCR FROM EMPLOYEES WHERE WORK_PHONE_1_FORMAT = P_FROM_FULL_TELEPHONE; RETURN L_DEPT_DESCR; EXCEPTION WHEN TOO_MANY_ROWS THEN L_DEPT_DESCR := 'Multiple Departments'; RETURN L_DEPT_DESCR; WHEN NO_DATA_FOUND THEN L_DEPT_DESCR := 'No Department Assigned'; RETURN L_DEPT_DESCR; WHEN OTHERS THEN NULL; END;
This is the point of view that I'll use in the report:
CREATE OR REPLACE FORCE VIEW "VOIP"."TOP_USERS_BY_CALLS_V" ("TOP_NO", "EMPLOYEE_NAME", "EMPLOYEE_DEPARTMENT", "PHONE_NUMBER", "QUANTITY_CALLS") AS SELECT ROWNUM, VOIP_PKG.GET_EMPLOYEE_NAME(FROM_FULL_TELEPHONE), VOIP_PKG.GET_DEPARTMENT_NAME(FROM_FULL_TELEPHONE), FROM_FULL_TELEPHONE, QUANTITY_CALLS FROM ( SELECT MBD.FROM_FULL_TELEPHONE, COUNT(1) QUANTITY_CALLS FROM MONTHLY_BILLING_DETAILS MBD WHERE MBD.FROM_FULL_TELEPHONE IS NOT NULL AND MBD.FROM_FULL_TELEPHONE <> '000-000-0000' AND LENGTH(MBD.FROM_FULL_TELEPHONE) = 12 AND LENGTH(MBD.TO_FULL_TELEPHONE) = 12 AND SUBSTR(MBD.TO_FULL_TELEPHONE,1,3) NOT IN (SELECT AREA_CODE FROM NYNJ_METRO_AREA_CODES) AND SUBSTR(MBD.TO_FULL_TELEPHONE,1,3) NOT IN ('800','822','833','844', '855','866','877','888') GROUP BY MBD.FROM_FULL_TELEPHONE ORDER BY QUANTITY_CALLS DESC ) WHERE ROWNUM <= 100;
Explain Plan output and Extended SQL Trace:
SQL> SQL> show parameter user_dump_dest NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ user_dump_dest string D:\ORACLEHOMES\ADMIN\RTS9\UDUM P SQL> SQL> show parameter optimizer NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ optimizer_dynamic_sampling integer 2 optimizer_features_enable string 10.2.0.5 optimizer_index_caching integer 0 optimizer_index_cost_adj integer 100 optimizer_mode string ALL_ROWS optimizer_secure_view_merging boolean TRUE SQL> SQL> show parameter db_file_multi NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ db_file_multiblock_read_count integer 16 SQL> SQL> show parameter db_block_size NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ db_block_size integer 8192 SQL> 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 3 , pname 4 , pval1 5 , pval2 6 from 7 sys.aux_stats$; SNAME PNAME PVAL1 PVAL2 -------------------- -------------------- ---------- -------------------- SYSSTATS_INFO STATUS COMPLETED SYSSTATS_INFO DSTART 02-09-2009 15:46 SYSSTATS_INFO DSTOP 02-09-2009 15:46 SYSSTATS_INFO FLAGS 1 SYSSTATS_MAIN CPUSPEEDNW 1259.6206 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.03 SQL> SQL> explain plan for 2 SELECT 3 TOP_NO, 4 EMPLOYEE_NAME, 5 EMPLOYEE_DEPARTMENT, 6 PHONE_NUMBER, 7 QUANTITY_CALLS 8 FROM 9 TOP_USERS_BY_CALLS_V 10 ORDER BY 11 QUANTITY_CALLS DESC; Explained. Elapsed: 00:00:00.18 SQL> SQL> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Plan hash value: 826236322 ---------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ---------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 4042 | 1313 (1)| 00:00:16 | | 1 | SORT ORDER BY | | 1 | 4042 | 1313 (1)| 00:00:16 | | 2 | VIEW | TOP_USERS_BY_CALLS_V | 1 | 4042 | 1312 (1)| 00:00:16 | |* 3 | COUNT STOPKEY | | | | | | | 4 | VIEW | | 1 | 25 | 1312 (1)| 00:00:16 | |* 5 | SORT ORDER BY STOPKEY | | 1 | 26 | 1312 (1)| 00:00:16 | | 6 | HASH GROUP BY | | 1 | 26 | 1312 (1)| 00:00:16 | |* 7 | FILTER | | | | | | |* 8 | TABLE ACCESS BY INDEX ROWID| MONTHLY_BILLING_DETAILS | 1 | 26 | 1310 (1)| 00:00:16 | |* 9 | INDEX FULL SCAN | MONTHLY_BILL_INDEX3 | 934 | | 449 (1)| 00:00:06 | |* 10 | INDEX FULL SCAN | NYNJ_METRO_AREA_CODES_UK1 | 1 | 4 | 1 (0)| 00:00:01 | ---------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 3 - filter(ROWNUM<=100) 5 - filter(ROWNUM<=100) 7 - filter( NOT EXISTS (SELECT 0 FROM VOIP."NYNJ_METRO_AREA_CODES" "NYNJ_METRO_AREA_CODES" WHERE LNNVL("AREA_CODE"<>SUBSTR(:B1,1,3)))) 8 - filter(LENGTH("MBD"."TO_FULL_TELEPHONE")=12 AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'800' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'822' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'833' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'844' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'855' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'866' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'877' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'888') 9 - filter(LENGTH("MBD"."FROM_FULL_TELEPHONE")=12 AND "MBD"."FROM_FULL_TELEPHONE"<>'000-000-0000' AND "MBD"."FROM_FULL_TELEPHONE" IS NOT NULL) 10 - filter(LNNVL("AREA_CODE"<>SUBSTR(:B1,1,3))) 33 rows selected. Elapsed: 00:00:00.82 SQL> SQL> rollback; Rollback complete. Elapsed: 00:00:00.00 SQL> SQL> set autotrace traceonly arraysize 100 SQL> SQL> alter session set tracefile_identifier = 'mytrace1'; Session altered. Elapsed: 00:00:00.01 SQL> SQL> alter session set events '10046 trace name context forever, level 8'; Session altered. Elapsed: 00:00:00.15 SQL> SQL> SELECT 2 TOP_NO, 3 EMPLOYEE_NAME, 4 EMPLOYEE_DEPARTMENT, 5 PHONE_NUMBER, 6 QUANTITY_CALLS 7 FROM 8 TOP_USERS_BY_CALLS_V 9 ORDER BY 10 QUANTITY_CALLS DESC; 100 rows selected. Elapsed: 00:10:37.68 Execution Plan ---------------------------------------------------------- Plan hash value: 826236322 ---------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ---------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 4042 | 1313 (1)| 00:00:16 | | 1 | SORT ORDER BY | | 1 | 4042 | 1313 (1)| 00:00:16 | | 2 | VIEW | TOP_USERS_BY_CALLS_V | 1 | 4042 | 1312 (1)| 00:00:16 | |* 3 | COUNT STOPKEY | | | | | | | 4 | VIEW | | 1 | 25 | 1312 (1)| 00:00:16 | |* 5 | SORT ORDER BY STOPKEY | | 1 | 26 | 1312 (1)| 00:00:16 | | 6 | HASH GROUP BY | | 1 | 26 | 1312 (1)| 00:00:16 | |* 7 | FILTER | | | | | | |* 8 | TABLE ACCESS BY INDEX ROWID| MONTHLY_BILLING_DETAILS | 1 | 26 | 1310 (1)| 00:00:16 | |* 9 | INDEX FULL SCAN | MONTHLY_BILL_INDEX3 | 934 | | 449 (1)| 00:00:06 | |* 10 | INDEX FULL SCAN | NYNJ_METRO_AREA_CODES_UK1 | 1 | 4 | 1 (0)| 00:00:01 | ---------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 3 - filter(ROWNUM<=100) 5 - filter(ROWNUM<=100) 7 - filter( NOT EXISTS (SELECT 0 FROM VOIP."NYNJ_METRO_AREA_CODES" "NYNJ_METRO_AREA_CODES" WHERE LNNVL("AREA_CODE"<>SUBSTR(:B1,1,3)))) 8 - filter(LENGTH("MBD"."TO_FULL_TELEPHONE")=12 AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'800' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'822' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'833' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'844' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'855' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'866' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'877' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'888') 9 - filter(LENGTH("MBD"."FROM_FULL_TELEPHONE")=12 AND "MBD"."FROM_FULL_TELEPHONE"<>'000-000-0000' AND "MBD"."FROM_FULL_TELEPHONE" IS NOT NULL) 10 - filter(LNNVL("AREA_CODE"<>SUBSTR(:B1,1,3))) Statistics ---------------------------------------------------------- 365 recursive calls 0 db block gets 689543 consistent gets 212906 physical reads 0 redo size 5984 bytes sent via SQL*Net to client 400 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 2 sorts (memory) 0 sorts (disk) 100 rows processed SQL> SQL> disconnect
Part of the automatic trace output:
SELECT TOP_NO, EMPLOYEE_NAME, EMPLOYEE_DEPARTMENT, PHONE_NUMBER, QUANTITY_CALLS FROM TOP_USERS_BY_CALLS_V ORDER BY QUANTITY_CALLS DESC call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 1 0.00 0.43 0 0 0 0 Execute 1 0.00 0.00 0 0 0 0 Fetch 2 24.70 635.81 212587 631823 0 100 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 4 24.70 636.25 212587 631823 0 100 Misses in library cache during parse: 1 Optimizer mode: ALL_ROWS Parsing user id: 148 Rows Row Source Operation ------- --------------------------------------------------- 100 SORT ORDER BY (cr=689531 pr=212900 pw=0 time=636823070 us) 100 VIEW TOP_USERS_BY_CALLS_V (cr=689531 pr=212900 pw=0 time=642681672 us) 100 COUNT STOPKEY (cr=631823 pr=212587 pw=0 time=635667026 us) 100 VIEW (cr=631823 pr=212587 pw=0 time=635666810 us) 100 SORT ORDER BY STOPKEY (cr=631823 pr=212587 pw=0 time=635666493 us) 2512 HASH GROUP BY (cr=631823 pr=212587 pw=0 time=635666125 us) 27112 FILTER (cr=631823 pr=212587 pw=0 time=519230237 us) 315563 TABLE ACCESS BY INDEX ROWID MONTHLY_BILLING_DETAILS (cr=381523 pr=212587 pw=0 time=580209555 us) 394473 INDEX FULL SCAN MONTHLY_BILL_INDEX3 (cr=2679 pr=2679 pw=0 time=26793918 us)(object id 206675) 226627 INDEX FULL SCAN NYNJ_METRO_AREA_CODES_UK1 (cr=250300 pr=0 pw=0 time=3575488 us)(object id 206605) Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ SQL*Net message to client 2 0.00 0.00 db file sequential read 212587 0.20 611.67 SQL*Net message from client 2 0.00 0.00 SQL*Net more data to client 2 0.00 0.00 ********************************************************************************
DBMS_XPLAN. Output DISPLAY_CURSOR:
SQL> SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST')); PLAN_TABLE_OUTPUT ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- SQL_ID 1ut636vt58jdw, child number 0 ------------------------------------- SELECT /*+ gather_plan_statistics */ TOP_NO, EMPLOYEE_NAME, EMPLOYEE_DEPARTMENT, PHONE_NUMBER, QUANTITY_CALLS FROM TOP_USERS_BY_CALLS_V ORDER BY QUANTITY_CALLS DESC Plan hash value: 826236322 -------------------------------------------------------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads | OMem | 1Mem | Used-Mem | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | | 100 |00:09:56.06 | 689K| 210K| | | | | 1 | SORT ORDER BY | | 1 | 1 | 100 |00:09:56.06 | 689K| 210K| 13312 | 13312 |12288 (0)| | 2 | VIEW | TOP_USERS_BY_CALLS_V | 1 | 1 | 100 |00:10:04.98 | 689K| 210K| | | | |* 3 | COUNT STOPKEY | | 1 | | 100 |00:09:54.89 | 631K| 210K| | | | | 4 | VIEW | | 1 | 1 | 100 |00:09:54.89 | 631K| 210K| | | | |* 5 | SORT ORDER BY STOPKEY | | 1 | 1 | 100 |00:09:54.88 | 631K| 210K| 6144 | 6144 | 6144 (0)| | 6 | HASH GROUP BY | | 1 | 1 | 2512 |00:09:54.88 | 631K| 210K| 821K| 821K| 1153K (0)| |* 7 | FILTER | | 1 | | 27112 |00:08:58.57 | 631K| 210K| | | | |* 8 | TABLE ACCESS BY INDEX ROWID| MONTHLY_BILLING_DETAILS | 1 | 1 | 315K|00:08:57.07 | 381K| 210K| | | | |* 9 | INDEX FULL SCAN | MONTHLY_BILL_INDEX3 | 1 | 934 | 394K|00:00:23.02 | 2679 | 2679 | | | | |* 10 | INDEX FULL SCAN | NYNJ_METRO_AREA_CODES_UK1 | 250K| 1 | 226K|00:00:03.47 | 250K| 0 | | | | -------------------------------------------------------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 3 - filter(ROWNUM<=100) 5 - filter(ROWNUM<=100) 7 - filter( IS NULL) 8 - filter((LENGTH("MBD"."TO_FULL_TELEPHONE")=12 AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'800' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'822' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'833' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'844' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'855' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'866' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'877' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'888')) 9 - filter((LENGTH("MBD"."FROM_FULL_TELEPHONE")=12 AND "MBD"."FROM_FULL_TELEPHONE"<>'000-000-0000' AND "MBD"."FROM_FULL_TELEPHONE" IS NOT NULL)) 10 - filter(LNNVL("AREA_CODE"<>SUBSTR(:B1,1,3))) 35 rows selected. Elapsed: 00:00:00.50 SQL> SQL> spool off
Any help will be greatly appreciated. Please let me know if you need additional information.
Thank you
Erick
ediazjorge wrote:
Please let me know if you need additional information or do additional tests.
Thanks again!
Erick
It's to you if you are satisfied or interested in improvements (if possible).
If so the first thing I would like if you had your refreshed perspective as advised. According to expected area_code table cardinalities I doubt.
So, if not cool off with dbms_stats.gather_table_stats on two tables, area_codes and MONTHLY_BILLING_DETAILS.
Bottlenecks are now obviously the full table of MONTHLY_BILLING_DETAILS as well as the ANTI of LOOPS IMBRIQUEES scan.
At the moment I don't think that an index of MONTHLY_BILLING_DETAILS will help a lot, because most of the lines will pass filter predicates, and because we need some columns in it, I have now I there will be gain a full index scan.
I was surprissed that the optimizer pushes the substr <> predicates to both tables.
So depending on your data, you might try
1 make a factory of subquery select the two MONTHLY_BILLING_DETAILS columns that all directly apply predicates of membership and use it directly in the join instead of the table.
or
2. If all subtr to so are part of the table area_code choose in it using a subquery (or inline view) plant excluding these values.
Both are attempts to get rid of the substr excluding as filters of join predicates.
In fact, I was expecting a hash join anti as shown in the plan to explain instead of the nested loops anti, I expect to be more effective in this case.
Perhaps with correct cardinalities the optimizier would understand himself.
Just to test it, you can try the use_hash hint in the join:
Select / * + USE_HASH (MBD, one) * /.
..
OF MONTHLY_BILLING_DETAILS MBD,.
NYNJ_METRO_AREA_CODES one
(It's a good habit anyway usually use aliases and precede the names of columns. In the, it is easier to read queries are only trivial).
-
Help with anonymus pl/sql layout using javascript
Hi people.
I want to display records on a region (using apex 4.2), this anonymous pl/sql script below shows 3 records in database, but the layout only shows me the first album with its data, the other 2 files, only show me the labels.
I checked this same query creating a report and it shows the 3 files correctly.
I guess I'm doing something wrong with this javascript routine or certainly miss something,
in this link you can see the layout I get. (http://sdrv.ms/Xrv0J8).
Another is the little help I need to display in a line for each record. in fact, I'm getting a line for each label and a line for each data record. I have read and learned something is/div, but I don't know how to change it to get the desired results, any suggestion is welcome.
Thanks in advance for any help.
I am completely new in apex and java script, but I have several years of experience in pl/sql.
-------
The Script:
Begin
Declare
Anyth cursor is
Select the item,
To_char (delivery, ' month DD, YYYY hh24:mi:ss ") delivery.
Current_date
Of pending_items;
Begin
For a loop Anyth
Begin
Sys.Htp.P ("< script type =" text/javascript"> '");
Sys.Htp.P ('function cdtd() {'});
Sys.Htp.P ("var Christmas = new Date (" ' | ') ") a.Delivery | '")');
Sys.Htp.P ("var now = new Date();'");
Sys.Htp.P ("var timeDiff = xmas.getTime () - now.getTime ();'");
Sys.Htp.P (' if (timeDiff < = 0) {'});
Sys.Htp.P ('clearTimeout() (timer)');
-Sys.Htp.P ("document.write ("of the text here.")");
Sys.Htp.P (' / / execute all necessary code to the completion of the countdown here ');
Sys.Htp.P ('} ');
Sys.Htp.P (' var seconds = Math.floor(timeDiff / 1000);) ") ;
Sys.Htp.P ("var minutes = Math.floor(seconds / 60) ;");
Sys.Htp.P (' varhour = Math.floor(minutes / 60);) ") ;
Sys.Htp.P ("days var Math.floor(hours / 24) = ;"); ")
Sys.Htp.P (' hours = 24 ;'); %)
Sys.Htp.P (' minutes % = 60 ;');)
Sys.Htp.P (' seconds % = 60 ;');)
Sys.Htp.P (' document.getElementById("daysBox").innerHTML = days ;');)
Sys.Htp.P (' document.getElementById("hoursBox").innerHTML = hours;) ") ;
Sys.Htp.P (' document.getElementById("minsBox").innerHTML = minutes ;');)
Sys.Htp.P (' ;'); seconds = document.getElementById("secsBox").innerHTML)
Sys.Htp.P (' timer var = setTimeout ("cdtd ()", 1000);');
Sys.Htp.P ('} ');
Sys.Htp.P ("< /script >");
Sys.Htp.P ("days");
Sys.Htp.P ("< div id ="daysBox"> < / div > '");
Sys.Htp.P ("hours");
Sys.Htp.P ("< div id ="hoursBox"> < / div > '");
Sys.Htp.P ('minute');
Sys.Htp.P ("< div id ="minsBox"> < / div > '");
Sys.Htp.P ("seconds");
Sys.Htp.P ("< div id ="secsBox"> < / div > '");
Sys.Htp.P ("< script type =" text/javascript"> '");
Sys.Htp.P ('cdtd() < /script > ');
End;
End loop;
End;
End;For now, let's focus on delivery dates and the javascript.
Why you would put your javascript in htp.p called in a plsql region is beyond me. When you edit the page there is a region of javascript where you can put global variables and functions, a great spot for it then and much easier to manage than that.
Now, it is also clear that your query on pending items will return multiple records. Thus, using a report would serve you well in this case. However, using code like this:document.getElementById("daysBox").innerHTML = days; document.getElementById("hoursBox").innerHTML = hours; document.getElementById("minsBox").innerHTML = minutes; document.getElementById("secsBox").innerHTML = seconds;
you won't have to. getElementById is supposed to return an element identified by a code. If you have a report that contains multiple lines and elements on each line with the same ID, you're doing something wrong. You should be the date of delivery by rank, and I suppose that you put your code with htp.p because you don't know how to deal with this and passing the procedure of javascript.
But would it not more oppurtune for you simply create a report with a sql source when you calculate each part of the date and then refresh this region with a certain interval. If you would be refreshed every 5 minutes, not who is more fast enough to keep track of things? Remember, refreshing a region will execute the SQL again.
It is not that you cannot make a report multi-record with a countdown by rank, but are you sufficiently comfortable with javascript and jquery to encode and maintain that against leverage plsql and dynamic actions (there is even an action timer plugin supplied by oracle dynamic)? -
Need help with ics. SQL return null
Hi experts WCS.
I have this ics. SQL statement that returns an IList as null and nothing in the errStr in debugging print.
IList rsATypes is ics. SQL (, sqlATypes, listName, limit, bCache errStr);
The code is in one of my jsp. He ran very well in my local JSK (HyperSQL Db), but returns NULL in the case of Test (Oracle DB, if this is another).
I got the sql statement println during execution and run it directly in Oracle DB (same instance) it returns the expected result set.
The code snippet:
System.out.println("## ics.GetSSVar(\"pubid\") : " + ics.GetSSVar("pubid")); // Get Attribute Types String sqlATypes = "SELECT DISTINCT assetpublication.assettype " + "FROM assetpublication " + "LEFT JOIN approvedassets " + " ON assetpublication.assetid = approvedassets.assetid " + "WHERE pubid = '" + ics.GetSSVar("pubid") + "' " + "AND (tstate is null OR tstate <> 'A') " + "AND (voided is null OR voided <> 'T') " + "ORDER BY assettype; "; System.out.println("##0126 sqlATypes : " + sqlATypes); String from = "AssetPublication, ApprovedAssets"; // String listName = null; String listName = "ATypesList"; int limit = -1; // boolean bCache = true; boolean bCache = false; StringBuffer errStr = new StringBuffer(""); ics.ClearErrno(); IList rsATypes = ics.SQL(from, sqlATypes, listName, limit, bCache, errStr); System.out.println("## rsATypes : " + rsATypes); if (rsATypes == null) { System.out.println("## NO DATA in rsATypes! errStr : " + errStr.toString());
}
The journal:
## ics.GetSSVar("pubid") : 1374097570685 ## sqlATypes : SELECT DISTINCT assetpublication.assettype FROM assetpublication LEFT JOIN approvedassets ON assetpublication.assetid = approvedassets.assetid WHERE pubid = '1374097570685' AND (tstate is null OR tstate <> 'A') AND (voided is null OR voided <> 'T') ORDER BY assettype; ## rsATypes : null ## NO DATA in rsATypes! errStr :
I got enclosing try catch block, who did not take any exception.
The funny thing is, in the same piece of code, an ics. Casea used already worked (which I noticed outside because there was not enough for what I want to do):
StringBuffer errSB = new StringBuffer(""); ics.SetVar("assetid", id); IList approvedAsset = ics.SelectTo("ApprovedAssets", "state,voided,tstate,locked,reason,treason", "assetid", null, -1, null, true, errSB);
Any help/ideas from anyone would be really appreciated.
Thanks Guddu1223, I discovered why.
The SQL statement cannot end with a semicolon (see line 11 of my original above codes). Delete who had back all the records provided for in my resultset in the IList.
The reason why it works in my local, but not stable instance that I guess is my local JSK + HyperSQL, in WCS + Oracle DB instance trying...
-
I need help with the following sql.
I'm lost. I'm collecting information for the days of the month. For days I have not, I would like to query to get these days also.
The days of return I have with data and all other days where I'm not.How can I get the rest of the days of the month of June. If I execute sql against the following.
Select * from
(Select '02' as the double Study_Date
Union Select '03' as the double Study_Date
Union Select '04' as the double Study_Date
Union Select '04' as the double Study_Date
Union Select '05' as the double Study_Date
Union Select '06' as the double Study_Date
Union Select '09' as the double Study_Date
Union Select '10' as the double Study_Date
Union Select '11' as the double Study_Date
Union Select '12' as the double Study_Date
Union Select '13' as the double Study_Date
Union Select '16' as the double Study_Date
Union Select '19' as double Study_Date)Thank you
Howard
Hello, Howard.
Thanks for posting the sample data! Don't forget to post the exact results you want from these data.
Looks like you want something involving everyday of the month, they have a day corresponding to your table or not. This looks like a job for an outer join.
This should give you some ideas:
WITH days_wanted AS
(
SELECT TO_CHAR (LEVEL, 'fm00') n
OF the double
CONNECT BY LEVEL<=>=>
)
SELECT d.n
t.study_date
NVL2 (t.study_date
'Yes '.
'No '.
) AS in_table_x
OF days_wanted d
LEFT OUTER JOIN table_x t ON t.study_date = d.n
ORDER BY d.n
;
Output:
STUDY_DATE N IN_TABLE_X
--- ---------- ----------
01 NO.
02 02 Yes
03 03 Yes
04 04 Yes
05 05 Yes
Yes 06 06
07 NO.
08 NO.
09 09 Yes
10 10 Yes
11 11 Yes
12 12 Yes
13 13 Yes
14 NO.
15 NO.
16 16 Yes
17 NO.
18 NO.
19 19 Yes
20 NO.
21 NO.
22 NO.
23 NO.
24 NO.
25 NO.
26 NO.
27 NO.
28 NO.
29 NO.
30 NO.
You must use a DATE for study_date, not a VARCHAR2 column. What will you do if you have days of different months in the table?
-
[10 g/8i] Need help with setting up a query
I have a query that takes about 5 minutes to run, and if there is a way to make it faster, I would like to know. It is not a huge problem, but I get to sleep while waiting for it to end. =)
Here are the results of the explain plan command and the extra stuff generated by autotrace...
I also have the tkprof output, but let's start with that. I have absolutely no idea where to even start looking for something to improve.SQL> show parameter optimizer NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ optimizer_dynamic_sampling integer 2 optimizer_features_enable string 10.2.0.1 optimizer_index_caching integer 0 optimizer_index_cost_adj integer 100 optimizer_mode string ALL_ROWS optimizer_secure_view_merging boolean TRUE SQL> SQL> show parameter db_file_multi NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ db_file_multiblock_read_count integer 128 SQL> SQL> show parameter db_block_size NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ db_block_size integer 8192 SQL> 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 3 , pname 4 , pval1 5 , pval2 6 from 7 sys.aux_stats$; SNAME PNAME PVAL1 PVAL2 -------------------- -------------------- ----------- -------------------- SYSSTATS_INFO STATUS COMPLETED SYSSTATS_INFO DSTART 02-07-2006 22:54 SYSSTATS_INFO DSTOP 02-07-2006 22:54 SYSSTATS_INFO FLAGS 1.000 SYSSTATS_MAIN CPUSPEEDNW 500.790 SYSSTATS_MAIN IOSEEKTIM 10.000 SYSSTATS_MAIN IOTFRSPEED 4,096.000 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.03 SQL> explain plan into plan_table for 2 SELECT CONNECT_BY_ROOT b.parent_part AS part_nbr 3 , b.parent_part 4 , b.child_part 5 , eval_number ('1' || SYS_CONNECT_BY_PATH (b.qty_per, '*')) AS qty 6 FROM ( 7 SELECT doc_nbr AS parent_part 8 , comp_part AS child_part 9 , line_nbr 10 , qty_per 11 FROM bill@DB8I 12 WHERE lst_code IN ('G','M') 13 AND begn_eff <= SYSDATE 14 AND end_eff > SYSDATE 15 AND component_type = 'R' 16 AND doc_type = 'BILL' 17 AND status = 'RL' 18 ) b 19 , part@DB8I p 20 , dual 21 WHERE b.child_part = p.part_nbr 22 START WITH b.parent_part = 'MYPARTNBR' 23 CONNECT BY b.parent_part = PRIOR b.child_part 24 AND PRIOR p.part_type = 'M' 25 ; Explained. Elapsed: 00:00:00.23 SQL> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Plan hash value: 2565617462 -------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Inst |IN-OUT| -------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 299 | 519 (14)| 00:00:07 | | | |* 1 | CONNECT BY WITH FILTERING| | | | | | | | |* 2 | FILTER | | | | | | | | | 3 | COUNT | | | | | | | | | 4 | NESTED LOOPS | | 1 | 299 | 519 (14)| 00:00:07 | | | | 5 | NESTED LOOPS | | 1 | 217 | 517 (14)| 00:00:07 | | | | 6 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 | | | | 7 | REMOTE | BILL | 1 | 217 | 515 (14)| 00:00:07 | DB8I | R->S | | 8 | REMOTE | PART | 1 | 82 | 2 (0)| 00:00:01 | DB8I | R->S | |* 9 | HASH JOIN | | | | | | | | | 10 | CONNECT BY PUMP | | | | | | | | | 11 | COUNT | | | | | | | | | 12 | NESTED LOOPS | | 1 | 299 | 519 (14)| 00:00:07 | | | | 13 | NESTED LOOPS | | 1 | 217 | 517 (14)| 00:00:07 | | | | 14 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 | | | | 15 | REMOTE | BILL | 1 | 217 | 515 (14)| 00:00:07 | DB8I | R->S | | 16 | REMOTE | PART | 1 | 82 | 2 (0)| 00:00:01 | DB8I | R->S | | 17 | COUNT | | | | | | | | | 18 | NESTED LOOPS | | 1 | 299 | 519 (14)| 00:00:07 | | | | 19 | NESTED LOOPS | | 1 | 217 | 517 (14)| 00:00:07 | | | | 20 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 | | | | 21 | REMOTE | BILL | 1 | 217 | 515 (14)| 00:00:07 | DB8I | R->S | | 22 | REMOTE | PART | 1 | 82 | 2 (0)| 00:00:01 | DB8I | R->S | -------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("DOC_NBR"='MYPARTNBR') 2 - filter("DOC_NBR"='MYPARTNBR') 9 - access("DOC_NBR"=NULL AND NULL='M') Remote SQL Information (identified by operation id): ---------------------------------------------------- 7 - SELECT "DOC_NBR","BEGN_EFF","END_EFF","LST_CODE","COMP_PART_NBR","QTY_PE R","COMPONENT_TYPE","DOC_TYPE","STATUS" FROM "BILL" "BILL" WHERE "COMPONENT_TYPE"='R' AND "DOC_TYPE"='BILL' AND "STATUS"='RL' AND ("LST_CODE"='G' OR "LST_CODE"='M') AND "END_EFF">:1 AND "BEGN_EFF"<=:2 (accessing 'DB8I ' ) 8 - SELECT "PART_NBR","PART_TYPE" FROM "PART" "P" WHERE :1="PART_NBR" (accessing 'DB8I ' ) 15 - SELECT "DOC_NBR","BEGN_EFF","END_EFF","LST_CODE","COMP_PART_NBR","QTY_PE R","COMPONENT_TYPE","DOC_TYPE","STATUS" FROM "BILL" "BILL" WHERE "COMPONENT_TYPE"='R' AND "DOC_TYPE"='BILL' AND "STATUS"='RL' AND ("LST_CODE"='G' OR "LST_CODE"='M') AND "END_EFF">:1 AND "BEGN_EFF"<=:2 (accessing 'DB8I ' ) 16 - SELECT "PART_NBR","PART_TYPE" FROM "PART" "P" WHERE :1="PART_NBR" (accessing 'DB8I ' ) 21 - SELECT "DOC_NBR","BEGN_EFF","END_EFF","LST_CODE","COMP_PART_NBR","QTY_PE R","COMPONENT_TYPE","DOC_TYPE","STATUS" FROM "BILL" "BILL" WHERE "COMPONENT_TYPE"='R' AND "DOC_TYPE"='BILL' AND "STATUS"='RL' AND ("LST_CODE"='G' OR "LST_CODE"='M') AND "END_EFF">:1 AND "BEGN_EFF"<=:2 (accessing 'DB8I ' ) 22 - SELECT "PART_NBR","PART_TYPE" FROM "PART" "P" WHERE :1="PART_NBR" (accessing 'DB8I ' ) ... ... ... Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("DOC_NBR"='MYPARTNBR') 2 - filter("DOC_NBR"='MYPARTNBR') 9 - access("DOC_NBR"=NULL AND NULL='M') Remote SQL Information (identified by operation id): ---------------------------------------------------- 7 - SELECT "DOC_NBR","BEGN_EFF","END_EFF","LST_CODE","COMP_PART_NBR","QTY_PE R","COMPONENT_TYPE","DOC_TYPE","STATUS" FROM "BILL" "BILL" WHERE "COMPONENT_TYPE"='R' AND "DOC_TYPE"='BILL' AND "STATUS"='RL' AND ("LST_CODE"='G' OR "LST_CODE"='M') AND "END_EFF">:1 AND "BEGN_EFF"<=:2 (accessing 'DB8I ' ) 8 - SELECT "PART_NBR","PART_TYPE" FROM "PART" "P" WHERE :1="PART_NBR" (accessing 'DB8I ' ) 15 - SELECT "DOC_NBR","BEGN_EFF","END_EFF","LST_CODE","COMP_PART_NBR","QTY_PE R","COMPONENT_TYPE","DOC_TYPE","STATUS" FROM "BILL" "BILL" WHERE "COMPONENT_TYPE"='R' AND "DOC_TYPE"='BILL' AND "STATUS"='RL' AND ("LST_CODE"='G' OR "LST_CODE"='M') AND "END_EFF">:1 AND "BEGN_EFF"<=:2 (accessing 'DB8I ' ) 16 - SELECT "PART_NBR","PART_TYPE" FROM "PART" "P" WHERE :1="PART_NBR" (accessing 'DB8I ' ) 21 - SELECT "DOC_NBR","BEGN_EFF","END_EFF","LST_CODE","COMP_PART_NBR","QTY_PE R","COMPONENT_TYPE","DOC_TYPE","STATUS" FROM "BILL" "BILL" WHERE "COMPONENT_TYPE"='R' AND "DOC_TYPE"='BILL' AND "STATUS"='RL' AND ("LST_CODE"='G' OR "LST_CODE"='M') AND "END_EFF">:1 AND "BEGN_EFF"<=:2 (accessing 'DB8I ' ) 22 - SELECT "PART_NBR","PART_TYPE" FROM "PART" "P" WHERE :1="PART_NBR" (accessing 'DB8I ' ) Statistics ---------------------------------------------------------- 381 recursive calls 1 db block gets 0 consistent gets 0 physical reads 304 redo size 15558 bytes sent via SQL*Net to client 417 bytes received via SQL*Net from client 5 SQL*Net roundtrips to/from client 6 sorts (memory) 0 sorts (disk) 379 rows processed SQL> disconnect Disconnected from Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
Performance would be much better if the whole query would be executed on the remote side, but the query uses the local function eval_number as well as parts of the query are executed on the remote side and results are brought alongside local and then only filtering is performed. Try the following:
SELECT part_nbr, parent_part, child_part, eval_number ('1' || path) qty FROM ( SELECT CONNECT_BY_ROOT b.parent_part part_nbr, b.parent_part, b.child_part, SYS_CONNECT_BY_PATH(b.qty_per, '*') path FROM ( SELECT doc_nbr parent_part, comp_part child_part, line_nbr qty_per FROM bill@DB8I WHERE lst_code IN ('G','M') AND begn_eff <= SYSDATE AND end_eff > SYSDATE AND component_type = 'R' AND doc_type = 'BILL' AND status = 'RL' ) b, part@DB8I p WHERE b.child_part = p.part_nbr START WITH b.parent_part = 'MYPARTNBR' CONNECT BY b.parent_part = PRIOR b.child_part AND PRIOR p.part_type = 'M' ) /
SY.
-
[10g] need help with order by hierarchical query clause
I have the following data samples:
And the following query gives me exactly what I want, in the order I want. However, I wonder if there is a way to get this order without creating the column SEQ, given that I don't need in my resultsCREATE TABLE bill_test1 ( parent_part CHAR(25) , child_part CHAR(25) , line_nbr NUMBER(5) , qty_per NUMBER(9,5) ); INSERT INTO bill_test1 VALUES ('ABC-1','ABC-10',100,1); INSERT INTO bill_test1 VALUES ('ABC-1','ABC-20',200,2); INSERT INTO bill_test1 VALUES ('ABC-1','ABC-30',300,3); INSERT INTO bill_test1 VALUES ('ABC-1','HARDWARE-1',401,10); INSERT INTO bill_test1 VALUES ('ABC-1','HARDWARE-2',402,5); INSERT INTO bill_test1 VALUES ('ABC-10','ABC-155',100,2); INSERT INTO bill_test1 VALUES ('ABC-10','HARDWARE-1',200,1); INSERT INTO bill_test1 VALUES ('ABC-155','RAW-2',100,4.8); INSERT INTO bill_test1 VALUES ('ABC-155','HARDWARE-3',200,3); INSERT INTO bill_test1 VALUES ('ABC-20','RAW-1',100,10.2); INSERT INTO bill_test1 VALUES ('ABC-30','RAW-3',100,3);
SELECT part_nbr , parent_part , child_part FROM ( SELECT CONNECT_BY_ROOT b.parent_part AS part_nbr , b.parent_part , b.child_part , SYS_CONNECT_BY_PATH(b.line_nbr,' ') AS seq FROM bill_test1 b , dual CONNECT BY parent_part = PRIOR child_part ) WHERE part_nbr = 'ABC-1' ORDER BY seq ; Results of above query, except with SEQ included in SELECT (just to show what I'm sorting off of): PART_NBR PARENT_PART CHILD_PART SEQ ---------------------------- ---------------------------- ---------------------------- ----------------- ABC-1 ABC-1 ABC-10 100 ABC-1 ABC-10 ABC-155 100 100 ABC-1 ABC-155 RAW-2 100 100 100 ABC-1 ABC-155 HARDWARE-3 100 100 200 ABC-1 ABC-10 HARDWARE-1 100 200 ABC-1 ABC-1 ABC-20 200 ABC-1 ABC-20 RAW-1 200 100 ABC-1 ABC-1 ABC-30 300 ABC-1 ABC-30 RAW-3 300 100 ABC-1 ABC-1 HARDWARE-1 401 ABC-1 ABC-1 HARDWARE-2 402
Hello
As long as there is that a single root, brothers and SŒURS of ORDER BY, you say, but you can not do in a subquery (well, you can, but usually there is no interest in a subquery). If the CONNECT BY in a subquery, there is no guarantee that the main request will preserve the hierarchical order which provides the subquery.
The query you posted does not require a query of Tahina, so you can say:
SELECT CONNECT_BY_ROOT b.parent_part AS part_nbr , b.parent_part , b.child_part --, SYS_CONNECT_BY_PATH(b.line_nbr,' ') AS seq FROM bill_test1 b WHERE CONNECT_BY_ROOT b.parent_part = 'ABC-1' CONNECT BY parent_part = PRIOR child_part ORDER SIBLINGS BY b.line_nbr ;
I said the query you posted does not require a subquery. It also does not require double, so I guess that what you posted is a simplification of what you are really doing, and that could have a subquery. In particular, if you want to GROUP BY part_nbr, you need the subquery. We can use CONNECT_BY_ROOT expression in the WHERE clause (or, come to think of it, use a START WITH clause instead WHERE), but, for some reason, we cannot use CONNECT_BY_ROOT in a clause GROUP BY; We need to calculate CONNECT_BY_ROOT in a subquery, give it a name (like part_nbr) and Super GROUP OF this column in a query.
This requires that there is that one node root. ORDER OF brothers and SŒURS means just that: children of a common parent will appear in the order, but the root nodes, which have no parents, may not be in order.
Here's what I meant by using START WITH place WHERE:
SELECT CONNECT_BY_ROOT b.parent_part AS part_nbr , b.parent_part , b.child_part --, SYS_CONNECT_BY_PATH(b.line_nbr,' ') AS seq FROM bill_test1 b START WITH b.parent_part = 'ABC-1' CONNECT BY parent_part = PRIOR child_part ORDER SIBLINGS BY b.line_nbr ;
This should be much more effective, because it reduces the results before waste you your time by getting their descendants.
With the help of a clause START WITH here is analogous to me sending you an email, saying "come to a meeting one my office at 03:00."
By using a WHERE clause here is similar by sending me an e-mail to all members of society, saying: "come to a meeting one my office at 3:00" and then, as people get here, tell everyone except you could go back.Brothers and SŒURS ORDER BY was introduced in Oracle 9.
Published by: Frank Kulash, December 9, 2010 14:39
Added version with the START WITH clause -
Please help me write this SQL query...
Thanks in advanceHi everyone, Please help me in this query. A patient can multiple types of Adresses (types P,M,D).If they have all the 3 types i need to select type: p and if they have (M and D) i need to select type M,and if they have only type D i have to select that. For each address i need to validate whether that particular address is valid or not (by start date and end date and valid flag) Patient table ============= Patient_id First_name last_name 1 sanjay kumar 2 ajay singh 3 Mike John Adress table ============ address_id patient_id adresss city type startdate enddate valid_flg 1 1 6222 dsadsa P 01/01/2007 01/01/2010 2 1 63333 dsad M 01/02/2006 01/01/2007 N 3 1 64564 fdf M 01/01/2008 07/01/2009 4 1 654757 fsdfsa D 01/02/2008 09/10/2009 5 2 fsdfsd fsdfsd M 01/03/2007 09/10/2009 6 2 jhkjk dsad D 01/01/2007 10/10/2010 7 3 asfd sfds D 01/02/2008 10/10/2009 output ===== 1 sanjay kumar 6222 dsadsa P 01/01/2007 01/01/2010 2 ajay singh fsdfsd fsdfsd M 01/03/2007 09/10/2009 3 mike john asfd sfds D 01/02/2008 10/10/2009
PhaniHello, Fabienne,.
This race for you (twisted code of Sarma):
SELECT patient_id, first_name, last_name, address, city, type, startdate, enddate FROM ( SELECT a.patient_id patient_id, first_name, last_name, address, city, type, startdate, enddate, ROW_NUMBER() OVER (PARTITION BY p.patient_id ORDER BY CASE type WHEN 'P' THEN 1 WHEN 'M' THEN 2 WHEN 'D' THEN 3 END) rn FROM patient p JOIN address a ON (p.patient_id = a.patient_id ) WHERE NVL(valid_flg, 'X') != 'N' AND SYSDATE BETWEEN startdate AND NVL(enddate, SYSDATE) ) WHERE rn = 1;
Edit, currently in the trial:
With Patient AS ( SELECT 1 Patient_id , 'sanjay' First_name, 'kumar' last_name FROM DUAL UNION ALL SELECT 2, 'ajay', 'singh' FROM DUAL UNION ALL SELECT 3, 'Mike', 'John' FROM DUAL), Address AS ( SELECT 1 address_id, 1 patient_id, '6222' address, 'dsadsa' city, 'P' type, to_date('01/01/2007', 'DD/MM/YYYY') startdate, to_date('01/01/2010', 'DD/MM/YYYY') enddate, NULL valid_flg FROM DUAL UNION ALL SELECT 2,1,'63333','dsad','M', to_date('01/02/2006', 'DD/MM/YYYY'), to_date('01/01/2007', 'DD/MM/YYYY'), ' N' FROM DUAL UNION ALL SELECT 3,1,'64564','fdf','M', to_date('01/01/2008', 'DD/MM/YYYY'), to_date('07/01/2009', 'DD/MM/YYYY'), NULL FROM DUAL UNION ALL SELECT 4,1,'654757','fsdfsa','D', to_date('01/02/2008', 'DD/MM/YYYY'), to_date('09/10/2009', 'DD/MM/YYYY'), NULL FROM DUAL UNION ALL SELECT 5,2,'fsdfsd ','fsdfsd','M', to_date('01/03/2007', 'DD/MM/YYYY'), to_date('09/10/2009', 'DD/MM/YYYY'), NULL FROM DUAL UNION ALL SELECT 6,2,' jhkjk','dsad','D', to_date('01/01/2007', 'DD/MM/YYYY'), to_date('10/10/2010', 'DD/MM/YYYY'), NULL FROM DUAL UNION ALL SELECT 7,3,'asfd',' sfds',' D', to_date('01/02/2008', 'DD/MM/YYYY'), to_date('10/10/2009', 'DD/MM/YYYY'), NULL FROM DUAL) -- end test data SELECT patient_id, first_name, last_name, address, city, type, startdate, enddate FROM ( SELECT a.patient_id patient_id, first_name, last_name, address, city, type, startdate, enddate, ROW_NUMBER() OVER (PARTITION BY p.patient_id ORDER BY CASE type WHEN 'P' THEN 1 WHEN 'M' THEN 2 WHEN 'D' THEN 3 END) rn FROM patient p JOIN address a ON (p.patient_id = a.patient_id ) WHERE NVL(valid_flg, 'X') != 'N' AND SYSDATE BETWEEN startdate AND NVL(enddate, SYSDATE) ) WHERE rn = 1; PATIENT_ID FIRST_ LAST_ ADDRESS CITY TY STARTDATE ENDDATE ---------- ------ ----- ------- ------ -- --------- --------- 1 sanjay kumar 6222 dsadsa P 01-JAN-07 01-JAN-10 2 ajay singh fsdfsd fsdfsd M 01-MAR-07 09-OCT-09 3 Mike John asfd sfds D 01-FEB-08 10-OCT-09
-
Need help with rewrite of a query
Hi friends,
PFB the query and the result. Please ignore where the conditions, they are only about 50% accurate.
SELECT XMLELEMENT ( 'majorLine' XMLATTRIBUTES ( ) d. ) line_id AS "Row Id" ),
xmlforest (d. ) ordered_item as "itemName" ,
d . ordered_quantity as 'quantity' ),
(SELECT XMLAGG (XMLELEMENT ()"Service" XMLATTRIBUTES (e. ))) line_id AS Service ),
( ) SELECT XMLAGG (XMLELEMENT ( "ServiceName" ))
XMLATTRIBUTES (of. ) ordered_item AS "ItemName" ),
xmlforest (of. ) ordered_item as "itemName" ,
de . ordered_quantity as 'quantity' )))
DE oe_order_lines_all of
OÙ de . line_id = e. line_id et de . link_to_line_id is null )))
DE oe_order_lines_all e
OÙ e. line_id = 143424538 ),
(SELECT XMLAGG (XMLELEMENT ()"minorLine" XMLATTRIBUTES (e. ))) line_id AS minorLine ),
( ) SELECT XMLAGG (XMLELEMENT ( "itemName" ))
XMLATTRIBUTES (of. ) ordered_item AS "ItemName" ),
xmlforest (of. ) ordered_item as "itemName" ,
de . ordered_quantity as 'quantity' )))
DE oe_order_lines_all of
OÙ de . line_id = e. line_id )))
DE oe_order_lines_all e
OÙ ( e. line_id = 143424538 ), (SELECT XMLAGG (XMLELEMENT ()"service" XMLATTRIBUTES (e. ))) line_id AS Service ),
( ) SELECT XMLAGG (XMLELEMENT ( "serviceName" ))
XMLATTRIBUTES (of. ) ordered_item AS "itemName" ),
xmlforest (of. ) ordered_item as "itemName" ,
de . ordered_quantity as 'quantity' )))
DE oe_order_lines_all of
OÙ de . line_id = e. line_id et de . link_to_line_id is null )))
DE oe_order_lines_all e
OÙ ( e. line_id = 143424538 ( )
( ) YOU "dept_list"
DE oe_order_lines_all d où d . line_id = 143424538 ;
The output is:
< majorLine Line Id='143424538'>
< itemName > 15454-TCC3-K9 = </ itemName >
< quantity > 10 < / quantity >
< Service SERVICE='143424538'>
< ServiceName ItemName'15454-TCC3-K9 ='=>
< itemName > 15454-TCC3-K9 = </ itemName >
< quantity > 10 < / quantity >
</ ServiceName >
</ Service >
< minorLine MINORLINE='143424538'>
< itemName ItemName'15454-TCC3-K9 ='=>
< itemName > 15454-TCC3-K9 = </ itemName >
< quantity > 10 < / quantity >
</ itemName >
</ minorLine >
< service SERVICE='143424538'>
< serviceName itemName'15454-TCC3-K9 ='=>
< itemName > 15454-TCC3-K9 = </ itemName >
< quantity > 10 < / quantity >
</ serviceName >
</ service >
</ majorLine >
But the production expected as below
< majorLine Line Id="143">
< itemName > 15454-K = </ itemName >
< quantity > 10 < / quantity >
< Service >
< lineId >143424538 < / lineId >
< itemName > 15454-9 = </ itemName >
< quantity > 10 < / quantity >
</ Service >
< minorLine MINORLINE='143424538'>
< itemName > 1549 = </ itemName >
< quantity > 10 < / quantity >
</ minorLine >
< service >
< lineId >143424538 < / lineId >
< itemName > 159= </ itemName >
< quantity > 10 < / quantity >
</ service >
</ majorLine >
So the exact structure of XML output will be like that. In the example above, I didn't add the service of minors and several minor lines.
I need to change the code above in the format below.
< majorLine = "123456" LineID >-> there will be only one line of Major
< itemNamme > MajorLineItem < / itemName >
< quantity > 2 < / quantity >
< service > -> there may be more than one service or no service of this major axis
< > < lineId > 123456 lineId
< itemNamme > serviceOfmajor < / itemName >
< quantity > 2 < / quantity >
< / service >
< minorLine LineID '456789' = > -> there are several minor this major line lines
< itemNamme > first_MinorlineItem < / itemName >
< quantity > 7 < / quantity >
< service >-> there may be more than one or NONE of the lines of service for one minor line
< > < lineId > 11212 lineId
< itemNamme > First_serivceOfMinor < / itemName >
< quantity > 2 < / quantity >
< / service >
< service >-> it may be more than one service lines for a line of minor
< > 1347657 < lineId > lineId
< itemNamme > second_serivceOfMinor < / itemName >
< quantity > 2 < / quantity >
< / service >
< minorLine LineID = "477838" > -> there are several minor this major line lines
< itemNamme > second_MinorlineItem < / itemName >
< quantity > 3 < / quantity >
< / majorLine >
Please help me to re - write the code. I used the approach of DOM node, its very long, I'm trying to replace it. Help, please. Let me know if you have any questions.
Thank you and best regards,
Arun Thomas T
Not a Constructive Question.
Maybe you are looking for
-
Help?
-
How to burn image files and videos on a DVD disc to play on a regular DVD player
I want to burn some pictutes and videos and play in a regular dvd what I need I have windows vista
-
I'm kinda not clear licensing of failover. I just got a license to upgrade to get VM to UNIFIED messaging which is an additional cost per user. If the decision is made to have a server in the unit of failover for those users of UM is there an additio
-
Eject USB and remove an instrument the same?
These methods are equal and they are both the safe way to stop USB in Windows 8 or it's just the remove method which is save him a?Please answer, thank you!
-
Quality/speed intermittent wireless
My HP DV7 laptop 6101sa has recently undergone some hardware issues. Wireless - Broadcom 4313 802.11b/g/n adapter all the minutes, or even seconds, my internet connection slows to a crawl and stops for 10 seconds. I can't browse the internet pages an