Home » SQL & PL/SQL » SQL & PL/SQL » Error in Stored procedure (11G with ODAC)
icon5.gif  Error in Stored procedure [message #612042] Fri, 11 April 2014 06:34 Go to next message
newbieDeveloper
Messages: 2
Registered: April 2014
Location: Kerala
Junior Member
Hi , I am new to Oracle and cant seem to find the issue in the procedure that i have written

Its a ASP .NET MVC 4.5 APP with ODAC linked to a Oracle 11 g

the errors reported are {"ORA-06550: line 18, column 31:\nPL/SQL: ORA-00907: missing right parenthesis\nORA-06550: line 10, column 9:\nPL/SQL: SQL Statement ignored\nORA-06550: line 33, column 7:\nPLS-00103: Encountered the symbol \"end-of-file\" when expecting one of the following:\n\n ( begin case declare end exit for goto if loop mod null\n pragma raise return select update while with <an identifier>\n <a double-quoted delimited\nORA-06512: at \"AXIOM_DP.PKG_UPLOAD_BATCHES\", line 15\nORA-06512: at line 1"}


and the procedure is this


create or replace
PACKAGE BODY PKG_UPLOAD_BATCHES AS
PROCEDURE USP_BATCHES_INSERT(
BATCH_SEQUENCE_ID IN NUMBER,
STATUS IN VARCHAR2,
PACKAGE_SEQUENCE_ID IN NUMBER,
IS_ACTIVATED IN VARCHAR2,
MODIFIED_BY NUMBER,
MODIFIED_DATE IN DATE,
resultset IN OUT SYS_REFCURSOR) AS

BEGIN
/* TODO implementation required */
--select ICCIDS from (SYS.dbms_debug_vc2coll ICCID_LIST)

EXECUTE IMMEDIATE
'BEGIN
FOR emp IN
(
SELECT dbd_iccid
FROM DEP_ICCID_TEMP
WHERE commission_pct is not NULL
)
LOOP
BEGIN
INSERT INTO DEP_BATCH_DETAILS(dbd_iccid,
dbd_isactivated,
dbd_modified_by,
dbd_modified_on,
dbd_status,
dbh_seq,
dpg_seq
)
SELECT (emp.dbd_iccid,
IS_ACTIVATED,
MODIFIED_BY,
MODIFIED_DATE,
STATUS,
BATCH_SEQUENCE_ID,
PACKAGE_SEQUENCE_ID
)
FROM dual
WHERE NOT EXISTS (SELECT NULL
FROM DEP_BATCH_DETAILS
WHERE DEP_ICCID = emp.dbd_iccid
)
END
END LOOP;
END; ';
COMMIT;
null;

END USP_BATCHES_INSERT;

END PKG_UPLOAD_BATCHES;





Its used to check whether each column in one table(ICCID_TEMP) exists in another table(DEP_BATCH_DETAILS) if not the column data and some other parameters are entered into the 2nd table.

The procedure compiled fine , I use sql devloper and dont know how to run it from there so i run the procedure from C# code


Thanks in Advance

Re: Error in Stored procedure [message #612046 is a reply to message #612042] Fri, 11 April 2014 07:29 Go to previous messageGo to next message
flyboy
Messages: 1903
Registered: November 2006
Senior Member
Hi,

the error is happening because of the parenthesis inside the SELECT statement in the dynamic code:
SQL> select (1, 2) from dual;
select (1, 2) from dual
         *
ERROR at line 1:
ORA-00907: missing right parenthesis

SQL> select 1, 2 from dual;

         1          2
---------- ----------
         1          2

Simply remove them, they have no use anyway.

Just a few comments to the posted code:
SELECT FROM DUAL is not necessary, you could use VALUES clause and include that WHERE condition to the SELECT in the cursor loop.
There is nothing dynamic in the code inside EXECUTE IMMEDIATE, so there is no need to use it and you should call it statically. Especially, if the only reason was the error above during compilation. Then, as you can see, it was useless, as it only shifted the failure to run time.
Re: Error in Stored procedure [message #612048 is a reply to message #612042] Fri, 11 April 2014 07:33 Go to previous messageGo to next message
cookiemonster
Messages: 13919
Registered: September 2008
Location: Rainy Manchester
Senior Member
Welcome to the forum.
Please read and follow How to use [code] tags and make your code easier to read?

The problem is there's a syntax error in your dynamic sql. Dynamic sql isn't checked at compile time.
But there's nothing actually dynamic about your dynamic sql so the sensible thing to do is rewrite it as static sql. Then oracle will throw the syntax error at compile time and sqlplus will even point to the bit of code calling it.
Re: Error in Stored procedure [message #612060 is a reply to message #612048] Fri, 11 April 2014 10:14 Go to previous messageGo to next message
newbieDeveloper
Messages: 2
Registered: April 2014
Location: Kerala
Junior Member
Did a few changes

this works fine now

CREATE OR replace PACKAGE BODY pkg_upload_batches 
AS 
  PROCEDURE Usp_batches_insert (batch_sequence_id   IN NUMBER, 
                                status              IN VARCHAR2, 
                                package_sequence_id IN NUMBER, 
                                is_activated        IN VARCHAR2, 
                                modified_by         NUMBER, 
                                modified_date       IN DATE, 
                                resultset           IN OUT SYS_REFCURSOR) 
  AS 
  BEGIN 
  /* TODO implementation required */ 
      --select ICCIDS from (SYS.dbms_debug_vc2coll ICCID_LIST) 
      merge INTO dep_batch_details n 
      USING dep_iccid_temp o 
      ON ( n.dbd_iccid = o.dbd_iccid ) 
      WHEN NOT matched THEN 
        INSERT (dbd_iccid, 
                dbd_isactivated, 
                dbd_modified_by, 
                dbd_modified_on, 
                dbd_status, 
                dbh_seq, 
                dpg_seq ) 
        VALUES ( o.dbd_iccid, 
                 is_activated, 
                 modified_by, 
                 modified_date, 
                 status, 
                 batch_sequence_id, 
                 package_sequence_id ); 

      COMMIT; 
  END; 
END pkg_upload_batches; 

*BlackSwan formatted & added {code} tags. Please do so yourself in the future.

[Updated on: Fri, 11 April 2014 11:37] by Moderator

Report message to a moderator

Re: Error in Stored procedure [message #612063 is a reply to message #612060] Fri, 11 April 2014 10:43 Go to previous message
Michel Cadot
Messages: 68637
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
cookiemonster wrote on Fri, 11 April 2014 14:33
Welcome to the forum.
Please read and follow How to use [code] tags and make your code easier to read?

Previous Topic: ORACLE QUERY
Next Topic: write a oracle query
Goto Forum:
  


Current Time: Tue Apr 16 16:24:11 CDT 2024