Can we override template_name in OBIEE/BIP burst definition while scheduling report job using ScheduleService::scheduleReport()? - obiee

We have a report with bursting query in OBIEE12c. We schedule report job using webservice via ScheduleService::scheduleReport() using web service client.
In the Burst Query we set the TEMPLATE for the generated report. Every thing is working fine.
select "invoice_table"."invid" as "KEY",
**'invoice_template1' as "TEMPLATE",**
'en-US' as "LOCALE",
'PDF' as "OUTPUT_FORMAT",
'EMAIL' as "DEL_CHANNEL",
'America/Los_Angeles' as "TIMEZONE",
...
The new requirement is to change the TEMPLATE in bursting query dynamically.
Is there any way to change the TEMPLATE set in Bursting query dynamically while invoking ScheduleService::scheduleReport() so that the generated report changed according to requirement.

There are different ways to do it. It all depends on what is the condition to change the TEMPLATE. If it is within reach of your bursting select command then you can use CASE expression to select the right TEMPLATE. But it is probably not.
I do burstings combined with BI_BURST_CONTROL table created for different reports where are all the data needed to control the execution. That table is joined to and part of bursting query. One of such looks like below where I use CASE to either send the report by mail or to save it to the directory. The same way you can change the TEMPLATE but only if you can define the condition for the CASE expression.
SELECT
mb.MATBR "KEY", -- DELIVER_BY Node beeing matched to KEY column
bc.TEMPLATE "TEMPLATE", -- Layout template to use (not name of Layout file)
bc.LOCALE "LOCALE", -- Localization (hr-HR)
'PDF' "OUTPUT_FORMAT", -- (PDF)
CASE mb.MATBR WHEN '000000' THEN 'File' ELSE 'Email' END "DEL_CHANNEL", -- (Email) (File) for not existing MATBR
CASE mb.MATBR WHEN '000000' THEN 'D:\File_Delivery' ELSE mb.MAIL END "PARAMETER1", -- (Email)To (File)Folder='D:\File_Delivery'
CASE mb.MATBR WHEN '000000' THEN 'Ost_' || To_Char(bc.ID) || '_' || :PROLAZ || '.pdf' ELSE Null END "PARAMETER2", -- (Email)Cc=Null (File)FileName
CASE mb.MATBR WHEN '000000' THEN Null ELSE bc.PARAMETER3 END "PARAMETER3", -- (Email)From (File)Null
CASE mb.MATBR WHEN '000000' THEN Null ELSE bc.PARAMETER4 END "PARAMETER4", -- (Email)Subject (File)Null
CASE mb.MATBR WHEN '000000' THEN Null ELSE bc.PARAMETER5 END "PARAMETER5", -- (Email)Message body (File)Null
CASE mb.MATBR WHEN '000000' THEN Null ELSE bc.PARAMETER6 END "PARAMETER6", -- (Email)Attachment=true (File)Null
Null "PARAMETER7", -- (Email)Reply to=Null (File)Null
Null "PARAMETER8", -- (Email)Bcc=Null (File)Null
Null "PARAMETER9", -- (Email)=Null (File)Null
Null "PARAMETER10", -- (Email)=Null (File)Null
bc.OUTPUT_NAME || mb.MATBR "OUTPUT_NAME" -- (Email)=AttFileName (with no extension) (File)Null
FROM
(
Select
MATBR "MATBR",
E_MAIL "MAIL"
From
SOME_TABLE#DBLINK
Where
DATE_START <= Last_Day(Add_Months(SysDate, -1)) And
Last_Day(Add_Months(SysDate, -2)) < Nvl(DATE_END, To_Date('11.10.2062', 'dd.mm.yyyy')) And
E_MAIL Is Not Null
UNION
Select '000000' "MATBR", Null "MAIL" From DUAL
) mb
INNER JOIN
BI_BURST_CONTROL bc ON(bc.OWNER_ID = 'OWNER_ID' And bc.ID = :ID)
The other way depends on your definition of SOAP envelope to invoke a ScheduleService. That envelope, in my case, is created by a package handling all the conditions and decisions within PL/SQL where it is not a problem to change the TEMPLATE or whatever else. Sample envelope generated by the package is here:
<?xml version="1.0" encoding="utf-8"?>
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap-env:Body>
<ns0:scheduleReport xmlns:ns0="http://xmlns.oracle.com/oxp/service/v2">
<ns0:scheduleRequest>
<ns0:dataModelUrl>http://some.url.of.bi.server:9502/xmlpserver/xdmeditor.jsp?f=/%7Euser/DPOP/DataModels/Otpr/Analyze_DataModel.xdm</ns0:dataModelUrl>
<ns0:jobLocale>hr-Hr</ns0:jobLocale>
<ns0:repeatCount>1</ns0:repeatCount>
<ns0:reportRequest>
<ns0:attributeCalendar>Gregorian</ns0:attributeCalendar>
<ns0:attributeFormat>pdf</ns0:attributeFormat>
<ns0:attributeLocale>hr-Hr</ns0:attributeLocale>
<ns0:attributeTemplate>Word_BI_PayListSQL_BLANK_7B.rtf</ns0:attributeTemplate>
<ns0:parameterNameValues>
<ns0:listOfParamNameValues>
<ns0:item>
<ns0:name>PASS_NUMBER</ns0:name>
<ns0:values>
<ns0:item>1</ns0:item>
</ns0:values>
</ns0:item>
<ns0:item>
<ns0:name>STEP</ns0:name>
<ns0:values>
<ns0:item>20</ns0:item>
</ns0:values>
</ns0:item>
</ns0:listOfParamNameValues>
</ns0:parameterNameValues>
<ns0:reportAbsolutePath>/~user/Payments/Reports/Work/PayListSQL_1_ver7_Report.xdo</ns0:reportAbsolutePath>
</ns0:reportRequest>
<ns0:scheduleBurstingOption>True</ns0:scheduleBurstingOption>
<ns0:startDate>2020-10-08T09:00:00+02:00</ns0:startDate>
<ns0:userJobName>PAYMENTS_2020-09_1</ns0:userJobName>
</ns0:scheduleRequest>
<ns0:userID>username</ns0:userID>
<ns0:password>password</ns0:password>
</ns0:scheduleReport>
</soap-env:Body>
</soap-env:Envelope>
I know that this will not solve your problem but hopefully it will give you an idea how to do it in your specific context. In my experience one of the two or a combination of both can solve almost every possible problem of the kind as in your question. Regards...

