Returning value in cursor
I have a function that worked pretty good until now processing a single records at the time, but now the application requirements has changed. It is required the same function to process any number of records that the application will enter as criteria. I tried to use a (ref)cursor, but I cannot use the returning value inside.
So, the chagne is below - instead of test_id = X, rownum <101 for example.
How can I make it work?
Thanks a lot for the help.
Mj
create table TEST ( test_id number, test_col varchar2(100));
insert into TEST values (1 , 'RAM' );
insert into TEST values (2, 'ram' );
insert into TEST values ( 3, 'rAm' );
set serveroutput on
DECLARE
v_delete_test_id number(9, 2) :=0;
BEGIN
DELETE FROM test
WHERE TEST_ID =1 -- the change is here using now where rownum<101 or 10
RETURNING test_id
INTO v_delete_test_id;
commit;
dbms_output.put_line('test_id ' ||v_delete_test_id|| 'returned');
END;
/
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/tuning.htm#sthref2236
Similar Messages
-
How to create a procedure function with a return value of ref cursor?
Can anybody provide a sample about how to create a procedure function with a return value of REF CURSOR?
I heard if I can create a function to return a ref cursor, I can use VB to read its recordset.
Thanks a lot.http://osi.oracle.com/~tkyte/ResultSets/index.html
-
How to get a stored function return value (which is not a cursor)?
I want to do so with ADO inside Visual Basic. I know how to call a stored procedure, but nothing I tried could help me in calling a stored function and getting its return code. Note that the function has no cursors within its argument or return code.
Your quick response would be appreciated
EyalEyal,
A stored function returns a value. You need to have the first parameter (of correct data type) for the returned value. The parameter binding is pretty much the same as you would do with stored procedures.
e.g. "begin :1= proc(....); end;"
Sinclair -
Ref cursor stopped returning values for the output.
Hi Everyone,
My DB version is
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
Please do have a look at the code, and let me know where I've gone wrong, because select query is fetching data. Previously procedure was returning values too through ref cursor. Please correct me where I've gone wrong.
create or replace
PROCEDURE
SPL_SPN_MISSING_EMR_AOE_DTL (IN_PATIENT_ID NUMBER,
IN_FACILITY_ID NUMBER,
IN_DRAW_DT DATE,
IN_REQUISITION_NUMBER ORDER_REQUISITION_HEADER.REQUISITION_NUMBER%TYPE,
IN_CORP_ACRONYM CORPORATION.CORPORATION_ACRONYM%TYPE,
IN_ABCDEF_MRN PATIENT.ABCDEF_MRN%TYPE,
IN_ACCOUNT_NUMBER FACILITY_ACCOUNT_DETAIL.ACCOUNT_NUMBER%TYPE,
IN_HLAB_NUM FACILITY_ACCOUNT_DETAIL.HLAB_NUM%TYPE,
OV_COMMENTS OUT VARCHAR2,
OR_QUES_AND_ANS OUT SYS_REFCURSOR) AS
* Copyright (C) 2013 ABCDEF Laboratories
* All Rights Reserved
* This Work Contains Trade Secrets And Confidential Material Of
* ABCDEF Laboratories., And Its Use Of Disclosure In Whole Or In Part
* Without Express Written Permission Of ABCDEF Laboratories Is Prohibited.
* Company : ABCDEF Laboratories
* Project : ABCDEF Scorpion
* Name : SPL_SPN_MISSING_EMR_AOE_DTL
* In Parameters : In_Patient_Id Number
* In_Facility_Id Number
* In_Draw_Dt Date
* In_Requisition_Number Order_Requisition_Header.Requisition_Number%Type,
* In_Corp_Acronym Corporation.Corporation_Acronym%Type
* In_ABCDEF_Mrn Patient.ABCDEF_Mrn%Type
* In_Account_Number Facility_Account_Detail.Account_Number%Type
* In_Hlab_Num Facility_Account_Detail.Hlab_Num%Type
* Out Parameters : OV_COMMENTS Out Varchar2
* OR_QUES_AND_ANS Out Sys_Refcursor
* Description : This Procedure Will Fetch The Mising Emr Aoe Detail And Provide
* Necessary Comments As Well.
* Modification History :
* Date Version No. Author Description
* 21/01/2014 1.0 ABCDEF Initial Version
* 27/01/2014 1.1 ABCDEF Restricted the output for duplicate questions
* and answers, partially answered AOE. Also renamed
* the output variable names.
CC_PACKAGE_NAME CONSTANT VARCHAR2(50) := 'SPL_SPN_MISSING_EMR_AOE_DTL';
CC_PROCEDURE_NAME CONSTANT VARCHAR2(50) := 'SPL_SPN_MISSING_EMR_AOE_DTL';
VC_AVL_PAT_QUES VARCHAR2(1000);
VC_DUP_PAT_QUES VARCHAR2(1000);
VC_ACTUAL_QUES VARCHAR2(1000);
VC_ACTUAL_QUES_CNT NUMBER:= 0;
VR_QUES_AND_ANS SYS_REFCURSOR;
VN_AVL_PAT_QUES_CNT NUMBER := 0;
VN_DUP_PAT_QUES_CNT NUMBER := 0;
VN_EXACT_PAT_ID_CNT NUMBER := 0;
VN_DUPL_PAT_ID NUMBER := 0;
VN_EXTERNAL_ID PATIENT.EXTERNAL_ID%TYPE;
VC_OBX_QUES VARCHAR2(1000);
VC_OBX_QUES_CNT NUMBER := 0;
VN_OBX_QUES_CNT NUMBER := 0;
PAT_EXTERNAL_ID PATIENT.EXTERNAL_ID%TYPE;
VC_EXACT_BOOLEAN_VAL VARCHAR2(10) := 'FALSE';
VC_EXACT_PAR_BOOLEAN_VAL VARCHAR2(10) := 'FALSE';
VC_DUPL_BOOLEAN_VAL VARCHAR2(10) := 'FALSE';
VC_DUPL_PAR_BOOLEAN_VAL VARCHAR2(10) := 'FALSE';
VC_REJECTED_BOOLEAN_VAL VARCHAR2(10) := 'FALSE';
VC_REJECTED_PAR_BOOLEAN_VAL VARCHAR2(10) := 'FALSE';
VC_COMMENTS VARCHAR2(100);
VC_PAR_COMMENTS VARCHAR2(100);
VC_RETURN_EXACT_PAT CHAR(1) := 'N';
VC_RETURN_DUPL_PAT CHAR(1) := 'N';
VC_RETURN_REJECT_PAT CHAR(1) := 'N';
VC_CHK_FOR_EXT_ID CHAR(1) := 'N';
VN_MAX_MSG_ID INTERFACE_A04_OBX_SEGMENT.MSG_ID%TYPE;
VN_MAX_COUNT NUMBER := 0;
VN_ITERATION_RUN NUMBER := 0;
BEGIN
SPL_SPN_ERROR_LOGGING_SPK.INFO_PROC
(IC_PACKAGE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IC_PROCEDURE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IN_BATCH_ID => '100'
,IC_MESSAGE_TEXT => 'Start of the procedure with Patient_Id:'||IN_PATIENT_ID||' Facility_Id:'||IN_FACILITY_ID||
' Draw_Dt:'||IN_DRAW_DT||' Requisition_Number:'||IN_REQUISITION_NUMBER||' Corp_Acronym:'||IN_CORP_ACRONYM||
' ABCDEF_Mrn:'||IN_ABCDEF_MRN||' Account_Number:'||IN_ACCOUNT_NUMBER||' Hlab_Num:'||IN_HLAB_NUM);
<<AOE_TEST_LOOP>>
FOR AOE_REC IN (SELECT ORD.TEST_ID
FROM ORDER_REQUISITION_DETAIL ORD
WHERE ORD.REQUISITION_HDR_ID = (SELECT ORH.REQUISITION_HDR_ID
FROM ORDER_REQUISITION_HEADER ORH
WHERE ORH.REQUISITION_NUMBER = IN_REQUISITION_NUMBER)
AND ORD.TEST_CODE IN (SELECT TEST_CODE FROM INTERFACE_ADT_AOE_MASTER WHERE SOURCE_SYSTEM = IN_CORP_ACRONYM))
LOOP
VN_ITERATION_RUN := VN_ITERATION_RUN + 1;
SELECT COUNT(DISTINCT PATIENT_ID)
INTO VN_EXACT_PAT_ID_CNT
FROM EMR_ADTAOE_DTL
WHERE PATIENT_ID = IN_PATIENT_ID
AND TEST_ID = AOE_REC.TEST_ID
AND FACILITY_ID = IN_FACILITY_ID
AND (DRAW_DATE = IN_DRAW_DT
OR DRAW_DATE = TO_DATE('2999/12/31','YYYY/MM/DD'))
AND SOURCE_SYSTEM = IN_CORP_ACRONYM ;
--Collecting all questions in interface_adt_aoe_master
SELECT STRAGG(SUB1.QUESTION_CODE), COUNT(SUB1.QUESTION_CODE)
INTO VC_ACTUAL_QUES, VC_ACTUAL_QUES_CNT
FROM (SELECT DISTINCT QUESTION_CODE FROM INTERFACE_ADT_AOE_MASTER
WHERE TEST_CODE = (SELECT TEST_CODE FROM TEST WHERE TEST_ID = AOE_REC.TEST_ID)
AND SOURCE_SYSTEM = IN_CORP_ACRONYM
ORDER BY QUESTION_CODE) SUB1;
SPL_SPN_ERROR_LOGGING_SPK.INFO_PROC
(IC_PACKAGE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IC_PROCEDURE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IN_BATCH_ID => '100'
,IC_MESSAGE_TEXT => 'vc_actual_ques:'||VC_ACTUAL_QUES ||
' vn_exact_pat_id_cnt:'||VN_EXACT_PAT_ID_CNT||
' aoe_rec.test_id:'||AOE_REC.TEST_ID||
' VN_ITERATION_RUN:'||VN_ITERATION_RUN);
<<MAIN_IF_BLOCK>>
IF
VN_EXACT_PAT_ID_CNT = 1 AND
VN_ITERATION_RUN >= 1 THEN
--Collecting avaliable questions in emr_adtaoe_dtl
SELECT STRAGG(SUB.QUESTION_CODE), COUNT(DISTINCT SUB.QUESTION_CODE)
INTO VC_AVL_PAT_QUES, VN_AVL_PAT_QUES_CNT
FROM (SELECT DISTINCT QUESTION_CODE FROM EMR_ADTAOE_DTL
WHERE TEST_ID = AOE_REC.TEST_ID
AND PATIENT_ID = IN_PATIENT_ID
AND FACILITY_ID = IN_FACILITY_ID
AND (DRAW_DATE = IN_DRAW_DT
OR DRAW_DATE = TO_DATE('2999/12/31','YYYY/MM/DD'))
AND SOURCE_SYSTEM = IN_CORP_ACRONYM
AND ANSWER IS NOT NULL
ORDER BY QUESTION_CODE) SUB;
SPL_SPN_ERROR_LOGGING_SPK.INFO_PROC
(IC_PACKAGE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IC_PROCEDURE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IN_BATCH_ID => '100'
,IC_MESSAGE_TEXT => 'vc_avl_pat_ques:'||VC_AVL_PAT_QUES||
' vn_avl_pat_ques_cnt:'||VN_AVL_PAT_QUES_CNT);
<<CASE_1_AND_2>>
IF
VC_AVL_PAT_QUES = VC_ACTUAL_QUES THEN
VC_EXACT_BOOLEAN_VAL := 'TRUE';
VC_COMMENTS := 'AOE AVAILABLE';
ELSIF--<<case_1_and_2>>
(VC_AVL_PAT_QUES != VC_ACTUAL_QUES OR VC_AVL_PAT_QUES IS NULL) AND
VN_AVL_PAT_QUES_CNT >= 0 THEN
VC_EXACT_PAR_BOOLEAN_VAL := 'TRUE';
VC_PAR_COMMENTS := 'PARTIAL AOE AVAILABLE';
END IF;--<<case_1_and_2>>
ELSIF
VN_EXACT_PAT_ID_CNT = 0 AND
VN_ITERATION_RUN > 1 THEN
VC_EXACT_PAR_BOOLEAN_VAL := 'TRUE';
VC_PAR_COMMENTS := 'PARTIAL AOE AVAILABLE';
ELSIF--<<Main_if_block>>
VN_EXACT_PAT_ID_CNT = 0 THEN
<<DUPL_PAT_LOOP>>
FOR PAT_ID_REC IN(SELECT DISTINCT PATIENT_ID
FROM PATIENT P
WHERE P.ABCDEF_MRN = IN_ABCDEF_MRN
AND EXISTS(SELECT 1 FROM EMR_ADTAOE_DTL EAD
WHERE EAD.PATIENT_ID = P.PATIENT_ID
AND EAD.TEST_ID = AOE_REC.TEST_ID
AND EAD.FACILITY_ID = IN_FACILITY_ID
AND (EAD.DRAW_DATE = IN_DRAW_DT
OR EAD.DRAW_DATE = TO_DATE('2999/12/31','YYYY/MM/DD'))
AND EAD.SOURCE_SYSTEM = IN_CORP_ACRONYM)
AND P.PATIENT_ID != IN_PATIENT_ID)
LOOP
--Collecting avaliable questions in emr_adtaoe_dtl
SELECT STRAGG(SUB.QUESTION_CODE), COUNT(QUESTION_CODE)
INTO VC_DUP_PAT_QUES, VN_DUP_PAT_QUES_CNT
FROM (SELECT QUESTION_CODE FROM EMR_ADTAOE_DTL
WHERE TEST_ID = AOE_REC.TEST_ID
AND PATIENT_ID = PAT_ID_REC.PATIENT_ID
AND FACILITY_ID = IN_FACILITY_ID
AND (DRAW_DATE = IN_DRAW_DT
OR DRAW_DATE = TO_DATE('2999/12/31','YYYY/MM/DD'))
AND SOURCE_SYSTEM = IN_CORP_ACRONYM
AND ANSWER IS NOT NULL
ORDER BY QUESTION_CODE) SUB;
<<CASE_3_AND_4>>
IF
VC_DUP_PAT_QUES = VC_ACTUAL_QUES THEN
VC_DUPL_BOOLEAN_VAL := 'TRUE';
VC_COMMENTS := 'AOE AVAILABLE FOR DUPLICATE PATIENT';
ELSIF
VC_DUP_PAT_QUES != VC_ACTUAL_QUES AND
VN_DUP_PAT_QUES_CNT >= 0 THEN
VC_DUPL_PAR_BOOLEAN_VAL := 'TRUE';
VC_PAR_COMMENTS := 'PARTIAL AOE AVAILABLE FOR DUPLICATE PATIENT';
END IF;--<<case_3_and_4>>
VN_DUPL_PAT_ID := PAT_ID_REC.PATIENT_ID;
SPL_SPN_ERROR_LOGGING_SPK.INFO_PROC
(IC_PACKAGE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IC_PROCEDURE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IN_BATCH_ID => '100'
,IC_MESSAGE_TEXT => 'vc_dup_pat_ques:'||VC_DUP_PAT_QUES||
' vn_dup_pat_ques_cnt:'||VN_DUP_PAT_QUES_CNT||
' VC_COMMENTS:'||VC_COMMENTS||
' VC_PAR_COMMENTS:'||VC_PAR_COMMENTS);
END LOOP DUPL_PAT_LOOP;
VC_CHK_FOR_EXT_ID := 'Y';
IF
VC_CHK_FOR_EXT_ID = 'Y' THEN
<<EXTERNAL_ID_LOOP>>
FOR P_PAT_EXT_ID_REC IN (SELECT DISTINCT P.EXTERNAL_ID
FROM PATIENT P
WHERE P.ABCDEF_MRN = IN_ABCDEF_MRN
AND P.EXTERNAL_ID IS NOT NULL)
LOOP
INSERT INTO TT_A04_OBX_QUES_ANS_DTL
(SELECT IAOBX.MSG_ID, IAOBX.OBSERVATION_IDENTIFIER, IAOBX.OBSERVATION_VALUE, IAM.UOM
FROM INTERFACE_A04_OBX_SEGMENT IAOBX, INTERFACE_ADT_AOE_MASTER IAM
WHERE IAOBX.OBSERVATION_IDENTIFIER = IAM.QUESTION_CODE
AND (IAOBX.OBSERVATION_DTM = TO_CHAR(IN_DRAW_DT,'YYYYMMDD')
OR IAOBX.OBSERVATION_DTM = TO_CHAR(TO_DATE('2999/12/31','YYYY/MM/DD'),'YYYYMMDD'))
AND IAOBX.MSG_ID IN (SELECT IPID.MSG_ID
FROM INTERFACE_A04_PID_SEGMENT IPID
WHERE IPID.PATIENT_ID_EXTERNAL = P_PAT_EXT_ID_REC.EXTERNAL_ID
AND IPID.MSG_ID IN (SELECT IMSH.MSG_ID
FROM INTERFACE_A04_MSH_SEGMENT IMSH
WHERE (TRIM('W' FROM SUBSTR(IMSH.SENDING_FACILITY,5,LENGTH(IMSH.SENDING_FACILITY))) = IN_ACCOUNT_NUMBER
OR SUBSTR(IMSH.SENDING_FACILITY,2,LENGTH(IMSH.SENDING_FACILITY)) = IN_HLAB_NUM))));
BEGIN
SELECT STRAGG(SUB3.OBSERVATION_IDENTIFIER), COUNT(OBSERVATION_IDENTIFIER)
INTO VC_OBX_QUES, VC_OBX_QUES_CNT
FROM (SELECT DISTINCT OBSERVATION_IDENTIFIER
FROM TT_A04_OBX_QUES_ANS_DTL
ORDER BY OBSERVATION_IDENTIFIER)SUB3;
IF
VC_OBX_QUES = VC_ACTUAL_QUES THEN
VC_COMMENTS := 'AOE RECEIVED IN A REJECTED ADT';
VC_REJECTED_BOOLEAN_VAL := 'TRUE';
ELSIF
VC_OBX_QUES != VC_ACTUAL_QUES AND
VC_OBX_QUES_CNT > 0 THEN
VC_PAR_COMMENTS := 'PARTIAL AOE RECEIVED IN A REJECTED ADT';
VC_REJECTED_PAR_BOOLEAN_VAL := 'TRUE';
END IF;
VN_EXTERNAL_ID := P_PAT_EXT_ID_REC.EXTERNAL_ID;
EXCEPTION
WHEN NO_DATA_FOUND THEN
VC_REJECTED_BOOLEAN_VAL := 'FALSE';
VC_REJECTED_PAR_BOOLEAN_VAL := 'FALSE';
END;
SPL_SPN_ERROR_LOGGING_SPK.INFO_PROC
(IC_PACKAGE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IC_PROCEDURE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IN_BATCH_ID => '100'
,IC_MESSAGE_TEXT => 'vc_obx_ques:'||VC_OBX_QUES||
' vc_obx_ques_cnt:'||VC_OBX_QUES_CNT);
END LOOP EXTERNAL_ID_LOOP;
END IF;
END IF;--<<Main_if_block>>
END LOOP AOE_TEST_LOOP;
--Returning output as per the execution result.
IF
VC_EXACT_BOOLEAN_VAL = 'TRUE' AND
VC_EXACT_PAR_BOOLEAN_VAL = 'FALSE' THEN
OV_COMMENTS := VC_COMMENTS;
VC_DUPL_BOOLEAN_VAL := NULL;
VC_DUPL_PAR_BOOLEAN_VAL := NULL;
VC_REJECTED_BOOLEAN_VAL := NULL;
VC_REJECTED_PAR_BOOLEAN_VAL := NULL;
VC_RETURN_EXACT_PAT := 'Y';
ELSIF
--VC_EXACT_BOOLEAN_VAL = 'TRUE' AND
VC_EXACT_PAR_BOOLEAN_VAL = 'TRUE' THEN
OV_COMMENTS := VC_PAR_COMMENTS;
VC_DUPL_BOOLEAN_VAL := NULL;
VC_DUPL_PAR_BOOLEAN_VAL := NULL;
VC_REJECTED_BOOLEAN_VAL := NULL;
VC_REJECTED_PAR_BOOLEAN_VAL := NULL;
VC_RETURN_EXACT_PAT := 'Y';
END IF;
IF
VC_RETURN_EXACT_PAT = 'Y' THEN
--Returning result set (OV_COMMENTS,Question and Answer) for the exact patient.(Case 1 (AOE) and 2 (PARTIAL AOE))
SELECT MAX (SUB.COUNT_QUES_ANS)
INTO VN_MAX_COUNT FROM (SELECT COUNT(*) OVER (PARTITION BY EAD.QUESTION_CODE, EAD.ANSWER) AS COUNT_QUES_ANS
FROM EMR_ADTAOE_DTL EAD , INTERFACE_ADT_AOE_MASTER IAM, TEST T
WHERE T.TEST_ID = EAD.TEST_ID
AND IAM.TEST_CODE = T.TEST_CODE
AND EAD.SOURCE_SYSTEM = IAM.SOURCE_SYSTEM
AND EAD.QUESTION_CODE = IAM.QUESTION_CODE
AND EAD.PATIENT_ID = IN_PATIENT_ID
AND EAD.FACILITY_ID = IN_FACILITY_ID
AND (TRUNC(EAD.DRAW_DATE) = IN_DRAW_DT
OR TRUNC(EAD.DRAW_DATE) = TRUNC(TO_DATE('12-31-2999','mm-dd-yyyy')))
AND EAD.SOURCE_SYSTEM = IN_REQUISITION_NUMBER) SUB;
IF
VN_MAX_COUNT > 1 THEN
SPL_SPN_ERROR_LOGGING_SPK.INFO_PROC
(IC_PACKAGE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IC_PROCEDURE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IN_BATCH_ID => '100'
,IC_MESSAGE_TEXT => 'exact patient duplicate scenario'||' vn_max_count:'||VN_MAX_COUNT);
OPEN VR_QUES_AND_ANS FOR
SELECT DISTINCT IAM.QUESTION_CODE,
(SELECT DISTINCT CASE
WHEN EAD.ANSWER IS NULL THEN NULL
WHEN LENGTH(TRIM(TRANSLATE(EAD.ANSWER, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', ' '))) IS NULL THEN EAD.ANSWER
ELSE TO_CHAR(TRUNC(EAD.ANSWER * DECODE(UPPER(IAM.UOM), 'KGS', 2.20462,1),2))
END
FROM EMR_ADTAOE_DTL EAD , TEST T
WHERE T.TEST_ID = EAD.TEST_ID
AND IAM.TEST_CODE = T.TEST_CODE
AND EAD.SOURCE_SYSTEM = IAM.SOURCE_SYSTEM
AND EAD.QUESTION_CODE = IAM.QUESTION_CODE
AND EAD.PATIENT_ID = IN_PATIENT_ID
AND EAD.FACILITY_ID = IN_FACILITY_ID
AND (TRUNC(EAD.DRAW_DATE) = IN_DRAW_DT
OR TRUNC(EAD.DRAW_DATE) = TRUNC(TO_DATE('12-31-2999','mm-dd-yyyy')))
AND EAD.SOURCE_SYSTEM = IN_CORP_ACRONYM
AND EAD.ANSWER IS NOT NULL
AND EAD.STATUS = DECODE(IAM.MATCH_TYPE, 'AT', EAD.STATUS, 'N')
) AS ANSWER
FROM INTERFACE_ADT_AOE_MASTER IAM
WHERE IAM.SOURCE_SYSTEM = IN_CORP_ACRONYM
AND IAM.TEST_CODE IN (SELECT ORD.TEST_CODE
FROM ORDER_REQUISITION_DETAIL ORD
WHERE ORD.REQUISITION_HDR_ID = (SELECT ORH.REQUISITION_HDR_ID
FROM ORDER_REQUISITION_HEADER ORH
WHERE ORH.REQUISITION_NUMBER = IN_REQUISITION_NUMBER)
AND EXISTS (SELECT 1 FROM EMR_ADTAOE_DTL EAD1, INTERFACE_ADT_AOE_MASTER IAM1, TEST T1
WHERE ORD.TEST_ID = EAD1.TEST_ID
AND IAM1.TEST_CODE = T1.TEST_CODE
AND EAD1.SOURCE_SYSTEM = IAM1.SOURCE_SYSTEM
AND EAD1.QUESTION_CODE = IAM1.QUESTION_CODE
AND EAD1.PATIENT_ID = IN_PATIENT_ID
AND EAD1.FACILITY_ID = IN_FACILITY_ID
AND (TRUNC(EAD1.DRAW_DATE) = IN_DRAW_DT
OR TRUNC(EAD1.DRAW_DATE) = TRUNC(TO_DATE('12-31-2999','mm-dd-yyyy')))
AND EAD1.SOURCE_SYSTEM = IN_CORP_ACRONYM
AND EAD1.ANSWER IS NOT NULL
AND EAD1.STATUS = DECODE(IAM1.MATCH_TYPE, 'AT', EAD1.STATUS, 'N')));
ELSIF
VN_MAX_COUNT = 1 THEN
SPL_SPN_ERROR_LOGGING_SPK.INFO_PROC
(IC_PACKAGE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IC_PROCEDURE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IN_BATCH_ID => '100'
,IC_MESSAGE_TEXT => 'exact patient unique scenario'||' vn_max_count:'||VN_MAX_COUNT);
OPEN VR_QUES_AND_ANS FOR
SELECT DISTINCT IAM.QUESTION_CODE,
(SELECT DISTINCT CASE
WHEN EAD.ANSWER IS NULL THEN NULL
WHEN LENGTH(TRIM(TRANSLATE(EAD.ANSWER, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', ' '))) IS NULL THEN EAD.ANSWER
ELSE TO_CHAR(TRUNC(EAD.ANSWER * DECODE(UPPER(IAM.UOM), 'KGS', 2.20462,1),2))
END
FROM EMR_ADTAOE_DTL EAD , TEST T
WHERE T.TEST_ID = EAD.TEST_ID
AND IAM.TEST_CODE = T.TEST_CODE
AND EAD.SOURCE_SYSTEM = IAM.SOURCE_SYSTEM
AND EAD.QUESTION_CODE = IAM.QUESTION_CODE
AND EAD.PATIENT_ID = IN_PATIENT_ID
AND EAD.FACILITY_ID = IN_FACILITY_ID
AND (TRUNC(EAD.DRAW_DATE) = IN_DRAW_DT
OR TRUNC(EAD.DRAW_DATE) = TRUNC(TO_DATE('12-31-2999','mm-dd-yyyy')))
AND EAD.SOURCE_SYSTEM = IN_CORP_ACRONYM
AND EAD.ANSWER IS NOT NULL
AND EAD.STATUS = DECODE(IAM.MATCH_TYPE, 'AT', EAD.STATUS, 'N')
) AS ANSWER
FROM INTERFACE_ADT_AOE_MASTER IAM
WHERE IAM.SOURCE_SYSTEM = IN_CORP_ACRONYM
AND IAM.TEST_CODE IN (SELECT ORD.TEST_CODE
FROM ORDER_REQUISITION_DETAIL ORD
WHERE ORD.REQUISITION_HDR_ID = (SELECT ORH.REQUISITION_HDR_ID
FROM ORDER_REQUISITION_HEADER ORH
WHERE ORH.REQUISITION_NUMBER = IN_REQUISITION_NUMBER));
END IF;
OR_QUES_AND_ANS := VR_QUES_AND_ANS;
SPL_SPN_ERROR_LOGGING_SPK.INFO_PROC
(IC_PACKAGE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IC_PROCEDURE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IN_BATCH_ID => '100'
,IC_MESSAGE_TEXT => 'vc_exact_boolean_val:'||VC_EXACT_BOOLEAN_VAL||
' vc_exact_par_boolean_val:'||VC_EXACT_PAR_BOOLEAN_VAL||
' OV_COMMENTS:'||OV_COMMENTS);
END IF;
IF
VC_DUPL_BOOLEAN_VAL = 'TRUE' AND
VC_DUPL_PAR_BOOLEAN_VAL = 'FALSE' THEN
OV_COMMENTS := VC_COMMENTS;
VC_EXACT_BOOLEAN_VAL := NULL;
VC_EXACT_PAR_BOOLEAN_VAL := NULL;
VC_REJECTED_BOOLEAN_VAL := NULL;
VC_REJECTED_PAR_BOOLEAN_VAL := NULL;
VC_RETURN_DUPL_PAT := 'Y';
ELSIF
--VC_DUPL_BOOLEAN_VAL = 'TRUE' AND
VC_DUPL_PAR_BOOLEAN_VAL = 'TRUE' THEN
OV_COMMENTS := VC_PAR_COMMENTS;
VC_EXACT_BOOLEAN_VAL := NULL;
VC_EXACT_PAR_BOOLEAN_VAL := NULL;
VC_REJECTED_BOOLEAN_VAL := NULL;
VC_REJECTED_PAR_BOOLEAN_VAL := NULL;
VC_RETURN_DUPL_PAT := 'Y';
END IF;
IF
VC_RETURN_DUPL_PAT = 'Y' THEN
--Returning result set (OV_COMMENTS,Question and Answer) for the duplicate patient.(Case 3 (AOE) and 4 (PARTIAL AOE))
SELECT MAX (SUB.COUNT_QUES_ANS)
INTO VN_MAX_COUNT FROM (SELECT COUNT(*) OVER (PARTITION BY EAD.QUESTION_CODE, EAD.ANSWER) AS COUNT_QUES_ANS
FROM EMR_ADTAOE_DTL EAD , INTERFACE_ADT_AOE_MASTER IAM, TEST T
WHERE T.TEST_ID = EAD.TEST_ID
AND IAM.TEST_CODE = T.TEST_CODE
AND EAD.SOURCE_SYSTEM = IAM.SOURCE_SYSTEM
AND EAD.QUESTION_CODE = IAM.QUESTION_CODE
AND EAD.PATIENT_ID = VN_DUPL_PAT_ID
AND EAD.FACILITY_ID = IN_FACILITY_ID
AND (TRUNC(EAD.DRAW_DATE) = IN_DRAW_DT
OR TRUNC(EAD.DRAW_DATE) = TRUNC(TO_DATE('12-31-2999','mm-dd-yyyy')))
AND EAD.SOURCE_SYSTEM = IN_REQUISITION_NUMBER) SUB;
IF
VN_MAX_COUNT > 1 THEN
SPL_SPN_ERROR_LOGGING_SPK.INFO_PROC
(IC_PACKAGE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IC_PROCEDURE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IN_BATCH_ID => '100'
,IC_MESSAGE_TEXT => 'duplicate patient duplicate scenario'||' vn_max_count:'||VN_MAX_COUNT);
OPEN VR_QUES_AND_ANS FOR
SELECT DISTINCT IAM.QUESTION_CODE,
(SELECT DISTINCT CASE
WHEN EAD.ANSWER IS NULL THEN NULL
WHEN LENGTH(TRIM(TRANSLATE(EAD.ANSWER, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', ' '))) IS NULL THEN EAD.ANSWER
ELSE TO_CHAR(TRUNC(EAD.ANSWER * DECODE(UPPER(IAM.UOM), 'KGS', 2.20462,1),2))
END
FROM EMR_ADTAOE_DTL EAD , TEST T
WHERE T.TEST_ID = EAD.TEST_ID
AND IAM.TEST_CODE = T.TEST_CODE
AND EAD.SOURCE_SYSTEM = IAM.SOURCE_SYSTEM
AND EAD.QUESTION_CODE = IAM.QUESTION_CODE
AND EAD.PATIENT_ID = VN_DUPL_PAT_ID
AND EAD.FACILITY_ID = IN_FACILITY_ID
AND (TRUNC(EAD.DRAW_DATE) = IN_DRAW_DT
OR TRUNC(EAD.DRAW_DATE) = TRUNC(TO_DATE('12-31-2999','mm-dd-yyyy')))
AND EAD.SOURCE_SYSTEM = IN_CORP_ACRONYM
AND EAD.ANSWER IS NOT NULL
AND EAD.STATUS = DECODE(IAM.MATCH_TYPE, 'AT', EAD.STATUS, 'N')
) AS ANSWER
FROM INTERFACE_ADT_AOE_MASTER IAM
WHERE IAM.SOURCE_SYSTEM = IN_CORP_ACRONYM
AND IAM.TEST_CODE IN (SELECT ORD.TEST_CODE
FROM ORDER_REQUISITION_DETAIL ORD
WHERE ORD.REQUISITION_HDR_ID = (SELECT ORH.REQUISITION_HDR_ID
FROM ORDER_REQUISITION_HEADER ORH
WHERE ORH.REQUISITION_NUMBER = IN_REQUISITION_NUMBER)
AND EXISTS (SELECT 1 FROM EMR_ADTAOE_DTL EAD1, INTERFACE_ADT_AOE_MASTER IAM1, TEST T1
WHERE ORD.TEST_ID = EAD1.TEST_ID
AND IAM1.TEST_CODE = T1.TEST_CODE
AND EAD1.SOURCE_SYSTEM = IAM1.SOURCE_SYSTEM
AND EAD1.QUESTION_CODE = IAM1.QUESTION_CODE
AND EAD1.PATIENT_ID = VN_DUPL_PAT_ID
AND EAD1.FACILITY_ID = IN_FACILITY_ID
AND (TRUNC(EAD1.DRAW_DATE) = IN_DRAW_DT
OR TRUNC(EAD1.DRAW_DATE) = TRUNC(TO_DATE('12-31-2999','mm-dd-yyyy')))
AND EAD1.SOURCE_SYSTEM = IN_CORP_ACRONYM
AND EAD1.ANSWER IS NOT NULL
AND EAD1.STATUS = DECODE(IAM1.MATCH_TYPE, 'AT', EAD1.STATUS, 'N')));
ELSIF
VN_MAX_COUNT = 1 THEN
SPL_SPN_ERROR_LOGGING_SPK.INFO_PROC
(IC_PACKAGE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IC_PROCEDURE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IN_BATCH_ID => '100'
,IC_MESSAGE_TEXT => 'duplicate patient unique scenario'||' vn_max_count:'||VN_MAX_COUNT);
OPEN VR_QUES_AND_ANS FOR
SELECT DISTINCT IAM.QUESTION_CODE,
(SELECT DISTINCT CASE
WHEN EAD.ANSWER IS NULL THEN NULL
WHEN LENGTH(TRIM(TRANSLATE(EAD.ANSWER, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', ' '))) IS NULL THEN EAD.ANSWER
ELSE TO_CHAR(TRUNC(EAD.ANSWER * DECODE(UPPER(IAM.UOM), 'KGS', 2.20462,1),2))
END
FROM EMR_ADTAOE_DTL EAD , TEST T
WHERE T.TEST_ID = EAD.TEST_ID
AND IAM.TEST_CODE = T.TEST_CODE
AND EAD.SOURCE_SYSTEM = IAM.SOURCE_SYSTEM
AND EAD.QUESTION_CODE = IAM.QUESTION_CODE
AND EAD.PATIENT_ID = VN_DUPL_PAT_ID
AND EAD.FACILITY_ID = IN_FACILITY_ID
AND (TRUNC(EAD.DRAW_DATE) = IN_DRAW_DT
OR TRUNC(EAD.DRAW_DATE) = TRUNC(TO_DATE('12-31-2999','mm-dd-yyyy')))
AND EAD.SOURCE_SYSTEM = IN_CORP_ACRONYM
AND EAD.ANSWER IS NOT NULL
AND EAD.STATUS = DECODE(IAM.MATCH_TYPE, 'AT', EAD.STATUS, 'N')
) AS ANSWER
FROM INTERFACE_ADT_AOE_MASTER IAM
WHERE IAM.SOURCE_SYSTEM = IN_CORP_ACRONYM
AND IAM.TEST_CODE IN (SELECT ORD.TEST_CODE
FROM ORDER_REQUISITION_DETAIL ORD
WHERE ORD.REQUISITION_HDR_ID = (SELECT ORH.REQUISITION_HDR_ID
FROM ORDER_REQUISITION_HEADER ORH
WHERE ORH.REQUISITION_NUMBER = IN_REQUISITION_NUMBER));
END IF;
OR_QUES_AND_ANS := VR_QUES_AND_ANS;
SPL_SPN_ERROR_LOGGING_SPK.INFO_PROC
(IC_PACKAGE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IC_PROCEDURE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IN_BATCH_ID => '100'
,IC_MESSAGE_TEXT => 'vc_dup_pat_ques:'||VC_DUP_PAT_QUES||
' vc_dupl_boolean_val:'||VC_DUPL_BOOLEAN_VAL||
' vc_dupl_par_boolean_val:'||VC_DUPL_PAR_BOOLEAN_VAL||
' OV_COMMENTS:'||OV_COMMENTS);
END IF;
IF
VC_REJECTED_BOOLEAN_VAL = 'TRUE' AND
VC_REJECTED_PAR_BOOLEAN_VAL = 'FALSE' THEN
OV_COMMENTS := VC_COMMENTS;
VC_EXACT_BOOLEAN_VAL := NULL;
VC_EXACT_PAR_BOOLEAN_VAL := NULL;
VC_DUPL_BOOLEAN_VAL := NULL;
VC_DUPL_PAR_BOOLEAN_VAL := NULL;
VC_RETURN_REJECT_PAT := 'Y';
ELSIF
--VC_REJECTED_BOOLEAN_VAL = 'FALSE' AND
VC_REJECTED_PAR_BOOLEAN_VAL = 'TRUE' THEN
OV_COMMENTS := VC_PAR_COMMENTS;
VC_EXACT_BOOLEAN_VAL := NULL;
VC_EXACT_PAR_BOOLEAN_VAL := NULL;
VC_DUPL_BOOLEAN_VAL := NULL;
VC_DUPL_PAR_BOOLEAN_VAL := NULL;
VC_RETURN_REJECT_PAT := 'Y';
ELSIF
VC_REJECTED_BOOLEAN_VAL = 'FALSE' AND
VC_REJECTED_PAR_BOOLEAN_VAL = 'FALSE' THEN
--Returning result set (OV_COMMENTS) for the rejected ADT.(Case 7)
OV_COMMENTS := 'AOE NOT RECEIVED IN ADT';
OR_QUES_AND_ANS := NULL;
SPL_SPN_ERROR_LOGGING_SPK.INFO_PROC
(IC_PACKAGE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IC_PROCEDURE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IN_BATCH_ID => '100'
,IC_MESSAGE_TEXT => 'vc_obx_ques:'||VC_OBX_QUES||
' vc_rejected_boolean_val:'||VC_REJECTED_BOOLEAN_VAL||
' vc_rejected_par_boolean_val:'||VC_REJECTED_PAR_BOOLEAN_VAL||
' OV_COMMENTS:'||OV_COMMENTS);
VC_EXACT_BOOLEAN_VAL := NULL;
VC_EXACT_PAR_BOOLEAN_VAL := NULL;
VC_DUPL_BOOLEAN_VAL := NULL;
VC_DUPL_PAR_BOOLEAN_VAL := NULL;
END IF;
IF
VC_RETURN_REJECT_PAT = 'Y' THEN
--Returning result set (OV_COMMENTS,Question and Answer) for the rejected ADT.(Case 5 (AOE) and 6 (PARTIAL AOE))
--In case of multiple external id with same patient, facility and draw date; the lastest record should be picked.
SELECT MAX(MSG_ID) INTO VN_MAX_MSG_ID FROM TT_A04_OBX_QUES_ANS_DTL;
OPEN VR_QUES_AND_ANS FOR
SELECT DISTINCT IAM.QUESTION_CODE,
(SELECT DISTINCT
CASE
WHEN TOBX.OBSERVATION_VALUE IS NULL THEN NULL
WHEN LENGTH(TRIM(TRANSLATE(TOBX.OBSERVATION_VALUE, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', ' '))) IS NULL THEN TOBX.OBSERVATION_VALUE
ELSE TO_CHAR(TRUNC(TOBX.OBSERVATION_VALUE * DECODE(UPPER(TOBX.UOM), 'KGS', 2.20462,1),2))
END
FROM TT_A04_OBX_QUES_ANS_DTL TOBX
WHERE TOBX.OBSERVATION_IDENTIFIER = IAM.QUESTION_CODE
AND TOBX.MSG_ID = VN_MAX_MSG_ID) AS ANSWER
FROM INTERFACE_ADT_AOE_MASTER IAM
WHERE SOURCE_SYSTEM = IN_CORP_ACRONYM;
OR_QUES_AND_ANS := VR_QUES_AND_ANS;
SPL_SPN_ERROR_LOGGING_SPK.INFO_PROC
(IC_PACKAGE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IC_PROCEDURE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IN_BATCH_ID => '100'
,IC_MESSAGE_TEXT => 'vc_rejected_boolean_val:'||VC_REJECTED_BOOLEAN_VAL||
' vc_rejected_par_boolean_val:'||VC_REJECTED_PAR_BOOLEAN_VAL||
' OV_COMMENTS:'||OV_COMMENTS);
END IF;
SPL_SPN_ERROR_LOGGING_SPK.INFO_PROC
(IC_PACKAGE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IC_PROCEDURE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IN_BATCH_ID => '100'
,IC_MESSAGE_TEXT => 'End of the procedure with Patient_Id:'||IN_PATIENT_ID||' Facility_Id:'||IN_FACILITY_ID||
' Draw_Dt:'||IN_DRAW_DT||' Requisition_Number:'||IN_REQUISITION_NUMBER||' Corp_Acronym:'||IN_CORP_ACRONYM||
' ABCDEF_Mrn:'||IN_ABCDEF_MRN||' Account_Number:'||IN_ACCOUNT_NUMBER||' Hlab_Num:'||IN_HLAB_NUM);
EXCEPTION
WHEN NO_DATA_FOUND THEN
SPL_SPN_ERROR_LOGGING_SPK.ERROR_PROC
(IC_PACKAGE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IC_PROCEDURE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IN_BATCH_ID => '100'
,IC_MESSAGE_TEXT => SQLERRM);
WHEN OTHERS THEN
SPL_SPN_ERROR_LOGGING_SPK.ERROR_PROC
(IC_PACKAGE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IC_PROCEDURE_NAME => 'SPL_SPN_MISSING_EMR_AOE_DTL'
,IN_BATCH_ID => '100'
,IC_MESSAGE_TEXT => SQLERRM);
END SPL_SPN_MISSING_EMR_AOE_DTL;
Regards,
BS2012.Hey Guys,
I'm sorry, that I troubled you all. But I found the issue and solved it.
The actual problem is residing at that max of that partition by query. I had a misconception that this query will always return a value which is positive number like 1,2 etc.
But sometimes it's returning null as well. So the ref cursor is fetching nothing. Now I've modified my code and everything is working fine. Thanks for your help and support.
Regards,
BS2012. -
Hi! I am doing a conversion from MSSQL to Oracle with C++ and MFC ODBC. Any comment is appreciated!! I have Oracle 8i and Oracle ODBC 8.1.6 installed.
My question is how to retrieve the return value AND ALSO the resultSet at the same time by using Oracle function without modifying my souce codes (except puttting mypackage. string infron of my procedure name, see below).
-- My source code in C++ with MSSQL ....
sqlStr.Format("{? = call ListOfCustomers(%i)}", nNameID);
RcOpen = CustomerList.Open(CRecordset::forwardOnly, sqlStr, CRecordset::readOnly );
Where CustoemrList is a Crecordset object...
IN DoFieldExchange(CFieldExchange* pFX) I have ...
//{{AFX_FIELD_MAP(CQOSDB_Group)
pFX->SetFieldType(CFieldExchange::outputColumn);
RFX_Long(pFX, T("Name"), mCustoemrName);
//}}AFX_FIELD_MAP
// output parameter
pFX->SetFieldType( CFieldExchange::outputParam );
RFX_Int( pFX, T("IndexCount"), mCustomerNumber);
-- m_CustomerNumber is where i store the return value!!!
-- In Oracle Version, i have similar codes with ...
sqlStr.Format("{? = call mypackage.ListOfCustomers(%i)}", nNameID);
RcOpen = CustomerList.Open(CRecordset::forwardOnly, sqlStr, CRecordset::readOnly );
-- I have oracle package/Body codes as following...
create or replace package mypackage
as
type group_rct is ref cursor;
Function listgroups(
nameID NUMBER ,
RC1 IN OUT Mypackage.group_rct ) return int;
end;
Create or replace package body mypackage
as
Function listgroups(
NameID NUMBER ,
RC1 IN OUT Mypackage.group_rct )return int
IS
BEGIN
OPEN RC1 FOR SELECT Name
from Customer
WHERE ID = NameIDEND ListGroups;
END
return 7;
END listgroups;
END MyPackage;
Ive simplified my codes a bit....
nullyes, it is exactly what i want to do and I am using Oracle ODBC driver.
I tried using procedure with 1 OUT var fo numeric value and the other IN OUT ref cursor var instead of function, but error occurs when I called it from the application. It give me a memory ecxception error!!
sqlStr.Format("{? = call ListOfCustomers(%i)}", nNameID);
RcOpen = CustomerList.Open(CRecordset::forwardOnly, sqlStr, CRecordset::readOnly );
it seems to me that the ? marker var is making all the trouble... can you please give me any more comment on this?? thanks!
null -
Error getting return value from function
Hello
I'm getting a error calling a function with ODP.NET from C#
Code:
OracleCommand oraCom = new OracleCommand("NORMALIZACION.nif",oraCon);
oraCom.CommandType = CommandType.StoredProcedure;
OracleParameter param1 = new OracleParameter("numnif",OracleDbType.Varchar2);
param1.Value= "73667866A";
param1.Direction = ParameterDirection.Input;
OracleParameter param2 = new OracleParameter("nif",OracleDbType.Varchar2);
param2.Size = 10; //FIXME line
param2.Direction = ParameterDirection.ReturnValue;
oraCom.Parameters.Add(param1);
oraCom.Parameters.Add(param2);
oraCom.ExecuteNonQuery();
nif_norm = oraCom.Parameters["nif"].Value.ToString();
if i write the FIXME line i get a error (ORA-06502) complaining about the size, no matter the value i wrote.
If i don't write the FIXME line, it works but nif_norm is always empty, although the function i call is a single return 'Hello';
Where am I wrong??
Any help, examples with varchar2 as return value???
BTW: the same code with the MS provider for Oracle works fine.Good point -- i shall do so.
What I think I'm missing, in my quest for ODP.NET competence, is a solid set of example code. I've searched around and found various fragements here and there, but when it comes to data access from .NET there must surely be some finitie set of possibilities (if we can discount bad practices like building dynamic SQL statements without bind variables).
For example, possibly in increasing order of complexity ...
* Read a single value from a SQL statement ... "select emp_name from emp where rownum < 2"
* Read a single value by passing in a parameter ... "select emp_name from emp where user_id = :?"
* read multiple values ... "select emp_name from emp where user_id in (:?,:?)"
* execute a stored procedure with no in or out parameters
* retreive a value from a function with no parameters
* pass a parameter to a stored procedure
* read an out parameter from a stored procedure
Then work with in and out ref cursors, blobs, whatever.
Thoughts? -
The return value of sqlcode when select an empty table in a proc code
Table: test
there is an empty table. But when I use "select * from test" in a proc code, I found the return value of sqlca.sqlcode is 0, not 1403 (NO MORE DATA). Why ?EXEC SQL DECLARE individual_cursor CURSOR for
SELECT IATA_C, DELAY, UPDATE_TIME
FROM TBL_TIME
WHERE IATA_C <> '***' AND
FLAG = 1;
EXEC SQL OPEN individual_cursor;
while(1) {
printf("in while");
if (sqlca.sqlcode == 1403 && individual_flag == 0) {
printf("no any data");
return 1;
} else if (sqlca.sqlcode == SQLNOMORE) {
break;
EXEC SQL FETCH individual_without_general_cursor INTO :pnrtime.airline, :pnrtime.delay, :pnrtime.update_time;
EXEC SQL CLOSE individual_cursor;
The result is:
in while
in while
no any data
Since the table is empty, why "in while" is printed twice? And "no any data" is printed in the end? I cannot decide the empty when using "select ... into" in proc unless using "select count(*) from test", right? Thx. -
DML Returning Values In Forms 6i
Hi there!
I am watching the following behavior in Forms 6i:
Whenever I set DML Returning Value to "Yes" in a data block that corresponds to a table Database (8.0.5) returns to me the updated values, but this doesnot happen with a data block that corresponds to an updatable view. What can I do about that?
GeorgeThere are many ways you could do this. One way would be to create a When-Validate-Item trigger on the USER_ID field that checks the database to see if the value already exists and raise an exception if it exists. For example:
/* When-Validate-Item trigger */
DECLARE
n_dummy NUMBER := 0;
CURSOR test_User_ID IS
SELECT count(*)
FROM YOUR_TABLE_NAME_HERE
WHERE USER_ID = :YOUR_BLOCK_NAME.USER_ID;
BEGIN
OPEN test_User_ID;
FETCH test_User_ID INTO n_dummy;
CLOSE test_User_ID;
IF ( n_dummy > 0 ) THEN
MESSAGE('User ID " '||:YOUR_BLOCK_NAME.USER_ID||' " already exists. Please enter a unique User ID.',ACKNOWLEDGE);
RAISE Form_Trigger_Failure;
END IF;
END;Please understand that this is just sample code and will need to be modified in order to work in your form. Also note, I'm not positive the "ACKNOWLEDGE" parameter to the MESSAGE built-in is valid for Forms 6i. Please confirm this before using.
Hope this helps.
Craig...
If mine or someone else's response is helpful or correct, please mark it accordingly -
How to return a ref cursor from this dbms_sql?
Hi,
Can anyone show me how to return a ref cursor from this dbms_sql based procedure? I see 11g has a dbms_sql.to_refcursor(cursor_handle). How can this be done is 10g?
Thx.
CREATE OR REPLACE PROCEDURE Sample_Get_t
p_sample_id sample.sample_id%TYPE,
p_contract_id sample.contr_id%TYPE
IS
cursor_handle INT;
sql_stmnt varchar2(500);
rows_processed NUMBER;
BEGIN
sql_stmnt :=
'SELECT
sample_id,
contr_id,
rcpt_id
FROM
sample s
WHERE
s.contr_id = :1
and s.sample_id = :2
ORDER BY
sample_id';
cursor_handle := dbms_sql.open_cursor;
dbms_sql.parse(cursor_handle, sql_stmnt, dbms_sql.native);
dbms_sql.bind_variable(cursor_handle, ':1', p_contract_id);
dbms_sql.bind_variable(cursor_handle, ':2', p_sample_id);
rows_processed := dbms_sql.execute(cursor_handle);
dbms_sql.close_cursor(cursor_handle);
END Sample_Get_t;In 10 this cannot be done with dbms_sql (to my knowledge). There are a couple of other options.
1) open the ref cursor for the dynamic statement using bind variables (or SYS_CONTEXT variables, which i prefer since they are much easier to deal with when you are dynamically adding predicates).
declare
wRefCursor SYS_REFCURSOR;
begin
open wRefCursor for 'select * from all_objects where owner = :Logged_in_user' using user;
end;
/or using the context (the context will bind for you)
declare
wRefCursor SYS_REFCURSOR;
begin
open wRefCursor for 'select * from all_objects where owner = SYS_CONTEXT(''CONTEXT_NAME'', ''VARIABLE_NAME'') ';
end;
/Be aware that contexts ALWAYS return varchar values, so if you are comparing to a number you should wrap it in TO_NUMBER, a date, TO_DATE and so on....
2) change the DBMS_SQL to do an insert into a global temporary table and return the ref cursor which select's * from GTT;
3) upgrade to Oracle 11 :) -
Sys_refcursor not fetching any data although query returns value
hi!!!
I am using sys_refcursor to return columns,and using below procedure to do so.Although data is there in table_1 and table_2.
PROCEDURE test_pro(abc_date N DATE,
cur_get_data OUT sys_refcursor
OPEN cur_get_data
for
select A.col1,B.col2
from table_1 A
where A.dis_date=abc_date
left outer join
table_2 B
on
A.dis_date=B.dis_date;
IF cur_get_data%rowcount=0
then
raise e_error;
END if;
EXCEPTION
when e_error
then
------no_data_found;
when others
then
--------(giving SQL error with error code);
END test_pro;
while running below sql in sql window of pl/sql developer fetching
data
select A.col1,B.col2
from table_1 A
where A.dis_date=abc_date
left outer join
table_2 B
on
A.dis_date=B.dis_date;
but while testing the test_pro in test window of pl/sql developer it is
not fetching any data and raising e_error each time
is there any problem arising using IF cur_get_data%rowcount=0 as each time it is going to exception block..
so can somebody please put some ideas what cud be the possible reason for this??Welcome to the forum!
Unfortunatley you posted to the wrong forum. This question belongs in the SQL and PL/SQL forum.
PL/SQL
>
sys_refcursor not fetching any data although query returns value
but while testing the test_pro in test window of pl/sql developer it is
not fetching any data and raising e_error each time
is there any problem arising using IF cur_get_data%rowcount=0 as each time it is going to exception block..
>
A cursor doesn't fetch data - your code has to do that. The code you posted doesn't have any FETCH statements so no data will be fetched.
There is no problem using 'IF cur_get_data%rowcount=0' but it will always be 0 in your code because you are not fetching any data.
I'm guessing that you are trying to determine if there are any rows for the query. That isn't going to work since a cursor doesn't fetch rows.
You just have to return the cursor to the caller and the caller will have to perform at least one fetch to see if there are any rows.
If the above answers your question the just mark the question ANSWERED. Otherwise, since you have posted in the wrong forum
1. repost the question in the SQL and PL/SQL forum
2. Edit this post to add a link to the new thread in the other forum
3. Mark this question ANSWERED so people will follow up in the other forum.
Thanks. -
Ref cursor to object and return to ref cursor
how i will call object type from refcursor and return value to ref cursor .
I need a help. please help me.
takes oracle object types as input/output.
PROCEDURE createserviceorder(
P_serviceorder IN serviceorder,
P_serviceid in out p_sm_type.serviceid,
P_serviceorderid out p_sm_type.serviceorderid,
Returnstatus out callstatus);
The serviceorder, callstatus are oracle object types.
The wrapper procedure for this API would be something like the example with pseudo code below
PROCEDURE createserviceorderwrapper(
P_serviceorder IN REFCURSOR,
P_serviceid in out p_sm_type.serviceid,
P_serviceorderid out p_sm_type.serviceorderid,
Returnstatus out REFCURSOR)
Map from ref cursor P_serviceorder to oracle object for serviceorder;
Map from other data types to local variables;
Call createserviceorder (pass the parameters here and get output .);
Map output callstatus to its equivalent REF CURSOR variable;
Return callstatus (and other out parameters if any )as REF CURSORS;
} -
Unable to capture return values in web services api
At the time of login to web services if my server is down ,
it returns following error :
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1438)
at java.lang.String.substring(String.java:1411)
I want to capture this error so that i can try another server to login. how do i capture this error
Another place where i want to capture the return Value is when i look for a report on the server
rh = boBIPlatform.get("path://InfoObjects/Root Folder/"src_folder"/" + reportName +
"@SI_SCHEDULEINFO,SI_PROCESSINFO" ,oGetOptions);
oInfoObjects = rh.getInfoObjects();
CrystalReport = (CrystalReport)oInfoObjects.getInfoObject(0);
Here if the report is not there on the server , it returns a null handler exception.
but if i try catching it by checking my responsehandler is null like rh == null it does not catch it.
Any help will be appreciated
thanks
Rakesh GuptaTed : i have two cases
1) server = server_st.nextToken();
providerURL = "http://"server"/dswsbobje/services";
sessConnURL = new URL(providerURL + "/session");
Connection boConnection = new Connection(sessConnURL);
Session boSession = new Session(boConnection);
EnterpriseCredential boEnterpriseCredential = new EnterpriseCredential();
boEnterpriseCredential.setLogin(userid);
boEnterpriseCredential.setPassword(pwd);
boEnterpriseCredential.setAuthType(auth);
SessionInfo boSI = boSession.login(boEnterpriseCredential);
I have got a list of servers running web servcies stored in my tokens. when i pass the first server name say " test:8080" and that server is down , i want to catch somewhere in the code above that it did not get the connection so that i can loop back and try with the second server say test1:8080
This is for failover purposes.
at present when i was trying to capture return value of boSI it breaks giving the error
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1438)
at java.lang.String.substring(String.java:1411)
2nd case :
I am geeting reports from the server and scheduling them:
i run the following code which works fine if reports is there
rh = boBIPlatform.get("path://InfoObjects/Root Folder/"src_folder"/" + reportName +
"@SI_SCHEDULEINFO,SI_PROCESSINFO" ,oGetOptions);
oInfoObjects = rh.getInfoObjects();
CrystalReport = (CrystalReport)oInfoObjects.getInfoObject(0);
Here if the report is not there on the server then i should be able to catch from the response handle rh that it has got a null value.
but rh does not return a null value
the code ultimately throws a null handle at the following line
CrystalReport = (CrystalReport)oInfoObjects.getInfoObject(0);
i am not able to catch the null value there also.
hope you got my issue. -
Multiple return values (Bug-ID 4222792)
I had exactly the same request for the same 3 reasons: strong type safety and code correctness verification at compile-time, code readability and ease of mantenance, performance.
Here is what Sun replied to me:
Autoboxing and varargs are provided as part of
JSRs 14 and 201
http://jcp.org/en/jsr/detail?id=14
http://jcp.org/en/jsr/detail?id=201
See also:
http://forum.java.sun.com/forum.jsp?forum=316
http://developer.java.sun.com/developer/earlyAccess/adding_generics/index.html
Multiple return values is covered by Bug-ID 4222792
Typically this is done by returning an array.
http://developer.java.sun.com/developer/bugParade/bugs/4222792.html
That's exactly the problem: we dynamically create instances of array objects that would better fit well within the operand stack without stressing the garbage collector with temporary Array object instances (and with their backing store: 2 separate allocations that need to be recycled when it is clearly a pollution that the operand stack would clean up more efficiently)
If you would like to engage in a discussion with the Java Language developers, the Generics forum would be a better place:
http://forum.java.sun.com/forum.jsp?forum=316
I know that (my report was already refering to the JSR for language extension) Generics is not what I was refering to (even if a generic could handle multiple return values, it would still be an allocated Object
instance to pack them, i.e. just less convenient than using a static class for type safety.
The most common case of multiple return values involve values that have known static datatypes and that should be checked with strong typesafety.
The simple case that involves returning two ints then will require at least two object instances and will not solve the garbage collection overhead.
Using a array of variable objects is exactly similar, except that it requires two instances for the components and one instance for the generic array container. Using extra method parameters with Integer, Byte, ... boxing objects is more efficient, but for now the only practical solution (which causes the least pollution in the VM allocator and garbage collector) is to use a custom class to store the return values in a single instance.
This is not natural, and needlessly complexifies many interfaces.
So to avoid this pollution, some solutions are used such as packing two ints into a long and returning a long, depacking the long after return (not quite clean but still much faster at run-time for methods that need to be used with high frequencies within the application. In some case, the only way to cut down the overhead is to inline methods within the caller code, and this does not help code maintenance by splitting the implementation into small methods (something that C++ can do very easily, both because it supports native types parameters by reference, and because it also supports inline methods).
Finally, suppose we don't want to use tricky code, difficult to maintain, then we'll have to use boxing Object types to allow passing arguments by reference. Shamely boxed native types cannot be allocated on the operand stack as local variables, so we need to instanciate these local variables before call, and we loose the capacity to track the cases where these local variables are not really initialized by an effective call to the method that will assign them. This does not help debugging, and is against the concept of a strongly typed language like Java should be:
Java makes lots of efforts to track uninitialized variables, but has no way to determine if an already instanciated Object instance refered in a local variable has effectively received an effective assignment because only the instanciation is kept. A typical code will then need to be written like this:
Integer a = null;
Integer b = null;
if (some condition) {
//call.method(a, b, 0, 1, "dummy input arg");
// the method is supposed to have assigned a value to a and b,
// but can't if a and b have not been instanciated, so we perform:
call.method(a = new Integer(), b = new Integer(), 0, 1, "dummy input
arg");
// we must suppose that the method has modified (not initialized!)
the value
// of a and b instances.
now.use(a.value(), b.value())
// are we sure here that a and b have received a value????
// the code may be detected at run-time (a null exception)
// or completely undetected (the method() above was called but it
// forgot to assign a value to its referenced objects a and b, in which
// case we are calling in fact: now.use(0, 0); with the default values
// or a and b, assigned when they were instanciated)
Very tricky... Hard to debug. It would be much simpler if we just used:
int a;
int b;
if (some condition) {
(a, b) = call.method(0, 1, "dummy input arg");
now.use(a, b);
The compiler would immediately detect the case where a and b are in fact not always initialized (possible use bere initialization), and the first invoked call.method() would not have to check if its arguments are not null, it would not compile if it forgets to return two values in some code path...
There's no need to provide extra boxing objects in the source as well as at run-time, and there's no stress added to the VM allocator or garbage collector simply because return values are only allocated on the perand stack by the caller, directly instanciated within the callee which MUST (checked at compile-time) create such instances by using the return statement to instanciate them, and the caller now just needs to use directly the variables which were referenced before call (here a and b). Clean and mean. And it allows strong typechecking as well (so this is a real help for programmers.
Note that the signature of the method() above is:
class call {
(int, int) method(int, int, String) { ... }
id est:
class "call", member name "method", member type "(IILjava.lang.string;)II"
This last signature means that the method can only be called by returning the value into a pair of variables of type int, or using the return value as a pair of actual arguments for another method call such as:
call.method(call.method("dummy input arg"), "other dummy input arg")
This is strongly typed and convenient to write and debug and very efficient at run-time...Can anyone give me some real-world examples where
multiple return values aren't better captured in a
class that logically groups those values? I can of
course give hundreds of examples for why it's better
to capture method arguments as multiple values instead
of as one "logical object", but whenever I've hankered
for multiple return values, I end up rethinking my
strategy and rewriting my code to be better Object
Oriented.I'd personally say you're usually right. There's almost always a O-O way of avoiding the situation.
Sometimes though, you really do just want to return "two ints" from a function. There's no logical object you can think of to put them in. So you end up polluting the namespace:
public class MyUsefulClass {
public TwoInts calculateSomething(int a, int b, int c) {
public static class TwoInts {
//now, do I use two public int fields here, making it
//in essence a struct?
//or do I make my two ints private & final, which
//requires a constructor & two getters?
//and while I'm at it, is it worth implementing
//equals(), how about hashCode()? clone()?
//readResolve() ?
}The answer to most of the questions for something as simple as "TwoInts" is usually "no: its not worth implementing those methods", but I still have to think about them.
More to the point, the TwoInts class looks so ugly polluting the top level namespace like that, MyUsefulClass.TwoInts is public, that I don't think I've ever actually created that class. I always find some way to avoid it, even if the workaround is just as ugly.
For myself, I'd like to see some simple pass-by-value "Tuple" type. My fear is it'd be abused as a way for lazy programmers to avoid creating objects when they should have a logical type for readability & maintainability.
Anyone who has maintained code where someone has passed in all their arguments as (mutable!) Maps, Collections and/or Arrays and "returned" values by mutating those structures knows what a nightmare it can be. Which I suppose is an argument that cuts both ways: on the one hand you can say: "why add Tuples which would be another easy thing to abuse", on the other: "why not add Tuples, given Arrays and the Collections framework already allow bad programmers to produce unmainable mush. One more feature isn't going to make a difference either way".
Ho hum. -
Unable to see function return values in Visual Studio 2013 debugger
Hi!
I can't see function return values in
Microsoft Visual Studio Ultimate 2013
Version 12.0.31101.00 Update 4
Microsoft .NET Framework
Version 4.5.51650
Installed Version: Ultimate<o:p></o:p>
as described in http://blogs.msdn.com/b/visualstudioalm/archive/2013/06/27/seeing-function-return-values-in-the-debugger-in-visual-studio-2013.aspx
So what can I do to get this functionality back?
MsdnMezzoHi MsdnMezzo,
Reference:
http://blogs.msdn.com/b/visualstudioalm/archive/2013/06/27/seeing-function-return-values-in-the-debugger-in-visual-studio-2013.aspx
If use the same sample in the above blog provided by you, how about the result? Could you debug it with the same steps? I could debug it in my side using the VS2013.
So to make sure that whether it is your VS IDE issue, please debug it with this sample, if it works well, I doubt that we would think about your specific project and the debugging steps.
If so, to really repro this issue, could you share us a sample with one drive? You could upload your project to one drive and share us the downloaded link in your new reply, I will download and repro this issue in my side.
Best Regards,
Jack
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Best way to use return values in a webservices
Hi all,
Scenario: We have three web services. What is the best way to do this acitivity or is it possible?
webservice1
webservice2
webservice3
Call invoke webservice1 & 2 (they need to their work do be done parallely and will return a value eg "string")and call webservices3 with input values as the returned value from webservice 1 & 2.
Thanks,
Shashi
Edited by: Shashi_sr on Sep 17, 2010 1:46 PMHi Shashi,
The way to achieve your desired functionality is as follows:
Create a flow activity, and within that flow activity, you will call web services (using an invoke activity) webservice1 and webservice2.
After the flow activity, you will then use another invoke activity to call the 3rd webservice using the output given by the first 2 webservices.
Maybe you are looking for
-
Synchronous server proxy trigger
Hi All, i have a interface like webservice <--> SAP XI <-- > SAP (Synchronous). we decided to go SOAP ---Proxy interface is it correct way? if it is correct then how we trigger the SAP report when we got the input from the webservice it should onlin
-
Transform/Bounding Box Bug Illustrator CC 2014 18.1.0
Hi Guys, I did a little screencast here, anyway the bug is a simple one to explain. For some reason the transform/bounding box disappears on single objects, but behaves normally on multiples and groups. Such a small thing but very annoying. cheers Da
-
Hi , I have a table with SM30. and my Select query for SD report takes what are the user ID;s maintained in the Ztable. But If the enduser is a Internal User and not maintained in the Ztable he should be able to see all the sales orders. If the enter
-
Building a new PC - transferring CS6
Hi, I have been in a world of PC pain for several months. I am about to build a new PC. I will be starting from scratch to ensure I dont transfer any gremlins from the old box. What do I need to do in advance to ensure I have no problems using PS CS6
-
Create object of SP.WorkflowServices.WorkflowSubscription through powershell
Hi team, It would be really great if someone can assist me in powershell for the below client object model var sub = new SP.WorkflowServices.WorkflowSubscription(context) Thanks Ba$va