Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What actually PROMPT<?> syntax do in oracle procedure?

So, in this code what exactly PROMPT syntax do?

PROMPT create or replace procedure abc (p_name, p_id)
AUTHID CURRENT_USER
as
begin
 dbms_output.put_line('hi');
end;

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

PROMPT has a meaning if you run some code in SQL*Plus (not many people do that nowadays). It displays text what follows that keyword.

SQL> help prompt

 PROMPT
 ------

 Sends the specified message or a blank line to the user's screen.

 PRO[MPT] [text]


SQL> prompt hello there!
hello there!
SQL>

In your case, it produces unwanted result as it displays the create procedure (instead of creating it):

SQL> PROMPT create or replace procedure abc (p_name, p_id)
create or replace procedure abc (p_name, p_id)
SQL> AUTHID CURRENT_USER
SP2-0734: unknown command beginning "AUTHID CUR..." - rest of line ignored.
SQL> as
SP2-0042: unknown command "as" - rest of line ignored.
SQL> begin
  2   dbms_output.put_line('hi');
  3  end;
  4  /
hi

PL/SQL procedure successfully completed.

SQL>

You got the result, but just as pure accident as

begin
  dbms_output.put_line('hi');
end;

was a valid PL/SQL block.


Code you posted (without prompt) is invalid:

SQL> create or replace procedure abc (p_name, p_id)
  2  AUTHID CURRENT_USER
  3  as
  4  begin
  5   dbms_output.put_line('hi');
  6  end;
  7  /

Warning: Procedure created with compilation errors.

SQL> show err
Errors for PROCEDURE ABC:

LINE/COL ERROR
-------- -----------------------------------------------------------------
1/22     PLS-00103: Encountered the symbol "," when expecting one of the
         following:
         in out <an identifier> <a double-quoted delimited-identifier>
         ... long double ref char time timestamp interval date binary
         national character nchar

3/1      PLS-00103: Encountered the symbol "AS" when expecting one of the
         following:
         with authid cluster order deterministic parallel_enable
         pipelined result_cache

6/4      PLS-00103: Encountered the symbol "end-of-file" when expecting
         one of the following:
         end not pragma final instantiable order overriding static
         member constructor map

SQL>

What does it mean? Procedure’s parameters have to have datatype:

SQL> create or replace procedure abc (p_name in varchar2, p_id in number)
  2  AUTHID CURRENT_USER
  3  as
  4  begin
  5   dbms_output.put_line('hi');
  6  end;
  7  /

Procedure created.

SQL> exec abc(null, null);
hi

PL/SQL procedure successfully completed.

SQL>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading