<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ā)表評論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲色欲啪啪久久WWW综合网| 亚洲XX00视频| 91久久成人免费| 久久国产高潮流白浆免费观看| a级毛片免费全部播放| 国产免费播放一区二区| 国产精品成人免费观看| 在线观看片免费人成视频播放| 二区久久国产乱子伦免费精品| 大妹子影视剧在线观看全集免费| 久久久久国色AV免费观看| jyzzjyzz国产免费观看| 久久久久国色AV免费观看| AAA日本高清在线播放免费观看| 久久精品国产免费一区| 午夜免费福利小电影| 69xx免费观看视频| 无码一区二区三区免费视频| 性做久久久久免费看| mm1313亚洲精品无码又大又粗 | 国内精品99亚洲免费高清| a毛片免费播放全部完整| 少妇无码一区二区三区免费| 99久久久精品免费观看国产 | 免费无码又爽又刺激网站 | 美国毛片亚洲社区在线观看| 免费看美女午夜大片| 福利免费在线观看| 免费人成视频在线观看网站| 免费无码AV电影在线观看| 国产a不卡片精品免费观看| 国产亚洲AV夜间福利香蕉149| 亚洲AV成人无码久久精品老人| 亚洲成a人片在线观看中文app | 亚洲成A人片在线观看无码不卡| 78成人精品电影在线播放日韩精品电影一区亚洲 | 30岁的女人韩剧免费观看| 国产成人免费爽爽爽视频| 可以免费观看一级毛片黄a| 亚洲国产精品无码av| wwwxxx亚洲|