open for.. [message #10192] |
Wed, 07 January 2004 23:50 |
resy
Messages: 86 Registered: December 2003
|
Member |
|
|
HI,
1 CREATE OR REPLACE PROCEDURE CHK (
2 TABLE_NAME IN VARCHAR2, AS_DATE DATE, INST_CODE VARCHAR2)
3 is
4 type col_type is REF CURSOR;
5 col_rt col_type;
6 IT_DESCR VARCHAR2(40);
7 AMT NUMBER(15,2);
8 begin
9 open col_rt for
10 ' SELECT ITEM_DESCRIPTION,' ||TABLE_NAME|| '.AMOUNT
11 FROM TBAS_MBR_TRN_HDR, '||TABLE_NAME||
12 WHERE A.MT_CR_TRN_ID = ' ||TABLE_NAME|| '.MT_CR_TRN_ID;
13 LOOP
14 fetch col_rt into IT_DESCR,AMT;
15 exit when col_rt%NOTFOUND;
16 DBMS_OUTPUT.PUT_LINE(IT_DESCR || ' ' || AMT);
17 END LOOP;
18* END;
SQL> /
Warning: Procedure created with compilation errors.
SQL> SHO ERR
Errors for PROCEDURE CHK:
LINE/COL ERROR
-------- -----------------------------------------------------------------
12/14 PLS-00103: Encountered the symbol "WHERE" when expecting one of
the following:
( - + case mod new null <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current max min prior sql stddev sum variance execute
forall merge time timestamp interval date
<a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
13/13 PLS-00103: Encountered the symbol "LOOP"
im stuck in this err.
can anybody help??
thanx.
|
|
|
Re: open for.. [message #10193 is a reply to message #10192] |
Thu, 08 January 2004 00:37 |
resy
Messages: 86 Registered: December 2003
|
Member |
|
|
SQL> CREATE OR REPLACE PROCEDURE CHK (
2 TABLE_NAME IN VARCHAR2, AS_DATE DATE, INST_CODE VARCHAR2)
3 is
4 type col_type is REF CURSOR;
5 col_rt col_type;
6 IT_DESCR TBAS_MBR_TRN_HDR.ITEM_DESCRIPTION%TYPE;
7 AMT NUMBER(15,2);
8 begin
9 open col_rt for
10 ' SELECT ITEM_DESCRIPTION,' ||TABLE_NAME|| '.AMOUNT
11 FROM TBAS_MBR_TRN_HDR, '||TABLE_NAME||
12 ' WHERE TBAS_MBR_TRN_HDR.MT_CR_TRN_ID = '||TABLE_NAME||'.MT_CR_TRN_ID
13 AND TBAS_MBR_TRN_HDR.AS_AT_DATE ='||'AS_DATE' ||
14 'AND TBAS_MBR_TRN_HDR.INST_CODE = '||'INST_CODE';
15 LOOP
16 fetch col_rt into IT_DESCR,AMT;
17 exit when col_rt%NOTFOUND;
18 END LOOP;
19 END;
20 /
Procedure created.
SQL> EXEC CHK('TBAS_MBR300','16-NOV-03','00002');
BEGIN CHK('TBAS_MBR300','16-NOV-03','00002'); END;
*
ERROR at line 1:
ORA-00933: SQL command not properly ended
ORA-06512: at "BSDMASTER.CHK", line 9
ORA-06512: at line 1
CAN ANYBODY SOLVE THIS?
|
|
|
Re: open for.. [message #10194 is a reply to message #10193] |
Thu, 08 January 2004 01:07 |
Rij
Messages: 12 Registered: September 2003
|
Junior Member |
|
|
try putting the query in a string and assign it to a variable say v_query. now open the ref cursor for that variable.
before opening the cursor just try to display the value of that string variable(v_query). just check if there is any syntax error or column name error.
|
|
|
Re: open for.. [message #10195 is a reply to message #10194] |
Thu, 08 January 2004 02:38 |
resy
Messages: 86 Registered: December 2003
|
Member |
|
|
1 CREATE OR REPLACE PROCEDURE CHK (
2 TABLE_NAME IN VARCHAR2, AS_DATE DATE, INST_CODE VARCHAR2)
3 is
4 type col_type is REF CURSOR;
5 col_rt col_type;
6 IT_DESCR TBAS_MBR_TRN_HDR.ITEM_DESCRIPTION%TYPE;
7 AMT NUMBER(15,2);
8 sQUERY VARCHAR2(2000) :=
9 'SELECT ITEM_DESCRIPTION,' ||TABLE_NAME|| '.AMOUNT
10 FROM TBAS_MBR_TRN_HDR, '||TABLE_NAME||
11 ' WHERE TBAS_MBR_TRN_HDR.MT_CR_TRN_ID = '||TABLE_NAME||'.MT_CR_TRN_ID
12 AND TBAS_MBR_TRN_HDR.AS_AT_DATE = :b1
13 AND TBAS_MBR_TRN_HDR.INST_CODE = :b2';
14 begin
15 open col_rt for sQUERY;
16 DBMS_OUTPUT.PUT_LINE('------------------');
17 DBMS_OUTPUT.PUT_LINE(SQUERY);
18 LOOP
19 fetch col_rt into IT_DESCR,AMT;
20 exit when col_rt%NOTFOUND;
21 END LOOP;
22* END;
SQL> /
Procedure created.
SQL> EXEC CHK('TBAS_MBR300','16-NOV-03','00002');
BEGIN CHK('TBAS_MBR300','16-NOV-03','00002'); END;
*
ERROR at line 1:
ORA-01008: not all variables bound
ORA-06512: at "BSDMASTER.CHK", line 15
ORA-06512: at line 1
:-((
|
|
|
Re: open for.. [message #10204 is a reply to message #10195] |
Thu, 08 January 2004 10:24 |
Todd Barry
Messages: 4819 Registered: August 2001
|
Senior Member |
|
|
create or replace procedure chk(
<b> table_name in all_tables.table_name%type,
as_date in tbas_mbr_trn_hdr.as_at_date%type,
inst_code in tbas_mbr_trn_hdr.inst_code%type)</b>
is
type col_type is ref cursor;
col_rt col_type;
it_descr tbas_mbr_trn_hdr.item_description%type;
amt number(15,2);
squery varchar2(2000);
begin
<b> squery := 'select t1.item_description, t2.amount' ||
' from tbas_mbr_trn_hdr t1, ' || table_name || ' t2' ||
' where t1.mt_cr_trn_id = t2.mt_cr_trn_id' ||
' and t1.as_at_date = :b1' ||
' and t1.inst_code = :b2';</b>
open col_rt
for squery
<b>using as_date, inst_code</b>;
dbms_output.put_line('------------------');
dbms_output.put_line(squery);
loop
fetch col_rt into it_descr, amt;
exit when col_rt%notfound;
dbms_output.put_line( 'Description: ' || it_descr || ', Amt: ' || amt);
end loop;
<b>close col_rt;</b>
end;
/
|
|
|
Re: open for.. [message #10210 is a reply to message #10204] |
Thu, 08 January 2004 18:10 |
resy
Messages: 86 Registered: December 2003
|
Member |
|
|
thanx. i got it whn wrote in this way.
SQL> ed
Wrote file afiedt.buf
1 CREATE OR REPLACE PROCEDURE CHK (
2 TABLE_NAME IN VARCHAR2, AS_DATE DATE, INST_CODE VARCHAR2)
3 is
4 type col_type is REF CURSOR;
5 col_rt col_type;
6 IT_DESCR TBAS_MBR_TRN_HDR.ITEM_DESCRIPTION%TYPE;
7 AMT NUMBER(15,2);
8 sQUERY VARCHAR2(2000) :=
9 'SELECT ITEM_DESCRIPTION,' ||TABLE_NAME|| '.AMOUNT
10 FROM TBAS_MBR_TRN_HDR, '||TABLE_NAME||
11 ' WHERE TBAS_MBR_TRN_HDR.MT_CR_TRN_ID = '||TABLE_NAME||'.MT_CR_TRN_ID
12 AND TBAS_MBR_TRN_HDR.AS_AT_DATE = :b1
13 AND TBAS_MBR_TRN_HDR.INST_CODE = :b2';
14 begin
15 open col_rt for sQUERY using as_date, inst_code;
16 DBMS_OUTPUT.PUT_LINE('------------------');
17 DBMS_OUTPUT.PUT_LINE(SQUERY);
18 LOOP
19 fetch col_rt into IT_DESCR,AMT;
20 exit when col_rt%NOTFOUND;
21 END LOOP;
22* END;
SQL> EXEC CHK('TBAS_MBR300','16-NOV-03','00002');
------------------
SELECT ITEM_DESCRIPTION,TBAS_MBR300.AMOUNT
FROM TBAS_MBR_TRN_HDR, TBAS_MBR300
WHERE TBAS_MBR_TRN_HDR.MT_CR_TRN_ID = TBAS_MBR300.MT_CR_TRN_ID
AND
TBAS_MBR_TRN_HDR.AS_AT_DATE = :b1
AND TBAS_MBR_TRN_HDR.INST_CODE = :b2
PL/SQL procedure successfully completed.
|
|
|
Why use only 1 out of 4 suggestions? [message #10235 is a reply to message #10210] |
Fri, 09 January 2004 08:09 |
Todd Barry
Messages: 4819 Registered: August 2001
|
Senior Member |
|
|
Well, yes, you needed the USING clause as I mentioned. You did not incorporate the suggestions to type the parameters (%type) and use aliases in the dynamic SQL to simplify the statement. You are also never closing the cursor. Using 1 suggestion out of 4 is not a great batting average...
|
|
|