Solved

Passing string of IDs to Oracle stored procedure

Posted on 2004-08-04
6
886 Views
Last Modified: 2008-03-17
We created a stored procedure to copy all fields of specified records from one table to another:

CREATE OR REPLACE PROCEDURE "XX"."EXPORT_XXXX" ( sIDS  VARCHAR2) IS
BEGIN
 INSERT INTO "XX"."EXPXXXX"  (SELECT * from "XX"."XXXX" WHERE XX.XXXX.INTID IN  (sIDS));
END;

If we call it with deXX.procEXPORT_XXXX( "1") then all is fine.
If we call it with deXX.procEXPORT_XXXX( "1,2,3") then Oracle indicates an invalid number.
I think the problem is that we cannot pass numbers in strings to Oracle.
Maybe we have to create an array inside the proc and populate it with the numbers extracted from the sIDS string.
Or maybe there is some other calling type we can use such as VARIANT.

Any solutions to the problem welcome.


0
Comment
Question by:CharlesSHill
  • 5
6 Comments
 
LVL 6

Expert Comment

by:PePi
ID: 11716735
why not create the sql string dynamically and pass it to the stored procedure for execution.
0
 

Author Comment

by:CharlesSHill
ID: 11716828
Good Idea, what would my Stored Procedure then look like? Sorry, have never worked with SPs
0
 
LVL 6

Expert Comment

by:PePi
ID: 11717879
i'm not familiar with Oracle SQL syntax. there is a system stored procedure for SQL Server called sp_executesql where you just pass the sql statement as a parameter. Oracle might have a similar system stored procedure that's equivalent to sp_executesql.

in my case, i created my own stored procedure using this system stored procedure.

CREATE PROCEDURE unsp_EXECUTE_SQL
(
    @sql nvarchar(4000)
)
AS
    EXEC sp_executesql @sql
GO

i then call this stored procedure and pass my dynamically created stored procedure.

hope this helps
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 6

Expert Comment

by:PePi
ID: 11717893
btw, is your application written in VB6? just curious
0
 
LVL 6

Expert Comment

by:PePi
ID: 11717961
ooops

i mean i call the stored procedure passing my dynamically created sql statement
0
 
LVL 6

Accepted Solution

by:
PePi earned 125 total points
ID: 11718623
i found the equivalent of sp_executesql for oracle. its EXECUTE IMMEDIATE and its syntax is:

EXECUTE IMMEDIATE SQL_string
   [INTO {define_variable[, define_variable]... | record}]
   [USING [IN | OUT | IN OUT] bind_argument
       [, [IN | OUT | IN OUT] bind_argument]...];

SQL_string
A string expression containing the SQL statement or PL/SQL block

define_variable
A variable that receives a column value returned by a query

record
A record based on a user-defined TYPE or %ROWTYPE that receives an entire row returned by a query

bind_argument
An expression whose value is passed to the SQL statement or PL/SQL block

INTO clause
Use for single-row queries; for each column value returned by the query, you must supply an individual variable or field in a record of compatible type.

USING clause
Allows you to supply bind arguments for the SQL string. This clause is used for both dynamic SQL and PL/SQL, which is why you can specify a parameter mode. This usage is only relevant for PL/SQL, however; the default is IN, which is the only kind of bind argument you would have for SQL statements.


example:

EXECUTE IMMEDIATE 'SELECT * FROM Employee WHERE Emp_ID = (eID)';
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question