标签:
--自定义类型 create or replace type mytype as object ( str1 number, str2 varchar2(10) ); --自定义类型集合 create or replace type mytype_list as table of mytype;
--1函数 返回字符串 create or replace function fun_ceshi1(num1 number, num2 number) return varchar2 as str1 varchar2(111); begin str1 := ‘测试时。。。‘; return str1; end; --取值 select fun_ceshi1(1,1) from dual;
--2函数 返回自定义类型 create or replace function fun_ceshi2(num1 number, num2 number) return mytype as my mytype; begin select mytype(ename1, ename2) into my from (select t.empno ename1, t.ename ename2 from emp t where rownum=1); return my; end; -- select fun_ceshi2(1,1) from dual;
--3函数 返回自定义类型集合 create or replace function fun_ceshi3(num1 number, num2 number) return mytype_list as my mytype_list; begin select mytype(ename1, ename2) BULK COLLECT into my from (select t.empno ename1, t.ename ename2 from emp t); return my; end; -- select * from table(fun_ceshi3(1,1));
--1存过 返回字符串 create or replace procedure pro_ceshi1(num1 number, num2 number, num3 out varchar2) as begin select ‘字符串num‘ into num3 from dual; end; --调用 declare num3 varchar2(111); begin pro_ceshi1(1, 1, num3); dbms_output.put_line(num3); end;
--2存过 返回自定义类型 create or replace procedure pro_ceshi2(num1 number, num2 number, strType out mytype) as begin select mytype(ename1, ename2) into strType from (select t.empno ename1, t.ename ename2 from emp t where rownum=1); end; --调用 declare strType mytype; begin pro_ceshi2(1, 1, strType); dbms_output.put_line(strType.str1 || ‘ ‘ || strType.str2); end;
--3存过 返回自定义类型集合 create or replace procedure pro_ceshi3(num1 number, num2 number, strType out mytype_list) as begin select mytype(ename1, ename2) BULK COLLECT into strType from (select t.empno ename1, t.ename ename2 from emp t); end; --调用 declare strType mytype_list; cursor c_c is select * from table(strType); begin pro_ceshi3(1, 1, strType); for v_r in c_c loop dbms_output.put_line(v_r.str1 || ‘ ‘ || v_r.str2); end loop; end;
标签:
原文地址:http://www.cnblogs.com/zhaopei/p/4250728.html