开发者

PL/SQL Exception Translation

开发者 https://www.devze.com 2023-04-07 12:15 出处:网络
I am inserting a new object in my database table, but I keep on retrieving a exception that states....

I am inserting a new object in my database table, but I keep on retrieving a exception that states....

    ERROR:insertproperty:ORA-06553: PLS-103: Encountered the symbol "EXCEPTION" when expecting one of the following:

   begin case declare exit for function goto if loop mod null
   package pragma procedure raise return select separate type
   update while with <an identifier>
   <a double-quoted delimited-identifier> <a bind variable> <<
   form table call close current define delete fetch lock insert
   open rollback savepoint set sql execute commit forall merge
ORA-06553: PLS-103: Encountered the symbol "EXCEPTION" when expec

but all I am doing is a simple insert into...

function insert(...)
begin
    begin 
     select table_seq.nextval
     into nextval 
     from dual

     begin
   开发者_JAVA技巧  insert into table(id, ....)
     values(nextval,....)
     end 
    end
end

the dots are all optional so not really needed.


The error indicates that there is a syntax problem near the EXCEPTION keyword. But your code outline doesn't indicate that any of your blocks have an exception section. That makes it rather difficult for us to provide much assistance.

In a comment, you seem to indicate that at least one of the blocks in your outline has an exception section. Can you post the actual code (or at least a more detailed outline that includes the syntax of whatever exception block is generating the error)?

Additionally, in a comment, it sounds like you do have a RETURN statement in your function that is returning some sort of status code. It is almost always a mistake to use return codes from functions-- it is much more robust to simply throw an exception (or even better, allow the exception that was generated to propagate up). It is generally a mistake to write a function in PL/SQL that does DML-- if you're doing DML, you almost always want that to be done in a procedure.


Your function doesn't return a value. I think you want to make it a PROCEDURE (and add some semicolons, an "AS" keyword etc.):

CREATE OR REPLACE
PROCEDURE insert_proc(...)
AS
BEGIN
   begin 
      select table_seq.nextval
        into nextval 
        from dual;

      begin
         insert into table(id, ....)
         values(nextval,....);
      end;
   end;
END insert_proc;

If you are using Oracle 11g, you can omit the call to the DUAL table:

CREATE OR REPLACE
PROCEDURE insert_proc(...)
AS
BEGIN
   insert into table(id, ....)
   values(nextvatable_seq.nextval,....);
END insert_proc;

N.B. You should add an exception section to handle any common exceptions that might occur, e.g. constraint violations etc.

Hope it helps

0

精彩评论

暂无评论...
验证码 换一张
取 消