Please help convert MSSQL Stored Procedure to Oracle PL/SQL
Hi there to all,
this be my first post to these forums. I have already posted this question on a microsoft msdn forum, until someone advised that I ask my question here - dunno why I didnt think of that! ?:|
Im working with an Oracle 10g Database from an ASP.NET 2.0 application, and want to know if it Oracle supports OPENXML (rhetorical question I fear!). The reason I ask is because I want to create an Oracle Stored Procedure that will accept an XML string as an input parameter, prepare it, select from it, and then insert it into an Oracle table.
I have done this successfully in SQL server using the following as an example:
CREATE PROCEDURE [dbo].[Employee_INSERT]
bq. @INSERTRECORD XML
AS
BEGIN
bq. DECLARE @XDOC INT; \\ EXEC sp_xml_preparedocument @XDOC OUTPUT, @INSERTRECORD; \\ INSERT INTO [dbo].[REC_Employees] (
bq. bq. [EMPTITLE], \\ [EMPFNAME], \\ [EMPLNAME], \\ [EMPDEPTID], \\ [EMPBEGINDATE], \\ [EMPACTIVE], \\ [EMPDATEADDED]
bq. )
bq. SELECT
bq. bq. [EMPTITLE] = Title, \\ [EMPFNAME] = Firstname, \\ [EMPLNAME] = LastName, \\ [EMPDEPTID] = DepartmentID, \\ [EMPBEGINDATE] = StartDate, \\ [EMPACTIVE] = IsActive, \\ [EMPDATEADDED] = GETUTCDATE()
bq. FROM
bq. bq. OPENXML(@XDOC, '/EMPREC/Table', 2) \\ WITH (
bq. bq. Title VARCHAR(10), \\ FirstName VARCHAR(50), \\ LastName VARCHAR(50), \\ DepartmentID INT, \\ StartDate DATETIME, \\ IsActive BIT
bq. bq. );
bq. EXEC sp_xml_removedocument @XDOC;
END
I would sincerely appreciate any help in this regard!
PS - Please excuse the formatting!
Much Thanks!
regards
shalan
Assuming your table is named DESTINATION
Name Null? Type
TITLE VARCHAR2(10)
FIRSTNAME VARCHAR2(50)
LASTNAME VARCHAR2(50)
DEPARTMENT NUMBER
STARTDATE DATE
ISACTIVE NUMBERYou can use a procedure like:
create or replace
procedure test (p_xml in xmltype)
is
begin
insert into destination
select title
, firstname
, lastname
, department
, to_date (startdate, 'yyyy-dd-mm hh24:mi:ss') startdate
, isactive
from (xmltable ('/EMPREC/Table' passing p_xml
columns title varchar2(5) path 'Title'
, firstname varchar2(10) path 'FirstName'
, lastname varchar2(10) path 'LastName'
, department number path 'Department'
, startdate varchar2(20) path 'StartDate'
, isactive number path 'IsActive'
) temp
end test;to create records in the table
Removed a unnecessary SELECT FROM DUAL...
Edited by: Alex Nuijten on Jan 19, 2009 2:24 PM
Similar Messages
-
How to convert MSSQL stored procedure to PostgreSQL
Hi,
Anyone can help me...?
How to convert MSSQL stored procedure to PostgreSQL function?
Is there any tool available to convert T-SQL from MSSQL to PostgreSQL?
Thanks in advanceHello
Here, I write one sample stored procedure of SQL Server which I need to convert into PostgreSQL. Please help me in this with PostgreSQL.
Thanks in advance.
Below is sample SQL Server stored procedure: require to convert into PostgreSQL stored procedure
CREATE PROCEDURE [dbo].[usp_GetData_ByTableName]
@TableName NVARCHAR(MAX)
,@IncludeKeepAlive BIT
,@RowsAffected BIGINT=0 OUTPUT
) AS
BEGIN
SET NOCOUNT ON
DECLARE @SQL VARCHAR(MAX)
Select data base on parameter.
SET @SQL =
SELECT *FROM '+@TableName+'
WHERE 1=1
+
CASE WHEN (@IncludeKeepAlive = 0)
THEN
AND [MessageTransactionID] <> 152
ELSE
END
EXECUTE SP_EXECUTESQL @SQL
RETURN 0 -
Converting DB2 stored procedure to Oracle?
I need a little help with a problem I ran across this week. I have an existing DB2 Stored procedure that calls a COBOL program. (See the procedure below). Now, I need to convert this DB2 to an Oracle Stored Procedure. I need the procedure to call the same COBOL program that this DB2 procedure does. Is it possible in Oracle? Do I need to write a Java wrapper class instead? Please help!!
CREATE PROCEDURE CO_CASEINFORMATION (
IN PARM1 CHAR(006) FOR SBCS DATA CCSID EBCDIC ,
IN PARM2 CHAR(018) FOR SBCS DATA CCSID EBCDIC ,
IN PARM3 CHAR(004) FOR SBCS DATA CCSID EBCDIC ,
IN PARM4 CHAR(008) FOR SBCS DATA CCSID EBCDIC ,
IN PARM5 CHAR(026) FOR SBCS DATA CCSID EBCDIC
LANGUAGE COBOL
EXTERNAL NAME COSP183
COLLID CACSDEV9
PARAMETER STYLE GENERAL
NOT DETERMINISTIC
MODIFIES SQL DATA
WLM ENVIRONMENT CACSDEV9
STAY RESIDENT YES
RESULT SETS 01
;Although I've never done that with COBOL, the documentation says it is possible to call an external COBOL procedure from within Oracle, without a Java wrapper class.
The way to do it is to rebuild your COBOL program with the Pro*COBOL pre-compiler.
Read the Pro*COBOL Programmer's Guide for more details. -
MSSQL stored procedures to Oracle migration
I am working on a migration from MSSQL2K to Oracle 10g. I have used the Oracle Migration Workbench to do the initial conversion, and I am having to do a ton of by hand conversion. There are some stored procedures that the OMWB did not bring over at all, however.
Does anybody know of a utility that can take a single MSSQL stored procedure and convert it to a Oracle PL/SQL procedure or function? I am somewhat tired of doing entire procedures by hand. It is very tedious.
wallyWally, there is a process to this kind of migration. In a lot of instances the OMWB will not map some of your stored procedures and hence, at the end of the migration you will see them as missing. Go back to the Source model view and using the log window, filter so you just see the errrors. Comment out the offending statements and right click on the object to parse it again. If it is correct it will appear in the Oracle Model. Once it has appeared there it will be generated into your Oracle database. However, you may still need to verifiy that you have got equivilence by testing the procedure.
-
How to call MSSQL stored procedure from oracle database
MSSQL and Oracle databases are linked thru ODBC link using Oracle HSODBC.
I can query MSSQL table or view from Oracle Database using standard notation for acessing remote objects schema.object@dblink_name...
Can anybody give me syntax for calling MSSQL stored procedure thru ODBC database link?
I tried syntax exec schema.stored_procedure@dblink_name but it doesn't work...i'm getting schema.stored_procedure must be declared error...
Tnx,in advance!
Dejan BoticaOracle database 10gR2.
MSSQL2000 database.
For example query:
select * from dbo.Tbl_Test@kron@dw_jamnica; works fine...
...while for example exec dbo.Test@kron@dw_jamnica;
reports error:
ORA-06550: line 1, column 7:
PLS-00201: identifier 'DBO.TEST@KRON@DW_JAMNICA' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Table Tbl_Test and procedure Test exists in MSSQL instance.
Regards,
Dejan -
Convert Informix "with resume" feature in stored procedures to Oracle PL/SQL
I am trying to convert an Informix stored procedure with the "return value with resume"
feature into Oracle PL/SQL.
So far, all I have gathered is that I need to use packages and reference cursors.
What is hazy is that how and when does this value get returned? Is it on the execution of the FETCH statement or do I need to specify a RETURN statement.
If anybody has any ideas or better yet any
concrete examples, please email me.
Thank you.This is a small example of the use of ref cursor , for further details see the Oracle documentation
PL/SQL User's Guide and Reference
Release 8.1.6
A77069-01 . The stored procedure converter for informix (downloadable from Oracle Technology Network) does not unfortunately cover this situation.
Turloch
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
BEGIN
OPEN RC1 FOR
SELECT VERSION FROM MTG_VERSION;
END byroyalty;
END; -
Dear Friends,
I have a lot of c-stored procedures for DB2,
now,I want to use these c-stored procedures in Oracle directly without any changes.
I'm not sure whether this method is right.
Please help me.
GuangI think, that the best way inclusion of business logic into ORACLE database as a TABLE-constraints, triggers and stored procedures for guaranteeing data integrity.
But if you have really a LOT of c-stored procedures and you need provide quick startup with ORACLE, than you can use your c-procedures as "external calls" with ORACLE.
Unfortunately I don't know DB2 c-stored procedures specifics and can't give finally recommendations for you.
Sincerely, Urry -
Importing function with multiple ref cursors in Stored Procedure of Oracle 12c database Using EF6
Hi Good day!
I can able to import function for stored procedure of oracle db and able to add the complex type and get the output but i tried to import the procedure which having two ref cursors and unable to retrieve the column information. Only able to retrieve the
columns of first ref cursor. Please help me to get the result of two ref cursors which acting as out parameters.Having to ref cursors return mutiple recordsets in an Oracle package is like haveng two resultsets return from a MS SQL Server sparc.
The link may point you in the right direction.
http://www.codeproject.com/Articles/675933/Returning-Multiple-Result-Sets-from-an-Entity-Fram -
How to call a sql server stored procedure from oracle
Hi all,
Please anybody tell me how to call a sql server stored procedure from oracle.
I've made an hsodbc connection and i can do insert, update, fetch data in sql server from oracle. But calling SP gives error. when I tried an SP at oracle that has line like
"dbo"."CreateReceipt"@hsa
where CreateReceipt is the SP of sql server and hsa is the DSN, it gives the error that "dbo"."CreateReceipt" should be declared.
my database version is 10g
Please help me how can i call it... I need to pass some parameters too to the SP
thanking youhi,
thank you for the response.
when i call the sp using DBMS_HS_PASSTHROUGH, without parameters it works successfully, but with parameters it gives the following error
ORA-28500: connection from ORACLE to a non-Oracle system returned this message:
[Generic Connectivity Using ODBC][Microsoft][ODBC SQL Server Driver]Invalid parameter number[Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index (SQL State: S1093; SQL Code: 0)
my code is,
declare
c INTEGER;
nr INTEGER;
begin
c := DBMS_HS_PASSTHROUGH.OPEN_CURSOR@hsa;
DBMS_HS_PASSTHROUGH.PARSE@hsa(c, 'Create_Receipt(?,?)');
DBMS_HS_PASSTHROUGH.BIND_VARIABLE@hsa(c,1,'abc');
DBMS_HS_PASSTHROUGH.BIND_VARIABLE@hsa(c,2,'xyz');
nr:=DBMS_HS_PASSTHROUGH.EXECUTE_NON_QUERY@hsa(c);
DBMS_HS_PASSTHROUGH.CLOSE_CURSOR@hsa(c);
end;
Create_Receipt is the sp which requires two parameters.
please give me a solution
thanking you
sreejith -
How to migrate MySQL stored procedure to Oracle
Hi All,
I migrated mysql 5.1.42-enterprise-gpl-advanced DB to oracle using sqldeveloper 3.1.07 tool.
DB objects migrated successfully except Stored Procedures.
I verified .sql and Out files.. Capture process not captured stored procedures SQL.
Could you please suggest, where I can verify exact error or how to fix this issue.
Thanks in advance.Hi,
The SQL*Developer version you are using is an old one and you should use the latest version available from this link -
Oracle SQL Developer
However, even the v4 version does not support the migration of MySQL stored procedures as shown in this link -
http://www.oracle.com/technetwork/developer-tools/sql-developer/supportedmigplatforms-086703.html
You will have to manually convert the MySQL stored procedures to an Oracle format, as even the 'Scratch Editor' under 'Tools - Migration' - does not have an option for MySQL conversion.
The documentation has details of the difference between MySQL and Oracle stored procedures -
Oracle® SQL Developer Supplementary Information for MySQL Migrations
in the chapter Triggers and Stored Procedures
Regards,
Mike -
How to create java stored procedure from oracle(Dastageer)
how to create java stored procedure from oracle-please help me to create the procedure.
Hi,
This forum is exclusively for discussions related to Sun Java Studio Creator. Please post your question in the appropriate forum.
Thanks,
RK. -
MSSQL Stored procedure : only one command executed
For a MSSQL Stored Procedure, We have used this
Solution1:
Just put SET NOCOUNT OFF in the end of the stored procedure. After that run the stored procedure in the Desktop Intelligence report.
Or
If the above doesnu2019t works then please try the following solution.
Solution2:
You have to add the given parameter in .sbo file -> save the file and run the stored Procedure.
This file should be located under <drive>\Business Objects\BusinessObjects Enterprise 11.5\dataAccess\RDBMS\connectionServer\odbc\odbc.sbo
<Defaults>
<Parameter Name="Force SQLExecute">Always</Parameter>
but it still does not work
What others?Hello
thank you for your answer but indicated procedure to test does not work too
the message is the same : u201CNo column and no data to fetchu201D
I return with more details :
to create a new report DesKi, I use this stored procedure
CREATE PROCEDURE dbo.test1 @matricule integer
AS
BEGIN
SET NOCOUNT OFF
delete from Temp_matr_boucle
execute absences_matricules_per_matr @matricule /* it is ok */
select MATRICULE ,NOM ,PRENOM ,CDDEP, NBR_PERIODE, NBR_JOURS , UNITE ,
DATE_MIN, DATE_MAX ,TYPE_ABSENCE, MATRICULE_CAR, NBR_JOURS_SERVICES
from Temp_matr_boucle as result /* not execute */
return
END
Launched directly from the database it work verry well.
Launched in Deski rapport, we get the same message
u201CNo column and no data to fatchu201D
The exec command works because the table "Temp_matr_boucle" is filled but is no longer running the select commande.
You have advisor to use one a two solutions (see replay from DWinkel)
1) SET NOCOUNT OFF
or
2) add the parameter:
<Defaults>
<Parameter Name="Force SQLExecute">Always</Parameter> in odbc.sbo file
Note that we use the OLEDB driver and not the odbc
We all tried both but the result is the same
thank you for your help
regards
Mariana -
Need sample source code for calling stored procedure in Oracle
Hi.
I try to call stored procedure in oracle using JCA JDBC.
Anybody have sample source code for that ?
Regards, Arnold.Thank you very much for a very quick reply. It worked, but I have an extended problem for which I would like to have a solution. Thank you very much in advance for your help. The problem is described below.
I have the Procedure defined as below in the SFCS1 package body
Procedure Company_Selection(O_Cursor IN OUT T_Cursor)
BEGIN
Open O_Cursor FOR
SELECT CompanyId, CompanyName
FROM Company
WHERE CompanyProvince IN ('AL','AK');
END Company_Selection;
In the Oracle Forms, I have a datablock based on the above stored procedure. When I execute the form and from the menu if I click on Execute Query the data block gets filled up with data (The datablock is configured to display 10 items as a tabular form).
At this point in time, I want to automate the process of displaying the data, hence I created a button and from there I want to call this stored procedure. So, in the button trigger I have the following statements
DECLARE
A SFCS1.T_Cursor;
BEGIN
SFCS1.Company_Selection(A);
go_Block ('Block36');
The cursor goes to the corresponding block, but does not display any data. Can you tell me how to get the data displayed. In the future versions, I'm planning to put variables in the WHERE clause. -
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! *{;-) -
SQLException while calling a Stored Procedure in Oracle
Hi all,
I am getting this error while calling a Stored Procedure in Oracle...
java.sql.SQLException: ORA-00600: internal error code, arguments: [12259], [], [
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:207)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:540)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1273)
at oracle.jdbc.ttc7.TTC7Protocol.fetch(TTC7Protocol.java:780)
at oracle.jdbc.driver.OracleResultSet.next(OracleResultSet.java:135)
at StoredProcedureDemo.main(StoredProcedureDemo.java:36)
The Program is ...
import java.sql.*;
public class StoredProcedureDemo {
public static void main(String[] args) throws Exception {
Connection con = null;
ResultSet rs = null;
Statement st = null;
CallableStatement cs = null;
int i;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:SHYAM","scott","tiger");
System.out.println("Got Connection ");
st = con.createStatement();
String createProcedure = "create or replace PROCEDURE Get_emp_names (Dept_num IN NUMBER) IS"
+" Emp_name VARCHAR2(10);"
+" CURSOR c1 (Depno NUMBER) IS"
+" SELECT Ename FROM emp WHERE deptno = Depno;"
+" BEGIN"
+" OPEN c1(Dept_num);"
+" LOOP"
+" FETCH c1 INTO Emp_name;"
+" EXIT WHEN C1%NOTFOUND;"
+" END LOOP;"
+" CLOSE c1;"
+" END;";
System.out.println("Stored Procedure is \n"+createProcedure);
i = st.executeUpdate(createProcedure);
System.out.println("After creating the Stored Procedure "+i);
cs = con.prepareCall("{call Get_emp_names(?)}");
System.out.println("After calling the Stored Procedure ");
cs.setInt(1,20);
System.out.println("Before executing the Stored Procedure ");
rs = cs.executeQuery();
System.out.println("The Enames of the given Dept are ....");
while(rs.next()) {
System.out.println("In The while loop ");
System.out.println(rs.getString(1));
catch (Exception e) {
e.printStackTrace();
Stored Procedure is ...
create or replace PROCEDURE Get_emp_names (Dept_num IN NUMBER) IS
Emp_name VARCHAR2(10);
CURSOR c1 (Depno NUMBER) IS
SELECT Ename FROM emp WHERE deptno = Depno;
BEGIN
OPEN c1(Dept_num);
LOOP
FETCH c1 INTO Emp_name;
EXIT WHEN C1%NOTFOUND;
END LOOP;
CLOSE c1;
END;
Stored procedure is working properly on sql*plus(Oracle 8.1.5)) editor. But it is not working from a standalone java application. Can anyone please give me a solution.
thanks and regards
Shyam KrishnaThe first solution is to not do that in java in the first place.
DDL should be in script files which are applied to oracle outside of java.
Other than I believe there are some existing stored procedures in Oracle that take DDL strings and process them. Your user has to have permission of course. You can track them down via the documentation.
Maybe you are looking for
-
Certain fields should be defaulted at Goods Receipt of equipments
Dear ALL When new Materials are arrived at Warehouse MIGO in the back ground Equipment is generated (Equipment with material and serial number) Now we want certain Data to be filled automatically in the background like company code, planning plant wh
-
Vendor Payments in Foreign Currency
Hi, Vendor account is maintained in INR We receive purchase invoice from vendor in USD. can we make payment in USD through out going payments. Thanks
-
Inserting pictures in Webi documents
Hello, I would like to paste or to insert a picture in my webi document. This picture can be a company logo or something like that. But the functionality of inserting a URL which goes to a picture is not enough. Is there no other way of inserting a p
-
My macbook is sleeping all the time!
About 2 weeks ago, my macbook instantly sleeped. From that day to now, my macbook could just not awake! do anyone knows how to fix it? or i have to buy another mac? Thanks, your answer is completely appreciated.
-
Can I copy the filter/motion/effect settings from one clip to others?
I've got a series of photos in my timeline, each will move with some random little rotation and zoom in/out pan, etc... on a black background. Can I save some time by setting up one photo with the effects the way I want it and then copying those sett