Related

Snowflake Query/task gets canceled cause of timelimit

I set up a code, to load Data from Google Analytics from a raw GA table to an adapted table, that offers more insights.
Somehow the Task is not running inside the defined time limit of 3600 seconds.
So the task is getting canceled and no data is loaded.
"Statement reached its statement or warehouse timeout of 3,600 second(s) and was canceled."
Then I load it in a manual way by using a fixed Clause: WHERE gae."DAY"='2020-03-31' instead of
WHERE gae."DAY">=CuRRENT_DATE-1. It takes still much time but works in the end.
How can I make this query faster? Or anyway, solve my problem.
CREATE OR REPLACE TASK dm."Website"."x009_002_all_GA_events"
WAREHOUSE = marketing_wh
SCHEDULE = 'USING CRON 26 5 * * * Europe/Berlin'
AS
merge into DM."Website".ALL_GA_EVENTS_CLEAN target --DM."Website".ALL_GA_EVENTS target
using (
SELECT
GAEVENTACTION AS GAEVENTACTION,
GAEVENTCATEGORY AS GAEVENTCATEGORY,
"DAY" AS Datum,
DEVICE_TYPE AS Device,
EVENT_COUNT AS EventCount,
GAUNIQUEEVENTS AS Uniqueevents,
EVENT_VALUE AS eventvalue,
LABELS AS labelz,
URL AS urlz,
--split_part(LABELS,'/_',2) AS "HITSTAMP",
CASE WHEN split_part(LABELS,'/_',2) IS NOT NULL THEN TRY_CAST(split_part(LABELS,'/_',2) AS timestamp) ELSE NULL END AS "HITSTAMP",
split_part(LABELS,'/_',3) AS EVENT_INFO,
split_part(LABELS,'/_',1) AS "SESSIONID",
CASE
WHEN CONTAINS (URL, '/checkout/')=TRUE THEN split_part(URL,'/',3)
WHEN CONTAINS (URL, '/auto/')=TRUE THEN split_part(split_part(URL,'/',3),'?',1)
WHEN CONTAINS (URL, '/angebote/')=TRUE THEN split_part(URL,'/',3)
ELSE 'no vehicle'
END AS vehicleID,
rank() over (partition BY "SESSIONID" order by "HITSTAMP") as "RANK",
CASE
WHEN (GAEVENTACTION= ('pdp_flash_offer_request' )) THEN
CASE WHEN split_part(LABELS,'/_',2)=(SELECT min(split_part(t2.LABELS,'/_',2))
FROM "DL_Datatap"."PUBLIC"."GA_all_events" t2
WHERE split_part(t2.LABELS,'/_',1)=split_part(gae.LABELS,'/_',1) AND gae.GAEVENTACTION=t2.GAEVENTACTION)
THEN TRUE
ELSE FALSE
END
WHEN (GAEVENTACTION= ('chat_started')) THEN
CASE WHEN split_part(LABELS,'/_',2)=(SELECT min(split_part(t2.LABELS,'/_',2))
FROM "DL_Datatap"."PUBLIC"."GA_all_events" t2
WHERE split_part(t2.LABELS,'/_',1)=split_part(gae.LABELS,'/_',1) AND gae.GAEVENTACTION=t2.GAEVENTACTION)
THEN TRUE
ELSE FALSE
END
WHEN (GAEVENTACTION= ('Direct_checkout_send')) THEN
CASE WHEN split_part(LABELS,'/_',2)=(SELECT min(split_part(t2.LABELS,'/_',2))
FROM "DL_Datatap"."PUBLIC"."GA_all_events" t2
WHERE split_part(t2.LABELS,'/_',1)=split_part(gae.LABELS,'/_',1) AND gae.GAEVENTACTION=t2.GAEVENTACTION)
THEN TRUE
ELSE FALSE
END
WHEN (GAEVENTACTION= ('pdp_offer_request')) THEN
CASE WHEN split_part(LABELS,'/_',2)=(SELECT min(split_part(t2.LABELS,'/_',2))
FROM "DL_Datatap"."PUBLIC"."GA_all_events" t2
WHERE split_part(t2.LABELS,'/_',1)=split_part(gae.LABELS,'/_',1) AND gae.GAEVENTACTION=t2.GAEVENTACTION)
THEN TRUE
ELSE FALSE
END
WHEN (GAEVENTACTION= ('agent-requested')) THEN
CASE WHEN split_part(LABELS,'/_',2)=(SELECT min(split_part(t2.LABELS,'/_',2))
FROM "DL_Datatap"."PUBLIC"."GA_all_events" t2
WHERE split_part(t2.LABELS,'/_',1)=split_part(gae.LABELS,'/_',1) AND gae.GAEVENTACTION=t2.GAEVENTACTION)
THEN TRUE
ELSE FALSE
END
WHEN (GAEVENTACTION= ('SERP_softlead_send')) THEN
CASE WHEN split_part(LABELS,'/_',2)=(SELECT min(split_part(t2.LABELS,'/_',2))
FROM "DL_Datatap"."PUBLIC"."GA_all_events" t2
WHERE split_part(t2.LABELS,'/_',1)=split_part(gae.LABELS,'/_',1) AND gae.GAEVENTACTION=t2.GAEVENTACTION)
THEN TRUE
ELSE FALSE
END
ELSE False
END AS "GOAL_EVENT"
FROM "DL_Datatap"."PUBLIC"."GA_all_events" gae
---WHERE gae."DAY"='2020-03-31'
WHERE gae."DAY">=CuRRENT_DATE-1
) SOURCE
ON target.SESSIONID=SOURCE."SESSIONID" AND target.HITSTAMP=SOURCE."HITSTAMP" AND target.EVENT_ACTION=SOURCE.GAEVENTACTION AND target."Date"=SOURCE.Datum
when NOT matched then INSERT (EVENT_ACTION, EVENT_CATEGORY, "Date", DEVICE, TOTAL_EVENTS, UNIQUE_EVENTS, EVENT_VALUE, EVENT_LABEL, URL, HITSTAMP, EVENT_INFO, SESSIONID, VEHICLEID, EVENT_SEQUENCE, GOAL_EVENT)
VALUES (SOURCE.GAEVENTACTION, SOURCE.GAEVENTCATEGORY, SOURCE.Datum, SOURCE.Device, SOURCE.eventcount, SOURCE.Uniqueevents, SOURCE. eventvalue, SOURCE.labelz, SOURCE.urlz, SOURCE."HITSTAMP", SOURCE.EVENT_INFO, SOURCE."SESSIONID", SOURCE.vehicleid, SOURCE."RANK", SOURCE."GOAL_EVENT"
)
You can increase the task timeout limit as a workaround:
CREATE OR REPLACE TASK dm."Website"."x009_002_all_GA_events"
WAREHOUSE = marketing_wh
SCHEDULE = 'USING CRON 26 5 * * * Europe/Berlin'
USER_TASK_TIMEOUT_MS = 86400000
AS
...
https://docs.snowflake.com/en/sql-reference/sql/create-task.html#optional-parameters
If you need help to tune your SQL, please submit a case to support. As they can see metadata of your tables, and execution plans of your previous runs, they can guide you to tune the query, cluster your target table etc..

