Professional Documents
Culture Documents
Dbms File
Dbms File
SQL> Declare
var number (05);
begin
var:=100;
dbms_output.put_line('var='||var);
end;
/
OUTPUT
var=100
SQL> Declare
a number(10);
b number(10);
c number(10);
begin
a:= &a;
b:= &b;
c:= a+b;
dbms_output.put_line('Sum='||c);
end;
/
OUTPUT
Enter value for a: 5
old 6: a:= &a;
new 6: a:= 5;
Enter value for b: 8
old 7: b:= &b;
new 7: b:= 8;
Sum=13
SQL> Declare
a number(10);
b number(10);
c number(10);
begin
a:= &a;
b:= &b;
c:= a/b;
dbms_output.put_line('div='||c);
exception when others then
dbms_output.put_line('check value of b');
end;
/
OUTPUT
Enter value for a: 6
old 6: a:= &a;
new 6: a:= 6;
Enter value for b: 0
old 7: b:= &b;
new 7: b:= 0;
check value of b
Table created.
SQL> begin
insert into dept1 values(1,'sales');
end;
/
SQL> begin
update dept1 set dept_name='finance' where dept_id=1;
end;
/
SQL> begin
delete from dept1;
end;
/
If else
SQL>declare
a number(6):=10;
b number(6);
begin
b:=a-2;
if(a<b) then
dbms_output.put_line(a||' is less than '||b);
else
dbms_output.put_line(a||' is greater than '||b);
end if;
end;
/
OUTPUT
10 is greater than 8
Trigger created.
Trigger created.
PROCEDURE
SQL>create or replace PROCEDURE greetings
as
begin
dbms_output.put_line('Good Morning Pooja Mam');
end;
/
Procedure created.
SQL> begin
greetings;
end;
/
Good Morning Pooja Mam
SQL> declare
a number;
begin
a:=4;
squareNum(a);
dbms_output.put_line('Square of (4): ' ||a);
end;
/
Square of (4): 16
PL/SQL procedure successfully completed.
FUNCTION
SQL> create FUNCTION FindMin( x IN number,y IN number)
return number
is
z number;
begin
if x<y then
z:=x;
else
z:=y;
end if;
return z;
end;
/
Function created.
SQL> declare
a number;
b number;
c number;
begin
a:=5;
b:=34;
c:= FindMin(a,b);
dbms_output.put_line('Maximum of (5,34): '||c);
end;
/
Maximum of (5,34): 5
SQL> declare
cursor c1 is select empno,ename,sal from emp;
Vno emp.emp%type;
Vname emp.ename%type;
Vsal emp.sal%type;
begin
open c1;
loop
fetch c1 into Vno,Vname,Vsal;
dbms_output.put_line(Vno || ','||Vname ||','|| Vsal);
end loop;
close c1;
end;
/