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 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...…
一.查询SQL Server中所有的表 SQL语句:SELECT * FROM sys.tables name列表示所有的表名. 二.查询SQL Server中所有的列 SQL语句:SELECT * FROM sys.columns name列表示所有的字段名称. 两张表根据object_id进行关联. 语法: select * from sys.tables t inner join sys.columns c on t.object_id=c.object and c.name='要查询的字…
一  以需要被查询的用户登录oracle(假如为A)   B为要查询A用户下的表的用户 二  执行查询语句: select 'grant select on A.'|| tname ||' to  B;' from tab; 以下为模拟结果: grant select on A.DEPT to  B; grant select on A.EMP to  B; grant select on A.BONUS to  B; grant select on A.SALGRADE to  B; gran…
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…
--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 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…
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…
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…
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 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…
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;…
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 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;…
如果不标明*是读取哪个表,确实会将所有三个表都读出来.需要小心…
select TABLE_NAME from information_schema.COLUMNS where COLUMN_NAME = 'type'…