Oracle case when, else, then error - missing keyword

The table I'm working with has these weird coded times, I'm trying to format them. The error I'm getting is "Missing Keyword". TRANS_NUMBER is a string of numbers that I need reformat.
CASE POST_TIME.TRANS_NUMBER
WHEN '' THEN ''
WHEN NULL THEN ''
WHEN SUBSTR(POST_TIME.TRANS_NUMBER,10,1) =':' THEN CONCAT('0', SUBSTR(POST_TIME.TRANS_NUMBER,9,1))
ELSE SUBSTR(POST_TIME.TRANS_NUMBER,9,2)
END AS "POSTED_HOUR",
CASE POST_TIME.TRANS_NUMBER
WHEN '' THEN ''
WHEN NULL THEN ''
WHEN SUBSTR(POST_TIME.TRANS_NUMBER,12,1) =':' THEN CONCAT( CONCAT( '0', SUBSTR(POST_TIME.TRANS_NUMBER,11,1) ), CONCAT(' ', SUBSTR(POST_TIME.TRANS_NUMBER,13,2) ) )
ELSE CONCAT( CONCAT( '0', SUBSTR(POST_TIME.TRANS_NUMBER,11,2) ), CONCAT(' ', SUBSTR(POST_TIME.TRANS_NUMBER,13,2) ) )
END AS "POSTED_MINUTE"
You're mixing up the syntax for simple and searched CASE statements which is why you're getting the error.
You can rewrite this as:
CASE WHEN POST_TIME.TRANS_NUMBER IS NULL THEN NULL
WHEN SUBSTR(POST_TIME.TRANS_NUMBER,10,1) = ':' THEN '0'||SUBSTR(POST_TIME.TRANS_NUMBER,9,1)
ELSE SUBSTR(POST_TIME.TRANS_NUMBER,9,2)
END AS "POSTED_HOUR",
CASE WHEN POST_TIME.TRANS_NUMBER IS NULL THEN NULL
WHEN SUBSTR(POST_TIME.TRANS_NUMBER,12,1) =':' THEN '0'||SUBSTR(POST_TIME.TRANS_NUMBER,11,1)||' '||SUBSTR(POST_TIME.TRANS_NUMBER,13,2)
ELSE '0'||SUBSTR(POST_TIME.TRANS_NUMBER,11,2)||' '||SUBSTR(POST_TIME.TRANS_NUMBER,13,2)
END AS "POSTED_MINUTE"
N.B. I've replaced each of your CONCAT()s with the more common and (IMHO) easily read ||
Plus the above is untested, since you didn't provide any example data for us to test with.
ETA: You don't even need to explicitly handle the case when POST_TIME.TRANS_NUMBER is null, as SUBSTR() of a null value returns null.
Your 3rd when should be nested case:
CASE POST_TIME.TRANS_NUMBER
WHEN '' THEN ''
WHEN NULL THEN ''
else
case WHEN SUBSTR(POST_TIME.TRANS_NUMBER,10,1) =':' THEN CONCAT('0', SUBSTR(POST_TIME.TRANS_NUMBER,9,1))
ELSE SUBSTR(POST_TIME.TRANS_NUMBER,9,2)
end
END AS "POSTED_HOUR",

