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;
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;
/
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;
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;
/
declare
a number;
begin
a:=f(10,20);
dbms_output.put_line(a);
end;
/
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;