I'm trying to create Procedure where I'm passing dynamic table but I'm not able to achieve my goal and getting "PL/SQL: ORA-00942: table or view does not exist".Please let me know if doing wrong somewhere
CREATE OR REPLACE Procedure DE_DUP_PRO1 (Dy_Table_Name in varchar2)
--RETURN NUMBER
AS
v_hol varchar2(300);
CURSOR De_DUB_CUR IS
SELECT S.TRANS_GUID AS OLD_TRANS_GUID,
H.TRANS_GUID AS NEW_TRANS_GUID,
CASE
WHEN H.TRANS_GUID IS NULL
THEN 0
ELSE 1
END as TRN_STAT,
P.INTR_PHARMACY_ID as INT_PHARMACY_ID ,S.EXTRNL_PHARMACY_ID as EXT_PHARMACY_ID ,S.PHARMACY_NM as PHARMACY_NAME ,S.PHARMACY_ADDR as PHARMACY_ADDRESS,
S.SUPPLIERS_PSCR_DRUG_CD as SP_PSCR_DRUG_CD, S.PSCR_DRUG_IPU_CD as PS_DRUG_IPU_CD,'IPU' as IPU_Value, S.PSCR_DRUG_DESC as PS_DRUG_DESC,
S.DSPNSD_DRUG_PACK_SIZE as DS_DRUG_PACK_SIZE, S.RX_ID as R_ID, S.RX_ITEM_SEQ as R_ITEM_SEQ, S.RX_REPEAT_STATUS as R_REPEAT_STATUS, S.RX_TYP as R_TYPE,
S.EXMT_STATUS as EX_STATUS,S.PSCR_QTY as PS_QTY, S.NRSG_HM_IND as NR_HM_IND,S.RX_DSPNSD_DT as R_DSPNSD_DT, S.RX_DSPNSD_TM as R_DSPNSD_TM,
S.SUPPLIERS_DSPNSD_DRUG_CD as SP_DSPNSD_DRUG_CD, S.DSPNSD_DRUG_IPU_CD as DS_DRUG_IPU_CD, 'IPU' as IPU_Value2,S.DSPNSD_DRUG_DESC as DS_DRUG_DESC,
S.GENERIC_USE_MARKER as GC_USE_MARKER, S.DSPNSD_UNIT_OF_QTY as DS_UNIT_OF_QTY, S.DSPNSD_QTY as DS_QTY, 'EUR' as EUR_Value1,S.COST_OF_DSPNSD_QTY as CT_OF_DSPNSD_QTY ,
S.VERBOSE_DOSAGE as VER_DOSAGE
FROM (SELECT stg.*, row_number() over ( partition BY key_clmns_hash ORDER BY 1 ) AS RN FROM Dy_Table_Name stg ) s
-- From( SELECT stg.TRANS_GUID,stg.EXTRNL_PHARMACY_ID,stg.PHARMACY_NM,stg.PHARMACY_ADDR,stg.SUPPLIERS_PSCR_DRUG_CD,stg.PSCR_DRUG_IPU_CD,stg.PSCR_DRUG_DESC,stg.DSPNSD_DRUG_PACK_SIZE,
-- stg.RX_ID,stg.RX_ITEM_SEQ,stg.RX_REPEAT_STATUS,stg.RX_TYP,stg.EXMT_STATUS,stg.PSCR_QTY,stg.NRSG_HM_IND,stg.RX_DSPNSD_DT,stg.RX_DSPNSD_TM,stg.SUPPLIERS_DSPNSD_DRUG_CD,
-- stg.DSPNSD_DRUG_IPU_CD,stg.DSPNSD_DRUG_DESC,stg.GENERIC_USE_MARKER,stg.DSPNSD_UNIT_OF_QTY,stg.DSPNSD_QTY,stg.COST_OF_DSPNSD_QTY,stg.VERBOSE_DOSAGE, row_number() over ( partition BY key_clmns_hash ORDER BY 1 ) AS RN FROM Dy_File_Name stg ) s
LEFT JOIN ps_pharmacy p ON s.extrnl_pharmacy_id = p.extrnl_pharmacy_id LEFT JOIN ps_rx_hist H ON h.key_clmns_hash = s.key_clmnS_hash
AND h.rx_dspnsd_dt = s.rx_dspnsd_dt AND s.supplier_pharmacy_cd = h.SUPPLIER_PHARMACY_CD AND s.detl_clmns_hash <> h.detl_clmns_hash WHERE S.RN = 1;
BEGIN
FOR De_Dub_rec IN De_DUB_CUR
LOOP
DBMS_OUTPUT.PUT_LINE ( De_Dub_rec.OLD_TRANS_GUID || '|' || De_Dub_rec.NEW_TRANS_GUID || '|' || De_Dub_rec.TRN_STAT || '|' || De_Dub_rec.INT_PHARMACY_ID || '|' ||
De_Dub_rec.EXT_PHARMACY_ID || '|' || De_Dub_rec.PHARMACY_NAME|| '|' || De_Dub_rec.PHARMACY_ADDRESS || '|' || De_Dub_rec.SP_PSCR_DRUG_CD || '|' ||
De_Dub_rec.PS_DRUG_IPU_CD || '|' || De_Dub_rec.IPU_Value || '|' || De_Dub_rec.PS_DRUG_DESC || '|' || De_Dub_rec.DS_DRUG_PACK_SIZE || '|' || De_Dub_rec.R_ID || '|' ||
De_Dub_rec.R_ITEM_SEQ || '|' || De_Dub_rec.R_REPEAT_STATUS || '|' || De_Dub_rec.R_TYPE || '|' || De_Dub_rec.EX_STATUS || '|' || De_Dub_rec.PS_QTY || '|' || De_Dub_rec.NR_HM_IND || '|' || De_Dub_rec.R_DSPNSD_DT
|| '|' || De_Dub_rec.R_DSPNSD_TM || '|' || De_Dub_rec.SP_DSPNSD_DRUG_CD || '|' || De_Dub_rec.DS_DRUG_IPU_CD|| '|' || De_Dub_rec.IPU_Value2 || '|' ||
De_Dub_rec.DS_DRUG_DESC|| '|' || De_Dub_rec.GC_USE_MARKER|| '|' || De_Dub_rec.DS_UNIT_OF_QTY|| '|' || De_Dub_rec.DS_QTY|| '|' || De_Dub_rec.EUR_Value1|| '|' ||
De_Dub_rec.CT_OF_DSPNSD_QTY|| '|' || De_Dub_rec.VER_DOSAGE);
END LOOP;
-- RETURN 0;
END DE_DUP_PRO1;
/
After executing I'm getting below
LINE/COL ERROR
-------- -----------------------------------------------------------------
7/7 PL/SQL: SQL Statement ignored
21/106 PL/SQL: ORA-00942: table or view does not exist
36/6 PL/SQL: Statement ignored
36/29 PLS-00364: loop index variable 'DE_DUB_REC' use is invalid
You have to use dynamic sql.
for example;
CREATE OR REPLACE Procedure DE_DUP_PRO1 (
Dy_Table_Name in varchar2
)
AS
v_sql varchar2(1500);
v_clm1 number; -- if clm1 datatype is number
v_clm1 number; -- if clm2 datatype is number
begin
v_sql := 'select clm1, clm2 from ' || Dy_Table_Name;
open cur for v_sql;
loop
FETCH cur INTO v_clm1, v_clm2;
EXIT WHEN cur%NOTFOUND;
-- process v_clm1, v_clm2
end loop;
end DE_DUP_PRO1;
/
Related
I'm troubled with this error when running SP, I don't know why. pls help me
error in line AND thlt.CODE = ' || p_CODE|| ' when CODE is varchar2
A_ID NUMBER, P_A_Ids VARCHAR2, v_expression VARCHAR2, p_CODE VARCHAR2
...
OPEN v_cursor FOR
' SELECT thltCt.A_ID A_ID,
Sum( ' || v_expression || ' ) "VALUE"
FROM tableA thlt join tableB thltCt on thlt.ID = thltCt.THLT_ID
WHERE thlt.LS IS NOT NULL
AND thlt.CODE = ' || p_CODE|| '
AND thltCt.A_ID IN (' || P_A_Ids || ' )
GROUP BY (thltCt.A_ID)';
From the comments i think it will work like this :
' SELECT thltCt.A_ID A_ID,
Sum( ' || v_expression || ' ) "VALUE"
FROM tableA thlt join tableB thltCt on thlt.ID = thltCt.THLT_ID
WHERE thlt.LS IS NOT NULL
AND thlt.CODE = '' ' || p_CODE|| ' ''
AND thltCt.A_ID IN ( ' || P_A_Ids || ' )
GROUP BY (thltCt.A_ID)';
I have created a stored procedure where I'm struggling with the same and it is created successfully and I'm getting error .Where i have create a record and using with open cursor.
I'm executing like this
declare
DUP_FILE_NAME varchar2(100) := 'T_MCL_051270_20160314_001.039_duplicates_20160510155707';
begin
IRE_DE_DUP_PROC5('T_MCL_051270_20160314_00121914',DUP_FILE_NAME ,'DE_DUP_OUTPUT','DE_DUP_DUPLICATES');
end;
Error
Error at line 1
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at "PS_ADMIN.IRE_DE_DUP_PROC5", line 70
ORA-06512: at line 9
Stored Procedure
CREATE OR REPLACE PROCEDURE IRE_DE_DUP_PROC5(Dy_File_Name IN VARCHAR2,
DUP_FILE_NAME IN OUT VARCHAR2,
DE_DUP_OUTPUT_NAME IN VARCHAR2,
DE_DUP_DUPLICATES_NAME IN VARCHAR2)
AS
CLREF SYS_REFCURSOR;
OUT_FILE UTL_FILE.FILE_TYPE;
DE_DUP_FILE UTL_FILE.FILE_TYPE;
OUT_DIR VARCHAR2 (200) := DE_DUP_OUTPUT_NAME;
OUT_DE_DUP_DIR VARCHAR2 (300) := DE_DUP_DUPLICATES_NAME;
INPUT_FILE_NAME VARCHAR2(200) := REGEXP_REPLACE(DUP_FILE_NAME,'_duplicates_[0-9]+','');
EXT_PHARMA_ID1 VARCHAR2(80);
L_REC_COUNT NUMBER :=0;
L_DUP_COUNT NUMBER :=0;
L_UPD_COUNT NUMBER :=0;
L_DEL_COUNT NUMBER :=0;
VSLQ_TEXT VARCHAR2(2000);
TYPE REC_TYP IS RECORD
(
TRANS_GUID VARCHAR2(60),
PREV_TRANS_GUID VARCHAR2(255),
TRN_STAT NUMBER(1),
INT_PHARMACY_ID VARCHAR2(20),
EXT_PHARMACY_ID VARCHAR2(80),
PHARMACY_NAME VARCHAR2(50),
PHARMACY_ADDRESS VARCHAR2(512),
SP_PSCR_DRUG_CD VARCHAR2(800),
PS_DRUG_IPU_CD VARCHAR2(20),
IPU_Value VARCHAR2(4),
PS_DRUG_DESC VARCHAR2(150),
DS_DRUG_PACK_SIZE VARCHAR2(400),
R_ID VARCHAR2(40),
R_ITEM_SEQ NUMBER(38),
R_REPEAT_STATUS VARCHAR2(10),
R_TYPE VARCHAR2(10),
EX_STATUS VARCHAR2(800),
PS_QTY VARCHAR2(400),
NR_HM_IND NUMBER(38),
R_DSPNSD_DT DATE,
R_DSPNSD_TM VARCHAR2(20),
SP_DSPNSD_DRUG_CD VARCHAR2(20),
DS_DRUG_IPU_CD VARCHAR2(20),
IPU_Value2 VARCHAR2(4),
DS_DRUG_DESC VARCHAR2(150),
GC_USE_MARKER NUMBER(38),
DS_UNIT_OF_QTY VARCHAR2(800),
DS_QTY VARCHAR2(400),
EUR_Value1 VARCHAR2(4),
CT_OF_DSPNSD_QTY NUMBER(38),
VER_DOSAGE VARCHAR2(2048)
);
REC REC_TYP;
BEGIN
VSLQ_TEXT := ' SELECT
/*+ use_hash(s,H) leading(s h) */
S.TRANS_GUID AS TRANS_GUID,
H.TRANS_GUID AS PREV_TRANS_GUID,
CASE
WHEN S.DEL_IND = 1 AND H.DEL_IND = 0 THEN 2
WHEN H.TRANS_GUID IS NULL
THEN 0
ELSE 1
END AS TRN_STAT,
P.INTR_PHARMACY_ID AS INT_PHARMACY_ID ,
SUBSTR(S.EXTRNL_PHARMACY_ID,-6) AS EXT_PHARMACY_ID ,
S.PHARMACY_NM AS PHARMACY_NAME ,
S.PHARMACY_ADDR AS PHARMACY_ADDRESS,
S.SUPPLIERS_PSCR_DRUG_CD AS SP_PSCR_DRUG_CD,
S.PSCR_DRUG_IPU_CD AS PS_DRUG_IPU_CD,
''IPU'' AS IPU_Value,
S.PSCR_DRUG_DESC AS PS_DRUG_DESC,
S.DSPNSD_DRUG_PACK_SIZE AS DS_DRUG_PACK_SIZE,
S.RX_ID AS R_ID,
S.RX_ITEM_SEQ AS R_ITEM_SEQ,
S.RX_REPEAT_STATUS AS R_REPEAT_STATUS,
S.RX_TYP AS R_TYPE,
S.EXMT_STATUS AS EX_STATUS,
S.PSCR_QTY AS PS_QTY,
S.NRSG_HM_IND AS NR_HM_IND,
S.RX_DSPNSD_DT AS R_DSPNSD_DT,
S.RX_DSPNSD_TM AS R_DSPNSD_TM,
S.SUPPLIERS_DSPNSD_DRUG_CD AS SP_DSPNSD_DRUG_CD,
S.DSPNSD_DRUG_IPU_CD AS DS_DRUG_IPU_CD,
''IPU'' AS IPU_Value2,
S.DSPNSD_DRUG_DESC AS DS_DRUG_DESC,
S.GENERIC_USE_MARKER AS GC_USE_MARKER,
S.DSPNSD_UNIT_OF_QTY AS DS_UNIT_OF_QTY,
S.DSPNSD_QTY AS DS_QTY,
''EUR'' AS EUR_Value1,
S.COST_OF_DSPNSD_QTY AS CT_OF_DSPNSD_QTY ,
S.VERBOSE_DOSAGE AS VER_DOSAGE,
CASE WHEN S.DEL_IND = 1 AND H.DEL_IND = 0 THEN ''DEL''
WHEN S.DEL_IND = 1 AND H.DEL_IND IS NULL THEN ''DEL_IGNR''
WHEN S.DETL_CLMNS_HASH <> H.DETL_CLMNS_HASH THEN ''UPDT''
WHEN S.DETL_CLMNS_HASH = H.DETL_CLMNS_HASH THEN ''DUPL''
WHEN H.DETL_CLMNS_HASH IS NULL THEN ''NEW''
ELSE ''ERR''
END AS REC_STAT
FROM
(SELECT stg.*,
row_number() over ( partition BY key_clmns_hash, rx_dspnsd_dt, del_ind ORDER BY 1) AS RN
FROM ' || Dy_File_Name || ' stg
) s
LEFT JOIN ps_pharmacy p ON s.extrnl_pharmacy_id = p.extrnl_pharmacy_id
LEFT JOIN ps_rx_hist H
ON h.key_clmns_hash = s.key_clmnS_hash
AND h.rx_dspnsd_dt = s.rx_dspnsd_dt
AND s.supplier_pharmacy_cd = h.SUPPLIER_PHARMACY_CD
WHERE s.RN = 1';
OPEN CLREF FOR VSLQ_TEXT;
LOOP
FETCH CLREF INTO REC;
EXIT WHEN CLREF%NOTFOUND;
/*FOR REC IN (')
LOOP*/
DBMS_OUTPUT.PUT_LINE('"'|| REC.TRANS_GUID || '"'||REC.PREV_TRANS_GUID || '"|"' || REC.TRN_STAT || '"|' || REC.INT_PHARMACY_ID || '|' || substr(REC.EXT_PHARMACY_ID,-6) || '|"' ||
REC.PHARMACY_NAME || '"|"' || REC.PHARMACY_ADDRESS || '"|' || REC.SP_PSCR_DRUG_CD || '|' || REC.PS_DRUG_IPU_CD || '|"' || REC.IPU_Value || '"|"' || REC.PS_DRUG_DESC ||
'"|' || REC.DS_DRUG_PACK_SIZE || '|"' || REC.R_ID || '"|' || REC.R_ITEM_SEQ || '|' || REC.R_REPEAT_STATUS || '|"'|| REC.R_TYPE || '"|"'
|| REC.EX_STATUS || '"|' || REC.PS_QTY || '|' || REC.NR_HM_IND || '|'|| to_char(to_date(REC.R_DSPNSD_DT,'dd-mon-yy' ),'yyyymmdd')
|| '|'|| REC.R_DSPNSD_TM || '|' || REC.SP_DSPNSD_DRUG_CD || '|' || REC.DS_DRUG_IPU_CD || '|"' || REC.IPU_Value2 || '"|"'
|| REC.DS_DRUG_DESC || '"|' || REC.GC_USE_MARKER || '|"' || REC.DS_UNIT_OF_QTY || '"|' || REC.DS_QTY || '|"' || REC.EUR_Value1
|| '"|' || REC.CT_OF_DSPNSD_QTY || '|"' || REC.VER_DOSAGE || '"');
END LOOP;
CLOSE CLREF;
END;
You should change this: VSLQ_TEXT VARCHAR2(2000); to:
VSLQ_TEXT VARCHAR2(4000);
When you assign VSLQ_TEXT := ' SELECT....., length of the string is ~ 2963 > 2000 as your original declare of VSLQ_TEXT
I'm trying to execute stored procedure, I'm getting stuck in 54 line 'EXECUTE IMMEDIATE' basically. I'm passing SQL statement into for loop.Please let me know I'm doing wrong somewhere?
CREATE OR REPLACE Procedure DE_DUP_PROC (Dy_File_Name in USER_TABLES.table_name%type,
SUPPLIER_CD in varchar2,
EXT_PHARMA_ID in varchar2,
FLAG_VALUE in varchar2,
DE_REC_COUNT out NUMBER) --RETURN NUMBER
AS
SEQ_NO_SHO Number(38); --EEEE
WYYYYNNN VARCHAR2(250) := 'W2015021';
YYYYNNN VARCHAR2(10);
CUR_DATE Date;
--De_Rec_Count Number(38) := 3456;
DE_DUB_OUTPUT_FILE VARCHAR2(100);
/*CURSOR De_DUB_CUR IS */
DE_DUB_SQL_STATMNT VARCHAR2(3000) := 'SELECT S.TRANS_GUID AS OLD_TRANS_GUID,
H.TRANS_GUID AS NEW_TRANS_GUID,
CASE
WHEN H.TRANS_GUID IS NULL
THEN 0
ELSE 1
END as TRN_STAT,P.INTR_PHARMACY_ID as INT_PHARMACY_ID ,S.EXTRNL_PHARMACY_ID as EXT_PHARMACY_ID ,S.PHARMACY_NM as PHARMACY_NAME ,S.PHARMACY_ADDR as PHARMACY_ADDRESS,
S.SUPPLIERS_PSCR_DRUG_CD as SP_PSCR_DRUG_CD, S.PSCR_DRUG_IPU_CD as PS_DRUG_IPU_CD,''IPU'' as IPU_Value, S.PSCR_DRUG_DESC as PS_DRUG_DESC,
S.DSPNSD_DRUG_PACK_SIZE as DS_DRUG_PACK_SIZE, S.RX_ID as R_ID, S.RX_ITEM_SEQ as R_ITEM_SEQ, S.RX_REPEAT_STATUS as R_REPEAT_STATUS, S.RX_TYP as R_TYPE,
S.EXMT_STATUS as EX_STATUS,S.PSCR_QTY as PS_QTY, S.NRSG_HM_IND as NR_HM_IND,S.RX_DSPNSD_DT as R_DSPNSD_DT, S.RX_DSPNSD_TM as R_DSPNSD_TM,
S.SUPPLIERS_DSPNSD_DRUG_CD as SP_DSPNSD_DRUG_CD, S.DSPNSD_DRUG_IPU_CD as DS_DRUG_IPU_CD, ''IPU'' as IPU_Value2,S.DSPNSD_DRUG_DESC as DS_DRUG_DESC,
S.GENERIC_USE_MARKER as GC_USE_MARKER, S.DSPNSD_UNIT_OF_QTY as DS_UNIT_OF_QTY, S.DSPNSD_QTY as DS_QTY, ''EUR'' as EUR_Value1,S.COST_OF_DSPNSD_QTY as CT_OF_DSPNSD_QTY ,
S.VERBOSE_DOSAGE as VER_DOSAGE FROM
(SELECT stg.*, row_number() over (partition BY key_clmns_hash ORDER BY 1) AS RN FROM '|| Dy_File_Name ||' stg ) s
LEFT JOIN ps_pharmacy p
ON s.extrnl_pharmacy_id = p.extrnl_pharmacy_id
LEFT JOIN ps_rx_hist H
ON h.key_clmns_hash = s.key_clmnS_hash
AND h.rx_dspnsd_dt = s.rx_dspnsd_dt
AND s.supplier_pharmacy_cd = h.SUPPLIER_PHARMACY_CD
AND s.detl_clmns_hash <> h.detl_clmns_hash
WHERE s.RN = 1';
BEGIN
EXECUTE IMMEDIATE 'SELECT count(*) into DE_REC_COUNT
FROM (SELECT stg.*, row_number() over ( partition BY key_clmns_hash ORDER BY 1 ) AS RN FROM '|| Dy_File_Name ||' stg ) s
LEFT JOIN ps_pharmacy p ON s.extrnl_pharmacy_id = p.extrnl_pharmacy_id LEFT JOIN ps_rx_hist H ON h.key_clmns_hash = s.key_clmnS_hash
AND h.rx_dspnsd_dt = s.rx_dspnsd_dt AND s.supplier_pharmacy_cd = h.SUPPLIER_PHARMACY_CD AND s.detl_clmns_hash <> h.detl_clmns_hash WHERE S.RN = 1';
IF DE_REC_COUNT > 0 THEN
--select sysdate into CUR_DATE from dual;
--select PROC_PD_CD into WYYYYNNN from PS_ADMIN.PS_PROC_PD where PD_STRT_DT <= CURRENT_DATE and PD_END_DT >= CURRENT_DATE;
--select PROC_PD_CD into WYYYYNNN from PS_ADMIN.PS_PROC_PD where PD_STRT_DT <= CURRENT_DATE and PD_END_DT >= CURRENT_DATE; -- PD_STRT_DT<='16-AUG-15' and PD_STRT_DT >= '16-AUG-15';
select replace(WYYYYNNN,'W','') into YYYYNNN from dual;
SELECT PS_GET_PROC_PD(SUPPLIER_CD,EXT_PHARMA_ID,YYYYNNN) into SEQ_NO_SHO FROM DUAL;
select 'LRXIE'||FLAG_VALUE||'10_'||SUPPLIER_CD||'_'||EXT_PHARMA_ID||'_'||WYYYYNNN||'_'||SEQ_NO_SHO||'_'||DE_REC_COUNT||'.TXT' into DE_DUB_OUTPUT_FILE from dual;
--DBMS_OUTPUT.PUT_LINE( De_Dub_Output_File );
FOR De_Dub_rec IN EXECUTE IMMEDIATE DE_DUB_SQL_STATMNT
LOOP
dbms_output.enable(100000);
DBMS_OUTPUT.PUT_LINE ('"' || De_Dub_rec.OLD_TRANS_GUID || '"|"' || De_Dub_rec.NEW_TRANS_GUID || '"|' || De_Dub_rec.TRN_STAT || '|' || De_Dub_rec.INT_PHARMACY_ID || '|' || De_Dub_rec.EXT_PHARMACY_ID || '|"' ||
De_Dub_rec.PHARMACY_NAME|| '"|"' || De_Dub_rec.PHARMACY_ADDRESS || '"|' || De_Dub_rec.SP_PSCR_DRUG_CD || '|' || De_Dub_rec.PS_DRUG_IPU_CD || '|"' || De_Dub_rec.IPU_Value || '"|"' ||
De_Dub_rec.PS_DRUG_DESC || '"|' || De_Dub_rec.DS_DRUG_PACK_SIZE || '|"' || De_Dub_rec.R_ID || '"|' || De_Dub_rec.R_ITEM_SEQ || '|' || De_Dub_rec.R_REPEAT_STATUS || '|"' ||
De_Dub_rec.R_TYPE || '"|"' || De_Dub_rec.EX_STATUS || '"|' || De_Dub_rec.PS_QTY || '|' || De_Dub_rec.NR_HM_IND || '|"' || De_Dub_rec.R_DSPNSD_DT || '"|' || De_Dub_rec.R_DSPNSD_TM || '|' ||
De_Dub_rec.SP_DSPNSD_DRUG_CD || '|' || De_Dub_rec.DS_DRUG_IPU_CD|| '|"' || De_Dub_rec.IPU_Value2 || '"|"' || De_Dub_rec.DS_DRUG_DESC|| '"|' || De_Dub_rec.GC_USE_MARKER|| '|"' ||
De_Dub_rec.DS_UNIT_OF_QTY|| '"|' || De_Dub_rec.DS_QTY|| '|"' || De_Dub_rec.EUR_Value1|| '"|' || De_Dub_rec.CT_OF_DSPNSD_QTY || '|"' || De_Dub_rec.VER_DOSAGE || '"');
END LOOP;
DE_REC_COUNT :=0;
ELSE
DE_REC_COUNT :=1;
END IF;
END DE_DUP_PROC;
/
I'm getting this error:
LINE/COL ERROR
-------- -----------------------------------------------------------------
58/44 PLS-00103: Encountered the symbol "IMMEDIATE" when expecting one
of the following:
. ( * # % & - + / at loop mod remainder rem ..
<an exponent (**)> || multiset
The symbol ". was inserted before "IMMEDIATE" to continue.
There are two errors in your code. The first one is the compiler error you get. You can't use an execute immediate in a for loop (which is clearly documented in the manual)
You need to open a cursor and then loop over the cursor. So instead of
FOR De_Dub_rec IN EXECUTE IMMEDIATE DE_DUB_SQL_STATMNT
you need to use something like this:
OPEN De_Dub_cursor FOR DE_DUB_SQL_STATMNT;
LOOP
FETCH De_Dub_cursor INTO de_dub_cursor_record;
EXIT WHEN cv%NOTFOUND;
... do your stuff here
END LOOP;
Of course you will need to declare the cursor De_Dub_cursor and the record variable de_dub_cursor_record. Note that the record variables needs to be defined with all columns that your result returns (which essentially requires a new TYPE to be defined if I'm not mistaken)
The second error you have won't show up until you run the code. You have an INTO variable clause inside your SQL string for the first EXECUTE IMMEDIATE. This will not work. The into clause can not be used like that. You need to remove the into DE_REC_COUNT part from the string literal and use the INTO clause as an option to the execute immediate statement. Something like this:
EXECUTE IMMEDIATE 'SELECT count(*) FROM ....'
INTO DE_REC_COUNT;
Unrelated to your problems, but the select ... from dual can be replaced with a simple assignment.
So instead of
select replace(WYYYYNNN,'W','') into YYYYNNN from dual;
use
YYYYNNN := replace(WYYYYNNN,'W','');
or instead of:
SELECT PS_GET_PROC_PD(SUPPLIER_CD,EXT_PHARMA_ID,YYYYNNN) into SEQ_NO_SHO FROM DUAL;
select 'LRXIE'||FLAG_VALUE||'10_'||SUPPLIER_CD||'_'||EXT_PHARMA_ID||'_'||WYYYYNNN||'_'||SEQ_NO_SHO||'_'||DE_REC_COUNT||'.TXT' into DE_DUB_OUTPUT_FILE from dual;
use
SEQ_NO_SHO := PS_GET_PROC_PD(SUPPLIER_CD,EXT_PHARMA_ID,YYYYNNN);
DE_DUB_OUTPUT_FILE := 'LRXIE'||FLAG_VALUE||'10_'||SUPPLIER_CD||'_'||EXT_PHARMA_ID||'_'||WYYYYNNN||'_'||SEQ_NO_SHO||'_'||DE_REC_COUNT||'.TXT';
First, should be execute immediate 'select count(*) from ...' into DE_REC_COUNT;
That's what I see at first scan, but the fail is at second execute immediate.
There you should create a collection and execute immediate the query and bulk collect into that collection.
Then, you should loop in that collection and do the work that you do(the dbms_output stuff).
I have written a stored procedure to pull the data from three different table using join but I'm not able get the result.I'm also trying to pass dynamic table but there is error occurred.
CREATE OR REPLACE Procedure DE_DUP_PRO1 (Dy_File_Name in varchar2)
--RETURN NUMBER
AS
v_hol varchar2(300);
CURSOR De_DUB_CUR IS
SELECT S.TRANS_GUID AS OLD_TRANS_GUID,
H.TRANS_GUID AS NEW_TRANS_GUID,
CASE
WHEN H.TRANS_GUID IS NULL
THEN 0
ELSE 1
END as TRN_STAT,
P.INTR_PHARMACY_ID, S.EXTRNL_PHARMACY_ID, S.PHARMACY_NM, S.PHARMACY_ADDR, S.SUPPLIERS_PSCR_DRUG_CD, S.PSCR_DRUG_IPU_CD,
'IPU', S.PSCR_DRUG_DESC, S.DSPNSD_DRUG_PACK_SIZE, S.RX_ID, S.RX_ITEM_SEQ, S.RX_REPEAT_STATUS, S.RX_TYP, S.EXMT_STATUS,
S.PSCR_QTY, S.NRSG_HM_IND, S.RX_DSPNSD_DT, S.RX_DSPNSD_TM, S.SUPPLIERS_DSPNSD_DRUG_CD, S.DSPNSD_DRUG_IPU_CD, 'IPU',
S.DSPNSD_DRUG_DESC, S.GENERIC_USE_MARKER, S.DSPNSD_UNIT_OF_QTY, S.DSPNSD_QTY, 'EUR', S.COST_OF_DSPNSD_QTY, S.VERBOSE_DOSAGE
FROM (SELECT stg.*, row_number() over ( partition BY key_clmns_hash ORDER BY 1 ) AS RN FROM T_MCL_30404_20150317_020 stg ) s
LEFT JOIN ps_pharmacy p ON s.extrnl_pharmacy_id = p.extrnl_pharmacy_id LEFT JOIN ps_rx_hist H ON h.key_clmns_hash = s.key_clmnS_hash
AND h.rx_dspnsd_dt = s.rx_dspnsd_dt AND s.supplier_pharmacy_cd = h.SUPPLIER_PHARMACY_CD AND s.detl_clmns_hash <> h.detl_clmns_hash WHERE S.RN = 1;
BEGIN
FOR De_Dub_rec IN De_DUB_CUR
LOOP
DBMS_OUTPUT.PUT_LINE ( De_Dub_rec.OLD_TRANS_GUID || '|' || De_Dub_rec.NEW_TRANS_GUID || '|' || De_Dub_rec.TRN_STAT || '|' || De_Dub_rec.P.INTR_PHARMACY_ID || '|' || De_Dub_rec.S.EXTRNL_PHARMACY_ID
|| '|' || De_Dub_rec.S.PHARMACY_NM || '|' || De_Dub_rec.S.PHARMACY_ADDR || '|' || De_Dub_rec.S.SUPPLIERS_PSCR_DRUG_CD|| '|' || De_Dub_rec.S.PSCR_DRUG_IPU_CD || '|' || 'IPU'
|| '|' || De_Dub_rec.S.PSCR_DRUG_DESC || '|' || De_Dub_rec.S.DSPNSD_DRUG_PACK_SIZE || '|' || De_Dub_rec.S.RX_ID || '|' || De_Dub_rec.S.RX_ITEM_SEQ || '|' || De_Dub_rec.S.RX_REPEAT_STATUS
|| '|' || De_Dub_rec.S.RX_TYP || '|' || De_Dub_rec.S.EXMT_STATUS || '|' || De_Dub_rec.S.PSCR_QTY || '|' || De_Dub_rec.S.NRSG_HM_IND || '|' || De_Dub_rec.S.RX_DSPNSD_DT
|| '|' || De_Dub_rec.S.RX_DSPNSD_TM || '|' || De_Dub_rec.S.SUPPLIERS_DSPNSD_DRUG_CD || '|' || De_Dub_rec.S.DSPNSD_DRUG_IPU_CD || '|' || 'IPU' || '|' || De_Dub_rec.S.DSPNSD_DRUG_DESC
|| '|' || De_Dub_rec.S.GENERIC_USE_MARKER || '|' || De_Dub_rec.S.DSPNSD_UNIT_OF_QTY || '|' || De_Dub_rec.S.DSPNSD_QTY || '|' || 'EUR' || '|' || De_Dub_rec.S.COST_OF_DSPNSD_QTY
|| '|'|| De_Dub_rec.S.VERBOSE_DOSAGE );
END LOOP;
-- RETURN 0;
END DE_DUP_PRO1;
/
whenever I'm execute stored procedure I get below error
LINE/COL ERROR
-------- -----------------------------------------------------------------
7/3 PL/SQL: SQL Statement ignored
19/96 PL/SQL: ORA-00942: table or view does not exist
31/9 PL/SQL: Statement ignored
31/32 PLS-00364: loop index variable 'DE_DUB_REC' use is invalid
LINE/COL ERROR(Now it is resolved)
-------- -----------------------------------------------------------------
28/7 PL/SQL: Statement ignored
28/7 PLS-00402: alias required in SELECT list of cursor to avoid
duplicate column names
Your problem is that your query is selecting a few literal string values without setting any aliases:
select ..., 'IPU', ... , 'IPU', ..., 'EUR', ...
In the above case, Oracle will auto-generate ugly aliases that look something like this:
select ..., 'IPU' AS "'IPU'", ..., 'IPU' AS "'IPU'", ..., 'EUR' AS "'EUR'", ...
So as you can see, you now have 3 very ugly column names that are very awkward to work with, and 2 of them are duplicate, resulting in the error you are getting.
Consider giving them proper distinct aliases to avoid the ambiguity. This is just an example, but you should give a more meaningful alias according to the meaning of the value:
select ..., 'IPU' AS some_col_1, ..., 'IPU' AS some_col_2, ..., 'EUR' AS some_col_3, ...
The funny thing is that you are not currently using those 3 values when reading the query in your cursor for loop. When reading/looping through your cursor, instead of trying to read the 3 values from the cursor, you simply hard-code the values again as you are printing them out.
So in fact, if you really don't care about reading the 3 values from the cursor, just remove them from the query altogether. Otherwise, replace your hard-coded values from your DBMS_OUTPUT.PUT_LINE(...) with the aliases that you set.
So once your query is fixed, instead of:
DBMS_OUTPUT.PUT_LINE(... || 'IPU' || ... || 'IPU' || ... || 'EUR' || ...);
You should probably use the cursor like this:
DBMS_OUTPUT.PUT_LINE(... || De_Dub_rec.some_col_1 || ... || De_Dub_rec.some_col_2 || ... || De_Dub_rec.some_col_3 || ...);
As per my understanding the below code of line is generating the error due to column ambiguity.
SELECT stg.*, row_number() over ( partition BY key_clmns_hash ORDER BY 1
Just explicitly mention the column name with aliases in the above line instead of using stg.* and that will solve your problem
Here is the code.
p_id number,
p_mc varchar2
Both of the above parameters will be passed in during a procedure call.
EXECUTE IMMEDIATE 'INSERT INTO COUNT_MASTER_TEMP ' || 'SELECT COUNT (ar.'|| p_mc || ')' ||
'
FROM app_recipient ar
WHERE EXISTS (SELECT r.' || p_mc ||
' FROM app_recipient r
WHERE r.ID =' || p_id || ' AND ar.'|| p_mc || '= r.'|| p_mc ||')';
My stored procedure is as follows:
input parameters are p_id (which is a numeric value), p_mc is a actually a column name. sample data is p_id = 6372325 and p_mc can be MC1, MC2 till MC14.
CREATE OR REPLACE PROCEDURE HCP_360.sp_get_all_records
(p_id NUMBER,
p_mc varchar2,
p_detail OUT SYS_REFCURSOR)
IS
v_count NUMBER;
v_master_id NUMBER;
v_sql VARCHAR2(2000);
--v_sql2 VARCHAR2(2000);
v_mc VARCHAR2(255):=p_mc;
cur_detail SYS_REFCURSOR;
BEGIN
BEGIN
EXECUTE IMMEDIATE 'DELETE FROM COUNT_MASTER_TEMP';
execute immediate 'INSERT INTO COUNT_MASTER_TEMP ' ||
'SELECT COUNT (ar.'|| v_mc|| ')' || '
FROM app_recipient ar
WHERE EXISTS (SELECT r.' || v_mc || ' FROM app_recipient r
WHERE r.ID =' || p_id || ' AND ar.'|| v_mc || '= r.'|| v_mc||')';
END;
BEGIN
select c_count
into v_count
from COUNT_MASTER_TEMP;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
v_count := 0;
END;
BEGIN
IF v_count > 0
THEN
v_sql := 'SELECT master_id
FROM app_recipient
WHERE ' || v_mc || ' IN (SELECT r.'||v_mc ||
' FROM app_recipient r
WHERE r.ID = ' || p_id || ')
AND ROWNUM <= 1
AND master_id IS NOT NULL
ORDER BY master_id DESC';
EXECUTE IMMEDIATE 'DELETE FROM COUNT_MASTER_TEMP';
EXECUTE IMMEDIATE 'INSERT INTO COUNT_MASTER_TEMP ' || v_sql;
END IF;
select c_count
into v_master_id
from COUNT_MASTER_TEMP;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
v_master_id := 0;
END;
BEGIN
v_sql :=
'
SELECT r.ID,
r.master_id,
v.RECIPIENT_STATUS,
v.PARENT_OR_CHILD,
nvl(v.CHILD_COUNT, 0) CHILD_COUNT,
r.IS_PICKABLE,
r.IS_GOLDEN,
r.request_wf_state,
r.record_type,
r.first_name,
r.last_name,
r.'||v_mc ||
',r.middle,
r.title,
r.name_of_organization,
r.name_of_business,
r.address,
r.city,
r.state,
r.country,
v.HCP_TYPE,
v.HCP_SUBTYPE,
v.is_edit_locked,
v.record_type as rec_type,
v.DATA_SOURCE_NAME,
v.DEA_DATA,
v.NPI_DATA,
v.STATE_DATA,
RPPS,
v.finess,
v.siren_number
FROM app_recipient r
left join V_MASTER_RECIP_W_TRXN_OP v
on r.id = v.id
or r.master_id =' || v_master_id||
'WHERE' ||'r.'||v_mc || '= ANY
(SELECT ar.'||v_mc || 'FROM app_recipient ar WHERE r.ID =' || p_id || ')
UNION ALL
SELECT r.ID,
r.master_id,
v.RECIPIENT_STATUS,
v.PARENT_OR_CHILD,
nvl(v.CHILD_COUNT, 0) CHILD_COUNT,
r.IS_PICKABLE,
r.IS_GOLDEN,
r.request_wf_state,
r.record_type,
r.first_name,
r.last_name,
r.'||v_mc ||
',r.middle,
r.title,
r.name_of_organization,
r.name_of_business,
r.address,
r.city,
r.state,
r.country,
v.HCP_TYPE,
v.HCP_SUBTYPE,
v.is_edit_locked,
v.record_type as rec_type,
v.DATA_SOURCE_NAME,
v.DEA_DATA,
v.NPI_DATA,
v.STATE_DATA,
RPPS,
v.finess,
v.siren_number
FROM app_recipient r
left join V_MASTER_RECIP_W_TRXN_OP2 v
on r.id = v.id
or r.master_id =' || v_master_id ||'
WHERE r.'||v_mc ||'= ANY (SELECT ar.'||v_mc ||'FROM app_recipient ar WHERE r.ID =' ||v_master_id || ')';
open cur_detail for v_sql;
p_detail := cur_detail;
end;
END;
/
if you use pid as a VARCHAR with non-numeric data.. and you have embed it in single quotes, during query formation, or define it as a bind variable.
Always use bind variables where-ever possible.
EXECUTE IMMEDIATE
'INSERT INTO COUNT_MASTER_TEMP ' ||
'SELECT COUNT (ar.'|| p_mc || ')' ||
' FROM app_recipient ar ' ||
' WHERE EXISTS (SELECT r.' || p_mc ||
' FROM app_recipient r ' ||
' WHERE r.ID = :pid AND ar.'|| p_mc || '= r.'|| p_mc||')'
using pid;
You could test the string formation using DBMS_OUTPUT.
For example,
SQL> set serveroutput on
SQL> DECLARE
2 p_mc VARCHAR2(20);
3 p_id NUMBER;
4 BEGIN
5 p_mc := 'mc';
6 p_id := 1;
7 dbms_output.put_line( 'INSERT INTO COUNT_MASTER_TEMP ' ||
8 'SELECT COUNT (ar.'|| p_mc || ')' || '
9 FROM app_recipient ar
10 WHERE EXISTS (SELECT r.' || p_mc || ' FROM app_recipient r
11 WHERE r.ID =' || p_id || ' AND ar.'|| p_mc || '= r.'|| p_mc||')');
12 END;
13 /
INSERT INTO COUNT_MASTER_TEMP SELECT COUNT (ar.mc)
FROM app_recipient ar
WHERE
EXISTS (SELECT r.mc FROM app_recipient r
WHERE r.ID =1 AND ar.mc= r.mc)
PL/SQL procedure successfully completed.
SQL>
Always remember to first test the dynamic string using DBMS_OUTPUT. Once you are confirm that the string is correctly formed, remove/comment the dbms_output and use EXECUTE IMMEDIATE.
Update Thanks to Alex Poole. The actual issue is here:
'WHERE' ||'r.'||v_mc || '= ANY
After WHERE, there is no space, thus the query fails. You need to add a space after WHERE.
'WHERE ' ||'r.'||v_mc || '= ANY
The only way I can immediately see to get that error from insert is if you're passing the column name enclosed in single-quotes; you haven't shown the call and it's unlikely you'd do this from a SQL client (more likely you added quotes incorrectly in a JDBC/PHP/etc. parameter), but calling like this:
exec sp_get_all_records(6372325, '''MC1''', :detail);
would try to execute generated SQL that looks like this:
INSERT INTO COUNT_MASTER_TEMP SELECT COUNT (ar.'MC1')
FROM app_recipient ar
WHERE EXISTS (SELECT r.'MC1' FROM app_recipient r
WHERE r.ID =6372325 AND ar.'MC1'= r.'MC1')
with the column name starting with the illegal single-quote character, and that would indeed throw:
ORA-01747: invalid user.table.column, table.column, or column specification
ORA-06512: at "SCHEMA.SP_GET_ALL_RECORDS", line 17
ORA-06512: at line 1
and line 17 is the execute immediate 'INSERT....
You are also missing some whitespace in your final v_sql construct, which will case the open cur_detail to get an "ORA-00933: SQL command not properly ended" with what you've shown. You need to change
'WHERE' ||'r.'||v_mc || '= ANY
(SELECT ar.'||v_mc || 'FROM app_recipient ar WHERE r.ID =' || p_id || ')
to
' WHERE ' ||'r.'||v_mc || '= ANY
(SELECT ar.'||v_mc || ' FROM app_recipient ar WHERE r.ID =' || p_id || ')
with spaces ether side of the first WHERE, and before the FROM; and also in the second half of the union change
WHERE r.'||v_mc ||'= ANY (SELECT ar.'||v_mc ||'FROM app_recipient ar WHERE r.ID =' ||v_master_id || ')';
to
WHERE r.'||v_mc ||'= ANY (SELECT ar.'||v_mc ||' FROM app_recipient ar WHERE r.ID =' ||v_master_id || ')';
again adding a space before FROM.
Those won't get the ORA-01747 error you reported, but neither will the insert you showed, which seems to be valid with the arguments you are passing - unless you are incorrectly quoting the column name argument as shown above.
I was testing my procedure using PL/SQL developer. I still do not know why ORA-01747 was occurring. But I modified my procedure and wrote a PL/SQL code for testing the output.
Procedure is as follows:
CREATE OR REPLACE PROCEDURE HCP_360.sp_get_all_records
(p_id NUMBER,
p_mc in varchar2,
p_detail OUT SYS_REFCURSOR,
p_count OUT NUMBER,
p_error OUT NVARCHAR2)
IS
v_count NUMBER;
v_master_id NUMBER;
v_sql LONG;
--v_sql2 VARCHAR2(2000);
v_mc VARCHAR2(255):=p_mc;
cur_detail SYS_REFCURSOR;
BEGIN
BEGIN
-- v_sql := '(SELECT COUNT ( ' ||v_mc || ')' ||
-- '
-- FROM app_recipient
-- WHERE ' ||v_mc || ' IN (SELECT ' || v_mc ||
-- ' FROM app_recipient r
-- WHERE r.ID =' || p_id || ' AND '|| v_mc || '=' || v_mc ||'))';
v_sql :='(SELECT ar.'||v_mc || ' as v_count' ||
'
FROM app_recipient ar
WHERE EXISTS (SELECT r.'||v_mc ||
' FROM app_recipient r
WHERE r.ID =' || p_id || ' AND ar.'||v_mc || '= r.'||v_mc ||'))';
--EXECUTE IMMEDIATE 'DELETE FROM COUNT_MASTER_TEMP';
EXECUTE IMMEDIATE ' select nvl(count(*),0) as count from (' || v_SQL || ') '
INTO v_count;
END;
BEGIN
IF v_count > 0
THEN
v_sql := 'SELECT master_id
FROM app_recipient
WHERE ' || v_mc || ' IN (SELECT r.'||v_mc ||
' FROM app_recipient r
WHERE r.ID = ' || p_id || ')
AND ROWNUM <= 1
AND master_id IS NOT NULL
ORDER BY master_id DESC';
EXECUTE IMMEDIATE ' select nvl(master_id, 0) from (' || v_SQL || ') '
INTO v_master_id;
END IF;
END;
BEGIN
EXECUTE IMMEDIATE ' delete from GTT_RECIPEINTS_FOR_MC';
execute immediate 'insert into GTT_RECIPEINTS_FOR_MC
( MATCH_CODE_VALUE ,master_id ,id)
(SELECT r.'||v_mc ||', r.master_id, r.id
FROM app_recipient r
WHERE r.'||v_mc || '= ANY (SELECT r.'||v_mc || '
FROM app_recipient r
WHERE r.ID =' || p_id||')
UNION ALL
SELECT r.'||v_mc ||', r.master_id, r.id
FROM app_recipient r
WHERE r.ID =' ||v_master_id ||')';
end;
BEGIN
v_sql :=
'
select ( r.id) M_ID, r.RECIPIENT_STATUS, PARENT_OR_CHILD, nvl(CHILD_COUNT,0), r.IS_PICKABLE, r.IS_GOLDEN, r.ID, nvl(r.MASTER_ID,r.id) as MASTER_ID , r.request_wf_state,
r.TITLE, r.FIRST_NAME, r.MIDDLE, r.LAST_NAME,r.FULL_NAME_LNF, r.FULL_NAME_FNF, r.NAME_OF_ORGANIZATION,r.ADDRESS,
r.CITY, r.STATE, r.COUNTRY, r.HCP_TYPE, r.HCP_SUBTYPE, r.is_edit_locked, r.record_type as rec_type,
DATA_SOURCE_NAME,DEA_DATA,NPI_DATA,STATE_DATA,RPPS ,finess,siren_number from v_master_recip_w_trxn_op r join GTT_RECIPEINTS_FOR_MC p on r.id=p.id or r.id= p.master_id
order by id';
open cur_detail for v_sql;
p_detail := cur_detail;
p_count :=SQL%ROWCOUNT;
EXCEPTION
WHEN OTHERS
THEN
p_count := 0;
ROLLBACK;
end;
END;
/
And the PL/SQL code for testing is as follows:
SET SERVEROUTPUT ON SIZE 1000000
DECLARE
l_cursor SYS_REFCURSOR;
p_count number;
p_error NVARCHAR2 (255);
M_ID app_recipient.id%type ;
l_ID app_recipient.id%type ;
l_master_id app_recipient.master_id%type ;
l_RECIPIENT_STATUS V_MASTER_RECIP_W_TRXN_OP2.recipient_status%type;
l_PARENT_OR_CHILD V_MASTER_RECIP_W_TRXN_OP2.parent_or_child%type;
l_CHILD_COUNT V_MASTER_RECIP_W_TRXN_OP2.child_count%type;
l_IS_PICKABLE app_recipient.is_pickable%type;
l_IS_GOLDEN app_recipient.is_golden%type;
l_request_wf_state app_recipient.request_wf_state%type;
l_record_type app_recipient.record_type%type;
l_first_name app_recipient.first_name%type;
l_last_name app_recipient.last_name%type;
l_p_mc app_recipient.MC14%type;
l_middle app_recipient.middle%type;
l_title app_recipient.title%type;
l_name_of_organization app_recipient.name_of_organization%type;
l_name_of_business app_recipient.name_of_business%type;
l_address app_recipient.address%type;
l_city app_recipient.city%type;
l_state app_recipient.state%type;
l_country app_recipient.country%type;
l_HCP_TYPE v_master_recip_w_trxn_op.HCP_TYPE%type;
l_HCP_SUBTYPE V_MASTER_RECIP_W_TRXN_OP.HCP_SUBTYPE%type;
l_is_edit_locked V_MASTER_RECIP_W_TRXN_OP.is_edit_locked%type;
l_rec_type V_MASTER_RECIP_W_TRXN_OP.record_type%type;
l_DATA_SOURCE_NAME V_MASTER_RECIP_W_TRXN_OP.data_source_name%type;
l_DEA_DATA V_MASTER_RECIP_W_TRXN_OP.dea_data%type;
l_NPI_DATA V_MASTER_RECIP_W_TRXN_OP.npi_data%type;
l_STATE_DATA V_MASTER_RECIP_W_TRXN_OP.state_data%type;
l_RPPS V_MASTER_RECIP_W_TRXN_OP.rpps%type;
l_finess V_MASTER_RECIP_W_TRXN_OP.finess%type;
l_siren_number V_MASTER_RECIP_W_TRXN_OP.siren_number%type;
l_FULL_NAME_LNF V_MASTER_RECIP_W_TRXN_OP.siren_number%type;
l_FULL_NAME_FNF V_MASTER_RECIP_W_TRXN_OP.siren_number%type;
BEGIN
hcp_360.hcp360_application.get_recipients_for_mc(p_id => &&var,
p_mc => &&p_mc,
p_detail => l_cursor,
p_count => p_count,
p_error => p_error);
LOOP
FETCH l_cursor
INTO M_ID ,
l_RECIPIENT_STATUS ,
l_PARENT_OR_CHILD ,
l_CHILD_COUNT ,
l_IS_PICKABLE,
l_IS_GOLDEN,
l_ID,
L_MASTER_ID,
l_request_wf_state,
l_title,
l_first_name,
l_middle,
l_last_name,
l_FULL_NAME_LNF,
l_FULL_NAME_FNF,
l_name_of_organization,
l_address,
l_city,
l_state,
l_country,
l_HCP_TYPE,
l_HCP_SUBTYPE,
l_is_edit_locked,
l_rec_type,
l_DATA_SOURCE_NAME,
l_DEA_DATA,
l_NPI_DATA,
l_STATE_DATA,
l_RPPS,
l_finess,
l_siren_number;
EXIT WHEN l_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(M_ID || ' | ' ||
l_RECIPIENT_STATUS || ' | ' ||
l_PARENT_OR_CHILD || ' | ' ||
l_CHILD_COUNT || ' | ' ||
l_IS_PICKABLE || ' | ' ||
l_IS_GOLDEN || ' | ' ||
l_ID || ' | ' ||
L_MASTER_ID || ' | ' ||
l_request_wf_state || ' | ' ||
l_title || ' | ' ||
l_first_name || ' | ' ||
l_middle || ' | ' ||
l_last_name || ' | ' ||
l_FULL_NAME_LNF || ' | ' ||
l_FULL_NAME_FNF || ' | ' ||
l_name_of_organization || ' | ' ||
l_address || ' | ' ||
l_city || ' | ' ||
l_state || ' | ' ||
l_country || ' | ' ||
l_HCP_TYPE || ' | ' ||
l_HCP_SUBTYPE || ' | ' ||
l_is_edit_locked || ' | ' ||
l_rec_type || ' | ' ||
l_DATA_SOURCE_NAME || ' | ' ||
l_DEA_DATA || ' | ' ||
l_NPI_DATA || ' | ' ||
l_STATE_DATA || ' | ' ||
l_RPPS || ' | ' ||
l_finess || ' | ' ||
l_siren_number
);
END LOOP;
CLOSE l_cursor;
END;