Posts Oracle plsql Part 5
Post
Cancel

Oracle plsql Part 5

  • loops
1
2
3
4
5
6
7
8
9
10
11
12
13
declare
    i number;
begin
	 i:=0;
	loop
		 dbms_output.put_line(i);
		exit when i=5;
		i:=i+1;
	end loop;
exception
     when no_data_found then
	 dbms_output.put_line('error');
end;	
  • blocks within blocks
1
2
3
4
5
6
7
8
9
10
11
declare
    x number:=100;
begin
	 declare
	 	x number :=500;
	 begin
	 	x:=1000;
		dbms_output.put_line('value of x of inner block is '||x);
	 end inner_block;
		dbms_output.put_line('value of x of outer block is '||x);		
end;	
  • same nested blocks with label
1
2
3
4
5
6
7
8
9
10
11
12
13
<<outer_block>>
declare
    x number:=100;
begin
	 <<inner_block>>
	 declare
	 	x number :=500;
	 begin
	 	x:=1000;
		dbms_output.put_line('value of x of inner block is '||x);
	 end inner_block;
		dbms_output.put_line('value of x of outer block is '||x);		
end;	
  • with outer_block.x and inner_block.x
1
2
3
4
5
6
7
8
9
10
11
12
13
<<outer_block>>
declare
    x number:=100;
begin
	 <<inner_block>>
	 declare
	 	x number :=500;
	 begin
	 	x:=1000;
		dbms_output.put_line('value of x of inner block is '||outer_block.x);
	 end inner_block;
		dbms_output.put_line('value of x of outer block is '||x);		
end;	
This post is licensed under CC BY 4.0 by the author.