Killing the Stored Procedure
Hi All,
I'm having a serious and urgent problem.
Please help me in resolving this.
I'm trying to excute a Oracle Stored Procedure from the JSP Screen.
I.e When i click a Button in the Screen it will run the Stored Procedure (Update a table) at Background.
Where i require help is...
I'm clicking the Button to execute my Stored procedure. It has started the processes and running the Stored Procedure at backgroud.
Due to connection failure or by mistake i have clicked the button again to run the Stored Procedure before the first process gets completed.
What will be the behaviour of the System??
Will the data be updated twice in the Table??
Will it so table mutating error??
If any of these situations occurs how to overcome it??
Can i kill the first process before starting the second process, so that i will not get duplicate records in the table??
Please give me some guideline.
Regards,
Gita
Oh..my god this much complications.
In my Stored Procedure i have not done anything other than fetching a number of rows through a cursor for certain condition and inserting that into a output table and commiting the changes.
But the JSP is allowing to open multiple browers at the same time and process the stored procedure for the same parameters. This shows that the Stored Procedure is allowed to run for multiple seesions as it is nto showing any error message like dead lock or something.
How to overcome this??
Can i lock my Stored Procedure if it is clicked to run for the same parameters??
If the Stored Procedure is triggered for the different parameters then do not lock it.
I think diabling the button in JSP is of no use as it will be applicable only to that session. If my User opens a new session and process for the same parameter then it is of no use.
Many Thanks for explaining the things..
Regards,
Gita
Similar Messages
-
How to Kill a Stored Procedure?
Sombody knows how to kill a stored procedure from another stored peocedure?
I wanna know if exists a way to use therads in sored procedures.
Best Regards1) You can't. Unless you code a mechanism yourself, but then since
you can't thread Procedure calls that wouldn't help much.
2) You can try using DBMS_JOB, if your not in a hurry to have your procedure finish.
This is PL/SQL, not Java. You have to imagine all you get is a single thread running
static methods. You can get away from everything being static by using the CREATE TYPE
OBJECT stuff. but that doesn't help you thread your processes.
I hope someone else can give you a different answer,
Eric Kamradt -
Kill a stored procedure/function
Hi Experts,
I have requirement to kill or terminate the stored procedure/function through UI.
Is there anyway to kill or terminate the stored procedure/function in oracle.
Note:-it shouldn't impact the other running Stored procedures/functions.
Thanks in Adavnce!!!Some basics first.
You do not kill a procedure or function. You kill the process executing it.
The ALTER SYSTEM KILL SESSION command does not kill a process (session). It requests that process to terminate by communicating with the process via the SGA. If that process is in a synchronous kernel call (and waiting for that call to complete), the process is unable to even check the SGA, never mind respond to a kill-yourself instruction. Which means it cannot terminate itself.
User (application) code does NOT need the ALTER SYSTEM priv. That will be a very serious security violation. So if you do want to allow user code to make use of that priv to kill user sessions/processes, then you need to wrap that into a secure interface that user code can use. Such as a SYS owned KillUserSession() procedure, executing with definer rights, and ensuring the caller can only kill sessions that it owns (e.g. if caller is schema SCOTT, then only SCOTT sessions can be killed).
Last comment. Killing user sessions is kind of stupid. As that means you loose. You cannot design properly. You cannot code properly. And to establish some kind of sanity in processing, The Very Large Hammer needs to be employed. Killing sessions does NOT fix the problem. It treats the symptom. The problem is still there.
And to add a treat-the-symptom-by-killing-the-session button on a .Net (or any other) application? That is, IMO, four-letter-words epic lame.
What is the real problem? -
How to pass the parameter values to the stored procedure from java code?
I have a stored procedure written in sqlplus as below:
create procedure spInsertCategory (propertyid number, category varchar2, create_user varchar2, create_date date) AS BEGIN Insert into property (propertyid, category,create_user,create_date) values (propertyid , category, create_user, create_date); END spInsertCategory;
I am trying to insert a new row into the database using the stored procedure.
I have called the above procedure in my java code as below:
CallableStatement sp = null;
sp = conn.prepareCall("{call spInsertCategory(?, ?, ?, ?)}");
How should I pass the values [propertyid, category, create_user, create_date) from java to the stored procedure?[i.e., parameters]
Kindly guide me as I am new to java..Java-Queries wrote:
I have a stored procedure written in sqlplus as below:FYI. sqlplus is a tool from Oracle that provides a user interface to the database. Although it has its own syntax what you posted is actually PL/SQL. -
Error while executing the stored procedure through sender JDBC adapter
Hi All,
I am getting below error while executing the stored procedure through sender JDBC adapter.
Database-level error reported by JDBC driver while executing statement 'exec SapgetNextEntity 'SalesOrder''. The JDBC driver returned the following error message: 'com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.'. For details, contact your database server vendor.
what is the problem? any idea to anyone...
regards
Rameshhi Dharamveer,
I am not getting below statement for your reply
Try to use Refrence Cursor it will return u reference of resultset.
I mention SP like this
exec SapgetNextEntity 'SalesOrder'
SapgetNextEntity -
> SP Name
SalesOrder----
> Parameter I am passing...
regards
Ramesh -
How to use the Stored Procedure to update my UDF
I want to use the Stored Procedure to update my UDF U_InstokCS when the warehouse "OnHand" was changed. The UDF is display the stock by cases. I copied the query as follewing. I couldn't see any thing in the UDF after I made some transactions. Can anybody tell me why? How to continue it?
if @transaction_type in ('A','U','D') and @Object_type='64'
begin
Update OITW
Set U_InstokCS = OnHand/(Select T0.NumInBuy from [DBO].[OITM] T0
Where T0.ItemCode = @list_of_cols_val_tab_del)
Where ItemCode = @list_of_cols_val_tab_del
end
Thanks.
Ying ZhangYing,
The use of any stored procedures against the SAP Business One database is not allowed per SAP Support. There is not an instance where you can use SP's. The ONLY SP that you are allowed to use is the SBO_SP_TransactionNotification SP that comes with SAP Business One itself. You can read about the use of this SP from this article...
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e991e2b9-0901-0010-0395-ef5268b00aaf
Eddy -
Sender JDBC support the stored procedure in SQL Server 2005
Dear All,
My question here is , Sender is JDBC adpter support to call the Stored procedure in Microsoft SQL Server 2005?
I followed the below thread before posting this question
Sender JDBC Adapter Supports Stored Procedures????
In the thread Suraj response has mentioned SAP note: 941317, I checked the note, Note says it supported only ORACLE DBMS versions.
Could you please clarify about this to possibility to call the stored procedure in Microsoft SQL server 2005?
Thank you in Advance
SateeshHi Sateesh,
To answer your query, Yes it does. SP call works with SQL Server 2005 as well, the SP call should be "execute SPNAME <paramas>". In the place of update statement put any junk value as mentioned in the earlier comment.
But just one thing to be noted, the select or any other query returning the desired resultset must be the first statement in youre SP returning value to the calling app. Means if there are any update, deletion or intermediate select queries to be used with in your SP, those all should be placed after the Main Select query that returns the desired resultset. Variable declarions and assignments are allowed.
But if the seq of statements in your SP are like:
@var1 Varchar
Update <tablename>....
Select * from <tablename>
Then the output of the SP is :
1 row updated
<the resultset from select>
In such cases, PI can recognise the first value returned only, that is "1 row updated" and hence the returned resultset wouldn't be seen by PI or not be passed to integration engine. Hence the update should come after the main Select.
One more interesting piece of information, even if you copy and paste the entire SP code in place of the query string of Sender JDBC adapter, that too will work with all your variable declarations, multiple queries and updates and everything. Just have to follow the above rule.
Let us know what you find.
Regards,
Suddhasatta -
Executing the stored procedure with output which is a collection of objects
Hello,
I have the objects and collection of objects within an objects as below:
CREATE OR REPLACE TYPE SHARE_OUTST_T
AS OBJECT
SHR_OUTST_AMT number
CREATE OR REPLACE TYPE SECURITY_T
AS OBJECT
VOTE_PER_SHR number
, CUSIP varchar2(12)
, EXCHANGE varchar2(10)
, IV_TYPE_CD varchar2(10)
, SEC_TICKER_SYMB varchar2(20)
CREATE OR REPLACE TYPE ALTERNATE_ID_T
AS OBJECT
( ALT_ID_TYPE varchar2(20)
CREATE OR REPLACE TYPE ISSUE_MAINT_VERSION_T
AS OBJECT
IM_KEY_ID number
, IM_VER_NUM number
, EFF_TMSTMP timestamp
, EXP_TMSTMP timestamp
, NEXT_REVIEW_TMSTMP timestamp
, APPR_STATUS_REF_ID number
, VOTE number
, ADD_USR_ID varchar2(20)
, ADD_TMSTMP timestamp
, UPD_USR_ID varchar2(20)
, UPD_TMSTMP timestamp
, LOCK_LEVEL_NUM number
, ACTION VARCHAR2(1)
CREATE OR REPLACE TYPE ISSUE_SHARE_MAINT_T
AS OBJECT
IM_KEY_ID number
, IM_VER_NUM number
, SHR_OUTST_AMT number
, CURR_OUTST_AMT number
, ADD_USR_ID varchar2(20)
, ADD_TMSTMP timestamp
, UPD_USR_ID varchar2(20)
, UPD_TMSTMP timestamp
, LOCK_LEVEL_NUM number
, ACTION VARCHAR2(1)
CREATE OR REPLACE TYPE ISSUE_MAINT_COMMENT_T
AS OBJECT
IM_KEY_ID number
, IM_VER_NUM number
, COMMENT_TXT varchar2(400)
, ADD_USR_ID varchar2(20)
, ADD_TMSTMP timestamp
, UPD_USR_ID varchar2(20)
, UPD_TMSTMP timestamp
, LOCK_LEVEL_NUM number
, ACTION VARCHAR2(1)
CREATE OR REPLACE TYPE ISSUE_MAINT_COMMENT_COL_T AS TABLE OF ISSUE_MAINT_COMMENT_T;
CREATE OR REPLACE TYPE ISSUE_VERSION_T
AS OBJECT
SHARE_OUTST SHARE_OUTST_T
, SECURITY SECURITY_T
, ALTERNATE_ID ALTERNATE_ID_T
, ISSUER ISSUER_T
, ISSUE_MAINT_VERSION ISSUE_MAINT_VERSION_T
, ISSUE_SHARE_MAINT ISSUE_SHARE_MAINT_T
, ISSUE_MAINT_COMMENT_COL ISSUE_MAINT_COMMENT_T
CREATE OR REPLACE TYPE ISSUE_VERSION_COL_T AS TABLE OF ISSUE_VERSION_T;
And the stored procedure as :
=======================================
PROCEDURE get_all_issue_version_col
( pv_issue_version_col OUT issue_version_col_t
AS
CURSOR cur_issue_version
IS
SELECT
issue_version_t (
SHARE_OUTST_T (so.shr_outst_amt )
, SECURITY_T ( s.vote_per_shr
, s.sec_cusip
, s.PRI_MKT_EXCH_CD
, s.IV_TYPE_CD
, s.SEC_TICKER_SYMB )
, ALTERNATE_ID_T (a.ALT_ID_TYPE)
, ISSUER_T (i.ISSR_ID )
, ISSUE_MAINT_VERSION_T (imv.im_key_id
, imv.im_ver_num
, imv.eff_tmstmp
, imv.exp_tmstmp
, imv.next_review_tmstmp
, imv.appr_status_ref_id
, imv.vote
, imv.add_usr_id
, imv.add_tmstmp
, imv.upd_usr_id
, imv.upd_tmstmp
, imv.lock_level_num
, NULL )
, ISSUE_SHARE_MAINT_T (ism.im_key_id
, ism.im_ver_num
, ism.shr_outst_amt
, ism.curr_outst_amt
, ism.add_usr_id
, ism.add_tmstmp
, ism.upd_usr_id
, ism.upd_tmstmp
, ism.lock_level_num
, NULL)
, ISSUE_MAINT_COMMENT_T(imc.im_key_id
, imc.im_ver_num
, imc.comment_txt
, imc.add_usr_id
, imc.add_tmstmp
, imc.upd_usr_id
, imc.upd_tmstmp
, imc.lock_level_num
, NULL )
FROM
share_outst so
, security s
, alternate_id a
, issuer i
, issue_maintenance_version imv
, issue_share_maintenance ism
, issue_maintenance_comment imc
WHERE
s.sec_key_id = so.SEC_KEY_ID
and s.SEC_KEY_ID = a.SEC_KEY_ID
and s.MSTR_ISSR_KEY_ID = i.ISSR_KEY_ID
and s.SEC_CUSIP = imv.SEC_CUSIP (+)
and s.SEC_CUSIP = ism.SEC_CUSIP (+)
and imv.IM_KEY_ID = imc.IM_KEY_ID (+);
BEGIN
OPEN cur_issue_version ;
FETCH cur_issue_version BULK COLLECT INTO pv_issue_version_col ;
CLOSE cur_issue_version ;
END ;
PROCEDURE get_all_issue_col_v1
( pv_issue_version_col OUT NOCOPY issue_version_col_t
, pv_row_count IN number
, pv_issuer_id IN VARCHAR2
AS
CURSOR cur_issue_version
IS
SELECT
issue_version_t (
SHARE_OUTST_T (so.shr_outst_amt )
, SECURITY_T ( s.vote_per_shr
, s.sec_cusip
, s.PRI_MKT_EXCH_CD
, s.IV_TYPE_CD
, s.SEC_TICKER_SYMB )
, ALTERNATE_ID_T (a.ALT_ID_TYPE)
, ISSUER_T (i.ISSR_ID )
, ISSUE_MAINT_VERSION_T (imv.im_key_id
, imv.im_ver_num
, imv.eff_tmstmp
, imv.exp_tmstmp
, imv.next_review_tmstmp
, imv.appr_status_ref_id
, imv.vote
, imv.add_usr_id
, imv.add_tmstmp
, imv.upd_usr_id
, imv.upd_tmstmp
, imv.lock_level_num
, NULL )
, ISSUE_SHARE_MAINT_T (ism.im_key_id
, ism.im_ver_num
, ism.shr_outst_amt
, ism.curr_outst_amt
, ism.add_usr_id
, ism.add_tmstmp
, ism.upd_usr_id
, ism.upd_tmstmp
, ism.lock_level_num
, NULL)
, ISSUE_MAINT_COMMENT_T(imc.im_key_id
, imc.im_ver_num
, imc.comment_txt
, imc.add_usr_id
, imc.add_tmstmp
, imc.upd_usr_id
, imc.upd_tmstmp
, imc.lock_level_num
, NULL )
FROM
share_outst so
, security s
, alternate_id a
, issuer i
, issue_maintenance_version imv
, issue_share_maintenance ism
, issue_maintenance_comment imc
WHERE
s.sec_key_id = so.SEC_KEY_ID
and s.SEC_KEY_ID = a.SEC_KEY_ID
and s.MSTR_ISSR_KEY_ID = i.ISSR_KEY_ID
and s.SEC_CUSIP = imv.SEC_CUSIP (+)
and s.SEC_CUSIP = ism.SEC_CUSIP (+)
and imv.IM_KEY_ID = imc.IM_KEY_ID (+);
BEGIN
OPEN cur_issue_version ;
FETCH cur_issue_version BULK COLLECT INTO pv_issue_version_col ;
CLOSE cur_issue_version ;
END ;
====================
When I execute this stored procedure thru rapid sql, I get error
Error: ORA-06550: line 1, column 21:
PLS-00306: wrong number or types of arguments in call to 'GET_ALL_ISSUE_VERSION_COL'
ORA-06550: line 1, column 21:
PL/SQL: Statement ignored, Batch 1 Line 1 Col 21
What is that I am missing?
Any help would be greatly appreciated.I've never tried Rapid SQL, but my guess is that you can't pass objects through it. I'd write a test case on the server and try it there. It looks like it should work but I didn't build a test case. If it works on the server but not in the tool, it's like the tool. OCI8 doesn't support passing instantiated objects.
-
Hi i am using oracle 10g how to view the content of the stored procedure or trigger ?
Hi i am using oracle 10g .How to edit the content of the stored procedure or trigger ?
jklopkjl wrote:
Hi i am using oracle 10g .How to view the content of the stored procedure or trigger ?
query ALL_SOURCE
SQL> desc all_source
Name Null? Type
OWNER VARCHAR2(30)
NAME VARCHAR2(30)
TYPE VARCHAR2(12)
LINE NUMBER
TEXT VARCHAR2(4000) -
Problem in OUT Parameter in the stored procedure
Hi,
I have a problem in the OUT parameter of the stored procedure under the package. I encountered the error PLS-00306. Below are the codes.
Package
CREATE OR REPLACE package body test as
procedure sp_countries(rst OUT country_typ) as
sql_stmt VARCHAR2(300);
begin
sql_stmt := 'SELECT * FROM countries WHERE region_id = 1';
OPEN rst FOR sql_stmt;
end;
end test;
by the way. i declared the country_typ as this:
TYPE country_typ IS REF CURSOR;
Here is the code that will call this package:
declare
tst countries%ROWTYPE;
begin
test.sp_countries(tst);
dbms_output.put_line(tst.country_name);
end;Works for me. Although I had to use emp instead of your table:
SQL> create or replace
2 package test as
3 TYPE country_typ IS REF CURSOR;
4 procedure sp_countries(rst OUT country_typ);
5 end;
6 /
Package created.
SQL> CREATE OR REPLACE
2 package body test as
3 procedure sp_countries(rst OUT country_typ) as
4 sql_stmt VARCHAR2(300);
5 begin
6 sql_stmt := 'SELECT * FROM emp WHERE deptno = 20';
7 OPEN rst FOR sql_stmt;
8 end;
9 end test;
10 /
Package body created.
SQL> var tcur refcursor
SQL> exec test.sp_countries(:tcur);
PL/SQL procedure successfully completed.
SQL> print tcur
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 20
7566 JONES MANAGER 7839 02-APR-81 2975 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7902 FORD ANALYST 7566 03-DEC-81 3000 20
SQL> -
Should Output parameters always be declare at the beginning of the Stored Procedure?
Should Output parameters always be declare at the beginning of the Stored Procedure?
Usually input parameters listed first followed by output parameters. This is just a custom, not a requirement.
Blog: How to architect stored procedure parameters?
BOL: http://msdn.microsoft.com/en-us/library/ms187926.aspx
Kalman Toth Database & OLAP Architect
SQL Server 2014 Database Design
New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014 -
Can rs.last() be used after calling the stored procedure?
Can rs.last() be used after calling the stored procedure? If yes what should be the CURSOR types?
Can rs.last() be used after calling the stored
procedure? If yes what should be the CURSOR types?That would depend on the driver/database.
And as I said in your other post it is far more efficient to count records by just returning a count rather than a complete collection regardless of how you get to the end. -
Customize the stored procedure migrating of MWB
Hi, All,
Is there anybody know how much customize we can have for using
the MWB when migrate stored procedure? For sample I have a SQL
Server 6.5 strored procedure like following:
/******************* SQL Server 6.5 sp *************/
CREATE PROCEDURE sp_SelectUsers
AS
select
tbl_Sp_users.ID, UserName, Password, ExpiresOn,
PwdChangedDate, tbl_Sp_UserGrps.name
from
tbl_Sp_users, tbl_Sp_UserGrps
where
GroupID = tbl_Sp_UserGrps.id
order by username
/******************* end ***************************/
After I migrate it to Oracle 8 with MWB, I got following object,
one Pkg and one Procedure in Oracle db, like following:
/****************** Oracle Pkg **********************/
CREATE OR REPLACE PROCEDURE sp_SelectUsers(
RC1 IN OUT sp_SelectUsersPkg.RCT1)
AS
StoO_selcnt INTEGER;
StoO_error INTEGER;
StoO_rowcnt INTEGER;
StoO_errmsg VARCHAR2(255);
StoO_sqlstatus INTEGER;
BEGIN
OPEN RC1 FOR
SELECT tbl_Sp_users.ID, UserName, Password,
ExpiresOn, PwdChangedDate, tbl_Sp_UserGrps.name FROM
tbl_Sp_users, tbl_Sp_UserGrps
WHERE GroupID = tbl_Sp_UserGrps.id
ORDER BY username ;
END sp_SelectUsers;
/******************* Oracle Procedure ****************/
PROCEDURE sp_SelectUsers(
RC1 IN OUT sp_SelectUsersPkg.RCT1)
AS
StoO_selcnt INTEGER;
StoO_error INTEGER;
StoO_rowcnt INTEGER;
StoO_errmsg VARCHAR2(255);
StoO_sqlstatus INTEGER;
BEGIN
OPEN RC1 FOR
SELECT tbl_Sp_users.ID, UserName, Password,
ExpiresOn, PwdChangedDate, tbl_Sp_UserGrps.name FROM
tbl_Sp_users, tbl_Sp_UserGrps
WHERE GroupID = tbl_Sp_UserGrps.id
ORDER BY username ;
END sp_SelectUsers;
/******************* end *****************************/
As our client use RDO as access method, there is no way we can
use this migrated SP in RDO and return resultset. We need
convert this SP to following to be able to use RDO to get
resultset back in client:
/******************* need convert to *********************/
create or replace package sp_selectUsersPkg
as
cursor c1
is select tbl_Sp_users.ID, UserName, Password,ExpiresOn,
PwdChangedDate, tbl_Sp_UserGrps.name
from tbl_Sp_users, tbl_Sp_UserGrps
where GroupID = tbl_Sp_UserGrps.id
order by username;
type UsersCur
is ref cursor return c1%ROWTYPE;
procedure sp_selectUsers(UserCursor in out UsersCur );
END;
create or replace package body sp_selectUsersPkg
as
procedure sp_selectUsers(UserCursor in out UsersCur )
is
begin
open UserCursor for
select tbl_Sp_users.ID, UserName,
password, ExpiresOn,
PwdChangedDate, tbl_Sp_UserGrps.name
from tbl_Sp_users, tbl_Sp_UserGrps
where GroupID = tbl_Sp_UserGrps.id
order by username;
end;
end;
/******************* end *********************************/
Is there any idea how we can do this? I hope we don't need do
this manually.
Thank you very much for any help!
Jing
nullI have done a rough example of using VB6, RDO and ODBC
drivers, which may be of help to some workbench users:
Calling Oracle 8.1.5 stored procedures with ref cursors using RDO
and Visual
Basic.
Ver 0.1 [email protected]
Summary
Versions Used
Table
Code
With Explicit Ref Cursor Argument
Without Explicit Ref Cursor Argument
Actions
Summary
This gives a comparison of the connectivity between Visual Basic
and Oracle,
with both the intersolve and oracle drivers. The Oracle odbc
still has
significant
shortcomings in comparison to the intersolve/Merant driver.
Versions Used
Visiual Basic 6.0, Oracle odbc driver 8.1.5.3.0, Oracle Database
8.1.5.0.0 on
NT, intersolve/Merant 3.5 32 bit Oracle driver.
Table
html table replaced by rough results in ascii form
test case with named result set cursor variable:
sSQL = "{CALL reftest.GetEmpData(?)}"
oracle 8.1.5.3
could not find item indicated by text, known vb6.0 bug?, thinks
reftest is user
intersolve
could not find item indicated by text, known vb6.0 bug?, thinks
reftest is user
sSQL = "begin reftest.GetEmpData(?); end;"
oracle 8.1.5.3
run time error 40002 driver not capable
intersolve
ok
sSQL = "{CALL GetEmpData(?)}"
oracle 8.1.5.3
run time error 40002 driver not capable
intersolve
could not find item indicated by text,?(similar to bug above?)
at qd.rdoParameters(0).Type = rdTypeVARCHAR
sSQL = "begin GetEmpData(?); end;"
oracle 8.1.5.3
run time error 40002 driver not capable
intersolve
ok
procedure with result set last argument wanting to be simulated
as not
argument result set
strsql = "{CALL BYROYALTYPkg.byroyalty()}"
oracle 8.1.5.3
ok
intersolve
ok
strsql = "begin BYROYALTYPkg.byroyalty(); end;"
oracle 8.1.5.3
wrong number of arguments in byroyalty
intersolve
ok
strsql = "{CALL byroyalty() }"
oracle 8.1.5.3
wrong number of arguments
intersolve
ok
strsql = "begin byroyalty(); end;"
oracle 8.1.5.3
wrong number of arguments
intersolve
ok
Code
With Explicit Ref Cursor Argument
Oracle Stored Procedures and Packages
(on scott/tiger account)
create or replace package reftest as
cursor c1 is select ename from emp;
type empCur is ref cursor return c1%ROWTYPE;
procedure GetEmpData(EmpCursor in out empCur );
END;
create or replace package body reftest as
procedure GetEmpData(EmpCursor in out empCur) is
begin
open EmpCursor for select ename from emp;
end;
end;
create or replace procedure GetEmpData(EmpCursor in out
reftest.empCur)
is
begin
open EmpCursor for select ename from emp;
end;
VB code
Private Sub Command1_Click()
Dim cn As New rdoConnection
Dim qd As rdoQuery
Dim rs As rdoResultset
Dim cl As rdoColumn
Static Number As Integer
Number = 0
cn.Connect = "uid=scott; pwd=tiger; DSN=Oracle;"
'enable the MS Cursor library
cn.CursorDriver = rdUseOdbc
'Make the connection
cn.EstablishConnection rdDriverPrompt
sSQL = "BEGIN GetEmpData(?); END;"
Set qd = cn.CreateQuery("", sSQL)
qd.rdoParameters(0).Type = rdTypeVARCHAR
'Dynamic or Keyset is meaningless here
Set rs = qd.OpenResultset(rdOpenStatic)
'all the output is routed to the debug window
Debug.Print ".....Starting Result Sets....."
Do
Debug.Print
Debug.Print
Do Until rs.EOF
For Each cl In rs.rdoColumns
If IsNull(cl.Value) Then
Debug.Print " "; cl.Name; "NULL"; 'Error
trap for
null fields
Else
Debug.Print " "; cl.Name; " ";
cl.Value;
End If
Next
Debug.Print
rs.MoveNext
Loop
Loop While rs.MoreResults
cn.Close
End Sub
Without Explicit Ref Cursor Argument
Oracle Stored Procedures and Packages
(requires table:
SQL> desc MTG_VERSION
Name
Null?
Type
VERSION
NUMBER
create or replace PACKAGE BYROYALTYPkg AS
TYPE RT1 IS RECORD (
val MTG_VERSION.VERSION%TYPE
TYPE RCT1 IS REF CURSOR RETURN RT1;
PROCEDURE byroyalty(
RC1 IN OUT BYROYALTYPkg.RCT1);
END;
create or replace PACKAGE BODY BYROYALTYPkg AS
PROCEDURE byroyalty(
RC1 IN OUT BYROYALTYPkg.RCT1)
AS
StoO_selcnt INTEGER;
StoO_error INTEGER;
StoO_rowcnt INTEGER;
StoO_errmsg VARCHAR2(255);
StoO_sqlstatus INTEGER;
BEGIN
OPEN RC1 FOR
SELECT VERSION FROM MTG_VERSION;
END byroyalty;
END;
create or replace PROCEDURE byroyalty(
RC1 IN OUT BYROYALTYPkg.RCT1)
AS
StoO_selcnt INTEGER;
StoO_error INTEGER;
StoO_rowcnt INTEGER;
StoO_errmsg VARCHAR2(255);
StoO_sqlstatus INTEGER;
BEGIN
OPEN RC1 FOR
SELECT VERSION FROM MTG_VERSION;
END byroyalty;
VB code
Dim env1 As rdoEnvironment
Dim conn1 As rdoConnection
Dim strsql As String
Dim ps As rdoPreparedStatement
Dim rs As rdoResultset
Private Sub Command1_Click()
strsql = "begin byroyalty(); end;"
'in oracle odbc driver uses refcusor argument to
get result set
Set ps = conn1.CreatePreparedStatement("PsTest",
strsql)
Set rs = ps.OpenResultset(rdOpenStatic)
Text1 = rs!Version
rs.Close
End Sub
Private Sub Form_Load()
rdoEngine.rdoDefaultCursorDriver = rdUseOdbc
Set env1 = rdoEngine.rdoCreateEnvironment(" ", " ", " ")
strsql = "ODBC;DSN=tot4;UID=test;PWD=test;"
Set conn1 = env1.OpenConnection(" ", rdDriverPrompt, False,
strsql)
conn1.QueryTimeout = 3600
End Sub
Actions
Encourage odbc to allow result sets , via the odbc processed
extra
argument, outside of packages.
Document the current situation, and keep users informed of
developments.
Turloch
Oracle Migration Workbench Team
Turloch O'Tierney (guest) wrote:
: Jing,
: Note that there is an example in the FAQ where the intersolve
: driver was used so no change was required in the client code.
The
: intersolve driver optionally converts the extra argument into a
: result set. With the Oracle ODBC driver the argument needs to
be
: explicitly handled.
: Is there a problem with RDO and the 8.0.5 ODBC driver handling
: package references?
: Turloch
: Turloch O'Tierney
: Oracle,
: Migration and Technology Group.
: FAQ entry reproduced:
: How are result sets/dynasets returned to the calling program?
: The Oracle Migration Workbench parser adds an extra
argument
: of type REF CURSOR for result
: sets/dynasets. This type is understood and can be
: manipulated by both PL/SQL and Oracle JDBC. Oracle8
: release 8.0.5 ODBC drivers support REF CURSORs which means
: that the additional argument must be
: explicitly handled by the application, and the client
: application code must be changed. However, some
: third-party vendors such as Intersolv supply ODBC drivers
: for Oracle that support REF CURSORs and can, in
: addition, implicitly make use of REF CURSORs for using
: result sets/dynasets. Therefore, no change is
: required in the client application code. This is
illustrated
: in the following examples of an MS SQL Server
: stored procedure and its equivalent Oracle package and
: stored procedure as generated by the Oracle
: Migration Workbench parser.
: MS SQL Server Stored Procedure
: CREATE PROCEDURE byroyalty
: AS
: select au_id from titleauthor
: GO
: Oracle8i Package and Stored Procedure
: PACKAGE BYROYALTYPkg AS
: TYPE RT1 IS RECORD (
: au_id titleauthor.au_id%TYPE
: TYPE RCT1 IS REF CURSOR RETURN RT1;
: END;
: PROCEDURE byroyalty(
: RC1 IN OUT byroyaltyPkg.RCT1)
: AS
: StoO_selcnt INTEGER;
: StoO_error INTEGER;
: StoO_rowcnt INTEGER;
: StoO_errmsg VARCHAR2(255);
: StoO_sqlstatus INTEGER;
: BEGIN
: OPEN RC1 FOR
: SELECT au_id FROM titleauthor;
: END byroyalty;
: The following example illustrates the typical ODBC code
used
: by Intersolv to call the above MS SQL Server
: stored procedure. This code also works for the above
: Oracle8i package and stored procedure. Note that error
: handling must be added in a real application:
: SQLPrepare(...,'{call byroyalty()}',...)
: SQLExecute()
: SQLBindCol()
: SQLFetch()
: Comments:
: SQLPrepare(...,'{call byroyalty()}',...) is the ODBC SQL
: syntax used to execute stored procedures.
: SQLExecute()executes the stored procedure.
: SQLBindCol()assigns storage for result column 1 in the
: result set (au_id).
: SQLFetch() fetches the first record from the result set
: generated by the stored procedure.
: The following examples illustrate how to call the above MS
: SQL Server stored procedure with result
: sets/dynasets in Visual Basic using DAO and RDO on top of
: ODBC. This code works for Oracle8i packages
: and stored procedures if you use an Intersolv ODBC driver
to
: understand Oracle REF CURSORs.
: DAO
: Private Sub Command2_Click()
: Dim sSql As String
: sSql = "{call byroyalty()}"
: 'In Oracle ODBC driver use refcusor argument to get
: result set
: Set rCustomers = dbsServer.OpenRecordset(sSql,
: dbOpenDynamic)
: Text4 = rCustomers.Fields(0)
: theend:
: End Sub
: Please note, this example assumes that a DAO connection
has
: been set up already.
: RDO
: Private Sub Command1_Click()
: StrSql = "{call byroyalty}"
: 'in oracle odbc driver uses refcusor argument to get
: result set
: Set Ps = connx1.CreatePreparedStatement("PsTest",
: StrSql)
: Set Rs = Ps.OpenResultSet(rdOpenStatic)
: Text3 = Rs!au_id
: Rs.Close
: End Sub
: Please note, this example assumes that an RDO connection
has
: been set up already.
: Jing Zhang (guest) wrote:
: : Hi, All,
: : Is there anybody know how much customize we can have for
using
: : the MWB when migrate stored procedure? For sample I have a
SQL
: : Server 6.5 strored procedure like following:
: : /******************* SQL Server 6.5 sp *************/
: : CREATE PROCEDURE sp_SelectUsers
: : AS
: : select
: : tbl_Sp_users.ID, UserName, Password, ExpiresOn,
: : PwdChangedDate, tbl_Sp_UserGrps.name
: : from
: : tbl_Sp_users, tbl_Sp_UserGrps
: : where
: : GroupID = tbl_Sp_UserGrps.id
: : order by username
: : /******************* end ***************************/
: : After I migrate it to Oracle 8 with MWB, I got following
: object,
: : one Pkg and one Procedure in Oracle db, like following:
: : /****************** Oracle Pkg **********************/
: : CREATE OR REPLACE PROCEDURE sp_SelectUsers(
: : RC1 IN OUT sp_SelectUsersPkg.RCT1)
: : AS
: : StoO_selcnt INTEGER;
: : StoO_error INTEGER;
: : StoO_rowcnt INTEGER;
: : StoO_errmsg VARCHAR2(255);
: : StoO_sqlstatus INTEGER;
: : BEGIN
: : OPEN RC1 FOR
: : SELECT tbl_Sp_users.ID, UserName, Password,
: : ExpiresOn, PwdChangedDate, tbl_Sp_UserGrps.name FROM
: : tbl_Sp_users, tbl_Sp_UserGrps
: : WHERE GroupID = tbl_Sp_UserGrps.id
: : ORDER BY username ;
: : END sp_SelectUsers;
: : /******************* Oracle Procedure ****************/
: : PROCEDURE sp_SelectUsers(
: : RC1 IN OUT sp_SelectUsersPkg.RCT1)
: : AS
: : StoO_selcnt INTEGER;
: : StoO_error INTEGER;
: : StoO_rowcnt INTEGER;
: : StoO_errmsg VARCHAR2(255);
: : StoO_sqlstatus INTEGER;
: : BEGIN
: : OPEN RC1 FOR
: : SELECT tbl_Sp_users.ID, UserName, Password,
: : ExpiresOn, PwdChangedDate, tbl_Sp_UserGrps.name FROM
: : tbl_Sp_users, tbl_Sp_UserGrps
: : WHERE GroupID = tbl_Sp_UserGrps.id
: : ORDER BY username ;
: : END sp_SelectUsers;
: : /******************* end *****************************/
: : As our client use RDO as access method, there is no way we
can
: : use this migrated SP in RDO and return resultset. We need
: : convert this SP to following to be able to use RDO to get
: : resultset back in client:
: : /******************* need convert to *********************/
: : create or replace package sp_selectUsersPkg
: : as
: : cursor c1
: : is select tbl_Sp_users.ID, UserName, Password,ExpiresOn,
: : PwdChangedDate, tbl_Sp_UserGrps.name
: : from tbl_Sp_users, tbl_Sp_UserGrps
: : where GroupID = tbl_Sp_UserGrps.id
: : order by username;
: : type UsersCur
: : is ref cursor return c1%ROWTYPE;
: : procedure sp_selectUsers(UserCursor in out UsersCur );
: : END;
: : create or replace package body sp_selectUsersPkg
: : as
: : procedure sp_selectUsers(UserCursor in out UsersCur )
: : is
: : begin
: : open UserCursor for
: : select tbl_Sp_users.ID, UserName,
: : password, ExpiresOn,
: : PwdChangedDate, tbl_Sp_UserGrps.name
: : from tbl_Sp_users, tbl_Sp_UserGrps
: : where GroupID = tbl_Sp_UserGrps.id
: : order by username;
: : end;
: : end;
: : /******************* end *********************************/
: : Is there any idea how we can do this? I hope we don't need do
: : this manually.
: : Thank you very much for any help!
: : Jing
Oracle Technology Network
http://technet.oracle.com
null -
Import/export only the stored procedure from DMP
Hi all,
pls tell how to import/export only the stored procedure from a DMP file.
Best Regards,
Subirpls tell how to import/export only the stored
procedure from a DMP file.If you on 10g or above use expdp / impdp for import/export only the SP.
Overview of Oracle Data Pump
- Virag Sharma
http://virag.sharma.googlepages.com
http://viragsharma.blogspot.com/ -
Connection object is getting closed before the stored procedure is complete
Hi Everyone,
I am facing an issue where by the java connection object is closed before the stored procedure it is connected to is complete.
I am not sure if the fault is in SP or Connection pool.
After spending some time, i could able to figure out that the procedure is taking a tad more time for processing as there are over 1000 records in the database tables it is dealing with.
Would that be a potential cause ? or Am i required to handle it in Java only ?
I want to know what could be possible causes for this issue ?
Please Help.
FYI,
The following are the logs which says,
XYZ (Stored Procedure) : Start Time is 1349217771302 Procedure started here
INFO >2012-10-02 18:43:09,935 [ConnectionPool]: Closing connection: DataSource [ABC](684)
INFO >2012-10-02 18:46:03,512 DAO[main]: XYZ : End Time is 1349217963512 Procedure ended here
Thanks in Advance.Hi ,
Thank you all for your quick response.
Well it's my bad i dint provide you any code to look into thinking that i am dealt with a gen issue and also i am too paranoid to post any code i am dealing with in the forum (i am sorry).
But here is some information for you,
Database : Oracle 10g
Java: 1.5 version
We are using only One connection object for the entire java backend process .
The SP is of over 1000 lines of code which for obvious reasons i can't past it here but this morning i figured out an issue in SP where by a query taking way more than usual time to execute which led to SP's poor performance and also the reason for why it is taking very long time than usual.
This query is a simple SELECT query where it is trying fetch over 2000 records from a table of over 3 million records. The execution time is over 30-40 seconds which is the root cause of SP's poor performance.
When i eliminated this from the logic and ran the query it could able process (inserting huge volume around 5000 records of data) in 1 second instead of 3-4 minutes earlier.
I tried to replicate this issue (which occurred in our production server) in my local system but no luck as there was no connection issue here but only the substantial time difference.
We are using a customized connection pool which is as follows,
I am not sure what's going on here because it seems to be greek and latin to me.
What we are doing in our DAO is we are using method of the below ConnectionPool.getInstance(SCHEMA) to get the connection object.
Looking forward to seeking advice from you on how connection pool in general works.
public class ConnectionPool extends Thread
private static final ConnectionPool me = new ConnectionPool();
private Hashtable dataSources = new Hashtable();
private static final int MIN_TIMEOUT = 0;
private long timeOut;
private Hashtable cons = new Hashtable();
private Hashtable active = new Hashtable();
private boolean trace = false;
private ConnectionPool()
registerDataSources();
this.timeOut = PropertyManager.getIntProperty("connectionPool.timeOut", MIN_TIMEOUT);
setName("ConnectionPool");
setPriority(MIN_PRIORITY);
if (timeOut > 0)
start();
private void registerDataSources()
dataSources.clear();
Properties props = System.getProperties();
String app = props.getProperty("X", "Y");
for(Enumeration e = props.keys(); e.hasMoreElements();)
String key = (String) e.nextElement();
if (key.startsWith(app + ".connectionPool.dataSources.") && key.endsWith(".selector"))
String ds = key.substring((app + ".connectionPool.dataSources.").length(), key.length() - ".selector".length());
LogManager.logStatus("Registering [" + ds + "] (selector) " +
props.getProperty(app + ".connectionPool.dataSources." + ds + ".selector"));
dataSources.put(ds,
new GenDataSource(
ds,
props.getProperty(app + ".connectionPool.dataSources." + ds + ".selector")));
continue;
if (!key.startsWith(app + ".connectionPool.dataSources.") || !key.endsWith(".server"))
continue;
String ds = key.substring((app + ".connectionPool.dataSources.").length(), key.length() - ".server".length());
try
LogManager.logStatus("Registering [" + ds + "] " +
props.getProperty(app + ".connectionPool.dataSources." + ds + ".url"));
loadDriver(props.getProperty(app + ".connectionPool.dataSources." + ds + ".driver"));
catch (Exception se)
LogManager.logException(se);
GenDataSource genDataSource = new GenDataSource(
ds,
props.getProperty(app + ".connectionPool.dataSources." + ds + ".useMatrix", "false").equals("true"),
props.getProperty(app + ".connectionPool.dataSources." + ds + ".server"),
props.getProperty(app + ".connectionPool.dataSources." + ds + ".url"),
props.getProperty(app + ".connectionPool.dataSources." + ds + ".user"),
props.getProperty(app + ".connectionPool.dataSources." + ds + ".password"));
// Set the schema if schema is defined in settings.xml file
if (genDataSource != null && props.getProperty(app + ".connectionPool.dataSources." + ds + ".schema") != null ) {
genDataSource.setSchema(props.getProperty(app + ".connectionPool.dataSources." + ds + ".schema"));
dataSources.put(ds, genDataSource);
public static Connection getConnection(String dataSource) throws SQLException
GenDataSource ds = (GenDataSource) me.dataSources.get(dataSource);
if (me.timeOut <= 0)
if (ds.getSchema() != null )
return updateSchema ( ds);
else
return DriverManager.getConnection(ds.url(), ds.user(), ds.password());
String key = dataSource;
Stack free;
GenPooledConnection pc = null;
synchronized (me)
if ((free = (Stack) me.cons.get(key)) == null)
free = new Stack();
me.cons.put(key, free);
if (!free.empty())
pc = (GenPooledConnection) free.pop();
if (pc == null)
if (ds.getSchema() != null )
pc = new GenPooledConnection("DataSource [" + key + "]",
updateSchema ( ds), free, me.active, me.timeOut, me.trace);
else
pc = new GenPooledConnection("DataSource [" + key + "]",
DriverManager.getConnection(ds.url(), ds.user(), ds.password()), free, me.active, me.timeOut, me.trace);
else
pc.touch();
LogManager.logStatus("Using " + pc);
me.active.put(pc.id(), pc);
return pc;
public void run()
for(;;)
try
sleep(60 * 1000);
synchronized (me) {
for(Enumeration e = cons.elements(); e.hasMoreElements();)
Stack stack = (Stack) e.nextElement();
for (int i = stack.size()-1; i >= 0; i--)
GenPooledConnection pc = (GenPooledConnection) stack.elementAt(i);
if (pc.isExpired())
stack.removeElementAt(i);
catch (Exception e)
GenUtil.reportException(e);
private static Connection updateSchema ( GenDataSource ds) throws SQLException {
Connection con = DriverManager.getConnection(ds.url(), ds.user(), ds.password());
if (ds.getSchema() != null ) {
String sql = "SET SCHEMA " + ds.getSchema()+ ";";
LogManager.logDebugMessage("updating the Schema with sql statement " + sql);
PreparedStatement ps = con.prepareStatement(sql);
ps.execute();
ps.close();
return con;
}Thanks.
Edited by: EJP on 5/10/2012 14:09: added {noformat}{noformat} tags. Please use them.
Maybe you are looking for
-
Account determination Error while posting to FI
Dear gurus, At the time of billing there is an error "error in account determination table T030K" the posting is not happening to FI. I am using a manual condition for excise. I have checked in the OB40 settings. G/L account is assigned to that parti
-
II'm trying to set up my AirPort Extreme in the field without an Internet connection so that devises can communicate wirelessly but there aren't any IP addresses being generated
-
Pushing case statement applied in answers formula to Database
Hi All, There are three prompts, for which there is a kind of header report with narrative view, now when user selects value in prompt element1 and do not select anything in prompt element 2 and 3, in the header only element1 should be displayed and
-
Need help with color replacement tool ps CS6
I am trying to use the color replacement tool to change the color of a shirt on a picture. I have choosen white as the foreground color, but when I go to paint it comes out grey.... I tried using colors from the swatch and the same thing is happenin
-
What is the best way to install an Airport to a G5?
Hi. My G5 came without a built in Airport card. I've recently bought an Airport Extreme. What is the best way to install an Airport to a G5? Should I buy the Airport card from ebay or some other retailer & do the installation myself OR should I buy i