Oracle Apex Reports shows data of different user

I am working on Oracle Apex and not that familiar with it. The application I am working on has already been developed by some other developer who has left the company. The issue is - There is a main/super user with which the actual db connection is made (using DADS.conf file entry). After that, user is presented with a Login screen where he enters db subuser credentials. We have few application level contexts defined, so after subuser login we set the context like username for that subuser. In the application there is a report that is supposed to show data for logged in subuser. Now, when first user logs in, the reports shows correct data. When second user logs in from a different machine report starts showing data for the second user in both the application instances. Sometimes second user's report shows data for first user. This behavior is random. Apart from the report other application works fine. I seems that Apex in this case is using same physical database connection and hence the contexts are getting overwritten. I might be wrong here. I am very confused and unable to find any solution. Any help is appreciated.
Here is the report query (much complicated) -
With
Date_range as (
select * from X_LOHAC_DateRANGE_WK
)
--
,Haud_a
AS ( select wor_works_order_no haud_pk_id, WOR_CHAR_ATTRIB110 HAUD_NEW_VALUE, WOR_DATE_ATTRIB131 HAUD_TIMESTAMP
from work_orders
where 1=1
AND WOR_CHAR_ATTRIB110 in ('REV', 'REVUPD','REVCOMM','APPCOMM','APP','REJCOMM','REJ','INTREJ','APPUN')
AND WOR_DATE_ATTRIB131 BETWEEN (select min(st_range) from Date_range) AND (select max(end_range) from Date_range)
)
, haud as (
select h.*, range_value from haud_a h, Date_range
where HAUD_TIMESTAMP BETWEEN st_range AND end_range
)
--
--
--
, claims as
(
select a.woc_works_order_no, a.woc_interim_no, woc_claim_value, claim_previous from
(select woc_works_order_no, woc_interim_no, woc_claim_value
, lag(woc_claim_value) over (partition by woc_works_order_no order by woc_interim_no Asc) as claim_previous
from work_order_claims
order by woc_works_order_no, woc_interim_no asc) a
, (select woc_works_order_no, max(woc_interim_no) woc_interim_no from work_order_claims group by woc_works_order_no) b
where a.woc_works_order_no = b.woc_works_order_no
and a. woc_interim_no = b.woc_interim_no
)
--
, main as (
SELECT DISTINCT
'<p title="Click for forms" id="'||works_order_number||'" onmouseover="showWOLDetails(this);">'|| WORKs_ORDER_NUMBER||'</p>' WORKS_ORDER_NUMBER
,decode( DECODE (mai_sdo_util.wo_has_shape (hig.get_sysopt ('SDOWOLNTH'), wor.works_order_number),
'TRUE', 'Y','N'),
'N',
'<img width=24 height=24 src="/im4_framework/images/grey_globe.png" title="No Location">'
,'') map
,decode(im_framework.has_doc(works_order_number,'WORK_ORDERS'),0,
'<img width=24 height=24 src="/im4_framework/images/mfclosed.gif" title="No Documents">'
,'') DOCS
,(select ial_meaning from nm_inv_attri_lookup where ial_domain = 'INVOICE_STATUS' and ial_value = wor_char_attrib110) INVOICE_STATUS
,WOR_CHAR_ATTRIB111 as "INVOICE_STATUS_COMMENT"
,works_order_description
, claim_previous Previous_Claim_Amount
, woc_claim_value New_Claim_Amount
, WOR_CHAR_ATTRIB111 Claim_Comments
,bud.work_category_description Budget_Description
, 'BOQ' BOQ
,WOR_CHAR_ATTRIB115 "Correct area of work "
,WOR_CHAR_ATTRIB116 "Quality of Work OK"
,WOR_CHAR_ATTRIB70 "Correct BOQ_Uplifts"
,WOR_CHAR_ATTRIB113 "Before_After_Photos_Present" --"Before After Photos Present"
,WOR_CHAR_ATTRIB114 "Certification Comments"
--,(select hus_name from hig_audits, hig_users where haud_pk_id = haud.haud_pk_id and haud_timestamp = haud.haud_timestamp and haud_new_value = haud.haud_new_value and haud_attribute_name = haud.haud_attribute_name and rownum =1) Reviewed_By
, (select HUS_NAME from hig_users where hus_user_id = WOR_NUM_ATTRIB04 ) Reviewed_By
, works_order_number wor_number
, 'Edit' rec_edit
--
FROM imf_mai_work_orders_all_attrib wor,
imf_mai_work_order_lines wol,
haud
,claims
,imf_mai_budgets bud
,pod_nm_element_security,
pod_budget_security
WHERE 1=1
and wol.budget_id = bud.budget_id
AND works_order_number = haud_pk_id
AND works_order_number = claims.woc_works_order_no(+)
AND works_order_number = work_order_number
AND pod_nm_element_security.element_id = wol.network_element_id
AND pod_budget_security.BUDGET_CODE = wol.work_category
AND WOR_CHAR_ATTRIB110 = haud_new_value
AND range_value = :P40_DAYS
AND WOR_CHAR_ATTRIB110 = :P40_PRIORITY
)
--
Select * from main;
Setting Context just uses DBMS_SESSION package as follows -
DBMS_SESSION.SET_CONTEXT('NM3SEC', p_attribute, p_value);
In this case - p_attribute is USERNAME
You can't use DBMS_SESSION with apex since it's a stateless framework pooling multiple connections between multiple sessions.
Apex uses url based session-id's.
You should rather
1) Create an application item in Shared Components.
2) Set the value of the item as a post login procedure using apex_util.set_session_state
Use the value of that item in your SQL code.

