Want to manipulate the ref cursor
Hi,
iam having a procedure whiuch returns a ref cursor as a output parameter having 20 columns.
i had to manipulate only 2 columns in that ref cursor output in another calling procedure.
iam getting an error when iam fetching the ref cursor result into only 2 variables.
How can i achieve this ?
Why?
Let's see it ->
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
Elapsed: 00:00:00.18
satyaki>
satyaki>create or replace procedure r_gen_arg(
2 choice in number,
3 b in out sys_refcursor
4 )
5 is
6 str varchar2(500);
7 begin
8 if choice = 1 then
9 str := 'select * from emp';
10 elsif choice = 2 then
11 str := 'select * from dept';
12 end if;
13
14 open b for str;
15 exception
16 when others then
17 dbms_output.put_line(sqlerrm);
18 end;
19 /
Procedure created.
Elapsed: 00:00:04.51
satyaki>
satyaki>
satyaki>declare
2 rec_x emp%rowtype;
3 rec_y dept%rowtype;
4 w sys_refcursor;
5 begin
6 dbms_output.enable(1000000);
7 r_gen_arg(1,w);
8 loop
9 fetch w into rec_x;
10 exit when w%notfound;
11 dbms_output.put_line('Employee No: '||rec_x.empno||' - '||
12 'Name: '||rec_x.ename||' - '||
13 'Job: '||rec_x.job||' - '||
14 'Manager: '||rec_x.mgr||' - '||
15 'Joining Date: '||rec_x.hiredate||' - '||
16 'Salary: '||rec_x.sal||' - '||
17 'Commission: '||rec_x.comm||' - '||
18 'Department No: '||rec_x.deptno);
19 end loop;
20 close w;
21
22 r_gen_arg(2,w);
23 loop
24 fetch w into rec_y;
25 exit when w%notfound;
26 dbms_output.put_line('Department No: '||rec_y.deptno||' - '||
27 'Name: '||rec_y.dname||' - '||
28 'Location: '||rec_y.loc);
29 end loop;
30 close w;
31 exception
32 when others then
33 dbms_output.put_line(sqlerrm);
34 end;
35 /
Employee No: 9999 - Name: SATYAKI - Job: SLS - Manager: 7698 - Joining Date: 02-NOV-08 - Salary: 55000 - Commission: 3455 - Department No: 10
Employee No: 7777 - Name: SOURAV - Job: SLS - Manager: - Joining Date: 14-SEP-08 - Salary: 45000 - Commission: 3400 - Department No: 10
Employee No: 7521 - Name: WARD - Job: SALESMAN - Manager: 7698 - Joining Date: 22-FEB-81 - Salary: 1250 - Commission: 500 - Department No: 30
Employee No: 7566 - Name: JONES - Job: MANAGER - Manager: 7839 - Joining Date: 02-APR-81 - Salary: 2975 - Commission: - Department No: 20
Employee No: 7654 - Name: MARTIN - Job: SALESMAN - Manager: 7698 - Joining Date: 28-SEP-81 - Salary: 1250 - Commission: 1400 - Department No: 30
Employee No: 7698 - Name: BLAKE - Job: MANAGER - Manager: 7839 - Joining Date: 01-MAY-81 - Salary: 2850 - Commission: - Department No: 30
Employee No: 7782 - Name: CLARK - Job: MANAGER - Manager: 7839 - Joining Date: 09-JUN-81 - Salary: 4450 - Commission: - Department No: 10
Employee No: 7788 - Name: SCOTT - Job: ANALYST - Manager: 7566 - Joining Date: 19-APR-87 - Salary: 3000 - Commission: - Department No: 20
Employee No: 7839 - Name: KING - Job: PRESIDENT - Manager: - Joining Date: 17-NOV-81 - Salary: 7000 - Commission: - Department No: 10
Employee No: 7844 - Name: TURNER - Job: SALESMAN - Manager: 7698 - Joining Date: 08-SEP-81 - Salary: 1500 - Commission: 0 - Department No: 30
Employee No: 7876 - Name: ADAMS - Job: CLERK - Manager: 7788 - Joining Date: 23-MAY-87 - Salary: 1100 - Commission: - Department No: 20
Employee No: 7900 - Name: JAMES - Job: CLERK - Manager: 7698 - Joining Date: 03-DEC-81 - Salary: 950 - Commission: - Department No: 30
Employee No: 7902 - Name: FORD - Job: ANALYST - Manager: 7566 - Joining Date: 03-DEC-81 - Salary: 3000 - Commission: - Department No: 20
Department No: 10 - Name: ACCOUNTING - Location: NEW YORK
Department No: 20 - Name: RESEARCH - Location: DALLAS
Department No: 30 - Name: SALES - Location: CHICAGO
Department No: 40 - Name: LOGISTICS - Location: CHICAGO
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.85
satyaki>
satyaki>Here, i don't have to use separate variable to hold those required value.
Regards.
Satyaki De.
Similar Messages
-
How to handle the ref cursor which is returning "no rows"
I have written a function which is returning the REF CURSOR. But in one situation the REF CURSOR returns "no rows selected". To handle this situation an exception is raised "when no data found". But i dont know in this situation how should NULL cursor be returned through this function. Since I want to call this function in another procedure so something should be returned through this function by means of ref cursor. But since i am not able to handle this "no rows selected" situation i am not able move further.
Thanks in advance........I agree.
You would simply process the returned ref cursor irrespective of any rows actually returned in the cursor or not. You would be able to do at least one FETCH from the cursor (even if it does not actually contain any rows) and then determine the %NOTFOUND status to do the rest of the processing.
SQL> variable cur refcursor
SQL> exec open :cur for select * from scott.emp where rownum = 1 ;
PL/SQL procedure successfully completed.
SQL> print cur
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-1980 800 20
1 row selected.
SQL>
SQL> exec open :cur for select * from scott.emp where 1 = 2 ;
PL/SQL procedure successfully completed.
SQL> print cur
no rows selected
SQL>
SQL> SET SERVEROUTPUT ON
SQL> DECLARE
2 rec scott.emp%ROWTYPE;
3 bol BOOLEAN;
4 cur sys_refcursor;
5 BEGIN
6 OPEN cur FOR
7 SELECT * FROM scott.emp WHERE 1 = 2; /* assume this is your function call returning a ref cursor */
8 bol := FALSE;
9 LOOP
10 FETCH cur
11 INTO rec;
12 EXIT WHEN cur%NOTFOUND;
13 --
14 -- process the data here
15 --
16 bol := TRUE;
17 END LOOP;
18 CLOSE cur;
19 IF (bol)
20 THEN
21 dbms_output.put_line('At least one row was found');
22 ELSE
23 dbms_output.put_line('No rows were selected');
24 END IF;
25 END;
26 /
No rows were selected
PL/SQL procedure successfully completed.
SQL> -
How to print/store in file the ref cursor in pl/sql block ?
How to print/store in file the ref cursor in pl/sql block ?.
How to print/store in file the ref cursor in pl/sql block ?.You question is quite confusing?
So, i'm providing link in this manner.
For RefCursor,
http://www.oracle-base.com/articles/misc/UsingRefCursorsToReturnRecordsets.php
http://www.oracle.com/technology/oramag/code/tips2003/042003.html
For UTL_FILE,
http://www.morganslibrary.org/reference/utl_file.html
Regards.
Satyaki De.
Updated with new morgan library link.
Edited by: Satyaki_De on Feb 24, 2010 9:03 PM -
Problem with accepting the Ref Cursor in c# program
I am passing an argument as OUT Ref Cursor in a stored procedure. and calling the procedure from my c# program.
I can connect the database successfully but am getting the error on calling the procedure.
I am using the ODBC connection
My procedure's signatures are like:
CREATE OR REPLACE PACKAGE BODY packageName
IS
PROCEDURE GetOutput(returnCursor OUT Sys_RefCursor)
AS
BEGIN
OPEN returnCursor FOR
<<my select statement>>
END GetOutput;
END packageName;
My function call is like:
CString Extract::ExtractScript() const
CString script;
script.Format("{Call %s.%s()}", packageName,GetOutput);
return script;
I can compile the procedure successfully on Toad but while calling the procedure from the C# program it gives following error
Connection Successful
Problem executing SQL {Call packageName.GetOutput()}...
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'GetOutput'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Message was edited by:
user653288Hi Aga,
Thanks for your response.
I figured out the problem.
I was using the ODBC connection which wasnt updated for Oracle 10g.
I have updated that. Now its working fine.
Thanks again
Regards -
Regarding the Ref Cursor functional;ity
HI,
I am using ref cursor to return Result Set to .Net.
I am in doubt that , Is it requires multiple server trips to fill the DataSet at front end.
As my assumption it will return the address of the work area provided in Oracle server. After that for each row it make a server trip .
Is my assumption is right ?
Can any one tell me the functionality behind returning a Ref Cursor .
Thank you....This is (or ought to be) configurable on the .NET side. There will be a server round-trip to fetch every N records where N is a setting on the client. I'm not particularly experienced with .NET, so I'm not sure where this setting is set, but the folks over in the .NET forum might.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
I want to get the current Cursor row number
Hello!
Is it possible to get the current row number of a cursor in a cursor loop?
for c_1 in cursor_1
loop
dbms_output.put_line(c_1. ???) --> this should show: 1 in the first loop ,2,3,...
endloop
best regards,
wolfSQL> declare
2 cursor c is
3 select * from emp;
4 begin
5 for r in c loop
6 dbms_output.put_line(c%rowcount);
7 end loop;
8 end;
9 /
1
2
3
4
5
6
7
8
9
10
11
12
13
14
PL/SQL procedure successfully completed.Max
[My Italian Oracle blog|http://oracleitalia.wordpress.com/2010/02/07/aggiornare-una-tabella-con-listruzione-merge/] -
Manipulating data from a ref cursor in the data block of a form
I am using Oracle Forms 10g. I have a ref cursor which returns columns A, B, C, D, E where B, C, D, E are values. The "Query Data Source Name" attribute in the datablock contains "CCTR_Extract_pkg.cctr_refcur". The "Column Name" attribute of item A contains "A", item B contains "B", etc. All of these columns are displayed on the form and it all works perfectly.
I have a new request, the users would like a 6th column displayed - column F - where it equals D - B.
Is there any way of doing this in the form only or do I need to change the ref cursor to accomodate the new column and then the form?
If it can be achieved in the Form (only) - then how do I reference the 2 columns?
Thanks in anticipation
Michael
Edited by: user8897365 on 24-Aug-2011 10:32Is there any way of doing this in the form only or do I need to change the ref cursor to accomodate the new column and then the form? The REF_CURSOR is the data source of your block so you will have to modify the CCTR_Extract_pkg package and cctr_refcur REF_CURSOR.
If it can be achieved in the Form (only) - then how do I reference the 2 columns?After you have modified your database package, I recommend you run the Data Block Wizard on your block and let Forms detect the 2 new columns. You can do this manually, but it is safer to let Forms do it for you. If you want to do it manually, open the Query Data Source Columns property and add your new columns.
Hope this helps,
Craig B-)
If someone's response is helpful or correct, please mark it accordingly. -
What are the advantages to using a REF cursor
When would I want to use a REF cursor?
REF CURSORs are not cursors, they're references to cursors. This means they're dynamic. So you can completely change the query executed by the cursor.
For example you can use a REF CURSOR to select from one of a number of tables (depending on an input parameter or other sort of flag). The results are fetched into the same resultset holder and hence you only need a single lot of code to process the results.
Also you can also pass a REF CURSOR as a argument to other PL/SQL procedures and functions.
rgds, APC -
How to convert the varray to ref cursor
Hi,
Is there any way to convert varray to ref cursor....
i dont want to use any table or record as an ref cursor..
i just want to create a procedure which returns a ref cursor..
below is the sample procedure for it..
create or replace procedure FETCH_DATA1
tab_name in varchar2,
p_recordset1 OUT fetch_data_pak.ref_cursor
AS
type v_array1 is varray(1000) of t_transaction%rowtype;
v_array2 v_array1;
cursor s1 is select * from t_transaction where lastupdate_date > '08-Aug-09';
begin
open s1;
fetch s1 bulk collect into v_array2 limit 100;
close s1;
select * from table(cast (v_array2 as p_recordset1));
end FETCH_DATA1;
I need to convert the varray to ref cursor.....Why put it into a varray at all?
You can just open the ref cursor for that select you are desiring.
And if you need to limit it to returning just the first 100 (as your code seems to imply), wrap it and filter on rownum.
Something similar to this:
create or replace procedure FETCH_DATA1
tab_name in varchar2,
p_recordset1 OUT fetch_data_pak.ref_cursor
AS
begin
open p_recordset1 for
select /*+ first_rows(100) */ * from (
select * from t_transaction
where lastupdate_date > to_date('08-08-2009','DD-MM-YYYY')
--order by something
where rownum <= 100;
end FETCH_DATA1;And note, that you really should have an order by when you wish to limit yourself to "first 100 rows" - otherwise it will be "random 100 rows".
That goes for your cursor solution as well...
Edited by: Kim Berg Hansen on Nov 28, 2011 10:25 AM
Added explicit date conversion - it is bad practice not to explicitly convert dates ;-) -
Sorting the results returned by a Ref cursor
Hi All,
I have a scenario where i am asked to sort results returned by a ref cursor.
I have to pass the column to be sorted as the Input parameter to a stored procedure. I tried using 'order by sorting_parameter' in the ref cursor's select query, but it is not sorting the results. It is not throwing any error even.
Please help.
Many Thanks...Hi
i came across the below reply for a thread with the similar query as above.
<<
Justin Cave
Posts: 10,696
From: Michigan, USA
Registered: 10/11/99
Re: sort data in ref cursor
Posted: Feb 3, 2005 10:30 AM in response to: [email protected] Reply
No. You could sort the data in the SQL statement from which the REF CURSOR was created, but once you have a REF CURSOR, you cannot do anything but fetch from it.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC
>>
So, the results from a ref cursor cant be sorted?? There is no way out?
Kindly advise. -
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. -
Hello.
I ask you a favor and I hope you could help me out.
I have a lot of legacy functions that return REF CURSOR.
I'd like to have a generic method that convert a cursor variable to something what I could query with SELECT statement.
select * from TABLE(mypkg.CONVERT(LEGACYFUNCTION()));
Here I give you an example how I can deal with the problem.
But It's easy to see that "mypkg" depends on "ordr" table.
I would like the "mypkg" to be unaware of "ordr" table - it must be generic.
A legacy function looks like this one:
CREATE OR REPLACE FUNCTION LEGACYFUNCTION RETURN SYS_REFCURSOR AS
c SYS_REFCURSOR;
begin
OPEN c FOR SELECT * from ordr;
return c;
end;
Here my package that converts REF CURSOR to something good:
CREATE OR REPLACE PACKAGE mypkg AS
TYPE TabTyp IS TABLE OF ordr%ROWTYPE;
FUNCTION CONVERT(c IN SYS_REFCURSOR) RETURN TabTyp PIPELINED;
end;
CREATE OR REPLACE PACKAGE BODY mypkg AS
FUNCTION CONVERT(c IN SYS_REFCURSOR) RETURN TabTyp PIPELINED AS
data ordr%ROWTYPE;
begin
LOOP
FETCH c INTO data;
PIPE ROW(data);
EXIT WHEN c%NOTFOUND;
END LOOP;
CLOSE c;
end;
end;
I'm looking for something like SELET * FROM CONVERT(LEGACYFUNCTION());
Thanks> On Oracle 10.1 I can't even get compile:
CREATE OR REPLACE PACKAGE mypkg AS
FUNCTION CONVERT(c IN SYS_REFCURSOR) RETURN
SYS.ANYDATASET PIPELINED;
end;
It's work, but not for PIPELINED functions. I can't
generalize my first example.
Pipeline table functions can be generalised. In PL/SQL. Using the any data set type. It is possible.
BUT.. In this case it will be a major hack to make it work for you. I honestly think it is NOT the correct thing to do to solve your problem. Nor is it feasible with you proclaiming no Oracle experience as doing this, generically via a pipeline table, is not trivial coding.
> I'm java developer, thus I can't refactor Oracle
database.
Then you get an Oracle back-end developer that can. I harp almost everyday (in some forum on the net or in the office with our developers) that one fixes CAUSES and not symptoms.
The root cause you have is that the ref cursors returns data sets that you need to manipulate further - given your requirement that you want to run additional SQLs on the ref cursors.
Slapping any kind of interface layer over these ref cursors to as a "fix" does not address the cause. It is a fix that will not scale. A fix that is not robust. A fix that introduces more moving parts between the application and Oracle which means a bigger chance of failure.
So the choices you have seem simple. Either learn how to use Oracle and refactor the Oracle side - or get someone with the expertise do it.
I understand that is easy said. But these fact should not be ignored.
> I want to ask you a favor. Not write PL/SQL function
that return a REF CURSOR.
Er.. you missed me completely with that statement. Are you saying that a ref cursor pipeline is too complex or not doing the job? If so, then yes - I agree in principle that this is the wrong method for you to use to address your problem. -
Ref cursors and dynamic sql..
I want to be able to use a fuction that will dynamically create a SQL statement and then open a cursor based on that SQL statement and return a ref to that cursor. To achieve that, I am trying to build the sql statement in a varchar2 variable and using that variable to open the ref cursor as in,
open l_stmt for refcurType;
where refcurType is a strong ref cursor. I am unable to do so because I get an error indication that I can not use strong ref cursor type. But, if I can not use a strong ref cursor, I will not be able to use it to build the report based on the ref cursor because Reports 9i requires strong ref cursors to be used. Does that mean I can not use dynamic sql with Reports 9i ref cursors? Else, how I can do that? Any documentation available?Philipp,
Thank you for your reply. My requirement is that, sometimes I need to construct a whole query based on some input, and sometimes not. But the output record set would be same and the layout would be more or less same. I thought ref cursor would be ideal. Ofcourse, I could do this without dynamic SQL by writing the SQL multiple times if needed. But, I think dynamic SQL is a proper candidate for this case. Your suggestion to use lexical variable is indeed a good alternative. In effect, if needed, I could generate an entire SQL statement and place in some place holder (like &stmt) and use it as a static SQL query in my data model. In that case, why would one ever need ref cursor in reports? Is one more efficient over the other? My guess is, in the lexical variable case, part of the processing (like parsing) is done on the app server while in a function based ref cursor, the entire process takes place in the DB server and there is probably a better chance for re-use(?)
Thanks,
Murali. -
MS Access, ODBC and SPs returning ref cursor
I have some functions and procedures in a package returning ref cursors that work fine in my C++ batch applications. I would like for the GUI to be able to call these as well.
Unfortunately, we are using Access as the front end (for now), and we have not been able to get the ref cursors to work. Is this supported? We are using Oracle 8.0.5 on Solaris, and our clients is Access 97 on NT using Intersolv's ODBC driver.
My procedure looks something like:
package jec is
procedure open_sale_cur(
p_client_id number,
sale_curvar out sale_curtype)
is begin
open sale_curtype for select ... ;
end;
end;
And the Access code looks like this:
strSql = "begin jec.open_sale_cur(27, ?); end;"
qdfTemp = conMain.CreateQueryDef("", strSql)
qdfTemp.Parameters(0).Direction = dbParamOutput
qdfTemp.Execute()
This is the error when Execute() is called:
PLS-00306: wrong number or types of arguments in call to 'OPEN_SALE_CUR'
I am not an Access programmer; I am simply passing along this information. Any help would be greatly appreciated.We tried the {call...} syntax originally, but when we use it, we get an Oracle syntax error for the statement
SELECT * FROM {call ...}
Apparently Access prepends "SELECT..." before passing the SQL text to Oracle.
This is also the case for procedures with normal scalars, such as numbers, returned as OUT values. When we use anon PL/SQL syntax and "?" placeholders with such procedures, they work. When we use {call ...} syntax or omit OUT placeholders, they do not.
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Justin Cave ([email protected]):
I suspect that you want to simply execute the statement
strSql = {call open_sale_cur( 27 )}
The ODBC driver will automatically figure out that there's an output parameter which is a ref cursor and return that as the result set. Note that you may want to download the latest 8.0.5 ODBC driver (8.0.5.10 I believe) if there are any problems.
Justin<HR></BLOCKQUOTE>
null -
I want to fill the rows of the report from the loop
I want to fill the rows of the report from the loop
For example, in forms
cursor bdl is select code,decode(:global.user_lang,1,name,2,latin_name) name
from GL_ANALYSISHDR
begin
go_block('bdls');
clear_block;
first_record;
for rec in bdl loop
:bdls.code:=rec.code;
:bdls.name:=rec.name;
next_record;
end loop;
go_block('bdls');
first_record;
end;
I tried to use the REF CURSOR
But it return the values in one time and does not allow me to conduct and control ofWhy do you need to do it by a curesor loop? Can't you put the query in the datamodel of the report and simply pass the parameter to restrict the query?
Maybe you are looking for
-
On how many systems can i install dreamweaver cs6
About a month ago i have format my whole old pc with also dreamweaver cs6 deleted (i had troubles with my whole pc, thats the reason to format the whole pc) I sell the empty pc. only windows 7 on it. Now i have an new pc. and i have installed dreamwe
-
Hi We are using SQL 2005 as a database for PCM v12.1 and plan to upgrade to PCM v13 SP1. Has anybody using Microsoft Reporting Services for preparing reports ? could you please guide on the same ? How good it is ? Is it easy to prepare report (in com
-
Fail to install 9iAS9.0.2-a fully qualified hostname has not be specified
hello in order to study oracle9iAS,i download the 9iAS9.0.2 from your website,but at the first disk installation,it tell me: "installation has detected that a fully qualified hostname has not be specified for this host,oracle9i Application server ins
-
Hi, i am trying to run a script in SQL*Plus that has been supplied by Metalink but i am very new to SQL*Plus and i connot get the script to run correctly. FYI we are curently using Oracle 11.5.10. I logon to SQL*Plus successfully then i start the scr
-
Mass Migration of Contacts from One Org to Another
Hi All I have requirement to migrate dozens or hundreds of party relationship (organization contact) records from one organization to another. For example, if BONY Mellon sells a business unit to JP Morgan Chase, there may be hundreds of BONY contact