WHAT IS RECORD ?
Record is a composite data structure which hold data items of different kinds.Record consist of different fields similar to a row of data base table.
1)table base
2)cursor base record
3)user defined record

To create table base or cursor base record we prefer % row type attribute which provide record type to represent a rows in data base table.record can stored rows from data base table or fetch from  cursor variable and cursor.
e.g of table base
declare
v_rc employees.%rowtype;
begin
select * into v_rc
from emolyees
where employee_id=100;
dbms_output.put_line('employees details:'||'v_rc.last_name||v_rc.first_name||v_rc.salary);
end;
2)cursor base record
declare
cursor c_rec_emp is
select last_name,employee_id,salary from employees
v_c_r c_rec_emp.%rowtype;
begin
open c_rec_emp;
loop
fetch c_rec_emp into v_c_r;
exit when c_rec_emp %notfound;
dbms_output.put_line('employee datails:'||v_c_r.last_name||v_c_r.employee_id||v_c_r.salary);
end loop;
dbms_output.put_line('total number of rows:'||v_c_r.%rowcount)
close c_rec_emp;
end;
3)user defined record
declare
v_emp_id employees.employee_id%type;
v_name   employees.last_name%type;
v_sal        employees.salary%type;
cursor c_r_emp is
select employee_id,last_name,salary from employees
begin
open c_r_emp
loop
fetch c_r_emp into v_emp,v_name,v_sal;
exit when c_r_emp%notfound;
dbms_output.put_line('emp details:'||v_emp.employee_id||v_name.last_name||v_sal.salary);
end loop;
dbms_output.put_line('tota rows:'||var.%rowcount);
close c_r_emp;
end;

WHAT IS REF CURSOR?

Ref cursor is the one of the strong or flexible ways to generates query result from a oracle database to client application.it is the memory address of query work area on the data base.ref cursor only give the result from particular query it could'nt contain data.that result can not printing any time so that it not act as open cursor.lets do eg.

create or replace function get_dept_r(p_dept in number) return sys_refcursor
v_rc  sys_refcursor;
begin
open v_rc for employee_id,last_name,first_name from employees
where employee_id=p_dept;
return v_rc;
end;
we can call the function to get back the ref cursor.ref cursor does'nt contain any data at all ,it's just pointer to the query.it was not an open cursor and could not perform the task of printing  anything.
or variable type ref cursor is equivalent to the sys ref cursor.
exec:v_rc=get_dept_r;






















































































































Comments

Popular posts from this blog

Sql If Condition

GST AND GST TABLES IN ORACLE APPS