Let's write a procedure that outputs the string "Hello World!". Open your skeleton.sql file in Notepad. Replace the NULL statement with the DBMS_OUTPUT.PUT_LINE procedure call. Your program should look like this:
Save your file as skeleton.sql. From SQL*Plus, open your skeleton.sql file.
Execute the contents of the SQL*Plus buffer. Type a front slash and press <enter> like this:
SQL*Plus informs you the procedure has been created successfully and presents the SQL command prompt:
Run your procedure from the SQL*Plus command prompt with the EXECUTE command like this:
SQL*Plus assures you the procedure executed successfully:
But wait a minute! We wanted to see the string "Hello World!" Where did that go? SQL*Plus is quirky. A SET command is needed before output is shown from the DBMS_OUTPUT.PUT_LINE procedure. So let's do that. At the SQL*Plus command prompt, type:
SQL*Plus remains secretive and provides no feedback. Execute your procedure again. From the SQL*Plus command prompt, type:
Now it works! SQL*Plus rewards you with:
Suppose there is a problem with our procedure. Then what? We debug it, and that's what we're going to do next.
blog comments powered by Disqus |