How to return multiple results with XMLTABLE?

I want to do a query in Oracle using xmltable.
Everything works fine, but there are multiple (n) results for xml node "article_title". For each row the result "<string>Article Name1</string><string>Article Name 2</string>... is returned. But I want every article name to be returned as a single row.
How can I realize this?
SELECT
X.*
FROM
myTable C,
xmltable (
'$cust//member' PASSING C.STAT_XML as "cust"
COLUMNS
name VARCHAR(25) PATH '/member/name',
article_title XMLTYPE PATH '//string/text()'
) as X
WHERE X.name = 'articles';
I'm having a problem with this as well. I have an XML that's supposed to send shipment data from our warehouse management system back to our order management system, and it has various different things that have multiples. The entire XML message has a single ShipConfirmHeader section, so that's easy enough to pull out. Where I run into trouble is that it has a ShipConfirmDetail/Orders section, and there could be any number of orders listed. Within each order, there could be any number of order lines. I can pull the ShipConfirmHeader and the ShipConfirmDetail/Orders together OR I can pull the ShipConfirmHeader and the ShipConfirmDetail/Orders/OrderLineItem together, but when I try pulling the Orders together with the OrderLineItem, there's no way that I can see to join those, so I end up with a cartesian product. To complicate matters even more, each Order could have many Cartons associated with it, and each Carton could contain multiple OrderLineItems, and each Carton could have multiple CartonDetails.
I've included a sample of my XML below. In this example, there's only one Order, one OrderLine, and one Carton (called an LPN in the XML), because I've stripped out all the others (the original XML is over 4000 lines long).
Pulling stuff from the ShipConfirmHeader is relatively easy, like this:
xmltable('/tXML/Message/ShipConfirm/ShipConfirmSummary/ShipConfirmHeaderInfo/'
passing xmltype(msg_xml.full_xml)
columns
invoice_batch varchar2(20) path 'InvcBatchNbr'
) sc_hdr
But when I want to include any of the multiples, it gives me problems. I've tried a variety of things:
-- This gives the error "ORA-22950: cannot ORDER objects without MAP or ORDER method"
xmltable('/tXML/Message/ShipConfirm'
passing xmltype(msg_xml.full_xml)
columns
invoice_batch varchar2(20) path 'ShipConfirmSummary/ShipConfirmHeaderInfo/InvcBatchNbr',
order_dtl xmltype path 'ShipConfirmDetails/Orders'
) sc_hdr
-- This doesn't like the "../" in the XPATH
xmltable('/tXML/Message/ShipConfirm/ShipConfirmDetails/Orders/OrderLineItem'
passing xmltype(msg_xml.full_xml)
columns
invoice_batch varchar2(20) path '../../../ShipConfirmSummary/ShipConfirmHeaderInfo/InvcBatchNbr',
order_id varchar2(20) path '../TcOrderId',
order_line_id varchar2(20) path 'TcOrderLineId',
item_name varchar2(20) path 'ItemName'
) sc_hdr
-- This gives a cartesian product.
xmltable('/tXML/Message/ShipConfirm/ShipConfirmSummary/ShipConfirmHeaderInfo'
passing xmltype(msg_xml.full_xml)
columns
invoice_batch varchar2(20) path 'InvcBatchNbr'
) sc_hdr,
xmltable('/tXML/Message/ShipConfirm/ShipConfirmDetails/Orders'
passing xmltype(msg_xml.full_xml)
columns
order_id varchar2(20) path 'TcOrderId'
) sc_ord_hdr,
xmltable('/tXML/Message/ShipConfirm/ShipConfirmDetails/Orders/OrderLineItem'
passing xmltype(msg_xml.full_xml)
columns
order_line_id varchar2(20) path 'TcOrderLineId',
item_name varchar2(20) path 'ItemName'
) sc_ord_dtl
Here's the sample XML:
<?xml version="1.0" encoding="UTF-8"?>
<tXML>
<Header>
<Source>warehouse management system</Source>
<Action_Type></Action_Type>
<Sequence_Number></Sequence_Number>
<Batch_ID></Batch_ID>
<Reference_ID></Reference_ID>
<User_ID>CRONUSER</User_ID>
<Password></Password>
<Message_Type>ShipConfirm</Message_Type>
<Company_ID>1</Company_ID>
<Msg_Locale>English (United States)</Msg_Locale>
<Msg_Time_Zone>America/Denver</Msg_Time_Zone>
<Version>2018</Version>
</Header>
<Message>
<ShipConfirm>
<ShipConfirmSummary>
<CompanyName>Blah</CompanyName>
<FacilityName>Blah</FacilityName>
<ShipConfirmHeaderInfo>
<InvcBatchNbr>123456</InvcBatchNbr>
<LastInvcDttm>5/27/21 05:45</LastInvcDttm>
<ShippedDttm>5/27/21 05:45</ShippedDttm>
<DateCreated>5/27/21 05:45</DateCreated>
<StoreNbr></StoreNbr>
<ShipVia>ST</ShipVia>
<SchedDeliveryDate></SchedDeliveryDate>
<ProNbr></ProNbr>
<AppointmentNbr></AppointmentNbr>
<ManifestNbr></ManifestNbr>
<SealNbr></SealNbr>
<AppointmentDate></AppointmentDate>
<PartialShipConfirmStatus>5</PartialShipConfirmStatus>
<PreBillStatus>0</PreBillStatus>
<ApptMadeByID></ApptMadeByID>
<BillOfLading></BillOfLading>
<CancelQuantity>0.0</CancelQuantity>
<NbrOfLpns>26</NbrOfLpns>
<NbrOfPlts>0</NbrOfPlts>
<NbrOfOrders>26</NbrOfOrders>
<TotalWt>61.72</TotalWt>
<UserID>USER</UserID>
</ShipConfirmHeaderInfo>
</ShipConfirmSummary>
<ShipConfirmDetails>
<Orders>
<BatchCtrlNbr>123456</BatchCtrlNbr>
<DistributionShipVia>ST</DistributionShipVia>
<DoType>Customer Order</DoType>
<DsgShipVia>ST</DsgShipVia>
<OriginalShipVia>ST</OriginalShipVia>
<IncotermLocAvaTimeZoneId>America/New_York</IncotermLocAvaTimeZoneId>
<InvcBatchNbr>123456</InvcBatchNbr>
<IsBackOrdered>1</IsBackOrdered>
<MajorOrderCtrlNbr></MajorOrderCtrlNbr>
<OrderType>ECOMM_ORDER</OrderType>
<ShipDate>5/27/21 05:45</ShipDate>
<OrderStatus>Unplanned</OrderStatus>
<DoStatus>Shipped</DoStatus>
<TcCompanyId>1</TcCompanyId>
<TcOrderId>MYORDERID</TcOrderId>
<TotalNbrOfLpn>1</TotalNbrOfLpn>
<TotalNbrOfPlt>0</TotalNbrOfPlt>
<TotalNbrOfUnits>1</TotalNbrOfUnits>
<LineHaulShipVia>ST</LineHaulShipVia>
<PartialShipConfirmStatus>5</PartialShipConfirmStatus>
<PreBillStatus>0</PreBillStatus>
<OrderBillToInfo>
<BillToAddress1>Snip</BillToAddress1>
<BillToAddress2></BillToAddress2>
<BillToAddress3></BillToAddress3>
<BillToCity>Snip</BillToCity>
<BillToContact></BillToContact>
<BillToContactName></BillToContactName>
<BillToCountryCode>CA</BillToCountryCode>
<BillToCounty></BillToCounty>
<BillToFacilityName></BillToFacilityName>
<BillToName>Snip</BillToName>
<BillToPhoneNumber>Snip</BillToPhoneNumber>
<BillToPostalCode>Snip</BillToPostalCode>
<BillToStateProv>ON</BillToStateProv>
</OrderBillToInfo>
<OrderDestInfo>
<DestAddress1>Snip</DestAddress1>
<DestAddress2></DestAddress2>
<DestAddress3></DestAddress3>
<DestCity>Snip</DestCity>
<DestContact>Snip</DestContact>
<DestCountryCode>CA</DestCountryCode>
<DestCounty></DestCounty>
<DestDockDoorId>0</DestDockDoorId>
<DestFacilityAliasId></DestFacilityAliasId>
<DestFacilityId>0</DestFacilityId>
<DestFacilityName></DestFacilityName>
<DestName>Snip</DestName>
<DestPhoneNumber>Snip</DestPhoneNumber>
<DestPostalCode>Snip</DestPostalCode>
<DestStateProv>ON</DestStateProv>
</OrderDestInfo>
<OrderOriginInfo>
<OriginAddress1>Snip</OriginAddress1>
<OriginAddress2></OriginAddress2>
<OriginAddress3></OriginAddress3>
<OriginCity>Snip</OriginCity>
<OriginContact></OriginContact>
<OriginCountryCode>CA</OriginCountryCode>
<OriginFacilityAliasId>Snip</OriginFacilityAliasId>
<OriginFacilityId>1</OriginFacilityId>
<OriginFacilityName>Snip</OriginFacilityName>
<OriginPhoneNumber></OriginPhoneNumber>
<OriginPostalCode>Snip</OriginPostalCode>
<OriginStateProv>AB</OriginStateProv>
</OrderOriginInfo>
<OrderInfoFields>
<SplInstrCode1>MW</SplInstrCode1>
<SplInstrCode2>MW</SplInstrCode2>
</OrderInfoFields>
<OrderLineItem>
<InvcBatchNbr>123456</InvcBatchNbr>
<ItemId>159331</ItemId>
<ItemName>MYITEMNAME</ItemName>
<LineItemId>12053970</LineItemId>
<OrderQty>1</OrderQty>
<OrderQtyUom>Unit</OrderQtyUom>
<OrigItemId>159331</OrigItemId>
<OrigItemName>MYITEMNAME</OrigItemName>
<OrigOrderLineItemId>1</OrigOrderLineItemId>
<OrigOrderQty>1</OrigOrderQty>
<OrigOrderQtyUom>Unit</OrigOrderQtyUom>
<OutptOrderLineItemId>3782033</OutptOrderLineItemId>
<Price>15.39</Price>
<PriceTktType></PriceTktType>
<RetailPrice>0.0</RetailPrice>
<ShippedQty>1</ShippedQty>
<TcCompanyId>1</TcCompanyId>
<TcOrderLineId>1</TcOrderLineId>
<UnitVol>0.0744</UnitVol>
<UnitWt>0.58</UnitWt>
<Uom>Unit</Uom>
<UserCanceledQty>0</UserCanceledQty>
<OrderLineItemDefn>
<ItemStyle>Snip</ItemStyle>
<ItemStyleSfx>Snip</ItemStyleSfx>
</OrderLineItemDefn>
</OrderLineItem>
<Lpn>
<BillOfLadingNumber></BillOfLadingNumber>
<CFacilityAliasId>Snip</CFacilityAliasId>
<EstimatedWeight>0.58</EstimatedWeight>
<FinalDestFacilityAliasId></FinalDestFacilityAliasId>
<InvcBatchNbr>123456</InvcBatchNbr>
<LoadedDttm></LoadedDttm>
<ManifestNbr></ManifestNbr>
<MasterBolNbr></MasterBolNbr>
<NonInventoryLpnFlag>0</NonInventoryLpnFlag>
<NonMachineable></NonMachineable>
<OutptLpnId>730888</OutptLpnId>
<PackerUserid>USER</PackerUserid>
<ProcDttm>5/27/21 05:45</ProcDttm>
<ProcStatCode>0</ProcStatCode>
<QtyUom>Unit</QtyUom>
<ServiceLevel></ServiceLevel>
<ShipVia>ST</ShipVia>
<ShippedDttm>5/27/21 05:45</ShippedDttm>
<StaticRouteId></StaticRouteId>
<TcCompanyId>1</TcCompanyId>
<TcLpnId>98765</TcLpnId>
<TcOrderId>Snip</TcOrderId>
<TcParentLpnId></TcParentLpnId>
<TcShipmentId></TcShipmentId>
<TotalLpnQty>1</TotalLpnQty>
<TrackingNbr>Snip</TrackingNbr>
<VolumeUom>cu ft</VolumeUom>
<Weight>0.58</Weight>
<WeightUom>Lbs</WeightUom>
<LoadSequence>0</LoadSequence>
<oLPNXRefNbr></oLPNXRefNbr>
<LpnDetail>
<InvcBatchNbr>123456</InvcBatchNbr>
<ItemId>159331</ItemId>
<ItemName>MYITEMNAME</ItemName>
<LpnDetailId>20153787</LpnDetailId>
<OutptLpnDetailId>3689518</OutptLpnDetailId>
<QtyUom>Unit</QtyUom>
<SizeValue>1</SizeValue>
<TcCompanyId>1</TcCompanyId>
<TcLpnId>98765</TcLpnId>
<DistroNumber></DistroNumber>
<TcOrderLineId>1</TcOrderLineId>
<MinorOrderNbr>Snip</MinorOrderNbr>
<MinorPoNbr></MinorPoNbr>
</LpnDetail>
</Lpn>
</Orders>
</ShipConfirmDetails>
</ShipConfirm>
</Message>
</tXML>
Try something like this:
SELECT X.*
FROM my_table C,
xmltable('for $i in $cust//string , $j in $cust//member[./string=$i]/name return <member>{$j}{$i}</member>'
passing c.stat_xml AS "cust"
columns name varchar2(25) path '/member/name',
article_title xmltype path '//string') AS X
WHERE X.name = 'articles';
Here is a fiddle
I assumed that for every member you have one name but might have many strings

