Вы находитесь на странице: 1из 8

Q:-Write a PL sql program to print Hello World?

Ans:- Declaration
Executable
Execption Handling

begin
dbms_output.put_line('Hello World'); ///// Command to print Anything in Pl
Sql

end;

OR this Can be done by Declaring the value:

declare
a varchar(20);
begin
a:='Hello World!';
dbms_output.put_line(a);
end;

Q: Program to Print the Sum of two No.?


Ans:-
declare
a int:=10;
b int:=20;
c int;
begin
c:=a+b;
dbms_output.put_line('Sum='||c);
end;

Q: Proogram to print the Sum of two no. taken by user?


Ans:-

declare
a int:=:a;
b int:=:b;
c int;
begin
c:=a+b;
dbms_output.put_line(c);
end;

Q:- Write A pl sql program to print the greatest of Two No.?


Ans:-

declare
a int:=:a;
b int:=:b;
c int;
begin
if (a>b)
then
dbms_output.put_line(a);
else
dbms_output.put_line(b);
end if;
end;

Q: Write a PL/SQL program to Find the Greatest of Three No.?


Ans:-
declare
a int:=:a;
b int:=:b;
c int:=:c;
begin
if (a>b and a>c)
then
dbms_output.put_line(a);

elsif(b>a and b>c)


then
dbms_output.put_line(b);
else
dbms_output.put_line(c);

end if;
end;

Q:- Write a PL SQL program to Print that No. is Even Or odd?


Ans:-
declare
a int:=:a;
begin
if (a mod 2 =0)
then
dbms_output.put_line('NO. is even');
else
dbms_output.put_line('No. is Odd');
end if;
end;

//////////////////////////////////////////////////////////////////////////////////
TRIGGER:

create table t11


(
id int,
name varchar(20)
)

create table t12


(
id int,
name varchar(20)
)

desc t11
desc t12
create or replace trigger trig
After insert on t11
for each row
begin
insert into t12 values(:new.id,:new.name);
end;
insert into t11 values(11813609,'Prashant')
select * from t12

Q:-create a trigger which will insert a row in backup table whenever we delete from
Primary Table?
Ans:-

Q:- Write a PL SQL program which will print the no from 1 to 10?
Ans:-
begin
for i in 1..10
loop
dbms_output.put_line(i);
end loop;
end;

Q:- Reverse
begin
for i in reverse 1..10
loop
dbms_output.put_line(i);
end loop;
end;
///////////////////////////////////////////////////////////////////////////////////
///////////////////////
Q:- Write A pl Sql program which will print factorial of no. and no. should be
taken from users?
Ans:-

declare
a int:=:a;
fac int:=1;
begin
for i in 1..a
loop
fac:=fac*i;
end loop;
dbms_output.put_line(fac);
end;
///////////////////////////////////////////////////////////////////////////////////
//////////////////////
Q:- Write A Pl Sql Program To Print the Following Sequence :-

*
**
***
****
*****
******
Ans:-

declare
n number:=5;
i number;
j number;

begin
for i in 1..n
loop
for j in 1..i
loop
dbms_output.put('*');
end loop;
dbms_output.new_line;
end loop;
end;

WHILE LOOP :-

declare
i int:=10;
begin
while i<10
loop
dbms_output.put(i);
i=i+1;
end loop;
end;

Q:-Write a pl sql program to print reverse of num(1,2,3):-

x=mod(n,10)
r=(r+10)
r=trunk(r/10)
while i<10////////////////////////////
declare
num1 number(5);
num2 number(5);
rev number(5);
begin
num1:=:num1;
rev:=0;
while num1>0
loop
num2:=num1 mod 10;
rev:=num2+(rev*10);
num1:=floor(num1/10);
end loop;
dbms_output.put_line('Reverse number is: '||rev);
end;
//////////////////////////////////////////////////////////////////////////
10/8/19

Procedures:-
create or replace procedure Procedure Name(P1)
Parameters(IN,OUT,INOUT)
IS/AS
begin
Procedure Body
end;

to check output:- execute P1


begin
P1;
end;

Q:-program to Print Hello with Procedure:

create or replace procedure N1


is
begin
dbms_output.put_line('HELLO');
end;

begin
N1;
end;
///////////////////////////////
Q:- program to add two no. using Procedure?
Ans:-

create or replace procedure N2


(a int,b int)
is
begin
dbms_output.put_line(a+b);
end;
begin
N2(10,20);
end;

///or///
create or replace procedure N2
(a int,b int)
is
c int;
begin
c:=a+b;
dbms_output.put_line('sum='||c);
end;

begin
N2(10,20);
end;

////// no. taken from users:-


create or replace procedure N2
(a int,b int)
is
c int;
begin
c:=a+b;
dbms_output.put_line('sum='||c);
end;

begin
N2(:a,:b);
end;

Q;- Create a procedure which will update the salaries of employees the value should
be
taken from users?
Ans:-

create table empo


(
e_id int,
salary int
)
desc empo
insert into empo values(1,10000)
insert into empo values(2,20000)
insert into empo values(3,30000)
select * from empo

create or replace procedure p3


(a in int)
is
begin
update empo set salary=salary+10000 where e_id=a;
end;
begin
p3(2);
end;
-----------------------------------------------------------
22/10/19

create or replace function f1(a in int,b in int)


return int
as
begin
dbms_output.put_line(a+b);
return(a+b);
end;
select 100+200 from dual;

-------------------------------------------------------------
create a function which will display square root of function using in/out???

________________________________________________________________________
Q:-Create a Pl sql function which will return a factorial of a no.??
Ans:-
create or replace function f1(a in int,b in int)
return int
as
begin
if(a=0)
then
return(1)
else
return(a*f1(a-1))
end if;
end;

___________________________________________________________________________________
___________
**Indexing:-
Q:-Consider a harddisk in which block size is 1000 bytes , the record size is 100
bytes
the key fields is of 12 bytes and the pointer is of 8 bytes the harddisk contains a
file of
10000 record find the time complexity without index and with index.

___________________________________________________________________________________
___________
Q:-Write a program which will print the notification message whenever we try to
update,delete
and insert.

create or replace f1(a in int, b in int)


___________________________________________________________________________________
___________

Q:-Consider u r working as a database designer and u have been given a task


to create the backup of your Employee table that is whenever a row is deleted from
employee
table it will be automatically inserted in Backup Table.

1- implement the scenario using procedure


2-implement the same scenario using triggers
Ans:-
create table Employee1
(
E_id varchar(10),
E_name varchar(10),
Salary int,
Dept varchar(10)
)
desc Employee1
insert into Employee1 values('E1','A',20000,'HR')
insert into Employee1 values('E2','B',50000,'MRKT')
insert into Employee1 values('E3','C',40000,'MRKT')
insert into Employee1 values('E4','D',25000,'HR')
select * from Employee1

create table Backup


(
E_id varchar(10),
E_name varchar(10),
Salary int,
Dept varchar(10)
)
create or replace trigger TR
before delete on Employee1
for each row
begin
insert into backup values(:old.E_id,:old.E_name,:old.Salary,:old.Dept);
end;
delete from Employee1 where E_id='E1'
select * from backup

Вам также может понравиться