I inherited a query that is used for extract information from Oracle Database and they want now to create a XML file using SSIS. So far I read several forum and blogs and I found a way to connect it but not sure how I should use this query. I found that Oracle use XMLElement to create the XML but I got
Unsupported Oracle data type USERDEFINED encountered. (System.Data.OracleClient)
when I tried to run the query. I will provide part of the original query, because it is quite large code
SELECT
--SCHED_STASK.SCHED_ID,
ACFT_INV.INV_NO_SDESC AS "Aircraft",
SCHED_STASK.BARCODE_SDESC AS "Barcode",
EVT_EVENT.ACTUAL_START_DT AS "Act_Start_Dt",
EVT_EVENT.EVENT_DT AS "Act_End_Dt",
TASK_TASK.TASK_ORIGINATOR_CD AS "Originator",
SCHED_STASK.TASK_CLASS_CD AS "Class",
SCHED_STASK.TASK_SUBCLASS_CD AS "SubClass",
EVT_EVENT.EVENT_STATUS_CD AS "Status",
CASE
WHEN TASK_TASK.TASK_CD is null THEN null
WHEN TASK_TASK.TASK_CD is not null THEN TASK_TASK.TASK_CD||' ('||TASK_TASK.TASK_NAME||')'
END AS "Task Defn",
ORG_HR.HR_CD AS "Employee number / ID",
SCHED_WORK_TYPE.WORK_TYPE_CD AS "Worktype",
EVT_STAGE.STAGE_DT AS "Signed Date"
......
and a huge bunch of left joins. then the where clause
So could someone guide me on how to solve this scenario I will more than happy, quite new using Oracle, I am more familiar with MS SQL + SSIS than Oracle + SSIS
If I understand you correctly you want xml output from oracle sql? try this!
with data as(SELECT
'Blériot' AS Aircraft,
1234 AS BARCODE,
DATE '2018-01-01' ACT_START_DT,
DATE '2018-02-01' ACT_END_DT,
'Louis' Originator,
'XI' Class,
'Civil tourer/trainer/military' SubClass,
'Obsolete but cool' Status,
CASE
WHEN 'Rebuild on mass' IS NULL THEN NULL
WHEN 'Rebuild on mass' IS NOT NULL THEN 'Rebuild on mass'||' ('||'Splinters in the sky'||')'
END "Task Defn",
666 AS "Employee number / ID",
'capentry and seamstressing' Worktype,
DATE '2018-02-01' "Signed Date"
from dual)
SELECT XMLELEMENT("Project",
(XMLELEMENT("Aircraft",AIRCRAFT)),
(XMLELEMENT("BARCODE",BARCODE)),
(XMLELEMENT("ACT_START_DT",ACT_START_DT)),
(XMLELEMENT("ACT_END_DT",ACT_END_DT)),
(XMLELEMENT("Originator",Originator)),
(XMLELEMENT("Class",Class)),
(XMLELEMENT("SubClass",SubClass)),
(XMLELEMENT("Status",Status)),
(XMLELEMENT("Task Defn","Task Defn")),
(XMLELEMENT("Employee number / ID","Employee number / ID")),
(XMLELEMENT("Worktype",Worktype)),
(XMLELEMENT("Signed Date","Signed Date"))
)
from data
the result beeing:
<Project>
<Aircraft>Blériot</Aircraft>
<BARCODE>1234</BARCODE>
<ACT_START_DT>2018-01-01</ACT_START_DT>
<ACT_END_DT>2018-02-01</ACT_END_DT>
<Originator>Louis</Originator>
<Class>XI</Class>
<SubClass>Civil tourer/trainer/military</SubClass>
<Status>Obsolete but cool</Status>
<Task Defn>Rebuild on mass (Splinters in the sky)</Task Defn>
<Employee number / ID>666</Employee number / ID>
<Worktype>capentry and seamstressing</Worktype>
<Signed Date>2018-02-01</Signed Date>
</Project>
For This particular case, I decided to use another ssis control that I downloaded, it seems that over here the settings used by the company didnt allow a good interaction between the oracle and the ms ssis.
Related
SAP Bo has generated a SQL query for a report which is not working in Oracle SQL Developer. I am getting 'missing expression' error.
Below is the code, please help me finding out the error here.
and also help me to understand the role of #PROMPT here.
SELECT
CASE
WHEN MATERIAL IN #PROMPT('Enter materials which may not be shipped to SIMS:','C',,Multi,Free,Persistent) OR material IN #PROMPT'Enter materials which may not be shipped to SIMS(2):','C',,Multi,Free,Persistent)
THEN 'Not SIMS'
WHEN
material IN #PROMPT('Enter materials which can be shipped to SIMS:','C',,Multi,Free,Persistent)
THEN 'SIMS'
END
FROM
Materials;
Expecting query should work as the same is working in SAP BO.
Try it like this:
SELECT
CASE
WHEN MATERIAL IN(&Enter_NON_ShippableMaterials_SIMS) OR MATERIAL IN(&Enter_NON_ShippableMaterials_SIMS_2) THEN 'Not SIMS'
WHEN MATERIAL IN(&Enter_SIMS_ShippableMaterials) THEN 'SIMS'
END "SIMS_OR_NOT"
FROM
You will be prompted to input data 3 times. If data are of type VarChar2 and you need to enter a list of data as input then do it within single quotes separated by comma - 'MAT_1', 'MAT_2', ....
Regards...
Hey everyone im relativly new to Apache Drill and im having troubles converting my Oracle specific sql scripts (pl/sql) to Drill based querys.
For example i have a Scripts who checks for processed data in the last X Days.
In this script im using the the sysdate function.
Here is my old script:
SELECT i.id,i.status,status_text,i.kunnr,i.bukrs,i.belnr,i.gjahr,event,i.sndprn,i.createdate,executedate,tstamp,v.typ_text,i.docnum,i.description, i.*
FROM in_job i JOIN vstatus_injob v ON i.id= v.id
WHERE 1=1
AND i.createdate > sysdate - 30.5
order by i.createdate desc;
When i looked up in terms of drill specific Datetime Diff functions i found "TIMESTAMPDIFF".
So here is my "drillified" script:
SELECT i.id, i.status, status_text, i.kunnr, i.bukrs, i.belnr, i.gjahr, i.event, i.sndprn, i.createdate, i.executedate, i.tstamp,v.typ_text,i.docnum,i.description,i.*
FROM SchemaNAME.IN_JOB i JOIN SchemaNAME.VSTATUS_INJOB v ON i.id=v.id
WHERE TIMESTAMPDIFF(DAY, CURRENT_TIMESTAMP, i.createdate) >=30
And the Error that is returned reads like this:
DATA_READ ERROR: The JDBC storage plugin failed while trying setup the SQL query.
By further inspection i can see the Oracle specific error that reads:
Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "TIMESTAMPDIFF": invalid ID
So now my question:
I thought apache drill replaces the function "TIMSTAMPDIFF" at runtime. But from what i can see in the logs its more like that Drill Hands over the Function Call "TIMESTAMPDIFF" to the Oracle database.
If thats true, how could i change my script to calculate the time difference (in days) and compare it to an int (ie 30 in the script).
If i use sysdate like above Apache Drill jumps in and says it doesnt know "sysdate".
How would you guyes handle that?
Thanks in advance and so long
:)
I have found a solution...
Just in Case someone (or even me in the future) is having a similar problem.
{
"queryType": "SQL",
"query": "select to_char(SELECT CURRENT_TIMESTAMP - INTERVAL XX MONTH FROM (VALUES(1)),'dd.MM.yy')"
}
With some to_char and the use of the CURRENT_TIMESTAMP - Interval Function Calls i can get everything i needed.
I took the query above packed it into an Grafana Variable, named it "timeStmpDiff" and then queried everything with an json Api Call to my Drill instance.
Basically:
"query" : "SELECT i.id, i.status, status_text, i.kunnr, i.bukrs, i.belnr, i.gjahr, i.event, i.sndprn, i.createdate, i.executedate, i.tstamp,v.typ_text,i.docnum,i.description,i.* FROM ${Schema}.IN_JOB i JOIN ${Schema}.VSTATUS_INJOB v ON i.id=v.id WHERE i.createdate >= '${timeStmpDiff}' order by i.createdate desc"
You can, of course query it in on go with an subselect.
But because i use grafana it made sense to me to bundle that in a Variable.
I am trying to update a query to extract the hour from a timestamp and I keep getting an error. The error I get is due to the FROM clause I was using.
SELECT
analytics_platform_data_type
, activity_date_pt
, activity_timestamp_pt
, analytics_platform_timestamp_utc
, analytics_platform_timestamp_utc_iso
--This is the clause that is causing the problem (Begin)
, extract(hour from coalesce(activity_timestamp_pt)) as latd_hour_pt
--Clause above is the issue; Line above is line 9 (End)
, analytics_platform_ platform
, ad_channel_name
, publisher_name
, ip_address
, analytics_platform_unique_activity_id
, click_id
, latd_custom_fields
FROM table_date_range([AllData_AnalyticsMobileData_], timestamp('2018-09-
25'), timestamp('2018-09-27'))
where 1=1
and analytics_platform_data_type = 'CLICK'
and partner_name = 'ABC123'
If I remove the extract hour piece the query works fine. When I add it I get the error: Encountered " "FROM" "from "" at line 9, column 16. Was expecting: ")" ...
I have seen the clause I am trying to use in the above query used before, but it was a much more complex query that was using sub queries. Really not sure what the issue is. (Using Google Big Query Legacy SQL)
Your query is mixing Legacy Syntax (table_date_range) with Standard Syntax (Extract)
If for some reason you need to stick with Legacy SQL - use HOUR() instead of EXTRACT()
But it is much recommended to migrate stuff to Standard SQL - where you should use wildcard functions instead of table_date_range
Something like
FROM `project.dataset.AllData_AnalyticsMobileData_*`
WHERE _TABLE_SUFFIX BETWEEN '2018-09-25' AND '2018-09-27'
see more at https://cloud.google.com/bigquery/docs/reference/standard-sql/migrating-from-legacy-sql#table_decorators_and_wildcard_functions in Migrating to Standard SQL doc
We access an Oracle database through a web application. The web application is published, hosted and administered off-site. One component of the web application are dashboards, which use SQL to return data from the system on regular intervals that are then displayed and can trigger alarms should certain thresholds be reached.
The SQL has several parameters that are assigned in the dashboard setup: LOCATION, OWNER_DEPT, USING_DEPT and DAYS_AHEAD and appear to be working properly. Here is the query:
SELECT * FROM
(
SELECT DISTINCT
"MFIVE"."VIEW_WORK_REQ_OCC"."UNIT_NO" AS "UNIT NO", "MFIVE"."VIEW_WORK_REQ_OCC"."WORK_REQ_NO" AS "WORK REQ NO", "MFIVE"."VIEW_WORK_REQ_OCC"."JOB" AS "JOB",
CASE WHEN "MFIVE"."VIEW_WORK_REQ_OCC"."DUE_DATE" IS NULL THEN NULL ELSE ("MFIVE"."VIEW_WORK_REQ_OCC"."DUE_DATE") END AS "DUE DATE",
CASE WHEN "MFIVE"."VIEW_WORK_REQ_OCC"."FIRST_DATE" IS NULL THEN NULL ELSE ("MFIVE"."VIEW_WORK_REQ_OCC"."FIRST_DATE") END AS "FIRST DATE",
CASE WHEN "MFIVE"."VIEW_WORK_REQ_OCC"."LAST_DATE" IS NULL THEN NULL ELSE ("MFIVE"."VIEW_WORK_REQ_OCC"."LAST_DATE") END AS "LAST DATE"
FROM "MFIVE"."VIEW_WORK_REQ_OCC"
WHERE
("MFIVE"."VIEW_WORK_REQ_OCC"."MNT_PREVENTIVE_FL" = 'Y') AND
(UPPER("MFIVE"."VIEW_WORK_REQ_OCC"."LOCATION") LIKE UPPER(CONCAT(CONCAT('%', ':<LOCATION>'), '%'))) AND
(UPPER("MFIVE"."VIEW_WORK_REQ_OCC"."OWNER_DEPT") LIKE UPPER(CONCAT(CONCAT('%', ':<OWNER_DEPT>'), '%'))) AND
(UPPER("MFIVE"."VIEW_WORK_REQ_OCC"."USING_DEPT") LIKE UPPER(CONCAT(CONCAT('%', ':<USING_DEPT>'), '%'))) AND
("MFIVE"."VIEW_WORK_REQ_OCC"."DUE_DATE" >= SYSDATE + ':<DAYS_AHEAD>')
ORDER BY
"MFIVE"."VIEW_WORK_REQ_OCC"."UNIT_NO" ASC,
"MFIVE"."VIEW_WORK_REQ_OCC"."JOB" ASC,
CASE WHEN "MFIVE"."VIEW_WORK_REQ_OCC"."DUE_DATE" IS NULL THEN NULL ELSE ("MFIVE"."VIEW_WORK_REQ_OCC"."DUE_DATE") END AS "DUE DATE" ASC
)
The issue is with the statements involving "MFIVE"."VIEW_WORK_REQ_OCC"."DUE_DATE". We're attempting to return only values where DUE_DATE is greater than the SYSDATE plus the value in the DAYS_AHEAD parameter. Deleting these lines allows the query to execute properly; leaving them as-is returns the error ORA-00907: missing right parenthesis.
The majority of the SQL was lifted from the SQL as generated by an ad-hoc reporting component of the web application. The report runs properly, but we are not able to pass parameters through the ad-hoc reporting module. The modifications to the original were to add the bind variables.
I'm hoping someone can point me in the correct direction to remedy this issue. Any assistance is appreciated.
Thanks to Kaushik Nayak for helping me see the forest for the trees.
The correction only affects the ORDER BY clause:
...
ORDER BY
"MFIVE"."VIEW_WORK_REQ_OCC"."UNIT_NO" ASC,
"MFIVE"."VIEW_WORK_REQ_OCC"."JOB" ASC,
)
I use two cases in below query to get results of daction & ApprovalType.
While running the below query in Oracle SQL creates two new temp columns as daction_1 & ApprovalType _1 for daction & ApprovalType columns respectively. Now, i want to use these keywords in my IDOC code but since temp columns are created I'm not able to use them. How to resolve this?
SELECT WH.dActionDate,
WH.xWF_SendTo,
WH.dAction,
ATY.ApprovalType,
WH.xWorkflowComments,
CASE
WHEN NVL(ApprovalType,'') IS NULL
THEN xPurposeForRejection
ELSE ApprovalType
END AS ApprovalType,
CASE
WHEN NVL(dAction,'') ='SendTo'
AND NVL(ApprovalType,'') IS NOT NULL
OR NVL(dAction,'') ='Approve'
THEN 'Approve'
ELSE 'Reject'
END AS dAction
FROM WorkflowHistory WH,
Reason Re,
ApprovalType ATY
WHERE UPPER(dDocName) = UPPER('D_1239178')
AND xPurposeForSubmission = Re.ReasonID(+)
AND xDocApproval = ATY.ApprovalTypeID(+)
AND (dAction IN('Reject','Approve')
OR (dAction ='SendTo'
AND ApprovalType IS NOT NULL))
AND ROWNUM <= 5
ORDER BY dActionDate DESC,
dActionMillis
Looking at column names I assume that Idoc is script language used in Oracle Webcenter Content Server (formerly Oracle UCM). I don't have a running instance on-hand to check, but I am pretty sure that you can create database view with columns you need and then see it as regular table in Configuration Manager. Following link provides some details of configuration process. The other option is to move your logic to Idoc code itself although it may be less performant.