pl/sql PROGRAMING
Third type of sequence statement
1) goto statement: it transfer the flow of control to the label unconditionaly.
syntex: goto
OUTPUT:
Q: create a trigger that insert a tupple into t5when the tupple into t4 spaceficaly the trigger chacks w
hether the new tupple has a first coponent 10 or less and if show the reverse tupple into t5.
ANS:
create table t41
(
a int,
b char(10)
);
create table t51
(
c char(10),
d int
);
set serveroutput on;
create or replace trigger t41
after insert on t41
for each row
when(new.a<=10) //trigger restriction
begin
insert into t51 values(:new.b,:new.a);
end;
insert into t41 values(5,'asd')
https://www.mediafire.com/folder/9z3cmblhwymm0/ds_pracicle
Q:create a trigger that displays the number of employees after every delete in emp table
Ans:
create table emp0248
(
empno number(20),
name char(20)
);
create or replace trigger t0248
after delete on emp0248
declare
n int;
begin
select count(n) into n from emp;
dbms_output.put_line('Employee Remaining'||n||'after deletion');
end;
Q:stop the transection if the salary enter by the user exceed 50000 in table employee?
Ans:
create or replace trigger t0248
before inserte and delete of sal in emp
for each row
when(new.sal>50000)
begin
RAISE_APPLICATION_ERROR(20001,''MSC'); //use to raise problem in program
end;
server: http://172.17.14.100/isqlplus dated:- 4/4/14
subprograms:-
1)Procedures
2)Stored Procedure
3)Functions
Procedure-Syntex
set serverouput on;
declare
global variables
procedure procedurename(arguments IN/OUT/INOUT detatype)
IN/AS
begin
PL/SQL statements;
End procedurename
begin
exwcute start;
procedure calling;
end;
IN: this type of parameterwill accept the value from the user.
OUT: this type of parameter will return th value to the user.
IN/OUT:this type of parameter will accept as well as return the value from the user.
//WAP to find the product of two number
set serveroutput on;
declare
num1 number(2);
num2 number(2);
mul number(4);
procedure multiplication
(num1 IN number,
num2 IN number,
mul OUT number
)
IS
begin
mul:=num1*num2;
end multiplication;
begin
num1:=&num1;
num2:=&num2;
multiplication(num1,num2,mul);
dbms_output.put_line(mul);
end;
//Write a stored procedure to find sum of two number
set serveroutput on;
declare
num1 number(2);
num2 number(2);
mul number(4);
procedure multiplication
(num1 IN number,
num2 IN number,
mul OUT number
)
IS
begin
mul:=num1+num2;
end multiplication;
begin
num1:=&num1;
num2:=&num2;
multiplication(num1,num2,mul);
dbms_output.put_line(mul);
end;
// create or replace procedure->
create or replace procedure as321(num1 in number,num2 in number, asd out number)
is
begin
asd:=num1+num2;
end;
set serveroutput on;
declare
num1 number(2);
num2 number(2);
asd number(2);
begin
num1:=&num1;
num2:=&num2;
as321(num1,num2, asd);
dbms_output.put_line(asd);
end;
<---------------function---------------------->
syntex:
set serveruotput on;
declare
global variable
function functionname(argument
return datatype
is
begin
pl/sql statement;
return(variable);
end functionname;
begin
executable statements;
end;
mul:=multiply(num1,num2,mul);
dbms_output.put_line(mul);
end;
//Write a function to multiply two number
set serveroutput on;
declare
num1 number(2);
num2 number(2);
mul number(4);
function multiplication
(num1 IN number,
num2 IN number,
mul OUT number
)
return number
IS
begin
mul:=num1*num2;
return(mul);
end multiplication;
begin
num1:=&num1;
num2:=&num2;
mul:=multiplication(num1,num2,mul);
dbms_output.put_line(mul);
end;
syntex:
set serveruotput on;
declare
global variable
function functionname(argument
return datatype
is
begin
pl/sql statement;
return(variable);
end functionname;
begin
executable statements;
end;
mul:=multiply(num1,num2,mul);
dbms_output.put_line(mul);
end;
//Write a function to multiply two number
set serveroutput on;
declare
num1 number(2);
num2 number(2);
mul number(4);
function multiplication
(num1 IN number,
num2 IN number,
mul OUT number
)
return number
IS
begin
mul:=num1*num2;
return(mul);
end multiplication;
begin
num1:=&num1;
num2:=&num2;
mul:=multiplication(num1,num2,mul);
dbms_output.put_line(mul);
end;
server: http://172.17.14.100/isqlplus
//to find even or odd
set serveroutput on;
declare
a number(2);
begin
a:=&a;
if mod(a,2)=0
then
dbms_output.put_line('no is even');
else
dbms_output.put_line('no is odd');
end if;
end;
//to find greatest of three no.
set serveroutput on;
declare
a number(2);
b number(2);
c number(2);
begin
a:=&a;
b:=&b;
c:=&c;
if (a>b)and(a>c)
then
dbms_output.put_line('a is greatest no');
else if (b>a)and(b>c)
then
dbms_output.put_line('b is greatest no');
else if (c>a)and(c>b)
then
dbms_output.put_line('c is greatest no');
end if;
end if;
end if;
end;
//to find square of number
set serveroutput on;
declare
i number(2);
begin
i:=&i;
i:=i*i;
dbms_output.put_line(i);
end;
control structure
1.loop
2.while loop
3.for loop
<-----------------------loop---------------------->
//to print 1st 10 number
set serveroutput on;
declare
i number(2);
begin
i:=1;
loop
dbms_output.put_line(i);
i:=i+1;
exit when i>10;
end loop;
end;
<-------------------end data-blogger-escaped-loop----------------------="">
<---------------------while data-blogger-escaped-loop------------------="">
//to find square of 1st 10 number
set serveroutput on;
declare
i number(2);
begin
i:=1;
while i<11 data-blogger-escaped-br="">loop
dbms_output.put_line(i*i);
i:=i+1;
end loop;
end;
//sum of 1st 10 number
set serveroutput on;
declare
i number(2);
a number(2);
begin
i:=1;
a:=0;
while i<11 data-blogger-escaped-br="">loop
a:=a+i;
i:=i+1;
end loop;
dbms_output.put_line(a);
end;
<------------------end data-blogger-escaped-loop-----------------="" data-blogger-escaped-while="">
<---------------------for data-blogger-escaped-loop--------------------="">
//to prin table of 2
set serveroutput on;
declare
i number(2);
a number(2);
begin
i:=1;
for i in 1..10
loop
dbms_output.put_line('2 X '||i||'= '||a);
end loop;
end;
<------------------end data-blogger-escaped-for="" data-blogger-escaped-loop-------------------="">
//to find factorial of no
set serveroutput on;
declare
i number(10);
a number(10);
begin
i:=&i;
a:=1;
while i>1
loop
a:=i*a;
i:=i-1;
end loop;
dbms_output.put_line('factorial of '||i||' is '||a);
end;
//fibonacci series
set serveroutput on;
declare
i number(2);
a number(2);
b number(2);
c number(2);
n number(2);
begin
n:=&n;
b:=1;
a:=0;
dbms_output.put_line(a);
dbms_output.put_line(b);
for i in 1..n-2
loop
c:=a+b;
dbms_output.put_line(c);
a:=b;
b:=c;
end loop;
end;
SECRET OF YOUTUBE
step1: open youtube
step2: type "use the force luke" in the search box
step3: press enter
AND SEE WHATS HAPPEN
While watching youtube press "1980" and save your video from missile
step1: open youtube
step2: type "beam me up scotty" in the search box
step3: press enter
AND SEE WHATS HAPPEN
step1: open youtube
step2: Add "&pow=1&nohtml5=1" to your searching video
step3: press enter
IT WILL ADD A POW BUTTON ON THE YOUTUBE PLAYER BY WHICH YOU CAN CHANGE THE GRAPHICS OF VIDEO
step1: open youtube
step2: type "doge meme" in the search box
step3: press enter
AND SEE WHATS HAPPEN
Subscribe to:
Posts (Atom)
Popular Posts
Powered by Blogger.
About Me
Recent Comments
Blog Archive
Ads 300 x 250
Popular Posts
-
Third type of sequence statement 1) goto statement: it transfer the flow of control to the label unconditionaly. syntex: goto ; ...
-
SESSION 2013-2014 CSE316: OPERATING SYSTEM CONCEPT Time Allowed: 03:00 hrs ...
-
step1: open youtube step2: type "use the force luke" in the search box step3: press enter AND SEE WHATS HAPPEN ...