MY FIRST PROGRAM

MY FIRST PROGRAM

 PLSQL Tutorials - MY FIRST PROGRAM IN PL/SQL

DBMS_OUTPUT

This supplied package is an essential tool to debug the program written. So, use this and write your first program. This package prints the output of the program on to the screen.

You will read about many important supplied packages as you go forward.

Type the following at the SQL*Plus prompt.

setserveroutput on size 100000

This set command enables you to see the output on the screen up to 100000 characters.

-- this begin command starts the PLSQL block
Begin
-- this is the command to be executed by PLSQL after due validation
Dbms_output.put_line(‘Hello Guys .. I am now here, at the door steps of PLSQL. This is my first Program’);
-- this is to close the PLSQL Program
End;
-- this is to run the program
/

REM and # are to be used with Oracle SQL Plus client software to add comments. But can not be used with Oracle PLSQL engine. It can not understand this and spits errors and garbage.

Look at that out put.

SQL> -- this begin command starts the PLSQL block
SQL> Begin
2 -- this is the command to be executed by PLSQL after due validation
3 Dbms_output.put_line('Hello Guys .. I am now here, at the door steps of PLSQL. This is my first Program');
4 -- this is to close the PLSQL Program
5 End;
6 -- this is to run the program
7 /
Hello Guys .. I am now here, at the door steps of PLSQL. This is my first
Program

PL/SQL procedure successfully completed.

SQL>

Here is another program that lets you use loop.

Begin
-- start the loop
For I in 1..5 loop
-- print the output
DBMS_OUTPUT.PUT_LINE(I);
-- close the loop
END LOOP;
END;
/
SQL> Begin
2 -- start the loop
3 For I in 1..5 loop
4 -- print the output
5 DBMS_OUTPUT.PUT_LINE(I);
6 -- close the loop
7 END LOOP;
8 END;
9 /


PL/SQL procedure successfully completed.

SQL>

That is a great feeling. You have written programs. They are useful to you in many ways in your future programming skills.