This Is A FineDay

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            93 隨筆 :: 0 文章 :: 69 評論 :: 0 Trackbacks
          								
          										
          												
          														SQL
          														>
          														create?table?test
          														(
          														name?varchar2
          														(
          														4
          														),
          														text??varchar2
          														(
          														9
          														));



          SQL > create?view?test_view? as? select?text?from?test?where?name = userenv ( 'client_info' );



          SQL > insert?into?test?values ( 'zxx' , 'boy' );

          SQL > insert?into?test?values ( 'taw' , 'gril' );

          SQL > commit ;



          SQL > exec?dbms_application_info . set_client_info ( 'zxx' );

          SQL > select? *? from?test_view ;



          TEXT

          ---------

          boy

          --





          a
          create or replace type emp_type
          as object (
          empno number(4),
          ename varchar2(10)
          );
          /
          create or replace type emp_type_table as table of emp_type;
          /
          create or replace function emp_of_dept(p_deptno in number)
          return emp_type_table
          pipelined as
          l_emp_type emp_type;
          begin
          for l_myrow in (select empno, ename from emp
          where deptno = p_deptno) loop
          l_emp_type := emp_type(l_myrow.empno, l_myrow.ename);
          pipe row (l_emp_type);
          end loop;
          return;
          end emp_of_dept;
          /

          select * from table(emp_of_dept(10));
          EMPNO ENAME
          ---------- ----------
          7782 CLARK
          7839 KING
          7934 MILLER

          select * from table(emp_of_dept(30));
          EMPNO ENAME
          ---------- ----------
          7499 ALLEN
          7521 WARD
          7654 MARTIN
          7698 BLAKE
          7844 TURNER
          7900 JAMES

          Tom - what do you think about this??

          Followup:?
          I think it is alot more code then:

          create or replace?
          procedure foo( p_deptno in number, p_result_set out sys_refcursor )
          as
          begin
          open p_result_set for
          select empno, ename from emp where deptno = p_deptno;
          end;

          and having the client (which is doing Oracle stuff anyway) issue?

          begin foo( :n, :m ); end;


          It'll be less performant as well.?
          Neat "trick" but not best practice.?

          create or replace function f_test(p_num in number)
          return sys_refcursor
          is
          Result sys_refcursor;
          begin
          open Result for
          select * from t1 t where t1.c1=p_num;
          return(Result);
          exception
          when others then
          raise;
          end;

          select f_test(1) from dual;
          posted on 2008-04-20 15:00 Peter Pan 閱讀(1808) 評論(0)  編輯  收藏 所屬分類: DB
          主站蜘蛛池模板: 阜平县| 旺苍县| 文登市| 大关县| 论坛| 新巴尔虎左旗| 丽水市| 龙川县| 安陆市| 绥化市| 遂川县| 额尔古纳市| 扬州市| 库伦旗| 牙克石市| 旬阳县| 孟州市| 晋城| 延长县| 新郑市| 集贤县| 城口县| 航空| 社旗县| 廉江市| 灵武市| 冀州市| 大丰市| 名山县| 读书| 温州市| 文登市| 民权县| 方城县| 祁门县| 二连浩特市| 洪洞县| 巴林左旗| 合作市| 孝感市| 陈巴尔虎旗|