ref-cursor

Parameter issue with Oracle RefCursor

随声附和 提交于 2019-12-11 16:47:45
问题 I'm using ODP.NET (migrating from Microsoft's provider), and I have got stuck on a stored procedure that returns a refcursor. I have the following PL/SQL procedure (I have changed it a little bit to make it more general): PROCEDURE MyProc(parameter_no1 IN NUMBER, parameter_no2 IN NUMBER, RETCURSOR OUT ret_type) AS BEGIN OPEN RETCURSOR FOR SELECT ad.logo logo FROM tab_a a, tab_h h WHERE a.id IS NOT NULL AND a.h_id = h.id AND a.no1 = parameter_no1 AND a.no2= parameter_no2; END HanteraLogotype;

Returning a ref cursor from a Oracle Function

99封情书 提交于 2019-12-10 11:47:56
问题 I am getting the error - PLS-00382 Expression is of wrong type. I want to get the ref cursor as output. please let me know how can I do this create or replace function test_cur return sys_refcursor as var_ref sys_refcursor; begin open var_ref for select item,status from item_master where rownum <10; return var_ref; end; declare l_var sys_refcursor; l_item varchar2(100); l_status varchar2(10); begin l_var:=test_cur; open l_var; loop fetch l_var into l_item,l_status; exit when l_var%notfound;

How to access the procedure that return setof refcursor from PostgreSQL in Java?

萝らか妹 提交于 2019-12-08 03:48:29
Need to access a procedure that return setof refcursor from PostgreSQL. I am able to access the first object but not rest of object not rest of objects. con.setAutoCommit(false); try (CallableStatement proc = con.prepareCall("{ ? = call usp_sel_article_initialdata_new1() }")) { proc.registerOutParameter(1, Types.OTHER); proc.execute(); ResultSet results = (ResultSet) proc.getObject(1); while (results.next()) { System.out.println("Result Id" + results.getString(1)); System.out.println("Results Name" + results.getString(2)); } This give me the first refcursor values but when i try to use second

How to use record to loop a ref cursor?

淺唱寂寞╮ 提交于 2019-12-04 16:12:57
I want to write PL/SQL to test a function in a package. The package defines a cursor type TYPE ref_cursor IS REF CURSOR; I want to define a record based on that type. My code is: DECLARE cur PACKAGE_NAME.ref_cursor; rec cur%ROWTYPE; why is last line not correct? You can't define a record type based on a weakly-typed REF CURSOR. Since the cursor type defined in the package can be used to return data from an arbitrary query with arbitrary columns, the PL/SQL compiler can't determine an appropriate record type to fetch the data into. If you know the actual data being returned from the function,

CURSOR and REF CURSOR as a JDBC data type

萝らか妹 提交于 2019-12-04 12:53:33
Many RDBMS support "CURSOR" types of some sort. Those types are mostly useful when returned from stored procedures. An example in Oracle: TYPE t_cursor_type IS REF CURSOR; CREATE PROCEDURE p (c OUT t_cursor_type); When calling this procedure using JDBC, the OracleTypes.CURSOR = -10 "JDBC" type should be used. This type is not part of any standard and it is not going to be part of JDBC 4.1 in Java 7. Does anyone know whether the JSR guys will consider adding this type to the standard some time in the future? Or if other RDBMS have a similar "vendor-specific type"? Support for REF CURSORS was

How to access the structure and get the column list ,datatypes of refcursor?

こ雲淡風輕ζ 提交于 2019-11-30 07:39:38
问题 I have a procedure which gets me the output with refcursor and data/structure in cursor will be dynami. Each time depending on inputs datatypes and no of columns in cursor will vary. So how can I access this structure and get the datatypes ? 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_,

Calling a function that returns a refcursor

依然范特西╮ 提交于 2019-11-28 11:03:28
I am using Postgresql 8.3 and have the following simple function that will return a refcursor to the client CREATE OR REPLACE FUNCTION function_1() RETURNS refcursor AS $$ DECLARE ref_cursor REFCURSOR; BEGIN OPEN ref_cursor FOR SELECT * FROM some_table; RETURN (ref_cursor); END; $$ LANGUAGE plpgsql; Now , I can use the following SQL commands to call this function and manipulate the returned cursor ,but the cursor name is automatically generated by the PostgreSQL BEGIN; SELECT function_1(); --It will output the generated cursor name , for example , "<unnamed portal 11>" ; FETCH 4 from "<unnamed

Use text output from a function as new query

爱⌒轻易说出口 提交于 2019-11-28 00:27:53
In continuing from a previous case that was assisted by @Erwin Brandstetter and @Craig Ringer, I have fixed my code to become as follows. Note, that my function myresult() outputs now text , and not a table (as indeed, as was pointed out in the former case, there is no point in outputting a table object, since we would need to define all its columns ahead, which basically defies the entire purpose): CREATE OR REPLACE FUNCTION myresult(mytable text, myprefix text) RETURNS text AS $func$ DECLARE myoneliner text; BEGIN SELECT INTO myoneliner 'SELECT ' || string_agg(quote_ident(column_name::text),

What is the equivalent of Oracle’s REF CURSOR in MySQL when using JDBC?

别等时光非礼了梦想. 提交于 2019-11-27 23:22:11
In Oracle I can declare a reference cursor... TYPE t_spool IS REF CURSOR RETURN spool%ROWTYPE; ...and use it to pass a cursor as the return value... 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; ...and then capture it as a result set using JDBC... private Connection conn; private CallableStatement stmt; private OracleResultSet rset; [...clip...] stmt = conn.prepareCall("{ ? = call " + call + "}"); stmt.registerOutParameter(1, OracleTypes.CURSOR); stmt.execute(); rset

How to test an Oracle Stored Procedure with RefCursor return type?

僤鯓⒐⒋嵵緔 提交于 2019-11-27 11:34:00
I'm looking for a good explanation on how to test an Oracle stored procedure in SQL Developer or Embarcardero Rapid XE2. Thank you. Something like create or replace procedure my_proc( p_rc OUT SYS_REFCURSOR ) as begin open p_rc for select 1 col1 from dual; end; / variable rc refcursor; exec my_proc( :rc ); print rc; will work in SQL*Plus or SQL Developer. I don't have any experience with Embarcardero Rapid XE2 so I have no idea whether it supports SQL*Plus commands like this. DCookie Something like this lets you test your procedure on almost any client: DECLARE v_cur SYS_REFCURSOR; v_a