What is the correct syntax to break a PL/SQL procedure call in multiple lines?
Asked Answered
N

3

5

I am calling a PL/SQL procedure like this:

execute util.verify(src_schema => '&username',
                    stab       => '&tab_name');

and I get these errors:

SQL> execute util.verify(src_schema => '&username',
BEGIN util.verify(src_schema => 'u1',; END;

                                     *
ERROR at line 1:
ORA-06550: line 1, column 57: 
PLS-00103: Encountered the symbol ";" when expecting one of the following:
( - + case mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable>
continue avg count current exists 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
<an alternatively-quoted string literal with character set specification>
<an alternatively


SQL>                   stab       => '&tab_name',
SP2-0734: unknown command beginning "stab      ..." - rest of line ignored.

Looks like I cannot just break the call in between at a ,. How can I write this call in multiple lines?

Narva answered 25/12, 2010 at 7:51 Comment(0)
L
13

In SQLPlus, you put a dash at the end of lines that continues on the next line.

execute util.verify(src_schema => '&username', -
                    stab       => '&tab_name');

Update: Added link to documentation

EXECUTE, SQL*Plus® User's Guide and Reference

Larcher answered 25/12, 2010 at 10:11 Comment(2)
This is only for SQLPLUS commands, correct? SQL and PL/SQL commands typed into SQLPLUS automatically allow continuation to a new line.Tyeshatyg
@Shannon, I'm not sure how execute is classified. But sql/dml/ddl works with new lines (but not blank lines).Larcher
C
8

There is an alternative way, some thing like the below:

begin
    util.verify(src_schema => '&username',
                    stab       => '&tab_name');
end;
/
Ciscaucasia answered 25/12, 2010 at 7:56 Comment(1)
More elegant solution!!Tiphanie
F
6

execute xxxx; (or exec xxxx;) is a short-cut for writing begin xxxx; end;

It only works for one liners. So if you have multiple lines, you need to explicitly use begin and end.

Femininity answered 25/12, 2010 at 9:35 Comment(1)
That was mind blowing. Especially if you try to find description of behavior in extensive Oracle documentation...Bcd

© 2022 - 2024 — McMap. All rights reserved.