declare Type ref_cur_emp IS REF CURSOR RETURN scott.emp%RowType; cur_emp ref_cur_emp; rec_emp cur_emp%RowType; v_sql ) := 'select * from scott.emp t'; begin -- xxx Open cur_emp For v_sql; Open cur_emp For select * from scott.emp t; Loop fetch cur_emp…
declare Type ref_cur_variable IS REF cursor; cur_variable ref_cur_variable; v_ename ); v_deptno ); v_sal ,); v_sql ) := 'select t.ename, t.deptno, t.sal from scott.emp t'; begin Open cur_variable For v_sql; Loop fetch cur_variable InTo v_ename, v_dep…
declare Type ref_cur_variable IS REF cursor; cur_variable ref_cur_variable; rec_emp scott.emp%RowType; v_sql ) := 'select * from scott.emp t'; begin Open cur_variable For v_sql; Loop fetch cur_variable InTo rec_emp; Exit When cur_variable%NotFound; d…
CREATE OR REPLACE FUNCTION function_name RETURN DATE AS v_date DATE; BEGIN ; dbms_output.put_line(v_date); RETURN v_date; END function_name;…
declare Type ref_cur_variable IS REF cursor; cur_variable ref_cur_variable; v_empno scott.emp.empno%type; v_ename scott.emp.ename%type; v_sql ) := 'select t.empno, t.ename from scott.emp t'; begin Open cur_variable For v_sql; Loop fetch cur_variable…
declare v_empno scott.emp.empno%type; v_sal scott.emp.sal%type; ) is select t.empno, t.sal from scott.emp t where t.empno = v_empno; begin ); loop fetch cur_emp into v_empno, v_sal; exit when cur_emp%notfound; dbms_output.put_line(v_empno || ' ' || v…
declare r_emp scott.emp%rowtype; cursor cur_emp is select t.* from scott.emp t; begin open cur_emp; if cur_emp%isopen then dbms_output.put_line('is open...'); end if; loop fetch cur_emp into r_emp; if cur_emp%found then dbms_output.put_line('found...…
declare cursor cur_emp is select t.* from scott.emp t; begin for r_emp in cur_emp loop dbms_output.put_line(r_emp.empno || ' ' || r_emp.sal); end loop; end;…
declare r_emp scott.emp%rowtype; cursor cur_emp is select t.* from scott.emp t; begin open cur_emp; loop fetch cur_emp into r_emp; exit when cur_emp%notfound; dbms_output.put_line(r_emp.empno || ' ' || r_emp.sal); end loop; close cur_emp; end;…
declare v_empno scott.emp.empno%type; v_sal scott.emp.sal%type; cursor cur_emp is select t.empno, t.sal from scott.emp t; begin open cur_emp; loop fetch cur_emp into v_empno, v_sal; exit when cur_emp%notfound; dbms_output.put_line(v_empno || ' ' || v…
create or replace function function_demo RETURN emp PIPELINED as Type ref_cur_emp IS REF CURSOR RETURN emp%RowType; cur_emp ref_cur_emp; rec_emp cur_emp%RowType; begin Open cur_emp For select * from emp t; Loop fetch cur_emp InTo rec_emp; Exit When c…
--PACKAGE CREATE OR REPLACE PACKAGE test_141215 is TYPE type_ref IS record( ENAME ), SAL )); TYPE t_type_ref IS TABLE OF type_ref; FUNCTION retrieve(v_name varchar2) RETURN t_type_ref PIPELINED; END test_141215; -- PACKAGE BODY CREATE OR REPLACE PACK…
--PACKAGE CREATE OR REPLACE PACKAGE test_141213 is TYPE type_ref IS record( ENAME ), WORK_CITY ), SAL )); TYPE t_type_ref IS TABLE OF type_ref; FUNCTION retrieve(v_name varchar2) RETURN t_type_ref PIPELINED; END test_141213; -- PACKAGE BODY CREATE OR…
DECLARE v_sql ) := ''; v_count NUMBER; BEGIN v_sql := v_sql || 'select count(1) from scott.emp t'; EXECUTE IMMEDIATE v_sql INTO v_count; dbms_output.put_line(v_count); END;…
declare v_sal ) :; begin --if you could not see the output in console, you should set output on first use the command in command line : set serveroutput on dbms_output.put_line(v_sal); end;…
-- refer: -- http://www.cnblogs.com/gnielee/archive/2009/09/09/1563154.html -- http://www.cnblogs.com/yudy/archive/2012/07/18/2597874.html ); CREATE OR REPLACE FUNCTION splitstr(p_string IN VARCHAR2, p_delimiter IN VARCHAR2 := ',') RETURN ty_str_spli…
--Count the length of string select lengthb('select * from scott.emp') as countted_by_byte, length('select * from scott.emp') as countted_by_char from dual; --For some character encoding, the length() and the lengthb() is same in english --you may us…
CREATE OR REPLACE PACKAGE BODY temp_package_demo is FUNCTION f_demo(userid NUMBER) RETURN BOOLEAN IS v_temp ); BEGIN INTO v_temp FROM scott.emp WHERE empno = userid; RETURN TRUE; EXCEPTION WHEN NO_DATA_FOUND THEN RETURN FALSE; END; PROCEDURE p_demo_1…
CREATE OR REPLACE PACKAGE temp_package_demo is v_demo ); PROCEDURE p_demo_1(userid NUMBER DEFAULT v_demo, SAL number); FUNCTION f_demo(userid NUMBER) RETURN BOOLEAN; END temp_package_demo;…
declare v_sal ; begin loop v_sal :; dbms_output.put_line(v_sal); ; end loop; end;…
declare v_sal ; begin loop v_sal :; dbms_output.put_line(v_sal); then exit; end if; end loop; end;…
declare v_sal ; begin ) loop v_sal :; dbms_output.put_line(v_sal); end loop; end;…
declare v_display ); begin .. loop .. loop dbms_output.put_line(i || ' - ' || j); end loop; end loop; end;…
declare v_job ) := 'Programmer'; v_sal number; begin if v_job = 'Programmer' then v_sal :; elsif v_job = 'Senior Programmer' then v_sal :; else v_sal :; end if; dbms_output.put_line(v_sal); end;…
declare v_sal number; begin ; dbms_output.put_line(v_sal); end;…
declare v_sal ) :; begin --if you could not see the output in console, you should set output on first use the command in command line : set serveroutput on dbms_output.put_line(v_sal); end;…
Oracle 系列:REF Cursor 在上文  Oracle 系列:Cursor  (参见:http://blog.csdn.net/qfs_v/archive/2008/05/06/2404794.aspx)中  提到个思考:怎样让游标作为参数传递? 解决这个问题就需要用到 REF Cursor . 1,什么是 REF游标 ?  动态关联结果集的临时对象.即在运行的时候动态决定执行查询.   2,REF 游标 有什么作用?  实现在程序间传递结果集的功能,利用REF CURSOR也可以实现…
----4.7 ref游标(loop循环) /*** 怎么使用  REF游标 ?  ①声明REF 游标类型,确定REF 游标类型:   ⑴强类型REF游标:指定retrun type,REF 游标变量的类型必须和return type一致.    语法:Type   REF游标名   IS   Ref Cursor Return  结果集返回记录类型:   ⑵弱类型REF游标:不指定return type,能和任何类型的CURSOR变量匹配,用于获取任何结果集.    语法:Type   REF…
参考文章:https://www.cnblogs.com/huyong/archive/2011/05/04/2036377.html 在 PL/SQL 程序中,对于处理多行记录的事务经常使用游标来实现 使用有四个步骤:定义.打开.提取.关闭 例子: 09:52:04 SCOTT@std1> DECLARE 09:52:07 2 CURSOR c_cursor 09:52:07 3 IS SELECT ename, sal 09:52:07 4 FROM emp 09:52:07 5 WHERE…
在PL/SQL块中执行SELECT.INSERT.DELETE和UPDATE语句时,Oracle会在内存中为其分配上下文区(Context Area),即缓冲区.游标是指向该区的一个指针,或是命名一个工作区(Work Area),或是一种结构化数据类型. 在每个用户会话中,可以同时打开多个游标,其数量由数据库初始化参数文件中的OPEN_CURSORS参数定义. 对于不同的SQL语句,游标的使用情况不同: SQL语句 游标 非查询语句 隐式的 结果是单行的查询语句 隐式的或显示的 结果是多行的查询…