在Oracle中我可以声明一个引用游标......
TYPE t_spool IS REF CURSOR RETURN spool%ROWTYPE;
Run Code Online (Sandbox Code Playgroud)
...并使用它将光标作为返回值传递...
FUNCTION end_spool
RETURN t_spool
AS
v_spool t_spool;
BEGIN
COMMIT;
OPEN v_spool FOR
SELECT
*
FROM
spool
WHERE
key = g_spool_key
ORDER BY
seq;
RETURN v_spool;
END end_spool;
Run Code Online (Sandbox Code Playgroud)
...然后使用JDBC将其作为结果集捕获...
private Connection conn;
private CallableStatement stmt;
private OracleResultSet rset;
[...clip...]
stmt = conn.prepareCall("{ ? = call " + call + "}");
stmt.registerOutParameter(1, OracleTypes.CURSOR);
stmt.execute();
rset = (OracleResultSet)stmt.getObject(1);
Run Code Online (Sandbox Code Playgroud)
MySQL中的等价物是什么?
我想编写PL/SQL来测试包中的函数.包定义了游标类型
TYPE ref_cursor IS REF CURSOR;
Run Code Online (Sandbox Code Playgroud)
我想基于该类型定义记录.
我的代码是:
DECLARE
cur PACKAGE_NAME.ref_cursor;
rec cur%ROWTYPE;
Run Code Online (Sandbox Code Playgroud)
为什么最后一行不正确?
ref 游标可以像游标一样用于 for 循环吗?即喜欢
for i in cur_name
loop
dbms_output.put_line(i.column_name)
end loop;
Run Code Online (Sandbox Code Playgroud)
如果不可能那为什么?
我知道以下是可能的。即我可以将引用游标作为 Postgresql 中的返回值。
CREATE FUNCTION employeefunc(int) RETURNS refcursor AS '
DECLARE ref refcursor;
BEGIN
OPEN ref FOR SELECT * FROM employee where id = $1;
RETURN ref;
END;
Run Code Online (Sandbox Code Playgroud)
但是我们可以将引用游标作为 postgresql 函数中的 OUT 参数吗?
供您参考,请遵循我正在寻找的 Oracle 等效内容。
create or replace procedure employeefunc(rc out sys_refcursor) as
begin
open rc for 'select * from employee';
end;
Run Code Online (Sandbox Code Playgroud) postgresql plsql stored-procedures ref-cursor stored-functions
该软件包使用Oracle的两个独特功能,REF_CURSOR和包全局变量.我想将功能从Oracle移植到Postgresql或MySQL.
PACKAGE tox IS
/*=======================*/
g_spool_key spool.key%TYPE := NULL;
TYPE t_spool IS REF CURSOR RETURN spool%ROWTYPE;
/*=======================*/
PROCEDURE begin_spool;
/*=======================*/
PROCEDURE into_spool
(
in_txt IN spool.txt%TYPE
);
/*=======================*/
PROCEDURE reset_spool;
/*=======================*/
FUNCTION end_spool
RETURN t_spool;
/*=======================*/
FUNCTION timestamp
RETURN VARCHAR2;
/*=======================*/
END tox;
PACKAGE BODY tox
IS
/*========================================================================*/
PROCEDURE begin_spool
AS
/*=======================*/
BEGIN
/*=======================*/
SELECT
key.NEXTVAL
INTO
g_spool_key
FROM
DUAL;
/*=======================*/
END begin_spool;
/*========================================================================*/
PROCEDURE into_spool
(
in_txt IN spool.txt%TYPE
)
AS
/*=======================*/
BEGIN
/*=======================*/
INSERT INTO
spool
VALUES
( …Run Code Online (Sandbox Code Playgroud) 我想知道如何检查引用游标是否返回数据.
假设我在PL/SQL包中有以下代码:
type refcursor is ref cursor;
procedure Foo(cursorresult out refcursor) is
begin
open cursorresult for
select *
from table t
inner join t2 on t.id = t2.id
where t.column1 is null;
end;
procedure DoSomeghingIfFooHasResults is
curFoo refcursor;
begin
Foo(curSansOwner);
if curFoo%found then
-- Do something
end if;
end function;
Run Code Online (Sandbox Code Playgroud)
此代码用于更复杂的过程,Foo中的查询使用多个表.
我需要在asp.net应用程序中从Foo返回的数据,但是当Foo找到一些数据时我也需要做一些事情.
我想在几个地方重用查询,但我认为这不适合视图.
什么是最好的方式来知道Foo是否找到了什么?
谢谢.
我有一个过程,它使用refcursor获取输出,并且游标中的数据/结构将是动态的.每次都取决于输入数据类型而光标中没有列会有所不同.那么如何访问此结构并获取数据类型?
PROCEDURE PROC_B ( name_ IN VARCHAR2,
date_ IN DATE,
code_ IN VARCHAR2,
sp_name_ IN VARCHAR2,
wrapper_ OUT sys_refcursor,
datyapes_ OUT VARCHAR2,
TS2_ OUT VARCHAR2,
header_ OUT VARCHAR2)
AS
TS_ DATE;
BEGIN
PROC_A (name_, date_, code_, sp_name_, wrapper_, TS_, header_);
TS2_:= TO_CHAR(TS_, 'MM-DD-YYYY.HH24_MI');
-- Logic should come here for below requirement
-- Get the datatypes of variables from wrapper_ (ref cursor datatype) and send them back in datyapes_ .
-- Eg1 : If ref cursor returns 2 values with dataytpes …Run Code Online (Sandbox Code Playgroud) 我有一个PostgreSQL函数,它选择数据并通过refcursor返回它,类似于以下声明:
CREATE OR REPLACE FUNCTION my_function()
RETURNS refcursor AS
...
Run Code Online (Sandbox Code Playgroud)
如何通过CodeIgniter模型从此功能检索数据?我不能直接从函数中选择SELECT,因为它不直接返回数据.
ref-cursor ×8
oracle ×6
plsql ×4
postgresql ×3
cursor ×2
mysql ×2
oracle11g ×2
codeigniter ×1
java ×1
jdbc ×1
php ×1
record ×1