<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    編程生活

       :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      113 隨筆 :: 0 文章 :: 18 評論 :: 0 Trackbacks

    With 7.2 on up of the database you have cursor variables.  Cursor variables are cursors opened by a pl/sql routine and fetched from by another application or pl/sql routine (in 7.3 pl/sql routines can fetch from cursor variables as well as open them). The cursor variables are opened with the privelegs of the owner of the procedure and behave just like they were completely contained within the pl/sql routine. It uses the inputs to decide what database it will run a query on.

    Here is an example:
     

    create or replace package types
    as
        type cursorType is ref cursor;
    end;
    /

    create or replace function sp_ListEmp return types.cursortype
    as
        l_cursor    types.cursorType;
    begin
        open l_cursor for select ename, empno from emp order by ename;

        return l_cursor;
    end;
    /
    create or replace procedure getemps( p_cursor in out types.cursorType )

    as

    begin

          open p_cursor for select ename, empno from emp order by ename;

    end;

    /

    examples for SQLPlus, Pro*C, Java/JDBC, ODBC, ADO/ASP, DBI Perl and OCI follow:

    REM SQL*Plus commands to use a cursor variable

    variable c refcursor
    exec :c := sp_ListEmp
    print c

    exec getEmps( :c )

    print c


    and the Pro*C to use this would look like:

    static void process()
    {
    EXEC SQL BEGIN DECLARE SECTION;
        SQL_CURSOR  my_cursor;
        VARCHAR     ename[40];
        int         empno;
    EXEC SQL END DECLARE SECTION;

        EXEC SQL WHENEVER SQLERROR DO sqlerror_hard();

        EXEC SQL ALLOCATE :my_cursor;

        EXEC SQL EXECUTE BEGIN
            :my_cursor := sp_listEmp;
        END; END-EXEC;

        for( ;; )
        {
            EXEC SQL WHENEVER NOTFOUND DO break;
            EXEC SQL FETCH :my_cursor INTO :ename, empno;

            printf( "'%.*s', %d"n", ename.len, ename.arr, empno );
        }
        EXEC SQL CLOSE :my_cursor;
    }

    And the java to use this could be:
     

    import java.sql.*;
    import java.io.*;
    import oracle.jdbc.driver.*;
     

    class curvar
    {
      public static void main (String args [])
                         throws SQLException, ClassNotFoundException
      {
          String driver_class = "oracle.jdbc.driver.OracleDriver";
          String connect_string = "jdbc:oracle:thin:@slackdog:1521:oracle8";

          String query = "begin :1 := sp_listEmp; end;";
          Connection conn;

          Class.forName(driver_class);
          conn = DriverManager.getConnection(connect_string, "scott", "tiger");

          CallableStatement cstmt = conn.prepareCall(query);
          cstmt.registerOutParameter(1,OracleTypes.CURSOR);
          cstmt.execute();
          ResultSet rset = (ResultSet)cstmt.getObject(1);

          while (rset.next ())
            System.out.println( rset.getString (1) );
          cstmt.close();
      }
    }


    posted on 2007-10-25 17:02 wilesun 閱讀(510) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 麻豆国产入口在线观看免费| 91av免费在线视频| 精品亚洲AV无码一区二区三区| 亚洲A∨无码无在线观看| 亚洲视频一区网站| 亚洲色www永久网站| 亚洲成年轻人电影网站www| 在线观看人成视频免费无遮挡| 四虎影视成人永久免费观看视频 | 24小时免费直播在线观看| 永久黄网站色视频免费| 青青青亚洲精品国产| 久草视频在线免费看| 免费观看四虎精品国产永久| 亚洲国产综合专区电影在线| 久久无码av亚洲精品色午夜 | 国产乱子影视频上线免费观看| 处破女第一次亚洲18分钟| 亚洲AⅤ无码一区二区三区在线| 精品亚洲综合在线第一区| 中文有码亚洲制服av片| 少妇无码一区二区三区免费| 亚洲视频免费观看| 久久精品a一国产成人免费网站| 韩国亚洲伊人久久综合影院| 亚洲午夜久久久影院伊人 | 亚洲国产日韩视频观看| 国产一级高清免费观看| 免费看黄的成人APP| 免费在线观看污网站| 亚洲中文字幕无码久久2020| 国产yw855.c免费视频| 国产在线观看免费视频软件 | 亚洲尹人香蕉网在线视颅| 老司机精品免费视频| 亚洲精品黄色视频在线观看免费资源| 亚洲xxxx18| 欧美日韩国产免费一区二区三区| 美女尿口扒开图片免费 | 亚洲?V乱码久久精品蜜桃| 四虎影视成人永久免费观看视频|