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

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

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

    編程生活

       :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      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 閱讀(507) 評論(0)  編輯  收藏

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


    網站導航:
     
    主站蜘蛛池模板: 国产人成免费视频网站| 久久精品免费观看国产| 成人男女网18免费视频| 天黑黑影院在线观看视频高清免费| 又色又污又黄无遮挡的免费视| 亚洲午夜无码毛片av久久京东热| 成人毛片免费观看视频| 亚洲欧美国产国产综合一区| 日韩av无码成人无码免费| 波多野结衣免费视频观看| 亚洲另类无码专区首页| 国产伦精品一区二区三区免费迷| 亚洲精品无码久久久久久| 日韩成人免费在线| 亚洲最大的成网4438| 久久午夜夜伦鲁鲁片免费无码影视| 免费成人午夜视频| 一级视频在线免费观看| 亚洲色偷拍另类无码专区| 一区二区三区观看免费中文视频在线播放| 久久亚洲国产视频| 精品国产免费人成网站| 无码乱人伦一区二区亚洲| 中文免费观看视频网站| 亚洲av不卡一区二区三区| 亚洲网站免费观看| 朝桐光亚洲专区在线中文字幕| 五月婷婷综合免费| 无码乱人伦一区二区亚洲一| 黄在线观看www免费看| 亚洲AV电影天堂男人的天堂| 久久久久噜噜噜亚洲熟女综合| 99久9在线|免费| 国产精品亚洲色婷婷99久久精品| 日本免费网址大全在线观看| 在线视频亚洲一区| 亚洲国产成人一区二区三区| 在线观看黄片免费入口不卡| 亚洲中文无码av永久| 久久久亚洲精品蜜桃臀| 国拍在线精品视频免费观看|