Help! Need oracle help with constructing stored procedure that return resultsets
Suns tutorial path for returning resultsets from stored procedures indicates that the following should work...
CallableStatement cs = con.prepareCall("{call SHOW_SUPPLIERS}");
ResultSet rs = cs.executeQuery();
Thats if you build your stored procedure something like this ...
String createProcedure = "create procedure SHOW_SUPPLIERS " + "as " + "select SUPPLIERS.SUP_NAME, COFFEES.COF_NAME " + "from SUPPLIERS, COFFEES " + "where SUPPLIERS.SUP_ID = COFFEES.SUP_ID " + "order by SUP_NAME";
We are using oracle 8.1.6. However I've been told that with oracle procedures when you return a result set from a called procedure you return a p_cursor variable. Somthing like this
(p_cursor in out SHOW_SUPPLIERS.SHOCurTyp)
is
begin
open p_cursor for
select * from suppliers
In which case the above mentioned sun code doesn't work.
We want to use jdbc to call a stored procedure that returns a resultset that does not require us to import any proprietary oracle objects...
Is there another way to write these stored procedures, rather than using this cursor construct? Are we missing something in the way we invoke them?
Suns tutorial path for returning resultsets from stored procedures indicates that the following should work...
CallableStatement cs = con.prepareCall("{call SHOW_SUPPLIERS}");
ResultSet rs = cs.executeQuery();
Thats if you build your stored procedure something like this ...
String createProcedure = "create procedure SHOW_SUPPLIERS " + "as " + "select SUPPLIERS.SUP_NAME, COFFEES.COF_NAME " + "from SUPPLIERS, COFFEES " + "where SUPPLIERS.SUP_ID = COFFEES.SUP_ID " + "order by SUP_NAME";
We are using oracle 8.1.6. However I've been told that with oracle procedures when you return a result set from a called procedure you return a p_cursor variable. Somthing like this
(p_cursor in out SHOW_SUPPLIERS.SHOCurTyp)
is
begin
open p_cursor for
select * from suppliers
In which case the above mentioned sun code doesn't work.
We want to use jdbc to call a stored procedure that returns a resultset that does not require us to import any proprietary oracle objects...
Is there another way to write these stored procedures, rather than using this cursor construct? Are we missing something in the way we invoke them?
Similar Messages
-
Need Help With a Stored Procedure
Help With a Stored Procedure
Hi everyone.
I am quite new relative to creating stored procedures, so I anticipate that whatever help I could get here would be very much helpful.
Anyway, here is my case:
I have a table where I need to update some fields with values coming from other tables. The other tables, let us just name as tblRef1, tblRef2 and tblRef3. For clarity, let us name tblToUpdate as my table to update. tblToUpdate has the following fields.
PlanID
EmployeeIndicator
UpdatedBy
CreatedBy
tblRef1, tblRef2 and tblRef3 has the following fields:
UserName
EmpIndicator
UserID
In my stored procedure, I need to perform the following:
1. Check each row in the tblToUpdate table. Get the CreatedBy value and compare the same to the UserName and UserID field of tblRef1. If no value exists in tblRef1, I then proceed to check if the value exists in the same fields in tblRef2 and tblRef3.
2. If the value is found, then I would update the EmployeeIndicator field in tblToUpdate with the value found on either tblRef1, tblRef2 or tblRef3.
I am having some trouble writing the stored procedure to accomplish this. So far, I have written is the following:
CREATE OR REPLACE PROCEDURE Proc_Upd IS v_rec NUMBER;
v_plan_no tblToUpdate.PLANID%TYPE;
v_ref_ind tblToUpdate.EMPLOYEEINDICATOR%TYPE;
v_update_user tblToUpdate.UPDATEDBY%TYPE;
v_created_by tblToUpdate.CREATEDBY%TYPE;
v_correct_ref_ind tblToUpdate.EMPLOYEEIDICATOR%TYPE;
CURSOR cur_plan IS SELECT PlanID, EmployeeIndicator, UPPER(UpdatedBy), UPPER(CreatedBy) FROM tblToUpdate;
BEGIN
Open cur_plan;
LOOP
FETCH cur_plan INTO v_plan_no, v_ref_ind, v_update_user, v_created_by;
EXIT WHEN cur_plan%NOTFOUND;
BEGIN
-- Check if v_created_by has value.
IF v_created_by IS NOT NULL THEN
-- Get the EmpIndicator from the tblRef1, tblRef2 or tblRef3 based on CreatedBy
SELECT UPPER(EmpIndicator)
INTO v_correct_ref_ind
FROM tblRef1
WHERE UPPER(USERNAME) = v_created_by
OR UPPER(USERID) = v_created_by;
IF v_correct_ref_ind IS NOT NULL THEN
-- Update the Reference Indicator Field in the table TRP_BUSPLAN_HDR_T.
UPDATE TRP_BUSPLAN_HDR_T SET ref_ind = v_correct_ref_ind WHERE plan_no = v_plan_no;
ELSIF
-- Check the Other tables here????
END IF;
ELSIF v_created_by IS NULL THEN
-- Get the EmpIndicator based on the UpdatedBy
SELECT UPPER(EmpIndicator)
INTO v_correct_ref_ind
FROM tblRef1
WHERE UPPER(USERNAME) = v_update_user
OR UPPER(USERID) = v_created_by;
IF v_correct_ref_ind IS NOT NULL THEN
-- Update the Reference Indicator Field in the table TRP_BUSPLAN_HDR_T.
UPDATE TRP_BUSPLAN_HDR_T SET ref_ind = v_correct_ref_ind WHERE plan_no = v_plan_no;
ELSIF
-- Check the Other tables here????
END IF;
END IF;
END;
END LOOP;
CLOSE cur_plan;
COMMIT;
END
Please take note that the values in the column tblToUpdate.UpdatedBy or tblToUpdate.CreatedBy could match either the UserName or the UserID of the table tblRef1, tblRef2, or tblRef3.
Kindly provide more insight. When I try to execute the procedure above, I get a DATA NOT FOUND ERROR.
Thanks.Ah, ok; I got the updates the wrong way round then.
BluShadow's single update sounds like what you need then.
I also suggest you read this AskTom link to help you see why you should choose to write DML statements before choosing to write cursor + loops.
In general, when you're being asked to update / insert / delete rows into a table or several tables, your first reaction should be: "Can I do this in SQL?" If you can, then putting it into a stored procedure is usually just a case of putting the sql statement inside the procedure header/footers - can't really get much more simple than that! *{;-) -
Using XI - RFC table and an Oracle stored procedure that returns a cursor.
I need to create an interface using XI between an RFC table and an Oracle stored procedure that returns a cursor. We are on oarcle 9.2 and SP12.
My stored procedure looks something like this:
CREATE OR REPLACE
PROCEDURE testproc_xi2 (p_recordset1 OUT SYS_REFCURSOR,
in_quoteid IN varchar2 )
AS
BEGIN
OPEN p_recordset1 FOR
SELECT q.quote_id,
q.modified_by,
q.quote_status,
q.total_cost
FROM quote q
WHERE q.quote_id = in_quoteid
AND q.total_cost > 0 ;
END testproc_xi2 ;
My RFC has table and one import parameter .
I wanted to know how to create the data type for the ref cursor? and also for the table type in the RFC?
CAN XI handle multi rows coming from a Stored procedure? Are there any other alternative methods if this is not supported?Any pointers to this would be helpful.
I have called a Oracle SP from an RFC before, but that interface had one input parameter going to the stored procedure from the RFC and about 6 o/p parameters coming from the Stored procedure. This works fine.
Thanks for the help.
MalaMala,
i dont think there is anything called an rfc table...RFC stands for remote function call. That in essence would imply you need a rfc to jdbc connection.
yes XI can handle multiple rows cooming from the the stored procedure if you have them mapped appropriately.
Now as to how to create the data type within xi , you need to know what fields are going to be returned and whether they are nested and then just create them as you would for an xml
for ex
<Details>
<FirstName>
<LastName>
</Details>
that in xi would be smthing like
Details type of data occurence
FirstName type of data occurence
LastName type of data occurence.
Hope that helps.
If it does dont forget the points..:-) -
How Do I Call PL/SQL Stored Procedure That Returns String Array??
I Have Problem Calling An Oracle(8i) Stored Procedure That Returns Array Type (Multi Rows)
(As Good As String Array Type..)
In This Fourm, I Can't Find Out Example Source.
(Question is Exist.. But No Answer..)
I Want An Example,, Because I'm A Beginner...
(I Wonder...)
If It Is Impossible, Please Told Me.. "Impossible"
Then, I'll Give Up to Resolve This Way.....
Please Help Me !!!
Thanks in advance,// Try the following, I appologize that I have not compiled and run this ... but it is headed in the right direction
import java.sql.*;
class RunStoredProc
public static void main(String args[])
throws SQLException
try
Class.forName("oracle.jdbc.driver.OracleDriver");
catch(Exception ex)
ex.printStackTrace();
java.util.Properties props = new java.util.Properties();
props.put("user", "********"); // you need to replace stars with db userid
props.put("password", "********"); // you need to replace stars with userid db password
// below replace machine.domain.com and DBNAME, and port address if different than 1521
Connection conn =
DriverManager.getConnection("jdbc:oracle:thin:@machine.domain.com:1521:DBNAME", props);
// replace "Your Stored Procedure" with your stored procedure
CallableStatement stmt = conn.prepareCall("Your Stored Procedure");
ResultSet rset = stmt.execute();
while(rset.next())
System.out.println(rset.getString(1)); -
Stored procedure that returns multiple tables
Hello everyone,
I was wondering if there's a way to write a stored procedure that returns multiple result set as in sql server. for example, in sql server, you can write 2 select statements and when loading them in c#, u can get two data tables.
I am not sure having a single ref cursor for each select is the only solution. I might need to return a variable number of tables per procedure call (based on a certain criteria).
Any ideas?
thanks for your timeSure. Ref cursor is the only easier answer for your problem.
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
Elapsed: 00:00:01.43
satyaki>
satyaki>create or replace procedure ref_gen_arg(choice in int,b in out sys_refcursor)
2 is
3 str varchar2(500);
4 begin
5 if choice = 1 then
6 str := 'select * from emp';
7 elsif choice = 2 then
8 str := 'select * from dept';
9 end if;
10
11 open b for str;
12 exception
13 when others then
14 dbms_output.put_line(sqlerrm);
15 end;
16 /
Procedure created.
Elapsed: 00:00:04.38
satyaki>
satyaki>
satyaki>declare
2 rec_x emp%rowtype;
3 rec_y dept%rowtype;
4 w sys_refcursor;
5 begin
6 dbms_output.enable(1000000);
7 ref_gen_arg(1,w);
8 loop
9 fetch w into rec_x;
10 exit when w%notfound;
11 dbms_output.put_line('Employee No: '||rec_x.empno||' - '||
12 'Name: '||rec_x.ename||' - '||
13 'Job: '||rec_x.job||' - '||
14 'Manager: '||rec_x.mgr||' - '||
15 'Joining Date: '||rec_x.hiredate||' - '||
16 'Salary: '||rec_x.sal||' - '||
17 'Commission: '||rec_x.comm||' - '||
18 'Department No: '||rec_x.deptno);
19 end loop;
20 close w;
21
22 ref_gen_arg(2,w);
23 loop
24 fetch w into rec_y;
25 exit when w%notfound;
26 dbms_output.put_line('Department No: '||rec_y.deptno||' - '||
27 'Name: '||rec_y.dname||' - '||
28 'Location: '||rec_y.loc);
29 end loop;
30 close w;
31 exception
32 when others then
33 dbms_output.put_line(sqlerrm);
34 end;
35 /
Employee No: 9999 - Name: SATYAKI - Job: SLS - Manager: 7698 - Joining Date: 02-NOV-08 - Salary: 55000 - Commission: 3455 - Department No: 10
Employee No: 7777 - Name: SOURAV - Job: SLS - Manager: - Joining Date: 14-SEP-08 - Salary: 45000 - Commission: 3400 - Department No: 10
Employee No: 7521 - Name: WARD - Job: SALESMAN - Manager: 7698 - Joining Date: 22-FEB-81 - Salary: 1250 - Commission: 500 - Department No: 30
Employee No: 7566 - Name: JONES - Job: MANAGER - Manager: 7839 - Joining Date: 02-APR-81 - Salary: 2975 - Commission: - Department No: 20
Employee No: 7654 - Name: MARTIN - Job: SALESMAN - Manager: 7698 - Joining Date: 28-SEP-81 - Salary: 1250 - Commission: 1400 - Department No: 30
Employee No: 7698 - Name: BLAKE - Job: MANAGER - Manager: 7839 - Joining Date: 01-MAY-81 - Salary: 2850 - Commission: - Department No: 30
Employee No: 7782 - Name: CLARK - Job: MANAGER - Manager: 7839 - Joining Date: 09-JUN-81 - Salary: 4450 - Commission: - Department No: 10
Employee No: 7788 - Name: SCOTT - Job: ANALYST - Manager: 7566 - Joining Date: 19-APR-87 - Salary: 3000 - Commission: - Department No: 20
Employee No: 7839 - Name: KING - Job: PRESIDENT - Manager: - Joining Date: 17-NOV-81 - Salary: 7000 - Commission: - Department No: 10
Employee No: 7844 - Name: TURNER - Job: SALESMAN - Manager: 7698 - Joining Date: 08-SEP-81 - Salary: 1500 - Commission: 0 - Department No: 30
Employee No: 7876 - Name: ADAMS - Job: CLERK - Manager: 7788 - Joining Date: 23-MAY-87 - Salary: 1100 - Commission: - Department No: 20
Employee No: 7900 - Name: JAMES - Job: CLERK - Manager: 7698 - Joining Date: 03-DEC-81 - Salary: 950 - Commission: - Department No: 30
Employee No: 7902 - Name: FORD - Job: ANALYST - Manager: 7566 - Joining Date: 03-DEC-81 - Salary: 3000 - Commission: - Department No: 20
Department No: 10 - Name: ACCOUNTING - Location: NEW YORK
Department No: 20 - Name: RESEARCH - Location: DALLAS
Department No: 30 - Name: SALES - Location: CHICAGO
Department No: 40 - Name: LOGISTICS - Location: CHICAGO
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.73
satyaki>Regards.
Satyaki De. -
Call a Stored Procedure that returns a REFCURSOR using ODI Procedure
Hi,
I have a scenario wherein the stored procedure (TEST_PROC1) that returns a REFCURSOR. The second procedure(TEST_PROC2) will use the REFCURSOR as inpuut and insert it to a table.
Now, I need to execute the test procedures (TEST_PROC1 and TEST_PROC2) using the ODI Procedure but I always get error. However, I was able to execute the test procedures using sqlplus. Here is the command I used for sqlplus:
var rc refcursor
exec TEST_PROC1(:rc);
exec TEST_PROC2(:rc);
PL/SQL Stored Procedure:
-- TEST_PROC1 --
create or replace
PROCEDURE TEST_PROC1 (p_cursor IN OUT SYS_REFCURSOR)
AS
BEGIN
OPEN p_cursor FOR
SELECT *
FROM test_table1;
END;
-- TEST_PROC2 --
create or replace
procedure TEST_PROC2( rc in out sys_refcursor ) is
FETCH_LIMIT constant integer := 100;
type TFetchBuffer is table of test_table2%RowType;
buffer TFetchBuffer;
begin
loop
fetch rc bulk collect into buffer limit FETCH_LIMIT;
forall i in 1..buffer.Count
insert into test_table2(
c1, c2
) values(
buffer(i).c1, buffer(i).c2
exit when rc%NotFound;
end loop;
end;
Is there a way to call a PL/SQL Stored Procedure that returns a REFCURSOR using ODI Procedure?
Thanks,
CathyThanks for the reply actdi.
The procedure TEST_PROC1 is just a sample procedure. The requirement is that I need to call a stored procedure that returns a cursor using ODI and fetch the data and insert into a table, which in this case is test_table2.
I was able to execute a simple SQL procedure (without cursor) using ODI procedure. But when i try to execute the SQL procedure with cursor in ODI, I encountered error.
Do you have any idea how to do this? -
Function calling stored procedure that returns a cursor into a LOV
Hello,
Is it possible in HTML DB to implement a process that has a function that calls a stored procedure that returns a cursor, used to then populate a select list?
Or can I do a function call to a stored procedure in the 'List of values definition' box for the item itself that returns a cursor to populate the item's select list?Hi Vikas,
Actually, I just found another posting that shows how to do what I'm looking for:
Re: Filling a LOV with a cursor
Check it out. I posted another question in response to that discussion...maybe you could answer that? Thanks!
Laura -
Stored procedure that returns a cursor (result set)
Hi,
We have a stored procedure that returns a cursor (result set) but when I compliled it and catalouged (introspected) it in the OBPM I got all the primitive type parameters (either IN or OUT) in the proc call except the cursor type (the result set) which is the out param of the stored proc.
Any pointers please?
ThanksResult set is of RowType and is not supported as a Stored Procedure as far as I know.
HTH
Sharma -
How to execute stored procedure that returns a cursor?
How to execute a stored procedure that returns a cursor?
Follow the code:
CREATE OR REPLACE PROCEDURE stp_cashin_grupo
(p_func IN VARCHAR
,p_cod_grup IN Integer
,p_des_grup IN VARCHAR
,p_logi IN VARCHAR
,p_curs_rset OUT infoc.pck_cashin_grupo.curs_rset
IS
BEGIN
if p_func = '1' then
OPEN p_curs_rset FOR
select
cod_grup
,des_grup
,dat_manu_grup
,des_logi_manu
from infoc.tbl_cashin_grupo
order by des_grup;
end if;
END stp_cashin_grupo;
and the package:
CREATE OR REPLACE PACKAGE pck_cashin_grupo
AS
TYPE curs_rset IS REF CURSOR;
END pck_cashin_grupo;
My question is how to execute in sql plus?
EXEC stp_cashin_grupo('1',0,'','465990', my doubt is how to pass the cursor as return
Thanksmy doubt is how to pass the cursor as returnExample :
TEST@db102 > var c1 refcursor;
TEST@db102 > create or replace procedure ref1 (
2 v1 in varchar2,
3 cur1 out sys_refcursor)
4 is
5 begin
6 open cur1 for 'select * from '||v1;
7 end;
8 /
Procedure created.
TEST@db102 > exec ref1('dept',:c1);
PL/SQL procedure successfully completed.
TEST@db102 > print c1
DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
TEST@db102 > -
Call to Oracle stored procedure that returns ref cursor doesn't work
I'm trying to use an OData service operation with Entity Framework to call an Oracle stored procedure that takes an number as an input parameter and returns a ref cursor. The client is javascript so I'm using the rest console to test my endpoints. I have been able to successful call a regular Oracle stored procedure that takes a number parameter but doesn't return anything so I think I have the different component interactions correct. When I try calling the proc that has an ref cursor for the output I get the following an error "Invalid number or type of parameters". Here are my specifics:
App.config
<oracle.dataaccess.client>
<settings>
<add name="PGDATA_WC.ODATAPOC.GETWORKORDERSBYWINDFARMID.RefCursor.P_RESULTS" value="implicitRefCursor bindinfo='mode=Output'" />
<add name="PGDATA_WC.ODATAPOC.GETWORKORDERSBYWINDFARMID.RefCursorMetaData.P_RESULTS.Column.0" value="implicitRefCursor metadata='ColumnName=WINDFARM_ID;BaseColumnName=WINDFARM_ID;BaseSchemaName=PGDATA_WC;BaseTableName=WORKORDERS;NATIVEDATATYPE=Number;ProviderType=Int32'" />
<add name="PGDATA_WC.ODATAPOC.GETWORKORDERSBYWINDFARMID.RefCursorMetaData.P_RESULTS.Column.1" value="implicitRefCursor metadata='ColumnName=STARTTIME;BaseColumnName=STARTTIME;BaseSchemaName=PGDATA_WC;BaseTableName=WORKORDERS;NATIVEDATATYPE=Varchar2;ProviderType=Varchar2'" />
<add name="PGDATA_WC.ODATAPOC.GETWORKORDERSBYWINDFARMID.RefCursorMetaData.P_RESULTS.Column.2" value="implicitRefCursor metadata='ColumnName=ENDTIME;BaseColumnName=ENDTIME;BaseSchemaName=PGDATA_WC;BaseTableName=WORKORDERS;NATIVEDATATYPE=Varchar2;ProviderType=Varchar2'" />
<add name="PGDATA_WC.ODATAPOC.GETWORKORDERSBYWINDFARMID.RefCursorMetaData.P_RESULTS.Column.3" value="implicitRefCursor metadata='ColumnName=TURBINE_NUMBER;BaseColumnName=TURBINE_NUMBER;BaseSchemaName=PGDATA_WC;BaseTableName=WORKORDERS;NATIVEDATATYPE=Varchar2;ProviderType=Varchar2'" />
<add name="PGDATA_WC.ODATAPOC.GETWORKORDERSBYWINDFARMID.RefCursorMetaData.P_RESULTS.Column.4" value="implicitRefCursor metadata='ColumnName=NOTES;BaseColumnName=NOTES;BaseSchemaName=PGDATA_WC;BaseTableName=WORKORDERS;NATIVEDATATYPE=Varchar2;ProviderType=Varchar2'" />
<add name="PGDATA_WC.ODATAPOC.GETWORKORDERSBYWINDFARMID.RefCursorMetaData.P_RESULTS.Column.5" value="implicitRefCursor metadata='ColumnName=TECHNICIAN_NAME;BaseColumnName=TECHNICIAN_NAME;BaseSchemaName=PGDATA_WC;BaseTableName=WORKORDERS;NATIVEDATATYPE=Varchar2;ProviderType=Varchar2'" />
<add name="PGDATA_WC.ODATAPOC.GETWORKORDERSBYID.RefCursor.P_RESULTS" value="implicitRefCursor bindinfo='mode=Output'" />
</settings>
OData Service Operation:
public class OracleODataService : DataService<OracleEntities>
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
// TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
// Examples:
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.SetServiceOperationAccessRule("GetWorkOrdersByWindfarmId", ServiceOperationRights.All);
config.SetServiceOperationAccessRule("CreateWorkOrder", ServiceOperationRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
[WebGet]
public IQueryable<GetWorkOrdersByWindfarmId_Result> GetWorkOrdersByWindfarmId(int WindfarmId)
return this.CurrentDataSource.GetWorkOrdersByWindfarmId(WindfarmId).AsQueryable();
[WebGet]
public void CreateWorkOrder(int WindfarmId)
this.CurrentDataSource.CreateWorkOrder(WindfarmId);
Here is the stored procedure:
procedure GetWorkOrdersByWindFarmId(WINDFARMID IN NUMBER,
P_RESULTS OUT REF_CUR) is
begin
OPEN P_RESULTS FOR
select WINDFARM_ID,
STARTTIME,
ENDTIME,
TURBINE_NUMBER,
NOTES,
TECHNICIAN_NAME
from WORKORDERS
where WINDFARM_ID = WINDFARMID;
end GetWorkOrdersByWindFarmId;
I defined a function import for the stored procedure using the directions I found online by creating a new complex type. I don't know if I should be defining the input parameter, WindfarmId, in my app.config? If I should what would that format look like? I also don't know if I'm invoking the stored procedure correctly in my service operation? I'm testing everything through the rest console because the client consuming this information is written in javascript and expecting a json format. Any help is appreciated!
Edited by: 1001323 on Apr 20, 2013 8:04 AM
Edited by: jennyh on Apr 22, 2013 9:00 AMMaking the change you suggested still resulted in the same Oracle.DataAccess.Client.OracleException {"ORA-06550: line 1, column 8:\nPLS-00306: wrong number or types of arguments in call to 'GETWORKORDERSBYWINDFARMID'\nORA-06550: line 1, column 8:\nPL/SQL: Statement ignored"} System.Exception {Oracle.DataAccess.Client.OracleException}
I keep thinking it has to do with my oracle.dataaccess.client settings in App.Config because I don't actually put the WindfarmId and an input parameter. I tried a few different ways to do this but can't find the correct format. -
Invoking stored procedure that returns array(oracle object type) as output
Hi,
We have stored procedures which returns arrays(oracle type) as an output, can anyone shed some light on how to map those arrays using JPA annotations? I tried using jdbcTypeName but i was getting wrong type or argument error, your help is very much appreciated. Below is the code snippet.
JPA Class:
import java.io.Serializable;
import java.sql.Array;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.Id;
import org.eclipse.persistence.annotations.Direction;
import org.eclipse.persistence.annotations.NamedStoredProcedureQuery;
import org.eclipse.persistence.annotations.StoredProcedureParameter;
* The persistent class for the MessagePublish database table.
@Entity
@NamedStoredProcedureQuery(name="GetTeamMembersDetails",
procedureName="team_emp_maintenance_pkg.get_user_team_roles",
resultClass=TeamMembersDetails.class,
returnsResultSet=true,
parameters={
@StoredProcedureParameter(queryParameter="userId",name="I_USER_ID",direction=Direction.IN,type=Long.class),
@StoredProcedureParameter(queryParameter="employeeId",name="I_EMPLOYEEID",direction=Direction.IN,type=Long.class),
@StoredProcedureParameter(queryParameter="TEAMMEMBERSDETAILSOT",name="O_TEAM_ROLES",direction=Direction.OUT,jdbcTypeName="OBJ_TEAM_ROLES"),
@StoredProcedureParameter(queryParameter="debugMode",name="I_DEBUGMODE",direction=Direction.IN,type=Long.class)
public class TeamMembersDetails implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private long userId;
private List<TeamMembersDetailsOT> teamMembersDetailsOT;
public void setTeamMembersDetailsOT(List<TeamMembersDetailsOT> teamMembersDetailsOT) {
this.teamMembersDetailsOT = teamMembersDetailsOT;
public List<TeamMembersDetailsOT> getTeamMembersDetailsOT() {
return teamMembersDetailsOT;
Procedure
PROCEDURE get_user_team_roles (
i_user_id IN ue_user.user_id%TYPE
, o_team_roles OUT OBJ_TEAM_ROLES_ARRAY
, i_debugmode IN NUMBER :=0)
AS
OBJ_TEAM_ROLES_ARRAY contains create or replace TYPE OBJ_TEAM_ROLES_ARRAY AS TABLE OF OBJ_TEAM_ROLES;
TeamMembersDetailsOT contains the same attributes defined in the OBJ_TEAM_ROLES.A few things.
You are not using a JDBC Array type in your procedure, you are using a PLSQL TABLE type. An Array type would be a VARRAY in Oracle. EclipseLink supports both VARRAY and TABLE types, but TABLE types are more complex as Oracle JDBC does not support them, they must be wrapped in a corresponding VARRAY type. I assume your OBJ_TEAM_ROLES is also not an OBJECT TYPE but a PLSQL RECORD type, this has the same issue.
Your procedure does not return a result set, so "returnsResultSet=true" should be "returnsResultSet=false".
In general I would recommend you change your stored procedure to just return a select from a table using an OUT CURSOR, that is the easiest way to return data from an Oracle stored procedure.
If you must use the PLSQL types, then you will need to create wrapper VARRAY and OBJECT TYPEs. In EclipseLink you must use a PLSQLStoredProcedureCall to access these using the code API, there is not annotation support. Or you could create your own wrapper stored procedure that converts the PLSQL types to OBJECT TYPEs, and call the wrapper stored procedure.
To map to Oracle VARRAY and OBJECT TYPEs the JDBC Array and Struct types are used, these are supported using EclipseLink ObjectRelationalDataTypeDescriptor and mappings. These must be defined through the code API, as there is currently no annotation support.
I could not find any good examples or doc on this, your best source of example is the EclipseLink test cases in SVN,
http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/plsql/
http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/customsqlstoredprocedures/
James : http://www.eclipselink.org -
Issue with a stored procedure that uses a sys refcursor to output dataset..
Hi All:
I create a stored procedure that uses an in out sys ref cursor:
create or replace procedure FIRE_SALES_100_CALLS_REPORT
( p_cursor in out sys_refcursor)
IS
BEGIN
--Insert into the temp table the records for the rep sales
EXECUTE IMMEDIATE '
INSERT INTO TMP_SALES_CNT_BY_USER
TOTALPRODUCTSSOLD,
NUMBEROFCALLS,
SALESPER100CALLS,
SERVICEORDERNUM,
PRODUCT,
LOGIN,
FST_NAME,
LAST_NAME,
NAME,
POSITIONHELD,
CURRENTPARPARTYID,
QUERY_DATE,
CREATED_BY
SELECT e.TotalProductsSold,
e.NumberOfCalls,
((e.TotalProductsSold/e.NumberOfCalls)*100) AS SalesPer100Calls,
e.ServiceOrderNum,
e.Product,
e.login,
e.fst_name,
e.last_name,
e.name,
e.PositionHeld,
e.CurrentParPartyID,
e.query_date,
e.created_by
FROM (
SELECT COUNT(o.order_num) over ( partition by u.login
order by u.login) AS TotalProductsSold,
SUM(NVL(x.n_inbound,1) + NVL(x.n_outbound,1)) over (partition by u.login
order by u.login) AS NumberOfCalls,
o.order_num AS ServiceOrderNum,
pi.name as Product,
u.login,
c.fst_name,
c.last_name,
postn.name,
c.pr_held_postn_id as PositionHeld,
p.par_party_id as CurrentParPartyID,
NVL(x.query_date,NVL(o.last_upd, null)) AS query_date,
o.created_by
FROM firestg.SEB_S_order o
INNER join firestg.seb_s_order_item oi ON o.row_id = oi.order_id
INNER join firestg.seb_s_prod_int pi ON oi.prod_id = pi.row_id
INNER join firestg.SEB_s_contact c on c.Row_Id = o.created_by
INNER join firestg.SEB_s_user u on u.row_id = o.created_By
INNER join firestg.SEB_s_party p on p.row_id = c.pr_held_postn_id
INNER join firestg.SEB_s_postn postn on postn.row_id = c.pr_held_postn_id
LEFT OUTER JOIN (
SELECT taw.QUERY_DATE,
vaw.n_inbound,
vaw.n_outbound,
oaw.object_name, oaw.object_id
FROM GEN_T_AGENT_WEEK taw
INNER JOIN GEN_V_AGENT_WEEK vaw ON taw.time_key = vaw.time_key
INNER JOIN GEN_O_AGENT_WEEK oaw ON oaw.object_id = vaw.object_id) x
ON u.cti_acd_userid = x.object_name
WHERE NVL(x.query_date,NVL(o.last_upd, null)) BETWEEN (TRUNC (next_day (sysdate, ''SUN''))-14)
AND (TRUNC (next_day (sysdate, ''SUN''))-8)
AND o.status_cd IN (''Complete''))e';
--Lookup the first level to see if there is a higher level person
EXECUTE IMMEDIATE '
UPDATE TMP_SALES_CNT_BY_USER a
SET (ParPartyID_1ST, LOGIN_1ST,FST_NAME_1ST,LST_NAME_1ST,TITLE_1ST) =
(SELECT pa.par_party_id,
U.Login,
C.FST_NAME,
C.Last_Name,
p.name
FROM firestg.seb_s_postn p
inner join firestg.seb_s_user U on u.Row_Id = p.pr_emp_id
inner join firestg.seb_s_contact c on c.Row_Id = p.pr_emp_id
INNER join firestg.SEB_s_party pa on pa.row_id = c.pr_held_postn_id
WHERE p.row_id = a.currentparpartyid)
WHERE CurrentParPartyID IS NOT NULL';
--Lookup the second level to see if there is a higher level person
EXECUTE IMMEDIATE '
UPDATE TMP_SALES_CNT_BY_USER a
SET (ParPartyID_2ND, LOGIN_2ND,FST_NAME_2ND,LST_NAME_2ND,TITLE_2ND) =
(SELECT pa.par_party_id,
U.Login,
C.FST_NAME,
C.Last_Name,
p.name
FROM firestg.seb_s_postn p
inner join firestg.seb_s_user U on u.Row_Id = p.pr_emp_id
inner join firestg.seb_s_contact c on c.Row_Id = p.pr_emp_id
INNER join firestg.SEB_s_party pa on pa.row_id = c.pr_held_postn_id
WHERE p.row_id = a.ParPartyID_1ST)
WHERE a.ParPartyID_1ST IS NOT NULL';
--Lookup the third level to see if there is a higher level person
EXECUTE IMMEDIATE '
UPDATE TMP_SALES_CNT_BY_USER a
SET (ParPartyID_3RD, LOGIN_3RD,FST_NAME_3RD,LST_NAME_3RD,TITLE_3RD) =
(SELECT pa.par_party_id,
U.Login,
C.FST_NAME,
C.Last_Name,
p.name
FROM firestg.seb_s_postn p
inner join firestg.seb_s_user U on u.Row_Id = p.pr_emp_id
inner join firestg.seb_s_contact c on c.Row_Id = p.pr_emp_id
INNER join firestg.SEB_s_party pa on pa.row_id = c.pr_held_postn_id
WHERE p.row_id = a.ParPartyID_2ND)
WHERE a.ParPartyID_2ND IS NOT NULL';
--Lookup the fourth level to see if there is a higher level person
EXECUTE IMMEDIATE '
UPDATE TMP_SALES_CNT_BY_USER a
SET (ParPartyID_4TH, LOGIN_4TH,FST_NAME_4TH,LST_NAME_4TH,TITLE_4TH) =
(SELECT pa.par_party_id,
U.Login,
C.FST_NAME,
C.Last_Name,
p.name
FROM firestg.seb_s_postn p
inner join firestg.seb_s_user U on u.Row_Id = p.pr_emp_id
inner join firestg.seb_s_contact c on c.Row_Id = p.pr_emp_id
INNER join firestg.SEB_s_party pa on pa.row_id = c.pr_held_postn_id
WHERE p.row_id = a.ParPartyID_3RD)
WHERE a.ParPartyID_3RD IS NOT NULL';
--Lookup the fifth level to see if there is a higher level person
EXECUTE IMMEDIATE '
UPDATE TMP_SALES_CNT_BY_USER a
SET (ParPartyID_5TH, LOGIN_5TH,FST_NAME_5TH,LST_NAME_5TH,TITLE_5TH) =
(SELECT pa.par_party_id,
U.Login,
C.FST_NAME,
C.Last_Name,
p.name
FROM firestg.seb_s_postn p
inner join firestg.seb_s_user U on u.Row_Id = p.pr_emp_id
inner join firestg.seb_s_contact c on c.Row_Id = p.pr_emp_id
INNER join firestg.SEB_s_party pa on pa.row_id = c.pr_held_postn_id
WHERE p.row_id = a.ParPartyID_4TH)
WHERE a.ParPartyID_4TH IS NOT NULL';
-- If there was no 1st place then the rep is a VP
EXECUTE IMMEDIATE '
UPDATE TMP_SALES_CNT_BY_USER a
SET a.vp = a.last_name || '', '' || a.fst_name,
a.vp_login = a.login
WHERE a.login_1st IS NULL';
--If there is no second place then the rep has a VP and is a Director
EXECUTE IMMEDIATE '
UPDATE TMP_SALES_CNT_BY_USER a
SET a.vp = a.lst_name_1st || '', '' || a.fst_name_1st,
a.vp_login = a.login_1st,
a.director = a.last_name || '', '' || a.fst_name,
a.director_login = a.login
WHERE a.login_1st IS NOT NULL
AND a.login_2ND IS NULL';
--IF there is no third place then the rep has a VP, Director & is a Manager
EXECUTE IMMEDIATE '
UPDATE TMP_SALES_CNT_BY_USER a
SET a.vp = a.lst_name_2ND || '', '' || a.fst_name_2ND,
a.vp_login = a.login_2ND,
a.director = a.lst_name_1st || '', '' || a.fst_name_1st,
a.director_login = a.login_1st,
a.manager = a.last_name || '', '' || a.fst_name,
a.manager_login = a.login
WHERE a.login_1st IS NOT NULL
AND a.login_2ND IS NOT NULL
AND a.login_3rd IS NULL';
--If there is no fourth place then the rep has a VP, Dir, Manager, and is a Supervisor
EXECUTE IMMEDIATE '
UPDATE TMP_SALES_CNT_BY_USER a
SET a.vp = a.lst_name_3RD || '', '' || a.fst_name_3RD,
a.vp_login = a.login_3RD,
a.director = a.lst_name_2ND || '', '' || a.fst_name_2ND,
a.director_login = a.login_2ND,
a.manager = a.lst_name_1st || '', '' || a.fst_name_1st,
a.manager_login = a.login_1st,
a.supervisor = a.last_name || '', '' || a.fst_name,
a.supervisor_login = a.login
WHERE a.login_1st IS NOT NULL
AND a.login_2ND IS NOT NULL
AND a.login_3rd IS NOT NULL
AND a.login_4th IS NULL';
--If there is no fifth plance then the rep has a VP, Dir, Mgr, Supervisor, and is a Team Lead
EXECUTE IMMEDIATE '
UPDATE TMP_SALES_CNT_BY_USER a
SET a.vp = a.lst_name_4TH || '', '' || a.fst_name_4TH,
a.vp_login = a.login_4TH,
a.director = a.lst_name_3RD || '', '' || a.fst_name_3RD,
a.director_login = a.login_3RD,
a.manager = a.lst_name_2ND || '', '' || a.fst_name_2ND,
a.manager_login = a.login_2ND,
a.supervisor = a.lst_name_1st || '', '' || a.fst_name_1st,
a.supervisor_login = a.login_1st,
a.teamlead = a.last_name || '', '' || a.fst_name,
a.teamlead_login = a.login
WHERE a.login_1st IS NOT NULL
AND a.login_2ND IS NOT NULL
AND a.login_3rd IS NOT NULL
AND a.login_4th IS NOT NULL
AND a.login_5th IS NULL';
--If there is a fifth place then the rep has a VP, Dir, Mgr, Supervisor, Team Lead and is a rep
EXECUTE IMMEDIATE '
UPDATE TMP_SALES_CNT_BY_USER a
SET a.vp = a.lst_name_5TH || '', '' || a.fst_name_5TH,
a.vp_login = a.login_5TH,
a.director = a.lst_name_4TH || '', '' || a.fst_name_4TH,
a.director_login = a.login_4TH,
a.manager = a.lst_name_3RD || '', '' || a.fst_name_3RD,
a.manager_login = a.login_3RD,
a.supervisor = a.lst_name_2ND || '', '' || a.fst_name_2ND,
a.supervisor_login = a.login_2ND,
a.teamlead = a.lst_name_1st || '', '' || a.fst_name_1st,
a.teamlead_login = a.login_1st
WHERE a.login_1st IS NOT NULL
AND a.login_2ND IS NOT NULL
AND a.login_3rd IS NOT NULL
AND a.login_4th IS NOT NULL
AND a.login_5th IS NOT NULL';
open p_cursor for
SELECT tsc.vp,
tsc.director,
tsc.manager,
tsc.supervisor,
tsc.teamlead,
(tsc.last_name || ', ' || tsc.fst_name) AS Rep,
tsc.product,
tsc.totalproductssold,
tsc.numberofcalls,
tsc.salesper100calls
FROM TMP_SALES_CNT_BY_USER tsc;
END FIRE_SALES_100_CALLS_REPORT;
The table I use is a Global temp table.
This runs just fine in oracle but when I try to build a data foundation in Business Objects I get the error that says you cannot insert/update/delete in a READ ONLY Transaction.
I really need some advice on what to do since I really dont have access to a scheduled script and table that would store my data ahead of time.Well, AFAIK, BO is a reporting tool, so it si read-only by nature. I do not know if it possible to "tell" BO table is GTT and it is OK to write to it. You need to post this in BO forum.
SY. -
I need Help with the stored procedure
Hello, I new with VS.Net
I'm tring to call a stored procedure, but when i try to retrive the data don't return nothing.
my VB code is the follows
ocm_comando.Connection = ocn_coneccion
ocm_comando.CommandText = "WPROC_PRUEBA"
ocm_comando.CommandType = CommandType.StoredProcedure
ocm_comando.Parameters.Add("PNI_ID_ESTUDIO", OracleDbType.Decimal).Direction = ParameterDirection.Input
ocm_comando.Parameters("PNI_ID_ESTUDIO").Value = CType(vc_id_estudio, Integer)
ocm_comando.Parameters.Add("pco_precalificada", OracleDbType.Varchar2).Direction = ParameterDirection.Output
ocm_comando.Parameters.Add("pco_resultado", OracleDbType.Varchar2).Direction = ParameterDirection.Output
Txb_empresa.Text = ocm_comando.Parameters("pco_precalificada").Value
My stored procedure only take the parameter that I sent and make a simple select and return the value in the variable pco_precalificada
thank for your help
**** Sorry for mi EnglishYou forgot to actually execute the command. Before the last line, where you ask for the value of pco_precalificada, you need to:
1. Open the connection (if it's not already open)
2. Call ocm_comando.ExecuteNonQuery()
HTH,
Tom -
Help with Command - Stored Procedure
Hi all,
I'm having a great deal of difficulty getting my head around
an update command / stored procedure, I've pulled out all of my
books and spent the last two days on Google which has made my
confusion worse. In simple terms what I'm trying to do is update a
field in a table with the value y, but based on certain criteria.
So my table has the following fields -
JBAID
JBASiteID
JBADatePosted
JBAPostFor
JBANotified
What i want to do is update the value of field JBANotified on
all records that meeting the following criteria to Y
The criteria is -
WHERE DATEADD(d,JBAPostFor,JBADatePosted) BETWEEN DATEADD(d,
-7, GETDATE()) AND GETDATE() AND JBANotified = 'n' AND JBASiteID =
MMColParam (where MMColParam is Session("SITEID"))
So I've just tried building a command / stored procedure -
which reads (see attached code)(more than likely all wrong)
The things that I cant get my head around are -
Firstly getting the code right in the first place, running
the command on page load and then when the command has run
redirecting to the next page.
I really would appreciate some help with this -
thanks allEd Stewart wrote:
> Are you using CS3 with ASP/VBScript? There is a bug in
the command
> implementation that has this function broken.
>
> I asked about it in this forum several months ago, but
now I can't find my
> original post, but I did find another post that talks
about the same thing:
>
http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=12&catid=26
> 3&threadid=1281539&enterthread=y
>
> My solution is to drop back to DW8 for command editing,
but use CS3 for
> everything else. I don't know what you're supposed to do
if you don't have an
> earlier version.
>
> It looks like your sql is correct, but the bug prevents
the second code block
> is not being updated with the correct values.
>
> I hope a solution is forthcoming....
>
Create a stored procedure and then use a recordset to
exectute it,
making sure the recordset has matching parameters that the
stored
procedure expects.
Commands are broken, I reported it to Adobe and they said it
might get
fixed in the next version.
Steve -
Help with calling stored procedure and preparing statement
hi guys help please..I want to call a procedure set the ResultSet to TYPE_SCROLL_INSENSITIVE and CONCUR_UPDATABLE in order for me to scroll thru the resultset from 1st row to end row and vice-versa..but currently, my code has an error becuase im hot sure on how to do this..Can you please help me guys to solve this? Thanks in advance!
CODE:
int c = 0;
String searchArg = txtSearch.getText();
String studName, mInitial;
searchArg = searchArg.replace('*', '%');
con = FuncCreateDBConnection();
con.prepareCall("{call dbsample.usp_StudentInfo_SEARCH(?, ?)}");
*cStmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);*
cStmt.setString("searchArg", searchArg);
cStmt.setString("searchType", cmboSearchBy.getSelectedItem().toString());
rs = cStmt.executeQuery();
if (rs != null){
listModel = new DefaultListModel();
lstSearchResult.setModel(listModel);
while (rs.next()){
mInitial = rs.getString(4).substring(0, 1).toUpperCase();
studName = rs.getString(3) + ", " + rs.getString(2) + " " + mInitial + ".";
listModel.addElement(studName);
System.out.println("Rows:"+ rs.getString(2));
c++;
ERROR:
Incompatible Types
Found : java.sql.Statement
Required: java.sql.CallableStatementNevermind guys..i got it..
CODE:
int c = 0;
String searchArg = txtSearch.getText();
String studName, mInitial;
searchArg = searchArg.replace('*', '%');
con = FuncCreateDBConnection();
cStmt = con.prepareCall("{call dbsample.usp_StudentInfo_SEARCH(?, ?)}",ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
cStmt.setString("searchArg", searchArg);
cStmt.setString("searchType", cmboSearchBy.getSelectedItem().toString());
rs = cStmt.executeQuery();
if (rs != null){
listModel = new DefaultListModel();
lstSearchResult.setModel(listModel);
while (rs.next()){
mInitial = rs.getString(4).substring(0, 1).toUpperCase();
studName = rs.getString(3) + ", " + rs.getString(2) + " " + mInitial + ".";
listModel.addElement(studName);
System.out.println("Rows:"+ rs.getString(2));
c++;
} Edited by: daimous on Jan 31, 2008 6:04 PM
Maybe you are looking for
-
Dear All, Please help me in this i am getting when i am trying to post the Sales invoice after doing Post Good issue. Request all experts to help me in this. waiting for reply in anticipation. Details of Error given below Delivered/invoiced quantitie
-
Safari will not open (crashes) after running software update
My boss ran the latest software update this weekend (June 18, 2006), now safari will not run on his machine. It blinks the safari window, then quits. His default web page is www.apple.com I have read about issues with flash, javascript, plugins, etc.
-
Power Save Mode - how to disable
My new Pavilion laptop (model # 17-e123cl) is connected to an external monitor. When I fold down the laptop screen the power saver mode kicks in and the computer goes off. I want it to stay on so I can place my wireless keyboard on top of the Pavil
-
HELP! - BEAN and CLASS interchange?
When I setup to a bean like: <jsp:useBean id="logger" scope="application" class="Logger" /> I can use the bean and bean's functions fine in the JSP, but not within functions that exist in the JSP like: jspInit() it says the "logger" is undefined. Is
-
BC4J, jsp data tags, jbo tags , documentation
Hi everybody Would you please advise me where I can find information and documentation preferably in .pdf format about jbo jsp tags for working with BC4J? Thanks in advance