国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > Oracle > 正文

利用游標(biāo)返回結(jié)果集的的例子(Oracle 存儲(chǔ)過程)

2024-08-29 13:35:30
字體:
供稿:網(wǎng)友

在sqlplus中建立如下的內(nèi)容:1、程序包

SQL> create or replace package types  2  as  3      type cursorType is ref cursor;  4  end;  5  /

程序包已創(chuàng)建。

2、函數(shù)SQL> create or replace function sp_ListEmp return types.cursortype  2  as  3      l_cursor    types.cursorType;  4  begin  5      open l_cursor for select id, title from cf_news order by id;--表的名字  6      return l_cursor;  7  end;  8  /

函數(shù)已創(chuàng)建。

3、過程

SQL> create or replace PRocedure getemps( p_cursor in out types.cursorType )  2  as  3  begin  4        open p_cursor for select id, title from cf_news order by id;--表的名字  5  end;  6  /

過程已創(chuàng)建。

4、建立一個(gè)可執(zhí)行的java控制臺(tái)程序

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

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

      String query = "begin :1 := sp_listEmp; end;"; //此處調(diào)用前面建立的函數(shù)!      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();   } }

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 富平县| 闻喜县| 睢宁县| 吉安市| 梁河县| 石柱| 东乡族自治县| 江口县| 荥阳市| 宜兰县| 上蔡县| 呈贡县| 曲靖市| 宜昌市| 读书| 观塘区| 澜沧| 博乐市| 定西市| 昭平县| 边坝县| 鹤壁市| 饶阳县| 册亨县| 旬阳县| 朔州市| 南昌市| 阿合奇县| 岳阳县| 沾益县| 嘉鱼县| 连城县| 南雄市| 阳春市| 平顶山市| 天津市| 北宁市| 阳谷县| 申扎县| 长春市| 深泽县|