0% found this document useful (0 votes)
13 views5 pages

PL/SQL Programming Examples and Basics

The document provides examples of PL/SQL programs, demonstrating how to print strings, enter variable values via command line, initialize variables, and perform arithmetic operations. It includes code snippets for adding two numbers and comparing two user-entered numbers. Additionally, it mentions the use of 'SET VERIFY OFF' to suppress output of old and new values.

Uploaded by

efxzzgz639
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views5 pages

PL/SQL Programming Examples and Basics

The document provides examples of PL/SQL programs, demonstrating how to print strings, enter variable values via command line, initialize variables, and perform arithmetic operations. It includes code snippets for adding two numbers and comparing two user-entered numbers. Additionally, it mentions the use of 'SET VERIFY OFF' to suppress output of old and new values.

Uploaded by

efxzzgz639
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PL/SQL PROGRAMS

-- To print string we use single quotation


Begin
dbms_output.put_line('welcome to PL/SQL programming');
end;
/______________________________________________
-- To enter the value of variable using command line
DECLARE
a integer;
BEGIN
a:=&a;
dbms_output.put_line('Value of a is: ' || a);
end;
/
output:
Enter value for a: 10
old 4: a:=&a;
new 4: a:=10;
Value of a is: 10
PL/SQL procedure successfully completed.
__________________________________________________
Note: we can use set verify off to switch off the new and old
value display
SQL> SET VERIFY OFF;
SQL> set serveroutput on;
____________________________________________________
-- To initialize variables
DECLARE
a number :=10;
b number :=20;
c number;
BEGIN
c:=a+b;
dbms_output.put_line('Value of c is: ' || c);
end;
/
__________________________________________________
-- Addition of two numbers
DECLARE
a integer := 30;
b integer := 40;
c integer;
f real;
BEGIN
c := a + b;
dbms_output.put_line('Value of c: ' || c);
f := 100.0/3.0;
dbms_output.put_line('Value of f: ' || f);
END;
/_______________________________________________
DECLARE
name varchar2(20):='&name';
BEGIN
dbms_output.put_line('Entered name is: ' || name);
end;
__________________________________________________
DECLARE
N NUMBER;
M NUMBER;
BEGIN
DBMS_OUTPUT.PUT_LINE('ENTER A NUMBER');
N:=&NUMBER;

DBMS_OUTPUT.PUT_LINE('ENTER A NUMBER');
M:=&NUMBER;
IF N<M THEN
DBMS_OUTPUT.PUT_LINE(''|| N ||' IS GREATER THAN '||
M ||'');
ELSE
DBMS_OUTPUT.PUT_LINE(''|| M ||' IS GREATER THAN '||
N ||'');
END IF;
END;
/
___________________________________________________

You might also like