PLSQL 3
PLSQL 3
PL/SQL
q1)
q2)
SQL> declare
2 P number(5);
3 N number(1);
4 R number(2);
5 SI number(4,2);
6 begin
7 P:=&P;
8 N:=&N;
9 R:=&R;
10 SI:=(P*N*R)/100;
11 dbms_output.put_line('Simple Interest is '||SI);
Page 1
plsql_2
12 end;
13 /
Enter value for p: 10
old 7: P:=&P;
new 7: P:=10;
Enter value for n: 2
old 8: N:=&N;
new 8: N:=2;
Enter value for r: 12
old 9: R:=&R;
new 9: R:=12;
Simple Interest is 2.4
SQL> /
Enter value for p: 5
old 7: P:=&P;
new 7: P:=5;
Enter value for n: 3
old 8: N:=&N;
new 8: N:=3;
Enter value for r: 15
old 9: R:=&R;
new 9: R:=15;
Simple Interest is 2.25
q3)
SQL> declare
2 radius number(2);
3 area number(4,2);
4 begin
5 radius:=&radius;
6 area:=3.157*radius*radius;
7 dbms_output.put_line('Area of the circle is '||area);
8 end;
9 /
Enter value for radius: 2
old 5: radius:=&radius;
Page 2
plsql_2
new 5: radius:=2;
Area of the circle is 12.63
SQL> /
Enter value for radius: 5
old 5: radius:=&radius;
new 5: radius:=5;
Area of the circle is 78.93
q4)
SQL> declare
2 str varchar2(25);
3 len number;
4 begin
5 str:=&str;
6 len:=length(str);
7 dbms_output.put_line('Length of '||str||' is '||len);
8 end;
9 /
Enter value for str: 'SHIVANK'
old 5: str:=&str;
new 5: str:='SHIVANK';
Length of SHIVANK is 7
q5)
Page 3
plsql_2
SQL> declare
2 v_date1 varchar2(20);
3 v_date2 date;
4 begin
5 v_date1:=&v_date1;
6 v_date2:=to_date(v_date1,'dd-mm-yyyy');
7 dbms_output.put_line(v_date2);
8 end;
9 /
Enter value for v_date1: '25 October 2016'
old 5: v_date1:=&v_date1;
new 5: v_date1:='25 October 2016';
25-OCT-16
SQL> /
Enter value for v_date1: '20 June 2019'
old 5: v_date1:=&v_date1;
new 5: v_date1:='20 June 2019';
20-JUN-19
q6)
SQL> declare
2 num number;
3 begin
4 num:=#
5 if mod(num,2)=0 then
6 dbms_output.put_line(num||''||'Is Even Number');
7 else
8 dbms_output.put_line(num||''||'Is Odd Number');
9 end if;
10 end;
11 /
Enter value for num: 23
old 4: num:=#
Page 4
plsql_2
new 4: num:=23;
23Is Odd Number
SQL> /
Enter value for num: 14
old 4: num:=#
new 4: num:=14;
14Is Even Number
q7)
Page 5