loadet> er nu tilbage på arbejde - og har fundet den ref. jeg havde. Håber du kan have glæde af den:
SNIP:
Getting a Result Set Without Using OracleTypes.CURSOR
I tried to retrieve a refcursor from a stored procedure, using OracleTypes. CURSOR, and it works. But to do this I have to load the oracle.jdbc.driver, which is not agreeable. I need to use java.sql and retrieve multiple rows, using a stored procedure. Is there a way to retrieve multiple records by calling a stored procedure from a Java program without using the OracleTypes. CURSOR and not loading the oracle.jdbc.driver?
Basically you need a method to get a result set in JDBC without using any Oracle extensions. Instead of calling a stored procedure to get a query result, use a query to call a stored procedure, and that procedure then becomes the result set.
Here is a small example. You must create an object type in SQL to represent your result set type. For example, if I wanted to be able to return a result set with X and Y of type number, I would do the following:
ops$tkyte@DEV8I.WORLD> create or replace
type myScalarType
2 as object ( x int, y int )
3 /
Type created.
ops$tkyte@DEV8I.WORLD> create or replace
type myTableType
2 as table of myScalarType;
3 /
Type created.
Now I can create a function that returns that type.
ops$tkyte@DEV8I.WORLD> create or replace
2 function demo_proc2( p_rows_to_make_up in number )
3 return myTableType
4 as
5 l_data myTableType := myTableType();
6 begin
7 for i in 1 .. p_rows_to_make_up
8 loop
9 l_data.extend;
10 l_data(i) := myScalarType( i, i );
11 end loop;
12 return l_data;
13 end;
14 /
Function created.
Next, I select * from the stored procedure:
ops$tkyte@DEV8I.WORLD> select *
2 from the ( select cast( demo_proc2(5)
as mytableType )
3 from dual );
X Y
------ ------
1 1
2 2
3 3
4 4
5 5
ops$tkyte@DEV8I.WORLD>
In this fashion, Java never calls a stored procedure but instead invokes the above Select statement, which calls the stored procedure and gives you a result set. This "trick" of selecting from a stored procedure has many other useful applications as well. For another use of this feature, see "In List Question with Bind Variables" (
http://osi.oracle.com/wa /ask/owa/ask_tom_pkg.display?p_dispid=139812348065).