Anda di halaman 1dari 7

1) GREATER THAN LESS THAN :

declare
a number(2) := 90;
begin
--a:=10
if ( a < 20 ) then
dbms_output.put_line('a is less than 20');
else
dbms_output.put_line('a is greater than 20');
end if;
end;
/
________________________________________________________________________________
__
DECLARE
a number(3) := 100;
BEGIN
IF ( a = 10 ) THEN
dbms_output.put_line('Value of a is 10' );
ELSIF ( a = 20 ) THEN
dbms_output.put_line('Value of a is 20' );
ELSIF ( a = 30 ) THEN
dbms_output.put_line('Value of a is 30' );
ELSE
dbms_output.put_line('None of the values is matching');
END IF;

dbms_output.put_line('Exact value of a is: '|| a );

END; /

SWITCH CASE :
declare

grade char(1):='&S';
begin
case
when grade='A' then
dbms_output.put_line('Excellence..');
when grade='B' then
dbms_output.put_line('vERY GOOD..');
when grade='C' then
dbms_output.put_line('GOOD..');
ELSE
dbms_output.put_line('BAD..');
end case;
end;
/
____________________________________________________________
PRINT UPTO 50 AS 10,20,30,40,50 :

declare
x number :=10;
begin
loop
dbms_output.put_line(x);
x:=x+10
if x>50 then
exit;
end if;
end loop;
dbms_output.put_line(All value of x : ||x);
end;
/
PRINT IN BETWEEN 11 TO 20 USING WHILE:
declare
x number :=10;
begin
while x<20
loop
dbms_output.put_line('All value are :' || x);
x:=x+1;

end loop;
end;
/
PRINT IN BETWEEN 11 TO 20 USING FOR:
declare
x number(10);
begin
FOR x in 101..120 loop
dbms_output.put_line('All value are :' || x);
end loop;
end;
/

PRINT STRING FUNCTIONS :

declare
greeting varchar2(20) := 'jeevan malpani';
greeting2 varchar2(20) := 'JEEVAN MALPANI';
begin
-- Lower to Upper
dbms_output.put_line('In Upper case ' || UPPER(greeting));
-- Lower to Upper
dbms_output.put_line('In Upper case ' || UPPER(greeting));
-- INITCAP
dbms_output.put_line('Initcap result : ' || INITCAP(greeting));
-- RETRIVE FIRST CHARACTER IN STRING
dbms_output.put_line(SUBSTR(greeting,1,1));
-- RETRIVE LAST CHARACTER IN STRING
dbms_output.put_line(SUBSTR(greeting,-1,1));
--RETRIVE FIVE CHARACTER STARTING FROM SEVENTH POSITION
dbms_output.put_line(SUBSTR(greeting,7,5));

end;
/

PROCUDURE :
Print hello word using procedure:
create or replace procedure greeting as
begin
dbms_output.put_line('Hello World..');
end;
/

IN / OUT of PROCEDURE : declare


a number;
b number;
c number;
procedure find (x IN number,y IN number, z OUT number)IS
begin
z:= x+y;
end;
begin
a:=10;
b:=20;
find(a,b,c);
dbms_output.put_line(c);
end;
/

IN OUT of PROCEDURE :

declare
a number;
procedure square(x IN OUT number) IS
begin
x:=x*x;
end;
begin
a:=2;
square(a);
dbms_output.put_line('Square of (2) :'|| a);
end;
/

TWO FILE FUNCTION :


create or replace function f(x in number,y in number)return number is
begin
return(x+y);
end;
/

declare
a number;
begin
a:=f(10,20);
dbms_output.put_line(a);
end;
/

Finding record(dept table) through curser :


declare
cursor d_dept is select deptno,dname from dept;
d_deptno dept.deptno%type;
d_dname dept.dname%type;
begin
open d_dept;
loop
fetch d_dept into d_deptno,d_dname;
exit when d_dept%notfound;
dbms_output.put_line(d_deptno || ' ' || d_dname);
end loop;
close d_dept;
end;
/

Finding record(emp table) through curser :

declare
cursor d_emp is select empno,job,sal from emp;
d_empno emp.empno%type;
d_job emp.job%type;
d_sal emp.sal%type;
begin
open d_emp;
loop
fetch d_emp into d_empno,d_job,d_sal;

exit when d_emp%notfound;


dbms_output.put_line(d_empno || ' ' || d_job || ' ' || d_sal );
end loop;
close d_emp;
end;
/

Package (Compilation error :)


create or replace package pkg1 is
procedure pro1
--function f1(x number) return number;
function f2(x number,y number)return number;
end pkg1;
/
create or replace package body pkg1 is procedure pro1 is
begin
dbms_output.put_line('Hello World ..!');
end pro1;
--function f1(x number) return number is
--begin
--return(x*x);
--end fi;
function f2(x number,y number) return number is
begin
return(x+y);
end fi
end pkg1;
/

Anda mungkin juga menyukai