Suppress ORA-01403: no data found excpetion

I have the following code
SELECT SUM(nvl(book_value,
0))
INTO v_balance
FROM account_details
WHERE currency = 'UGX';
--Write the balance away
SELECT SUM(nvl(book_value,
0))
INTO v_balance
FROM account_details
WHERE currency = 'USD';
--Write the balance away
Now the problem is, there might not be data in the table for that specific currency, but there might be data for the 'USD' currency. So basically I want to select the sum into my variable and if there is no data I want my stored proc to continue and not throw the 01403 exception.
I don't want to put every select into statement in a BEGIN EXCEPTION END block either, so is there some way I can suppress the exception and just leave the v_balance variable in an undefined (NULL) state without the need for exception blocks?
select nvl(balance,0)
into v_balance
from
(
select sum(nvl(book_value,0)) as balance
from account_details
where currency = 'UGX'
);
SELECT L1.PKCODE L1CD, L1.NAME L1N, L1.LVL L1LVL,
L2.PKCODE L2CD, L2.NAME L2N, L2.LVL L2LVL,
L5.PKCODE L5CD, L5.NAME L5N,
INFOTBLM.OPBAL ( L5.PKCODE, :PSTDT, :PSTUC, :PENUC, :PSTVT, :PENVT ) OPBAL,
INFOTBLM.DEBIT ( L5.PKCODE, :PSTDT,:PENDT, :PSTUC, :PENUC, :PSTVT, :PENVT ) AMNTDR,
INFOTBLM.CREDIT ( L5.PKCODE, :PSTDT,:PENDT, :PSTUC, :PENUC, :PSTVT, :PENVT ) AMNTCR
FROM FSLVL L1, FSLVL L2, FSMAST L5
WHERE L2.FKCODE = L1.PKCODE
AND L5.FKCODE = L2.PKCODE
AND L5.PKCODE Between :PSTCD AND NVL(:PENCD,:PSTCD)
GROUP BY L1.PKCODE , L1.NAME , L1.LVL ,
L2.PKCODE , L2.NAME , L2.LVL ,
L5.PKCODE , L5.NAME
ORDER BY L1.PKCODE, L2.PKCODE, L5.PKCODE

Resources