Relações de parafusos e porcas que podem ser substituídos por normas similares.Descrição completa
Descripción completa
rwerweirjeirjwiorjwiorjw
transformer calculationFull description
--REF CURSOR It is basically a datatype.Ref cursor can be associated with the query at run-ti me. A cursor variable can be associated with different queries at run-time. --TYPES 1.STRONG REF CURSOR...Ref cursor with RETURN datatype 2.WEAK REF CURSOR....Ref cursor without RETURN datatype --STRONG REF CURSORS --SIMPLE REF CURSOR declare type ref_emp is ref cursor return emp%rowtype; salai ref_emp; --cursor variable i emp%rowtype; begin open salai for select * from emp; loop fetch salai into i; dbms_output.put_line(i.ename); end loop; end;
--REF CURSOR WITH MULTIPLE SELECT STATEMENTS declare type ref_emp is ref cursor return emp%rowtype; salai ref_emp; i emp%rowtype; begin open salai for select * from emp; loop fetch salai into i; exit when salai%notfound; dbms_output.put_line(i.ename); end loop; close salai; dbms_output.put_line('...............'); open salai for select * from emp where deptno=20; loop fetch salai into i; exit when salai%notfound; dbms_output.put_line(i.ename); end loop; close salai; end; --WEAK REF CURSOR declare type ref_emp is ref cursor; salai ref_emp; i emp%rowtype; begin open salai for select * from emp; loop fetch salai into i;
exit when salai%notfound; dbms_output.put_line(i.ename); end loop; end;
--OPENING A CURSOR VARIABLE THAT CONTAINS A QUERY FOR REF CURSOR declare type ref_emp is ref cursor; salai ref_emp; i emp%rowtype; stmt varchar2(50); begin stmt := 'select * from emp'; open salai for stmt; loop fetch salai into i; exit when salai%notfound; dbms_output.put_line(i.ename); end loop; end; --OPENING MULTIPLE SELECT STATEMENTS USING A LOGIC declare type ref_emp is ref cursor; salai ref_emp; i emp%rowtype; j employees%rowtype; stmt1 varchar2(50); stmt2 varchar2(50); vno number :=&no; begin stmt1 := 'select * from emp'; stmt2 := 'select * from employees'; if vno=1 then open salai for stmt1; loop fetch salai into i; exit when salai%notfound; dbms_output.put_line(i.ename); end loop; close salai; elsif vno=2 then open salai for stmt2; loop fetch salai into j; exit when salai%notfound; dbms_output.put_line(j.first_name); end loop; end if; end; declare type ref_emp is ref cursor; salai ref_emp; i emp%rowtype; j employees%rowtype; stmt1 varchar2(50);
stmt2 varchar2(50); deptno number :=&deptno; begin stmt1 := 'select * from emp'; stmt2 := 'select * from employees'; if deptno between 10 and 50 then open salai for stmt1; loop fetch salai into i; exit when salai%notfound; dbms_output.put_line(i.ename); end loop; close salai; elsif deptno between 60 and 150 then open salai for stmt2; loop fetch salai into j; exit when salai%notfound; dbms_output.put_line(j.first_name); end loop; end if; end; --SYS_REFCURSORS Oracle 9i introduced the pre-defined sys_refcursor type. The advantage of using this is we need not define our own ref cursor types. Sys_refcursor can be used to pass cursors from and to a stored procedure or func tion. we dont need to open a cursor returned by a function. HOW TO RETURN MULTIPLE ROWS FROM STORED PROCEDURES,FUNCTIONS...ETC?????? --USING FUNCTION create or replace function f1(p_deptno number) return sys_refcursor is salai sys_refcursor; stmt varchar2(50); begin stmt :='select * from employees where department_id=' ||p_deptno; open salai for stmt; return salai; end;
declare salai sys_refcursor; i employees%rowtype; begin salai :=f1(20); loop fetch salai into i; exit when salai%notfound; dbms_output.put_line(i.first_name); end loop; close salai; dbms_output.put_line('............'); salai :=f1(80); loop fetch salai into i; exit when salai%notfound; dbms_output.put_line(i.first_name);