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

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

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

2024-08-29 13:32:44
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
菜鳥(niǎo)學(xué)堂:

在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、過(guò)程

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  /

過(guò)程已創(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ā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 天门市| 扎鲁特旗| 兰溪市| 辽中县| 祥云县| 通渭县| 田阳县| 高碑店市| 安图县| 塔城市| 桓台县| 大理市| 静乐县| 龙岩市| 靖江市| 临海市| 满城县| 鄯善县| 香港| 永州市| 盐亭县| 崇明县| 南华县| 虎林市| 石渠县| 吴川市| 海南省| 晋宁县| 青海省| 大理市| 新建县| 绥芬河市| 常宁市| 保定市| 赣州市| 甘德县| 睢宁县| 光泽县| 阜阳市| 海阳市| 成都市|