Posts Oracle plsql Part 3
Post
Cancel

Oracle plsql Part 3

  • %rowtype for complete row into
1
2
3
4
5
6
7
8
9
10
declare
	mrec rahul_emp%rowtype;
begin
	 select * into mrec from rahul_emp
	 where empno=7900;
	 dbms_output.put_line(' the salary of employee '||mrec.ename||' is '||mrec.sal ||' job= '||mrec.job);
exception
     when no_data_found then
	 dbms_output.put_line('no such employee found');
end;	
  • taking input in plsql
1
2
3
4
5
6
7
8
9
10
declare
	mrec rahul_emp%rowtype;
begin
	 select * into mrec from rahul_emp
	 where empno=&input;
	 dbms_output.put_line(' the salary of employee '||mrec.ename||' is '||mrec.sal ||' job= '||mrec.job);
exception
     when no_data_found then
	 dbms_output.put_line('no such employee found');
end;	
  • taking input in plsql for a varchar requires single quotes in where
1
2
3
4
5
6
7
8
9
10
declare
	mrec rahul_emp%rowtype;
begin
	 select * into mrec from rahul_emp
	 where ename = '&input';
	 dbms_output.put_line(' the salary of employee '||mrec.ename||' is '||mrec.sal ||' job= '||mrec.job);
exception
     when no_data_found then
	 dbms_output.put_line('no such employee found');
end;
  • taking input in plsql for a varchar requires single quotes in where , making input to upper case
1
2
3
4
5
6
7
8
9
10
declare
	mrec rahul_emp%rowtype;
begin
	 select * into mrec from rahul_emp
	 where ename = upper('&input');
	 dbms_output.put_line(' the salary of employee '||mrec.ename||' is '||mrec.sal ||' job= '||mrec.job);
exception
     when no_data_found then
	 dbms_output.put_line('no such employee found');
end;	
This post is licensed under CC BY 4.0 by the author.