Declare Varchar2 Varchar2 Begin Select Into From Where Case When Then When Then When Then Else End End
Declare Varchar2 Varchar2 Begin Select Into From Where Case When Then When Then When Then Else End End
SQL> declare
2 v_var1 employees.last_name%type;
3 begin
4
select last_name into v_var1 from employees where
employee_id='&enter_emp_num';
5
if(length(v_var1)<=5) then
6
dbms_output.put_line('You have very short name');
7
elsif (length(v_var1)>5 and length(v_var1)<=10) then
8
dbms_output.put_line('You have some what medium length name');
9
else if(length(v_var1)>10 and length(v_var1)<=20) then
10
dbms_output.put_line('you are having a large name');
11
else
12
dbms_output.put_line('there is no range provided for the current
empployee');
13
end if;
14
end if;
15
end;
18 /
You have very short name
PL/SQL procedure successfully completed
CASE=============================
declare
v_var1 varchar2(10);
v_var2 varchar2(40);
begin
select job_id into v_var1 from employees where
employee_id='&enter_emp_number';
v_var2:=case v_var1 when 'PU_CLERK' then 'you have 5 collegues'
when 'ST_MAN' then 'you have 5 collegues'
when 'ST_CLERK' then 'you have 20 collegues'
else 'your job position is not known to me'
end;
dbms_output.put_line(v_var2);
end;
CASE===============================================
===
declare
v_var1 varchar2(10);
v_var2 varchar2(40);
begin
select job_id into v_var1 from employees where
employee_id='&enter_emp_number';
v_var2:=case when v_var1 ='PU_CLERK' then 'you have 5 collegues'
when v_var1 ='ST_MAN' then 'you have 5 collegues'
when v_var1 ='ST_CLERK' then 'you have 20
collegues'
else 'your job position is not known to me'
end;
dbms_output.put_line(v_var2);
end;
BASIC LOOP==================================
declare v_var1 number;
begin
v_var1:=1;
loop
dbms_output.put_line(v_var1);
v_var1:=v_var1+1;
exit when v_var1>10;
end loop;
end;
basic loop to insert into a table =============================
declare
v_var1 number;
v_var2 number;
begin
v_var1:=1;
v_var2:=1;
loop
insert into sample_nsk values(v_var1,to_char(to_date(v_var2, 'j'),
'jsp' ));
v_var1:=v_var1+1;
v_var2:=v_var2+1;
exit when v_var2=28;
end loop;
end;
select * from sample_nsk;
declare
v_var1 number;
v_var2 number;
v_var3 number;
begin
v_var2:=1;
v_var3:=100;
select commission_pct into v_var1 from employees where employee_id=100;
while (v_var1 is not null)
loop
v_var2:=v_var2+1;
select commission_pct into v_var1 from employees
where employee_id=v_var3;
v_var3:=v_var3+1;
end loop;
dbms_output.put_line('the '||v_var2||' employees have commission');
end;
output=======
the 4 employees have commission
PL/SQL procedure successfully completed
For loop to print 1 to 10 numbers==========
begin