I want to filter those employees with action_type with value 'Q' ,'R' or it can be null i.e. no action_type. I have used the old SQL syntax since this is the methodology followed in my firm.
I used "Union" in the query to include the null in the output too. But I think there can be a better and full proof way to do this
condition is :
AND ppa.action_type IN ( 'Q', 'R' )
SELECT *
FROM (SELECT DISTINCT papf.person_number,
name.first_name,
name.last_name,
paam.assignment_number,
py.payroll_name,
(SELECT meaning
FROM fnd_lookup_values
WHERE lookup_type LIKE 'ACTION_TYPE'
AND lookup_code = ppa.action_type
AND LANGUAGE = 'US'
AND enabled_flag = 'Y') ACTION_TYPE,
To_char(PPA.effective_date, 'DD-MON-YYYY')
EFFECTIVE_DATE,
ppa.payroll_action_id action_number
,
pcs.consolidation_set_name,
To_char(finc, 'DD-MON-YYYY') FINC,
pasv.user_status
FROM pay_assigned_payrolls_dn papd,
pay_payroll_terms pt,
pay_pay_relationships_dn pr,
pay_all_payrolls_f py,
per_all_people_f papf,
pay_payroll_actions ppa,
pay_consolidation_sets pcs,
per_person_names_f name,
pay_rel_groups_dn payrel,
per_all_assignments_m paam,
pay_payroll_rel_actions PPRA,
per_assignment_status_types_vl pasv,
pay_time_periods ptp,
per_legislative_data_groups_vl ldg
WHERE papd.payroll_term_id = pt.payroll_term_id
AND pt.payroll_relationship_id = pr.payroll_relationship_id
AND papd.payroll_id = py.payroll_id
AND pr.person_id = papf.person_id
AND ppa.payroll_id(+) = py.payroll_id
AND ptp.payroll_id = py.payroll_id
AND PPA.payroll_action_id(+) = PPRA.payroll_action_id
AND PPRA.payroll_relationship_id = pr.payroll_relationship_id
AND pasv.assignment_status_type_id =
paam.assignment_status_type_id
AND paam.assignment_type = 'E'
--ADDED condition---
AND pasv.user_status LIKE '%Payroll Eligible'
AND ( finc > ptp.start_date
OR finc IS NULL )
AND ppa.action_type IN ( 'Q', 'R' )
AND ldg.name = Nvl(:P_LEGISLATIVE_GROUP, ldg.name)
AND pasv.user_status = Nvl(:P_ASSIGNMENT_STATUS,
pasv.user_status)
AND To_char(Nvl(ppa.effective_date, SYSDATE), 'YYYY-MM-DD')
BETWEEN
To_char(Nvl(:p_from_date, SYSDATE), 'YYYY-MM-DD') AND To_char
(
Nvl(:p_TO_date, SYSDATE), 'YYYY-MM-DD')
-------
AND ldg.legislation_code = paam.legislation_code
AND ppa.consolidation_set_id(+) = pcs.consolidation_set_id
AND pcs.consolidation_set_id = py.consolidation_set_id
AND payrel.assignment_id = paam.assignment_id
AND payrel.group_type = 'A'
AND papf.person_id = name.person_id
AND name.name_type = 'GLOBAL'
AND payrel.parent_rel_group_id = papd.payroll_term_id
AND ppa.earn_time_period_id(+) = ptp.time_period_id
AND Nvl(ppa.effective_date, Trunc(SYSDATE)) BETWEEN
payrel.start_date AND payrel.end_date
AND Nvl(ppa.effective_date, Trunc(SYSDATE)) BETWEEN
papd.start_date AND papd.end_date
AND Trunc(SYSDATE) BETWEEN papf.effective_start_date AND
papf.effective_end_date
AND Trunc(SYSDATE) BETWEEN py.effective_start_date AND
py.effective_end_date
AND Trunc(SYSDATE) BETWEEN paam.effective_start_date AND
paam.effective_end_date
AND Trunc(SYSDATE) BETWEEN name.effective_start_date AND
name.effective_end_date
UNION
SELECT DISTINCT papf.person_number,
name.first_name,
name.last_name,
paam.assignment_number,
py.payroll_name,
(SELECT meaning
FROM fnd_lookup_values
WHERE lookup_type LIKE 'ACTION_TYPE'
AND lookup_code = ppa.action_type
AND LANGUAGE = 'US'
AND enabled_flag = 'Y') ACTION_TYPE,
To_char(PPA.effective_date, 'DD-MON-YYYY')
EFFECTIVE_DATE,
ppa.payroll_action_id action_number
,
pcs.consolidation_set_name,
To_char(finc, 'DD-MON-YYYY') FINC,
pasv.user_status
FROM pay_assigned_payrolls_dn papd,
pay_payroll_terms pt,
pay_pay_relationships_dn pr,
pay_all_payrolls_f py,
per_all_people_f papf,
pay_payroll_actions ppa,
pay_consolidation_sets pcs,
per_person_names_f name,
pay_rel_groups_dn payrel,
per_all_assignments_m paam,
pay_payroll_rel_actions PPRA,
per_assignment_status_types_vl pasv,
pay_time_periods ptp,
per_legislative_data_groups_vl ldg
WHERE papd.payroll_term_id = pt.payroll_term_id
AND pt.payroll_relationship_id = pr.payroll_relationship_id
AND papd.payroll_id = py.payroll_id
AND pr.person_id = papf.person_id
AND ppa.payroll_id(+) = py.payroll_id
AND ptp.payroll_id = py.payroll_id
AND PPA.payroll_action_id(+) = PPRA.payroll_action_id
AND PPRA.payroll_relationship_id = pr.payroll_relationship_id
AND pasv.assignment_status_type_id =
paam.assignment_status_type_id
AND paam.assignment_type = 'E'
--ADDED condition---
AND pasv.user_status LIKE '%Payroll Eligible'
AND ( finc > ptp.start_date
OR finc IS NULL )
AND ppa.action_type IS NULL
AND ldg.name = Nvl(:P_LEGISLATIVE_GROUP, ldg.name)
AND pasv.user_status = Nvl(:P_ASSIGNMENT_STATUS,
pasv.user_status)
AND To_char(Nvl(ppa.effective_date, SYSDATE), 'YYYY-MM-DD')
BETWEEN
To_char(Nvl(:p_from_date, SYSDATE), 'YYYY-MM-DD') AND To_char
(
Nvl(:p_TO_date, SYSDATE), 'YYYY-MM-DD')
-------
AND ldg.legislation_code = paam.legislation_code
AND ppa.consolidation_set_id(+) = pcs.consolidation_set_id
AND pcs.consolidation_set_id = py.consolidation_set_id
AND payrel.assignment_id = paam.assignment_id
AND payrel.group_type = 'A'
AND papf.person_id = name.person_id
AND name.name_type = 'GLOBAL'
AND payrel.parent_rel_group_id = papd.payroll_term_id
AND ppa.earn_time_period_id(+) = ptp.time_period_id
AND Nvl(ppa.effective_date, Trunc(SYSDATE)) BETWEEN
payrel.start_date AND payrel.end_date
AND Nvl(ppa.effective_date, Trunc(SYSDATE)) BETWEEN
papd.start_date AND papd.end_date
AND Trunc(SYSDATE) BETWEEN papf.effective_start_date AND
papf.effective_end_date
AND Trunc(SYSDATE) BETWEEN py.effective_start_date AND
py.effective_end_date
AND Trunc(SYSDATE) BETWEEN paam.effective_start_date AND
paam.effective_end_date
AND Trunc(SYSDATE) BETWEEN name.effective_start_date AND
name.effective_end_date)
There are two ways:
AND (action_type IN ('Q', 'R') OR action_type IS NULL)
or:
AND COALESCE(action_type, 'Q') IN ('Q', 'R')
Performance may or may not be better with one or the other depending on your particular situation.
How about or?
(ppa.action_type IN ( 'Q', 'R' ) or pa.action_type is null)
You can consider using Oracle spesific NVL function (NVL( value1, value2 ) replace value1 with value2 if value1 is null) briefly as
NVL( action_type, 'Q') IN ( 'Q', 'R' )
whenever action_type is null also, NVL( action_type, 'Q') matches with 'Q' which exists in the list within parentheses.
Related
I'm new to Oracle SQL and am still learning, I'm trying to work out what GROUP BY I need to use.
The subquery works by itself:
SELECT TO_CHAR(CREATE_DATE_TIME, 'DD-MON-YYYY') "DTTM"
, CASE_NBR
, COALESCE(PT.REF_FIELD_1, LPN.TC_ASN_ID) "REF_FIELD_1"
, COALESCE(PT.REF_FIELD_2, LPN.ASN_ID || LPN.ITEM_ID) "REF_FIELD_2"
FROM PIX_TRAN PT, LPN
WHERE ( ( PT.TRAN_TYPE = '300'
AND PT.TRAN_CODE = '01'
AND PT.ACTN_CODE = '20' )
OR ( PT.TRAN_TYPE = '300'
AND PT.TRAN_CODE = '04'
AND PT.ACTN_CODE = '21' ) )
AND SUBSTR(COALESCE(PT.REF_FIELD_1, LPN.TC_ASN_ID), 1, INSTR(COALESCE(PT.REF_FIELD_1, LPN.TC_ASN_ID), '_', 1)) != 'Return_'
AND PT.CASE_NBR = LPN.TC_LPN_ID (+)
AND PT.WHSE = 'DCV'
AND TRUNC(CREATE_DATE_TIME) = TRUNC(SYSDATE)
But when I try to add it as a subquery with a GROUP BY, I can't seem to work out what the correct GROUP BY should be?
SELECT 'PO Lines/LPNs Putaway' AS "FACILITY_ACTIVITY"
, TRUNC DTTM AS "CREATED"
, COUNT(DISTINCT REF_FIELD_1 || REF_FIELD_2)|| '/'|| COUNT(DISTINCT CASE_NBR) "Total"
FROM (
SELECT TO_CHAR(CREATE_DATE_TIME, 'DD-MON-YYYY') "DTTM"
, CASE_NBR
, COALESCE(PT.REF_FIELD_1, LPN.TC_ASN_ID) "REF_FIELD_1"
, COALESCE(PT.REF_FIELD_2, LPN.ASN_ID || LPN.ITEM_ID) "REF_FIELD_2"
FROM PIX_TRAN PT, LPN
WHERE ( ( PT.TRAN_TYPE = '300'
AND PT.TRAN_CODE = '01'
AND PT.ACTN_CODE = '20' )
OR ( PT.TRAN_TYPE = '300'
AND PT.TRAN_CODE = '04'
AND PT.ACTN_CODE = '21' ) )
AND SUBSTR(COALESCE(PT.REF_FIELD_1, LPN.TC_ASN_ID), 1, INSTR(COALESCE(PT.REF_FIELD_1, LPN.TC_ASN_ID), '_', 1)) != 'Return_'
AND PT.CASE_NBR = LPN.TC_LPN_ID (+)
AND PT.WHSE = 'DCV'
AND TRUNC(CREATE_DATE_TIME) = TRUNC(SYSDATE)
)
GROUP BY TRUNC(DTTM);
I've tried the following GROUP BY's
GROUP BY TRUNC(DTTM)
ERROR - "FROM Keyword not found where expected"
GROUP BY TRUNC(TO_CHAR(CREATE_DATE_TIME, 'DD-MON-YYYY'))
with changing the select clause to
TRUNC(TO_CHAR(CREATE_DATE_TIME, 'DD-MON-YYYY')) AS "CREATED"
ERROR - "CREATE_DATE_TIME" invalid identifier
GROUP BY TRUNC(CREATE_DATE_TIME)
with changing the select clause to
TRUNC(CREATE_DATE_TIME) AS "CREATED"
ERROR - "CREATE_DATE_TIME" invalid identifier
Can someone please point out what I'm missing?
I formatted your queries which makes it easy to see the issue
Original
SELECT
to_char(create_date_time, 'DD-MON-YYYY') "DTTM",
case_nbr,
coalesce(pt.ref_field_1, lpn.tc_asn_id) "REF_FIELD_1",
coalesce(pt.ref_field_2, lpn.asn_id || lpn.item_id) "REF_FIELD_2"
FROM
pix_tran pt,
lpn
WHERE
( ( pt.tran_type = '300'
AND pt.tran_code = '01'
AND pt.actn_code = '20' )
OR ( pt.tran_type = '300'
AND pt.tran_code = '04'
AND pt.actn_code = '21' ) )
AND substr(coalesce(pt.ref_field_1, lpn.tc_asn_id),
1,
instr(coalesce(pt.ref_field_1, lpn.tc_asn_id),
'',
1)) != 'Return'
AND pt.case_nbr = lpn.tc_lpn_id (+)
AND pt.whse = 'DCV'
AND trunc(create_date_time) = trunc(sysdate)
Inline view
select 'PO Lines/LPNs Putaway' as "FACILITY_ACTIVITY",
trunc dttm AS "CREATED" , COUNT(DISTINCT REF_FIELD_1 || REF_FIELD_2)|| '/'|| COUNT(DISTINCT CASE_NBR) "Total" FROM
(
select to_char(
create_date_time,
'DD-MON-YYYY'
) "DTTM",
case_nbr,
coalesce(
pt.ref_field_1,
lpn.tc_asn_id
) "REF_FIELD_1",
coalesce(
pt.ref_field_2,
lpn.asn_id || lpn.item_id
) "REF_FIELD_2"
from pix_tran pt,
lpn
where ( ( pt.tran_type = '300'
and pt.tran_code = '01'
and pt.actn_code = '20' )
or ( pt.tran_type = '300'
and pt.tran_code = '04'
and pt.actn_code = '21' ) )
and substr(
coalesce(
pt.ref_field_1,
lpn.tc_asn_id
),
1,
instr(
coalesce(
pt.ref_field_1,
lpn.tc_asn_id
),
'',
1
)
) != 'Return'
and pt.case_nbr = lpn.tc_lpn_id (+)
and pt.whse = 'DCV'
and trunc(create_date_time) = trunc(sysdate)
)
group by trunc(dttm);
You are missing the brackets on your TRUNC, and since your DTTM is a string, the use of trunc at all is probably not appropriate.
I would move the TRUNC inside the subquery (it will reduce the datetime to a date) and then just group by DTTM
I am new to SQL performance tuning. Below is the query that I need to enhance. Can someone please guide me on what or where should I start improving this query. I can only tweak this on query level, I am not allowed to alter the tables used in this SQL.
This is running on Oracle 12g.
This query is running for almost 10 hrs.
If possible, I want to make this query runs significantly with lower runtime.
cursor cursor2 is --logic 2
SELECT /*+ PARALLEL (PRD, 36) */
AST.ASSET_NUM
,AST.STATUS_CD
,PRD.NAME
,PR_ATTR.CHAR_VAL
,U_ATTR.CHAR_VAL
,SRV_AD.ADDR
,SRV_AD.ADDR_LINE_2
,SRV_AD.CITY
,UPPER(SRV_AD.STATE)
,SRV_AD.ZIPCODE
,SRV_AD.COUNTRY
,CX_ACT.OU_NUM
,CX_ACT.X_CCNA_ACNA_FRP
,CX_ACT.NAME
,CX_ACT.OU_TYPE_CD
,CX_ACT_x.ATTRIB_46
,BILL_ACCT.OU_NUM
,DECODE(LIFE_LINE.LIFE_ELIG_FLG, 'Y', 'Y', 'N')
,SR_AC_X.X_LOC_NUM
,SR_AC_X.X_BOOTH_LOC
,SR_AC_X.X_COINLESS_IND
,SERV_ACCT.X_WIRE_CENTER_FRP
,SALES_ORD.ORDER_NUM
,SALES_ORD_X.ATTRIB_06
,TO_CHAR(GREATEST ( NVL(AST.LAST_UPD, TO_DATE('01011900', 'MMDDYYYY'))
, NVL(PRD.LAST_UPD, TO_DATE('01011900', 'MMDDYYYY'))
, NVL(PR_ATTR.LAST_UPD, TO_DATE('01011900', 'MMDDYYYY'))
, NVL(U_ATTR.LAST_UPD, TO_DATE('01011900', 'MMDDYYYY'))
, NVL(SERV_ACCT.LAST_UPD, TO_DATE('01011900',
'MMDDYYYY'))
, NVL(SR_AC_X.LAST_UPD, TO_DATE('01011900', 'MMDDYYYY'))
, NVL(SRV_AD.LAST_UPD, TO_DATE('01011900', 'MMDDYYYY'))
, NVL(CX_ACT.LAST_UPD, TO_DATE('01011900', 'MMDDYYYY'))
, NVL(CX_ACT_X.LAST_UPD, TO_DATE('01011900', 'MMDDYYYY'))
, NVL(LIFE_LINE.LAST_UPD, TO_DATE('01011900', 'MMDDYYYY'))
, NVL(BILL_ACCT.LAST_UPD, TO_DATE('01011900', 'MMDDYYYY'))), 'DD-MM-YYYY HH24:MI:SS')
,CA.NC
,CA.NCI
,CA.SECNCI
,CA.NC1
,CA.ACT
,CA.SPEC
,CA.PIU
,CA.ACTI
,CA.CCNA
FROM A.S_ASSET AST
, A.S_PRD_INT PRD
, A.S_ASSET_XA PR_ATTR
, A.S_ASSET_XA U_ATTR
, A.S_ORG_EXT SERV_ACCT
, A.S_ORG_EXT_X SR_AC_X
, A.S_ADDR_PER SRV_AD
, A.S_ORG_EXT CX_ACT
, A.S_ORG_EXT_X CX_ACT_X
, A.S_SUBSIDY LIFE_LINE
, A.S_ORG_EXT BILL_ACCT
, A.S_BU BU
, A.S_ORDER SALES_ORD
, A.S_ORDER_X SALES_ORD_X
, B.CAMP_TEMP_XA CA
WHERE AST.ROW_ID = CA.ASSET_ROW_ID (+)
AND AST.ROW_ID = AST.ROOT_ASSET_ID
AND (AST.PRD_ID = PRD.ROW_ID AND PRD.part_num IN ('R', 'B', 'R_D', 'B_D', 'ND'))
AND (AST.ROW_ID = PR_ATTR.ASSET_ID AND PR_ATTR.ATTR_NAME = 'NUMBER')
AND (AST.ROW_ID = U_ATTR.ASSET_ID AND U_ATTR.ATTR_NAME = 'UNIVERSE')
AND AST.SERV_ACCT_ID = SERV_ACCT.ROW_ID (+)
AND SERV_ACCT.PAR_ROW_ID = SR_AC_X.PAR_ROW_ID (+)
AND SERV_ACCT.PR_ADDR_ID = SRV_AD.ROW_ID (+)
AND AST.OWNER_ACCNT_ID = CX_ACT.ROW_ID (+)
AND CX_ACT.PAR_ROW_ID = CX_ACT_X.PAR_ROW_ID (+)
AND CX_ACT.ROW_ID = LIFE_LINE.ACCNT_ID (+)
AND AST.X_FIRST_ORDER_NUM = SALES_ORD.ROW_ID (+)
AND SALES_ORD.ROW_ID = SALES_ORD_X.PAR_ROW_ID (+)
AND AST.BILL_ACCNT_ID = BILL_ACCT.ROW_ID (+)
AND SERV_ACCT.BU_ID = BU.ROW_ID
AND UPPER(SRV_AD.STATE) IN ( 'AB', 'CD', 'EF')
AND PR_ATTR.CHAR_VAL IS NOT NULL
AND BU.NAME <> 'WS';
I am facing issues while exeucting the below query as "ORA-01861: literal does not match format string". Not able to identify the actual issue.
select
*
from(
select
a.*,
rownum rnum
from(
SELECT
E1."BAMEVENT" AS "BAMEVENT",
E1."BCRMORDERID" AS "BCRMORDERID",
E1."COMPLETIONTIME" AS "COMPLETIONTIME",
E1."CONTACT" AS "CONTACT",
E1."CREATIONTIME" AS "CREATIONTIME",
E1."CURRENTOWNERID" AS "CURRENTOWNERID",
E1."CURRENTOWNERNAME" AS "CURRENTOWNERNAME",
E1."CUSTOMERNAME" AS "CUSTOMERNAME",
E1."CUSTOMERSEGMENT" AS "CUSTOMERSEGMENT",
E1."CUSTOMERSUBSEGMENT" AS "CUSTOMERSUBSEGMENT",
E1."CUSTOMERID" AS "CUSTOMERID",
E1."CUSTOMERREGION" AS "CUSTOMERREGION",
E1."ESCLATIONLEVELFIRED" AS "ESCALATIONLEVELFIRED",
E1."ESTIMATECOMPLETIONDATE" AS "ESTIMATECOMPLETETIME",
E1."OVERALLESTIMATECOMPLETIONDATE" AS "ESTIMATEDCLOSUREDATE",
E1."EVENTTYPE" AS "EVENTTYPE",
E1."EVENTWEIGHT" AS "EVENTWEIGHT",
E1."MODIFIEDBY" AS "MODIFIEDBY",
E1."MODIFIEDDATE" AS "MODIFIEDDATE",
E1."ORDERNUMBER" AS "ORDERNUMBER",
E1."ORDERSTATUS" AS "ORDERSTATUS",
E1."OWNER" AS "OWNER",
E1."PARTYID" AS "PARTYID",
E1."PARTYNAME" AS "PARTYNAME",
E1."PROCESSINSTANCEID" AS "PROCESSINSTANCEID",
E1."PRODUCTDESC" AS "PRODUCTDESCRIPTION",
E1."PRODUCTOFFERINGNAME" AS "PRODUCTOFFERING",
E1."REQUESTID" AS "REQUESTID",
E1."REQUESTEDDATE" AS "REQUESTEDDATE",
E1."REQUESTEDSYSTEM" AS "REQUESTEDSYSTEM",
E1."REVERSALREASON" AS "REVERSALREASON",
E1."SLABREACHED" AS "SLABREACHED",
E1."SMARTSEARCH" AS "SMARTSEARCH",
E1."TICKETNUMBER" AS "TICKETNUMBER",
E1."TRANSACTIONID" AS "TRANSACTIONID",
E1."PRODUCTIDENTIFIER" AS "PRODUCTIDENTIFIER",
C2."BUSINESSSEGMENT" AS "BUSINESSSEGMENT",
E1."PRODUCTIDENTIFIER" AS "COLUMN",
E1."ORDERCHANNEL" AS "ORDERCHANNEL",
E1."OVERALLPROGRESSPRCNT" AS "OVERALLPROGRESSPRCNT",
E1."PROCESSINSTANCEPRCNT" AS "PROCESSINSTANCEPRCNT",
O3."BCRMREQUESTTYPE" AS "BCRMREQUESTTYPE",
O3."OPRODUCTDETAIL_PRODUCTCATEGORY" AS "OPRODUCTDETAILPRODUCTCATEGOR",
O3."OPRODUCTDETAIL_PRODUCTLINE" AS "OPRODUCTDETAILPRODUCTLINE",
O3."OPRODUCTDETAIL_PRODUCTOFFERING" AS "OPRODUCTDETAILPRODUCTOFFERIN",
R4."CBCMREQUESTTYPE" AS "CBCMREQUESTTYPE",
R4."ORDERREFERENCENUMBER" AS "ORDERREFERENCENUMBER"
FROM
"BAMSPAPP"."ETOE_ORDER_TRACKER" E1,
"BAMSPAPP"."CUST_DETAILS" C2,
"BAMSPAPP"."ORDER_LINE_ITEMS_DETAILS" O3,
"BAMSPAPP"."REQUEST_DETAILS" R4
WHERE
(
E1."PROCESSINSTANCEID" = C2."PROCESSINSTANCEID"(+)
)
AND (
E1."PROCESSINSTANCEID" = O3."PROCESSINSTANCEID"(+)
)
AND (
E1."PROCESSINSTANCEID" = R4."PROCESSINSTANCEID"(+)
)
AND E1.CREATIONTIME >= '2019-02-01T00:00:00'
AND E1.CREATIONTIME < = '2019-05-06T00:00:00'
AND (
(
(
E1.ORDERSTATUS = 'Closed'
or E1.ORDERSTATUS = 'Cancelled'
)
and E1.PRODUCTIDENTIFIER = 'Mobile'
and NOT(E1.COMPLETIONTIME < SYSDATE -10)
)
OR (
(
E1.ORDERSTATUS = 'Closed'
or E1.ORDERSTATUS = 'Cancelled'
)
and (
E1.PRODUCTIDENTIFIER IS NULL
or E1.PRODUCTIDENTIFIER != 'Mobile'
)
and NOT(E1.COMPLETIONTIME < SYSDATE -30)
)
OR (
E1.ORDERSTATUS != 'Closed'
and E1.ORDERSTATUS != 'Cancelled'
)
)
order by
E1.CREATIONTIME
) a
where
rownum <= 5000
)
where
rnum >= 0
The error comes from comparing dates with character strings. Assuming CREATIONDATE is a date type field (which it should be) then the error is in the following conditions in your where clause:
E1.CREATIONTIME >= '2019-02-01T00:00:00'
AND E1.CREATIONTIME < = '2019-05-06T00:00:00'
You can solve it as follows:
E1.CREATIONTIME >= to_date('2019-02-01', 'YYYY-MM-DD')
AND E1.CREATIONTIME <= to_date('2019-05-06', 'YYYY-MM-DD')
Or from Oracle 11g onwards:
E1.CREATIONTIME >= date '2019-02-01'
AND E1.CREATIONTIME <= date '2019-05-06'
If however, these fields are character strings (varchar2), then the problem will be with the following condition:
NOT(E1.COMPLETIONTIME < SYSDATE -10)
Then you would need to fix it like this:
NOT(to_date(E1.COMPLETIONTIME, 'YYYY-MM-DD"T"HH24:MI:SS') < SYSDATE -10)
...where the second argument passed to the to_date function must represent the exact format of the field's content.
I have to add a column to this report - the new column name is: uda_value_desc
The code below will give me a result if I enter a PM_ITEM number, I need to insert the code into one of the in line views.
Any help would be appreciated
WITH item_temp AS (SELECT im.item
,uv.uda_value_desc uda_value_desc -----
FROM item_master im
,TABLE(mff_report.parse_strings(:PM_item)) t
, uda_item_lov uil
, uda_values uv
WHERE t.Column_Value = uil.item
and uil.UDA_ID = 511
and uv.uda_id = uil.uda_id
and uv.uda_value = uil.uda_value
and im.item = uil.item
UNION ALL
SELECT im.item
,null
FROM item_master im
,TABLE(mff_report.parse_strings(:PM_item)) t
WHERE t.COLUMN_VALUE = im.item_parent
AND im.item_level = im.tran_level
UNION ALL
SELECT sd.item
,null
FROM skulist_detail sd
,TABLE(mff_report.parse_strings(:PM_item_list)) t
WHERE t.COLUMN_VALUE = sd.skulist
UNION ALL
SELECT ia.item
,null
FROM mffecom.item_attr ia
,TABLE(mff_report.parse_strings(:PM_product_id)) t
WHERE t.COLUMN_VALUE = ia.product_id
UNION ALL
SELECT im.item
,null
FROM item_master im
WHERE :PM_item IS NULL
AND :PM_item_list IS NULL
AND :PM_product_id IS NULL )
SELECT v_item.item_parent
,uda_value_desc
,v_item.item
,mff_report.mff_merch_sql.get_brand_name(v_item.item) brand_name
,v_item.item_desc
,v_selling.product_id
,v_product.product_web_desc
,v_product.product_template
,v_product.romance_copy
,v_selling.selling_point_1
,v_selling.selling_point_2
,v_selling.selling_point_3
,v_selling.selling_point_4
,v_selling.selling_point_5
,v_selling.selling_point_6
,v_selling.selling_point_7
,v_selling.selling_point_8
,v_selling.selling_point_9
,v_selling.selling_point_10
,v_selling.selling_point_11
,v_selling.selling_point_12
,v_selling.selling_point_13
,v_selling.selling_point_14
,v_selling.selling_point_15
,v_selling.selling_point_16
,v_item.vpn
,v_item.diff_1
,v_item.diff1_desc
,v_item.diff_2
,v_item.diff2_desc
,v_item.diff_3
,v_item.diff3_desc
,v_item.diff_4
,v_item.diff4_desc
,v_item.supplier
,v_item.sup_name
,v_product.code_desc fulfillment_method_desc
,v_product.air_ship_restrict
,v_product.do_not_freeze
,v_product.free_shipping
,v_product.refrigerate
,v_product.serial_reqd
,v_product.vaccination
,v_product.is_consumable
,v_product.zero_weight
,v_product.restrict_state
,v_product.no_of_alt_image
,v_product.product_status
,v_product.item_ecom_status
,TO_CHAR(v_product.deactivate_date, 'MM/DD/YYYY') product_deactivate_date
,TO_CHAR(v_product.product_activate_date, 'MM/DD/YYYY') product_activate_date
,TO_CHAR(v_product.item_activate_date, 'MM/DD/YYYY') item_activate_date
,TO_CHAR(v_product.item_deactivate_date, 'MM/DD/YYYY') item_deactivate_date
,v_product.prod_created_by
,TO_CHAR(v_product.prod_created_date, 'MM/DD/YYYY') prod_created_date
,v_product.prod_updated_by
,v_product.item_created_by
,TO_CHAR(v_product.item_created_date, 'MM/DD/YYYY') item_created_date
,v_product.item_updated_by
,v_item.delete_type purge
,v_item.dept
,v_item.class
,v_item.subclass
,mff_orders_sql.buyer_for_item(v_item.item) buyer
,mff_orders_sql.buyer_name_for_item(v_item.item) buyer_name
,v_item.soh
,v_item.length
,v_item.width
,v_item.height
,v_item.weight
,v_variant.variant_id1
,v_variant.value_id1
,v_variant.variant_id2
,v_variant.value_id2
,v_variant.variant_id3
,v_variant.value_id3
,v_variant.variant_id4
,v_variant.value_id4
,v_variant.variant_id5
,v_variant.value_id5
,v_variant.variant_id6
,v_variant.value_id6
FROM (SELECT ia.item
,v_sell.product_id
,MIN(DECODE(row_num,1,selling_point)) selling_point_1
,MIN(DECODE(row_num,2,selling_point)) selling_point_2
,MIN(DECODE(row_num,3,selling_point)) selling_point_3
,MIN(DECODE(row_num,4,selling_point)) selling_point_4
,MIN(DECODE(row_num,5,selling_point)) selling_point_5
,MIN(DECODE(row_num,6,selling_point)) selling_point_6
,MIN(DECODE(row_num,7,selling_point)) selling_point_7
,MIN(DECODE(row_num,8,selling_point)) selling_point_8
,MIN(DECODE(row_num,9,selling_point)) selling_point_9
,MIN(DECODE(row_num,10,selling_point)) selling_point_10
,MIN(DECODE(row_num,11,selling_point)) selling_point_11
,MIN(DECODE(row_num,12,selling_point)) selling_point_12
,MIN(DECODE(row_num,13,selling_point)) selling_point_13
,MIN(DECODE(row_num,14,selling_point)) selling_point_14
,MIN(DECODE(row_num,15,selling_point)) selling_point_15
,MIN(DECODE(row_num,16,selling_point)) selling_point_16
FROM mffecom.item_attr ia
,(SELECT sp.product_id
,row_number () OVER (PARTITION BY sp.product_id ORDER BY sp.selling_point_id) row_num
,sp.selling_point
FROM mffecom.selling_point sp
ORDER BY sp.product_id
,sp.selling_point) v_sell
WHERE ia.product_id = v_sell.product_id
GROUP BY ia.item
,v_sell.product_id) v_selling
,(SELECT NVL(im.item_parent,im.item) item_parent
,im.item
,im.item_desc
,im.dept
,im.class
,im.subclass
,isupp.supplier
,s.sup_name
,isupp.vpn
,miim.stock_on_hand soh
,iscd.length
,iscd.width
,iscd.height
,iscd.weight
,im.diff_1
,di.diff_desc diff1_desc
,im.diff_2
,di2.diff_desc diff2_desc
,im.diff_3
,di3.diff_desc diff3_desc
,im.diff_4
,di4.diff_desc diff4_desc
,dp.delete_type
FROM item_supplier isupp
,sups s
,item_supp_country_dim iscd
,item_master im
,diff_ids di
,diff_ids di2
,diff_ids di3
,diff_ids di4
,daily_purge dp
,merch_item_inv_mv miim
WHERE isupp.item = im.item
AND isupp.item = miim.item (+)
AND isupp.supplier = s.supplier
AND isupp.item = iscd.item
AND isupp.supplier = iscd.supplier
AND isupp.primary_supp_ind = 'Y'
AND iscd.dim_object = 'EA'
AND im.item_level = im.tran_level
AND im.sellable_ind = 'Y'
AND im.diff_1 = di.diff_id (+)
AND im.diff_2 = di2.diff_id (+)
AND im.diff_3 = di3.diff_id (+)
AND im.diff_4 = di4.diff_id (+)
AND im.item = dp.key_value (+)) v_item
,(SELECT ia.item
,pm.product_id
,pm.product_web_desc
,pm.template product_template
,pm.romance_copy
,ia.air_ship_restrict
,ia.do_not_freeze
,ia.free_shipping
,ia.refrigerate
,ia.serial_reqd
,ia.vaccination
,ia.is_consumable
,ia.zero_weight
,pm.no_of_alt_image
,pm.status product_status
,ia.status item_ecom_status
,pm.deactivate_date deactivate_date
,pm.activate_date product_activate_date
,ia.activate_date item_activate_date
,ia.deactivate_date item_deactivate_date
,pm.created_by prod_created_by
,pm.create_datetime prod_created_date
,pm.updated_by prod_updated_by
,ita.created_by item_created_by
,ita.create_date item_created_date
,ia.updated_by item_updated_by
,str.restrict_state
,cd.code_desc
FROM MFFECOM.product_master pm
,MFFECOM.item_attr ia
,MFFECOM.ship_to_restrict str
,rms13.mff_brand mb
,rms13.item_attributes ita
,rms13.code_detail cd
WHERE ia.product_id = pm.product_id
AND ia.item = str.item (+)
AND ia.item = ita.item (+)
AND pm.brand_id = mb.brand_id (+)
AND to_char(ia.fulfillment_method) = cd.code
AND cd.code_type = 'EIFM') v_product
,(SELECT item
,product_id
,MIN(DECODE(row_num,1,variant_id)) variant_id1
,MIN(DECODE(row_num,1,value_id)) value_id1
,MIN(DECODE(row_num,2,variant_id)) variant_id2
,MIN(DECODE(row_num,2,value_id)) value_id2
,MIN(DECODE(row_num,3,variant_id)) variant_id3
,MIN(DECODE(row_num,3,value_id)) value_id3
,MIN(DECODE(row_num,4,variant_id)) variant_id4
,MIN(DECODE(row_num,4,value_id)) value_id4
,MIN(DECODE(row_num,5,variant_id)) variant_id5
,MIN(DECODE(row_num,5,value_id)) value_id5
,MIN(DECODE(row_num,6,variant_id)) variant_id6
,MIN(DECODE(row_num,6,value_id)) value_id6
FROM (SELECT item
,product_id
,row_number () OVER (PARTITION BY item ORDER BY variant_id) row_num
,variant_id
,value_id
FROM mffecom.item_variant)
GROUP BY item
,product_id) v_variant
,item_temp it
WHERE v_item.item = v_selling.item (+)
AND v_item.item = v_product.item (+)
AND v_item.item = v_variant.item (+)
AND v_item.item = it.item
AND v_item.supplier = NVL(:PM_supplier,v_item.supplier)
AND (v_product.prod_created_by = :PM_prod_created_by OR :PM_prod_created_by IS NULL)
AND (v_product.item_created_by = :PM_item_created_by OR :PM_item_created_by IS NULL)
AND (v_product.prod_created_date BETWEEN :prod_created_date_start AND :prod_created_date_to OR :prod_created_date_start IS NULL)
AND (v_product.item_created_date BETWEEN :item_created_date_start AND :item_created_date_to OR :item_created_date_start IS NULL)
ORDER BY v_product.product_id
I have a query which is used in an OBIEE report which erroring out for "ora-32044 while executing recursive WITH query". Tried running in SQL and it is erroring out in there as well. Can anyone take a look at the query and suggest how it can be run without the WITH clause. I have seen examples but without any level, for a case where WITH has been used in the middle of the query, how can it be rewritten without WITH clause so no ora-32044 occurs
`SELECT 1 dummy, oh.order_number, ol.line_number, ol.shipment_number,
oh.ordered_date, ot.NAME order_type, items.concatenated_segments item,
items.description item_description
,bom.assembly_item
,bom.component_item
,bom.implementation_date
,bom.disable_date as date_disabled
,bom.component_item_description
,ol.flow_status_code line_status
,ol.ordered_quantity,
ol.shipped_quantity,
ol.unit_selling_price,
ol.fulfilled_quantity,
ol.invoiced_quantity,
ol.cancelled_quantity,
ol.schedule_ship_date,
ol.promise_date,
ol.actual_shipment_date,
ol.request_date,
cust_acct.account_number customer_number,
party.party_name customer,
ct.trx_number invoice_number,
ctl.line_number inv_line_number,
ctl.extended_amount,
ct.trx_date invoice_date,
ct.creation_date invoice_creation_date,
wnd.NAME delivery_number,
wdd.released_status,
hp2.party_name endcustomer,
oh.attribute6 business_unit,
TO_CHAR (ol.actual_shipment_date, 'MM/YY') shipped_month,
TO_CHAR (ol.actual_shipment_date, '"Q"Q YY') shipped_qtr,
TO_CHAR (ol.actual_shipment_date, 'YYYY') shipped_year,
mc.segment1 product_group, mc.segment2 product_subgroup,
items.attribute7 drive_capacity,
items.attribute10 drive_form,
items.attribute8 drive_speed,
items.attribute6 drive_type,
items.attribute12 AgileParttype,
items.organization_id,
case when dis.arithmetic_operator = 'NEWPRICE' then operand
when dis.arithmetic_operator = '%'
then (ol.unit_selling_price* ol.ordered_quantity)*dis.operand/100.0
else NVL((NVL (ol.pricing_quantity, 0) * NVL (dis.adjusted_amount, 0)),0) end
discount_amount
FROM apps.oe_order_headers_all oh,
apps.oe_order_lines_all ol,
apps.wsh_new_deliveries wnd,
apps.wsh_delivery_assignments wda,
apps.wsh_delivery_details wdd,
apps.ra_customer_trx_all ct,
apps.ra_customer_trx_lines_all ctl,
apps.oe_transaction_types_tl ot,
(SELECT *
FROM apps.mtl_system_items_vl
WHERE organization_id = 84
) items,
apps.hz_parties party,
apps.hz_cust_accounts cust_acct,
apps.hz_parties hp2,
apps.hz_cust_accounts hca2,
apps.mtl_item_categories mic,
(SELECT *
FROM apps.mtl_category_sets
WHERE category_set_name = 'Inventory') ms,
apps.mtl_categories mc,
(select a.header_id, a.line_id ,a.list_header_id,a.creation_date,
a.arithmetic_operator,a.unit_selling_price,a.operand,
a.ordered_quantity, a.adjusted_amount
from
(select oh.header_id,
ol.line_id,pl.list_header_id,pl.creation_date,opa.arithmetic_operator,
ol.unit_selling_price,opa.operand,
ol.ordered_quantity, opa.adjusted_amount
from apps.oe_price_adjustments opa,
apps.oe_order_lines_all ol,
apps.oe_order_headers_all oh,
apps.qp_list_headers_vl pl
where oh.header_id = opa.header_id
and ol.line_id = opa.line_id
and opa.list_header_id = pl.list_header_id
and opa.applied_flag = 'Y'
AND opa.list_line_type_code = 'DIS') a,
(select oh.header_id, ol.line_id,max(pl.creation_date) creation_date, min(operand)
operand
from apps.oe_price_adjustments opa,
apps.oe_order_lines_all ol,
apps.oe_order_headers_all oh,
apps.qp_list_headers_vl pl
where oh.header_id = opa.header_id
and ol.line_id = opa.line_id
and opa.list_header_id = pl.list_header_id
and opa.applied_flag = 'Y'
AND opa.list_line_type_code = 'DIS'
group by oh.header_id, ol.line_id) b
where
a.header_id = b.header_id
and a.line_id = b.line_id
and a.creation_date = b.creation_date
and a.operand = b.operand ) dis
,(
WITH recursiveBOM (parent_item_id,parent_item,parent_org_id,assembly_item_id,
assembly_item,assembly_org_id,
component_item_id,component_item, component_item_description,implementation_date,
disable_date) AS
(
SELECT item.inventory_item_id parent_item_id
,item.segment1 parent_item
,item.organization_id parent_org_id
,bom.assembly_item_id
,msi.segment1 assembly_item
,bom.organization_id assembly_org_id
,bic.component_item_id
,msi2.segment1 component_item
,msi2.description component_item_description
,bic.implementation_date
,bic.disable_date
FROM apps.mtl_system_items_b item, apps.bom_bill_of_materials_v bom,
apps.bom_inventory_components_v bic, apps.mtl_system_items msi,
apps.mtl_system_items msi2
WHERE 1=1
AND bom.assembly_item_id = item.inventory_item_id
AND bom.organization_id = item.organization_id
AND bic.bill_sequence_id = bom.common_bill_sequence_id
AND msi.inventory_item_id = bom.assembly_item_id
AND msi.organization_id = bom.organization_id
AND msi2.inventory_item_id = bic.component_item_id
AND msi2.organization_id = msi.organization_id
AND bic.implementation_date IS NOT NULL
AND item.organization_id = 84
AND item.inventory_item_id > 0
UNION ALL
SELECT parent.parent_item_id
,parent.parent_item
,parent.parent_org_id
,bom.assembly_item_id
,msi.segment1 assembly_item
,bom.organization_id assembly_org_id
,bic.component_item_id
,msi2.segment1 component_item
,msi2.description component_item_description
,bic.implementation_date
,bic.disable_date
FROM recursiveBOM parent, apps.bom_bill_of_materials_v bom,
apps.bom_inventory_components_v bic, apps.mtl_system_items msi,
apps.mtl_system_items msi2
WHERE 1=1
AND bic.bill_sequence_id = bom.common_bill_sequence_id
AND msi.inventory_item_id = bom.assembly_item_id
AND msi.organization_id = bom.organization_id
AND msi2.inventory_item_id = bic.component_item_id
AND msi2.organization_id = msi.organization_id
AND bic.implementation_date IS NOT NULL
AND bom.assembly_item_id = parent.component_item_id
AND bom.organization_id = parent.assembly_org_id
AND bom.organization_id = 84
AND parent.assembly_org_id = 84
)
SELECT DISTINCT parent_item_id,parent_item,parent_org_id
,assembly_item_id
,assembly_item
,assembly_org_id
,component_item_id
,component_item
,component_item_description
,implementation_date
,disable_date
FROM recursiveBOM
) bom
WHERE oh.header_id = ol.header_id
AND ol.line_id = wdd.source_line_id
AND wdd.source_code = 'OE'
AND wda.delivery_detail_id = wdd.delivery_detail_id
AND wda.delivery_id = wnd.delivery_id
AND ol.line_id = ctl.interface_line_attribute6(+)
AND ctl.customer_trx_id = ct.customer_trx_id(+)
AND oh.order_type_id = ot.transaction_type_id
AND ol.inventory_item_id = items.inventory_item_id
AND ol.sold_to_org_id = cust_acct.cust_account_id
AND cust_acct.party_id = party.party_id
AND oh.end_customer_id = hca2.cust_account_id(+)
AND hca2.party_id = hp2.party_id(+)
AND items.inventory_item_id = mic.inventory_item_id(+)
AND items.organization_id = mic.organization_id(+)
AND mic.category_id = mc.category_id(+)
AND mic.category_set_id = ms.category_set_id(+)
and ol.line_id = dis.line_id(+)
and ol.header_id = dis.header_id(+)
AND bom.parent_item_id (+) = items.inventory_item_id
AND bom.parent_org_id (+) = items.organization_id `