MERGE into getting stuck all of a sudden - oracle
I have a stored procedure that is getting stuck on the merge into all of a sudden but has been working fine for years. Any advice ? The SP is in Oracle SQL developer and it is being executed in a Visual Studios SSIS package
Query below:
MERGE INTO CORE_APPT C
USING (
SELECT DISTINCT
TST_TKR_ID,
TST_TKR_ID_SRC,
APPT_ID_SRC,
APPT_CRETN_DTE,
APNTMT_DT,
ETS_APNTMT_ID,
ETS_TST_CNTR,
TST_STS_TYP_DESC,
APPT_STS_TYP,
TST_DLVR_MTHD_TYP_CDE,
DLVR_GRP_TYP,
TST_LNCH_TM,
TRNSCTN_ID,
TST_PKG_ID,
RND_TRIP_TST_FLG,
UPDT_DTE_TM,
PROD_ID,
ACTN_DTE_TM,
TST_DURN,
BRKRG_APPT_UPDT_DTM,
TST_APPT_TYP_CDE,
CNCL_MKUP_RSN_TYP,
DLNQNT_HLD_FLG,
TST_TKR_TST_UPDT_DTE_TM,
SCR_HLD_LVL_TYP_CDE,
SCR_CNCL_FLG,
ETS_CANDTE_SCR_HLD_FLG,
TST_CNTR_HLD_FLG,
TST_ADM_HLD_FLG,
ETS_SCR_CNCL_FLG,
TST_ADM_HLD_RSN_CDE,
TST_CNTR_HLD_RSN_CDE,
ETS_CANDTE_SCR_HLD_RSN_CDE,
ETS_SCR_CNCL_RSN_CDE,
DLNQNT_HLD_RSN_CDE,
TST_TKR_SCR_STS_TYP_CDE,
TST_TKR_SCR_STS_RSN_TYP_CDE,
PYMT_NO,
DATA_SRCE AS DATA_SRCE,
CURRENT_FLAG,
PRGRM_TYP,
sysdate as RCD_CRTD_DTE,
user as RCD_CRTD_USER,
REG_SYS_ID AS REG_SYS_ID,
TST_NAM AS TST_NAM,
CNTRY_SETL_RSP AS CNTRY_SETL_RSP
FROM STG_CMMN_APPT A
WHERE A.CURRENT_FLAG = 'Y'
) S
ON (C.APPT_ID_SRC = S.APPT_ID_SRC
AND C.REG_SYS_ID = S.REG_SYS_ID
AND C.DATA_SRCE = S.DATA_SRCE) -- added in EREG4.0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_STS_TYP,
S.TST_DLVR_MTHD_TYP_CDE,
S.DLVR_GRP_TYP,
S.TST_LNCH_TM,
S.TRNSCTN_ID,
S.TST_PKG_ID,
S.RND_TRIP_TST_FLG,
S.UPDT_DTE_TM,
S.PROD_ID,
S.ACTN_DTE_TM,
S.TST_DURN,
S.BRKRG_APPT_UPDT_DTM,
S.TST_APPT_TYP_CDE,
S.CNCL_MKUP_RSN_TYP,
S.DLNQNT_HLD_FLG,
S.TST_TKR_TST_UPDT_DTE_TM,
S.SCR_HLD_LVL_TYP_CDE,
S.SCR_CNCL_FLG,
S.ETS_CANDTE_SCR_HLD_FLG,
S.TST_CNTR_HLD_FLG,
S.TST_ADM_HLD_FLG,
S.ETS_SCR_CNCL_FLG,
S.TST_ADM_HLD_RSN_CDE,
S.TST_CNTR_HLD_RSN_CDE,
S.ETS_CANDTE_SCR_HLD_RSN_CDE,
S.ETS_SCR_CNCL_RSN_CDE,
S.DLNQNT_HLD_RSN_CDE,
S.TST_TKR_SCR_STS_TYP_CDE,
S.TST_TKR_SCR_STS_RSN_TYP_CDE,
S.PYMT_NO,
S.DATA_SRCE,
S.CURRENT_FLAG,
S.PRGRM_TYP,
S.RCD_CRTD_DTE,
S.RCD_CRTD_USER,
S.REG_SYS_ID,
S.TST_NAM,
S.CNTRY_SETL_RSP
)
;
TIA!
Related
SQLRPGLE & JSON_OBJECT CTE Statements -101 Error
This program compiles correctly, we are on V7R3 - but when running it receives an SQLCOD of -101 and an SQLSTATE code is 54011 which states: Too many columns were specified for a table, view, or table function. This is a very small JSON that is being created so I do not think that is the issue. The RPGLE code: dcl-s OutFile sqltype(dbclob_file); xfil_tofile = '/ServiceID-REFCODJ.json'; Clear OutFile; OutFile_Name = %TrimR(XFil_ToFile); OutFile_NL = %Len(%TrimR(OutFile_Name)); OutFile_FO = IFSFileCreate; OutFile_FO = IFSFileOverWrite; exec sql With elm (erpRef) as (select json_object ('ServiceID' VALUE trim(s.ServiceID), 'ERPReferenceID' VALUE trim(i.RefCod) ) FROM PADIMH I INNER JOIN PADGUIDS G ON G.REFCOD = I.REFCOD INNER JOIN PADSERV S ON S.GUID = G.GUID WHERE G.XMLTYPE = 'Service') , arr (arrDta) as (values json_array ( select erpRef from elm format json)) , erpReferences (refs) as ( select json_object ('erpReferences' : arrDta Format json) from arr) , headerData (hdrData) as (select json_object( 'InstanceName' : trim(Cntry) ) from padxmlhdr where cntry = 'US') VALUES ( select json_object('header' : hdrData format json, 'erpReferenceData' value refs format json) from headerData, erpReferences ) INTO :OutFile; Any help with this would be very much appreciated, this is our first attempt at creating JSON for sending and have not experienced this issue before. Thanks, John
I am sorry for the delay in getting back to this issue. It has been corrected, the issue was with the "values" statement. This is the correct code needed to make it work correctly: Select json_object('header' : hdrData format json, 'erpReferenceData' value refs format json) INTO :OutFile From headerData, erpReferences )
Error 71561: Unresolved reference to object
In Visual Studio 2017, SSDT 2015, I am receiving the "unresolved reference to object" error. This error is occurring 2,589 times, so it's not an issue with one particular piece of code. All of the code compiles and runs in SQL Server directly. I've tried everything from this post, except for disabling "extended Transact-SQL verification for common objects" because that option has been removed. I've tried pretty much everything else I can find on Google; I've been banging away on this for two days now. Here is an example of some of the code that's getting the error. It runs fine on SQL Server directly. The error comes up in the FROM clause on each line that contains a database reference. I can't remove those references or change the location of the view. This is also happening in stored procedures that reference the views. CREATE view [Migration].[vwCHILDS_Allegation_AllegationTrackingCharacteristics] as with src as ( select (select AllegationId from CWNS_Migration.Allegation.Allegation where SourceSystemId = cast(1 as int) and SourceSystemIdentifier = cast(a.IDNBR as nvarchar(64))) AllegationId , (select TrackingCharacteristicsId from CWNS_Migration.Allegation.TrackingCharacteristics where Code = dfrvmi1.DestinationDataFieldReferenceValueCode) TrackingCharacteristicsId , (select VerificationStatusId from CWNS_Migration.Allegation.VerificationStatus where Code = dfrvmi2.DestinationDataFieldReferenceValueCode) VerificationStatusId , cast(1 as int) SourceSystemId , cast(src.IDNBR as nvarchar(64)) SourceSystemIdentifier , src.IDNBR SourceSystemIdentifier_Numeric , case when src.CRET_DT_TM = '0001-01-01' then null else src.CRET_DT_TM end SourceSystemCreatedDateTime , ( select max(pe.PersonId) from CWNS_Migration.PersonIdentity.PersonIdentifier pe join CHILDSDB2.VLCHA.STAFF_USERID st on cast(st.FK_STAFFFK_PERSID as nvarchar(64)) = pe.Identifier and pe.PersonIdentificationSystemId = 4 where st.USERID = ltrim(rtrim(src.CRET_USER_ID))) SourceSystemCreatedPersonId from CHILDSDB2.VLCHA.RPT_TRKNG_CHAR src join CHILDSDB2.VLCHA.ALGTN a on a.FK_RPTRPT_NBR = src.FK_RPTRPT_NBR join CHILDSDB2.VLCHA.FINDING f on f.FK_ALGTNID = a.IDNBR join DataCatalog.dbo.DataFieldReferenceValueMappingInfo dfrvmi1 on dfrvmi1.SourceDataFieldReferenceValueDataFieldId = 5438 and dfrvmi1.SourceDataFieldReferenceValueCode = src.FK_TRKNG_CHAR_TCD and dfrvmi1.DestinationDataFieldReferenceValueDataFieldId = 20586 join DataCatalog.dbo.DataFieldReferenceValueMappingInfo dfrvmi2 on dfrvmi1.SourceDataFieldReferenceValueDataFieldId = 1775 and dfrvmi2.SourceDataFieldReferenceValueCode = f.FINDING_DET_CD and dfrvmi2.DestinationDataFieldReferenceValueDataFieldId = 55983 ) select src.* from src left join CWNS_Migration.Allegation.AllegationTrackingCharacteristics tgt on tgt.SourceSystemId = src.SourceSystemId and tgt.SourceSystemIdentifier = src.SourceSystemIdentifier left join CWNS_Migration.Quarantine.AllegationTrackingCharacteristics q on q.SourceSystemId = src.SourceSystemId and q.SourceSystemIdentifier = src.SourceSystemIdentifier and q.QExecutionId = 1 where q.QExecutionId is null and ( isnull(src.AllegationId, 0) <> isnull(tgt.AllegationId, 0) or isnull(src.TrackingCharacteristicsId, 0) <> isnull(tgt.TrackingCharacteristicsId, 0) or isnull(src.VerificationStatusId, 0) <> isnull(tgt.VerificationStatusId, 0) or try_cast(isnull(src.SourceSystemCreatedDateTime, '') as datetime) <> isnull(tgt.SourceSystemCreatedDateTime, '') or isnull(src.SourceSystemCreatedPersonId, '') <> isnull(tgt.SourceSystemCreatedPersonId, '') );
Add a Database reference to your project: You will need to refactor your code to use: [$(*ReferencedDatabaseName*)].schemaName.tableName
MERGE using Rowid Oracle Conversion in Postgres
Can some help me the best way convert the below Oracle code to Postgres MERGE INTO INCLUSION_EXCLUSION_ALL A USING (SELECT DISTINCT IEALL.rowid rid, IE.BLACKOUT_DURATION, ie.BLACKOUT_CATEGORY FROM INCLUSION_EXCLUSION_ALL IEALL, INCLUSION_EXCLUSION_RULES IE WHERE IE.PRI_PROMOTION_ID = IEALL.PRI_PROMOTION_ID AND IE.PRI_OFFER_ID = IEALL.PRI_OFFER_ID AND IE.SEC_PROMOTION_ID = IEALL.SEC_PROMOTION_ID AND IE.SEC_OFFER_ID = IEALL.SEC_OFFER_ID AND IE.BLACKOUT_DURATION > 0 AND (IEALL.BLACKOUT_DURATION <> IE.BLACKOUT_DURATION OR IEALL.BLACKOUT_CATEGORY <> IE.BLACKOUT_CATEGORY) --AND IE.INCL_EXCL_IND <> 'I' AND IE.SECONDARY_TYPE = 'B') B ON (A.rowid = B.rid) WHEN MATCHED THEN UPDATE SET A.BLACKOUT_DURATION = B.BLACKOUT_DURATION, A.BLACKOUT_CATEGORY = B.BLACKOUT_CATEGORY; Thank You, I want to know different ways on how we can do it as the rowid's are involved in here and are not compatible with Postgres esp in Joining using Alias even by using CTID, Please advise
Is MERGE supported in Greenplum Database 4.3.5.1 build 1
I am trying to create a merge statement for Greenplum DB and I am getting an syntax error. So I am wondering if the MERGE is even supported the way I am writing it. I have two approaches Approach 1- MERGE into public.table20 pritab USING ( select stgout.key1, stgout.key2, stgout.col1 from public.table20_stage stgout where stgout.sequence_id < 1000 ) as stgtab ON (pritab.key1 = stgtab.key1 and pritab.key2 = stgtab.key2) WHEN MATCHED THEN UPDATE SET pritab.key1 = stgtab.key1 ,pritab.key2 = stgtab.key2 ,pritab.col1 = stgtab.col1 WHEN NOT MATCHED THEN INSERT (key1, key2, col1) values (stgtab.key1, stgtab.key2, stgtab.col1); Approach 2: public.table20 pritab SET pritab.key1 = stgtab.key1 ,pritab.key2 = stgtab.key2 ,pritab.col1 = stgtab.col1 from ( select stgout.key1, stgout.key2, stgout.col1 from public.table20_stage stgout where stgout.sequence_id < 1000 ) as stgtab ON (pritab.key1 = stgtab.key1 and pritab.key2 = stgtab.key2) returning (stgtab.key1, stgtab.key2, stgtab.col1); Is there any other way or something is wrong with my syntax itself?
Merge is not supported in Greenplum but I wrote a blog post on how to achieve the results of a merge statement in Greenplum. http://www.pivotalguru.com/?p=104
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.