We have a process that imports jira data into an oracle database for reporting. The issue I am having at the moment is extracting custom fields and converting a row into a column in oracle.
jira custom data view
jira data view
This is how I am extracting the query, the problem here is that the performance just does not scale.
select A.*, (select cf.date_value from v_jira_custom_fields cf where cf.issue_id = a.issue_id and cf.custom_field_name = 'Start Date') Start_Date,
(select cf.number_value from v_jira_custom_fields cf where cf.issue_id = a.issue_id and cf.custom_field_name = 'Story Points') Story_Points,
(select cf.custom_value from v_jira_custom_fields cf where cf.issue_id = a.issue_id and cf.custom_field_name = 'Ready') Ready
from jira_data A
where A.project = 'DAK'
and A.issue_id = 2222
To really understand where the bottleneck is we'd need to get an execution plan and info about indexes that exists, at least.
Assuming you have indexes on issue_id and project in both tables, what I'd try next is to get rid of the 3 separate selects and join your jira_data to pivoted jira_custom_fields
with P as (
select
project
, issue_id
, story_type_s
, impacted_application_s
, impacted_application_c
, story_points_n
, start_date_d
, end_date_d
, ready_c
from v_jira_custom_fields
pivot (
max(string_value) as s
, max(number_value) as n
, max(text_value) as t
, max(date_value) as d
, max(custom_value) as c
for customfield_id in (
1 story_type
, 2 impacted_application
, 3 story_points
, 4 start_date
, 5 end_date
, 6 ready
)
)
)
select
A.*
, P.start_date_d start_date
, P.story_points_n story_points
, P.ready_c ready
from jira_data A
join P on A.project = P.project and A.issue_id = P.issue_id
where A.project = 'DAK'
and A.issue_id = 2222
I defined a stored procedure with input and output parameters and am getting the following error when I try to call the stored procedure.
[SQL0312] Variable KUNNR not defined or not usable.
Here is the call:
CALL R3QA6DATA.SP_ADDRESS_CHANGES ('1999-12-31 23:59:59', '2016-06-01 23:59:59', :KUNNR,:KUNN2,:NAME1,:NAME2,:STRAS,:ORT01,:REGIO,:PSTLZ,:LAND1,:TELF1,:TELFX,:DEFPA)
GO
Here is the stored procedure:
CREATE PROCEDURE R3QA6DATA.SP_ADDRESS_CHANGES
(IN STARTDATE TIMESTAMP, IN ENDDATE TIMESTAMP,
OUT KUNNR GRAPHIC(10), OUT KUNN2 GRAPHIC(10), OUT NAME1 GRAPHIC(35), OUT NAME2 GRAPHIC(35), OUT STRAS GRAPHIC(35), OUT ORT01 GRAPHIC(35),
OUT REGIO GRAPHIC(3), OUT PSTLZ GRAPHIC(10), OUT LAND1 GRAPHIC(3), OUT TELF1 GRAPHIC(16), OUT TELFX GRAPHIC(31), OUT DEFPA GRAPHIC(1) )
LANGUAGE SQL
BEGIN
SELECT DISTINCT
knvp.kunnr
, knvp.kunn2
, kna1.name1
, kna1.name2
, kna1.stras
, kna1.ort01
, kna1.regio
, kna1.pstlz
, kna1.land1
, kna1.telf1
, kna1.telfx
, knvp.defpa
INTO KUNNR, KUNN2, NAME1, NAME2, STRAS, ORT01, REGIO, PSTLZ, LAND1, TELF1, TELFX, DEFPA
FROM
R3QA6DATA.KNA1 AS kna1
INNER JOIN
R3QA6DATA.ZMBCM AS zmbcm
ON
kna1.KUNNR = zmbcm.KUNAG
INNER JOIN
R3QA6DATA.KNVV AS knvv
ON
( kna1.KUNNR = knvv.KUNNR )
INNER JOIN
R3QA6DATA.KNVP AS knvp
ON
(
knvv.KUNNR = knvp.KUNNR
AND
knvv.VKORG = knvp.VKORG
AND
knvv.VTWEG = knvp.VTWEG
AND
knvv.SPART = knvp.SPART
)
WHERE
kna1.MANDT = '010'
AND
knvp.PARVW IN ('WE', 'AG')
AND
(
knvv.VKORG = zmbcm.VKORG
AND
knvv.VTWEG = zmbcm.VTWEG
AND
knvv.SPART = zmbcm.SPART
)
AND
kna1.loevm = ' '
AND
knvv.loevm = ' '
AND
knvp.KUNN2 IN
(
SELECT
SUBSTRING(bdcp2.tabkey, 4, 10)
FROM
R3QA6DATA.BDCP2 AS bdcp2
WHERE
bdcp2.mestype = 'DEBMAS'
AND
(
( bdcp2.tabname = 'KNA1'
AND
bdcp2.fldname IN
('NAME1'
, 'NAME2'
, 'STRAS'
, 'ORT01'
, 'REGIO'
, 'LAND1'
, 'PSTLZ'
, 'TELF1'
, 'TELFX') )
OR
( bdcp2.tabname = 'KNVP' )
)
AND
(
bdcp2.cretime > STARTDATE
AND
bdcp2.cretime < ENDDATE
)
)
AND
zmbcm.STOREID = 4 ;
END
Go
In RPGLE or COBOL this issue usually happens if you have the variables defined in an external source and accessed through COPY statement. If this is the case in your problem then try using the source through INCLUDE.
I am trying to interpret Oracle script into SQL script and I see that I am converting the joins wrong as Oracle is using multiple instances of the same table(see orguserfield_c, orguserfield_e, etc in select statment). Could anyone please help me in converting the Oracle into SQL script. Thanks
ORACLE SCRIPT:
select distinct
wh_acctcommon.effdate
, wh_acctcommon.acctnbr
, wh_acctcommon.acctclosecurrmonthyn
, wh_acctcommon.acctofficer
, wh_acctcommon.acctofficernbr
, wh_acctcommon.acctopencurrmonthyn
, wh_acctcommon.notebal
, wh_acctcommon.branchname
, wh_acctcommon.branchorgnbr
, orguserfield_c.value branch_internal_no
, orguserfield_e.value branch_status
, orguserfield_h.value branch_hub_no
, orguserfield_i.value metro_micro
, orguserfield_j.value division
, userfieldvalue_l.userfieldvaluedesc division_name
, orguserfield.value region
, userfieldvalue.userfieldvaluedesc region_name
, wh_acctcommon.primaryownercity
, wh_acctcommon.closedate
, wh_acctcommon.compoundcalpercd
, wh_acctcommon.contractdate
, wh_acctcommon.datelastmaint
, wh_acctcommon.ownername
, wh_acctcommon.bankorgnbr
, wh_acctcommon.intbase
, wh_acctcommon.intmethcd
, wh_acctcommon.noteintrate
, wh_acctcommon.ownersortname
, wh_acctcommon.loanofficer
, wh_acctcommon.loanofficersnbr
, wh_acctcommon.mjaccttypcd
, wh_acctcommon.managingofficer
, wh_acctcommon.managingofficernbr
, acctacctrolepers.persnbr SBB_Portfolio_Mgr_Nbr
, persview.fullname SBB_Portfolio_Mgr
, acctacctrolepers_c.persnbr Orig_Loan_Officer_Nbr
, persview_d.fullname Orig_Loan_Officer
, acctacctrolepers_e.persnbr Collection_Officer_Nbr
, persview_e.fullname Collection_Officer
, wh_acctcommon.datemat
, wh_acctcommon.intminbalamt
, wh_acctcommon.intmincalcbaltypcd
, wh_acctcommon.monthendyn
, wh_acctcommon.notemtdavgbal
, wh_acctcommon.nameaddr1
, wh_acctcommon.nameaddr2
, wh_acctcommon.nameaddr3
, wh_acctcommon.nameaddr4
, wh_acctcommon.nameaddr5
, wh_acctcommon.notenextratechangedate
, wh_acctcommon.noteopenamt
, wh_acctcommon.originatingperson
, wh_acctcommon.origpersnbr
, wh_acctcommon.bookbalance
, wh_acctcommon.businessphone
, wh_acctcommon.homephone
, wh_acctcommon.currmiaccttypcd
, wh_acctcommon.product
, wh_acctcommon.calcbaltypcd
, wh_acctcommon.noteratechangecalpercd
, wh_acctcommon.daysmethcd
, wh_acctcommon.noteintcalcschednbr
, wh_acctcommon.ratetypcd
, wh_acctcommon.primaryownerstate
, wh_acctcommon.curracctstatcd
, wh_acctcommon.curracctstateffdate
, wh_acctcommon.taxidnbr
, wh_acctcommon.taxrptfororgnbr
, wh_acctcommon.taxrptforpersnbr
, wh_acctcommon.currterm
, wh_acctcommon.primaryownerzipcd
, wh_acctcommon.primaryownerzipcdsuff
from OSIBANK.wh_acctcommon
, OSIBANK.orguserfield
, OSIBANK.orguserfield orguserfield_c
, OSIBANK.orguserfield orguserfield_e
, OSIBANK.orguserfield orguserfield_h
, OSIBANK.orguserfield orguserfield_i
, OSIBANK.orguserfield orguserfield_j
, OSIBANK.userfieldvalue
, OSIBANK.userfieldvalue userfieldvalue_l
, OSIBANK.acctacctrolepers
, OSIBANK.persview
, OSIBANK.acctacctrolepers acctacctrolepers_c
, OSIBANK.persview persview_d
, OSIBANK.acctacctrolepers acctacctrolepers_e
, OSIBANK.persview persview_e
where ( wh_acctcommon.branchorgnbr = orguserfield.orgnbr(+)
and upper(orguserfield.userfieldcd(+)) = 'WREG'
and orguserfield.userfieldcd = userfieldvalue.userfieldcd(+)
and orguserfield.value = userfieldvalue.userfieldvalue(+)
)
and ( wh_acctcommon.branchorgnbr = orguserfield_c.orgnbr(+)
and upper(orguserfield_c.userfieldcd(+)) = 'WBRN'
)
and ( wh_acctcommon.branchorgnbr = orguserfield_e.orgnbr(+)
and upper(orguserfield_e.userfieldcd(+)) = 'WBRS'
)
and ( wh_acctcommon.branchorgnbr = orguserfield_h.orgnbr(+)
and upper(orguserfield_h.userfieldcd(+)) = 'WHBN'
)
and ( wh_acctcommon.branchorgnbr = orguserfield_i.orgnbr(+)
and upper(orguserfield_i.userfieldcd(+)) = 'WSIZ'
)
and ( wh_acctcommon.branchorgnbr = orguserfield_j.orgnbr(+)
and upper(orguserfield_j.userfieldcd(+)) = 'WDIV'
and orguserfield_j.userfieldcd = userfieldvalue_l.userfieldcd(+)
and orguserfield_j.value = userfieldvalue_l.userfieldvalue(+)
)
and ( wh_acctcommon.acctnbr = acctacctrolepers.acctnbr(+)
and upper(acctacctrolepers.acctrolecd(+)) = 'PMGR'
and acctacctrolepers.persnbr = persview.persnbr(+)
)
and ( wh_acctcommon.acctnbr = acctacctrolepers_c.acctnbr(+)
and acctacctrolepers_c.acctrolecd(+) = 'OLOF'
and acctacctrolepers_c.persnbr = persview_d.persnbr(+)
)
and ( wh_acctcommon.acctnbr = acctacctrolepers_e.acctnbr(+)
and acctacctrolepers_e.acctrolecd(+) = 'COFF'
and acctacctrolepers_e.persnbr = persview_e.persnbr(+)
);
SQL SCRIPT:
select
wh_acctcommon.[EFFDATE]
, wh_acctcommon.acctnbr
, wh_acctcommon.acctclosecurrmonthyn
, wh_acctcommon.acctofficer
, wh_acctcommon.acctofficernbr
, wh_acctcommon.acctopencurrmonthyn
, wh_acctcommon.notebal
, wh_acctcommon.branchname
, wh_acctcommon.branchorgnbr
,OUF.value AS 'branch_internal_no'
, OUF.value AS 'branch_status'
, OUF.value AS 'branch_hub_no'
, OUF.value AS 'metro_micro'
, OUF.value AS 'division'
, UFV.[USERFIELDVALUEDESC] AS 'division_name'
, OUF.value AS 'region'
, UFV.userfieldvaluedesc AS 'region_name'
, wh_acctcommon.primaryownercity
, wh_acctcommon.closedate
, wh_acctcommon.compoundcalpercd
, wh_acctcommon.contractdate
, wh_acctcommon.datelastmaint
, wh_acctcommon.ownername
, wh_acctcommon.bankorgnbr
, wh_acctcommon.intbase
, wh_acctcommon.intmethcd
, wh_acctcommon.noteintrate
, wh_acctcommon.ownersortname
, wh_acctcommon.loanofficer
, wh_acctcommon.loanofficersnbr
, wh_acctcommon.mjaccttypcd
, wh_acctcommon.managingofficer
, wh_acctcommon.managingofficernbr
, AARP.persnbr AS 'SBB_Portfolio_Mgr_Nbr'
, PV.fullname as 'SBB_Portfolio_Mgr'
, AARP.persnbr AS 'Orig_Loan_Officer_Nbr'
, PV.fullname AS 'Orig_Loan_Officer'
, AARP.persnbr as 'Collection_Officer_Nbr'
, PV.fullname AS 'Collection_Officer'
, wh_acctcommon.datemat
, wh_acctcommon.intminbalamt
, wh_acctcommon.intmincalcbaltypcd
, wh_acctcommon.monthendyn
, wh_acctcommon.notemtdavgbal
, wh_acctcommon.nameaddr1
, wh_acctcommon.nameaddr2
, wh_acctcommon.nameaddr3
, wh_acctcommon.nameaddr4
, wh_acctcommon.nameaddr5
, wh_acctcommon.notenextratechangedate
, wh_acctcommon.noteopenamt
, wh_acctcommon.originatingperson
, wh_acctcommon.origpersnbr
, wh_acctcommon.bookbalance
, wh_acctcommon.businessphone
, wh_acctcommon.homephone
, wh_acctcommon.currmiaccttypcd
, wh_acctcommon.product
, wh_acctcommon.calcbaltypcd
, wh_acctcommon.noteratechangecalpercd
, wh_acctcommon.daysmethcd
, wh_acctcommon.noteintcalcschednbr
, wh_acctcommon.ratetypcd
, wh_acctcommon.primaryownerstate
, wh_acctcommon.curracctstatcd
, wh_acctcommon.curracctstateffdate
, wh_acctcommon.taxidnbr
, wh_acctcommon.taxrptfororgnbr
, wh_acctcommon.taxrptforpersnbr
, wh_acctcommon.currterm
, wh_acctcommon.primaryownerzipcd
, wh_acctcommon.primaryownerzipcdsuff
FROM
[DNA_Staging].[dbo].[WH_ACCTCOMMON] wh_acctcommon
LEFT OUTER JOIN [DNA_Staging].[dbo].orguserfield OUF
ON wh_acctcommon.branchorgnbr = OUF .orgnbr
and upper(OUF.userfieldcd) IN( 'WREG','WBRN','WBRS','WHBN','WSIZ','WDIV')
LEFT OUTER JOIN [DNA_Staging].[dbo].userfieldvalue UFV
ON OUF.userfieldcd = UFV.userfieldcd
and OUF.value = UFV.userfieldvalue
LEFT OUTER JOIN [DNA_Staging].[dbo].[ACCTACCTROLEPERS] AARP
ON wh_acctcommon.acctnbr = AARP.acctnbr
and upper(AARP.acctrolecd) IN ('PMGR','OLOF','COFF')
LEFT OUTER JOIN [DNA_Cleanup_DM].[dbo].PERSVIEW PV
ON AARP.persnbr = PV.persnbr
This is mostly about converting the pre-SQL99 Oracle proprietary joins into SQL99 joins. Rather than try to convert your actual code, here is some advice:
The number of tables in the from clause should remain exactly the same in both queries. If a table is listed 5 times (with aliases) in the original query, you should have the same 5 instances in the revised query. A fatal flaw with your revised query is that you're trying to collapse these relationships using in. You simply can't do that and retain the meaning of the original query.
Start with the first table and work down, converting each comma in the original from clause into an on.
If a relationship in the original where clause contains the outer join indicator ((+)), then that relationship must go in the outer table's on clause. For instance, a.a = b.a(+) must become left join b on a.a = b.a.
i have created a query that is sued to display a data in a label. This particular query will then be stored into a program that we use. The query runs just fine until this morning when it returns the error ORA-30928: "Connect by filtering phase runs out of temp tablespace". I have Googled and found out that I can do any of the following:
Include a NO FILTERING hint - but did not work properly
Increase the temp tablespace - not applicable to me since this runs in a production server that I don't have any access to.
Are there other ways to fix this? By the way, below is the query that I use.
SELECT * FROM(
SELECT
gn.wipdatavalue
, gn.containername
, gn.l
, gn.q
, gn.d
, gn.l2
, gn.q2
, gn.d2
, gn.l3
, gn.q3
, gn.d3
, gn.old
, gn.qtyperbox
, gn.productname
, gn.slot
, gn.dt
, gn.ws_green
, gn.ws_pnr
, gn.ws_pcn
, intn.mkt_number dsn
, gn.low_number
, gn.high_number
, gn.msl
, gn.baketime
, gn.exptime
, NVL(gn.q, 0) + NVL(gn.q2, 0) + NVL(gn.q3, 0) AS qtybox
, row_number () over (partition by slot order by low_number) as n
FROM
(
SELECT
tr.*
, TO_NUMBER(SUBSTR(wipdatavalue, 1, INSTR (wipdatavalue || '-', '-') - 1)) AS low_number
, TO_NUMBER(SUBSTR(wipdatavalue, 1 + INSTR ( wipdatavalue, '-'))) AS high_number
, pm.msllevel MSL
, pm.baketime BAKETIME
, pm.expstime EXPTIME
FROM trprinting tr
JOIN CONTAINER c ON tr.containername = c.containername
JOIN a_lotattributes ala ON c.containerid = ala.containerid
JOIN product p ON c.productid = p.productid
LEFT JOIN otherdb.pkg_main pm ON trim(p.brandname) = trim(pm.pcode)
WHERE (c.containername = :lot OR tr.SLOT= :lot)
)gn
LEFT JOIN otherdb.intnr intn ON TRIM(gn.productname) = TRIM(intn.part_number)
connect by level <= HIGH_NUMBER + 1 - LOW_NUMBER and LOW_NUMBER = prior LOW_NUMBER and prior SYS_GUID() is not null
ORDER BY low_number,n
)
WHERE n LIKE :n AND wipdatavalue LIKE :wip AND ROWNUM <= 300 AND wipdatavalue NOT LIKE 0
I am using Oracle 11g too.
Thanks for the help everyone.
I have the following query against an Oracle database:
select * from (
select Person.pId, Person.lastName as patLast, Person.firstName as patFirst
, Person.dateOfBirth
, Medicate.mId, Medicate.startDate as medStart, Medicate.description
, cast(substr(Medicate.instructions, 1, 50) as char(50)) as instruct
, ml.convert_id_to_date(Prescrib.pubTime) as scripSigned
, max(ml.convert_id_to_date(Prescrib.pubTime)) over (partition by Prescrib.pId, Prescrib.mId) as LastScrip
, UsrInfo.pvId, UsrInfo.lastName as provLast, UsrInfo.firstName as provFirst
from ml.Medicate
join ml.Prescrib on Medicate.mId = Prescrib.mId
join ml.UsrInfo on Prescrib.pvId = UsrInfo.pvId
join ml.Person on Medicate.pId = Person.pId
where Person.isPatient = 'Y'
and Person.pStatus = 'A'
and Medicate.xId = 1.e+035
and Medicate.change = 2
and Medicate.stopDate > sysdate
and REGEXP_LIKE(Medicate.instructions
, ' [qtb]\.?[oi]?\.?[dw][^ayieo]'
|| '|[^a-z]mg?s'
|| '|ij'
|| '|[^a-z]iu[^a-z]'
|| '|[0-9 ]u '
|| '|[^tu]hs'
, 'i')
order by ScripSigned desc
) where scripSigned = lastScrip and scripSigned > date '2011-01-01'
I have a Report Parameter defined, DateBegin, defined as a DateTime, and I've associated it with a Query Parameter also called DateBegin. I just can't figure out how to replace "date '2011-01-01'" with "DateBegin" so that the blinkin' thing actually works. Thanks!
Use the Oracle format for parameters - so use the following:
) where scripSigned = lastScrip and scripSigned > :DateBegin
(The # sign is used in SQLServer to identify SQLServer variables.)