473,385 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Output parameter and dynamic sql

Hi.

I have a stored procedure on a Oracle 8.1.6 database that generates a
dynamic sql statement. This stored procedure has an output parameter
that needs to return a count from a view. I can generate and run the
sql successfuly, but when I try to return the count I get errors. I am
showing the relevant part of the procedure, since the rest of
concatenations are used to compose the sql.

CREATE OR REPLACE PROCEDURE getScoreEntries (user VARCHAR2, level
NUMBER, ret OUT NUMBER)
AS

sCall VARCHAR2(500);
nTotal NUMBER;

BEGIN
sCall := 'SELECT COUNT(*) INTO nTotal FROM vw_Scores WHERE
UserName=''' || user || '''';
sCall := sCall || --dynamic sql continues here...

EXECUTE IMMEDIATE sCall;
ret := nTotal;

END getTotalEntries;

Can anyone help me with this issue?

Thanks,
Robert Scheer
Jul 19 '05 #1
4 24604
A quick look of your code shows two things that need revising:
(1) You need to use the INTO clause of EXECUTE IMMEDIATE when you want
to get the results of a single-row query. In your case, the "count(*)"
value.
(2) Use bind arguments whenever possible (USING clause). That's the
"where username" condition for you.

So try something like this:

....
sCall := 'SELECT COUNT(*) FROM vw_Scores WHERE UserName = :username';

EXECUTE IMMEDIATE sCall INTO nTotal USING user;
....

Do read the PL/SQL guide for more detailed info. HTH.

rb******@my-deja.com (Robert Scheer) wrote in message news:<cf*************************@posting.google.c om>...
Hi.

I have a stored procedure on a Oracle 8.1.6 database that generates a
dynamic sql statement. This stored procedure has an output parameter
that needs to return a count from a view. I can generate and run the
sql successfuly, but when I try to return the count I get errors. I am
showing the relevant part of the procedure, since the rest of
concatenations are used to compose the sql.

CREATE OR REPLACE PROCEDURE getScoreEntries (user VARCHAR2, level
NUMBER, ret OUT NUMBER)
AS

sCall VARCHAR2(500);
nTotal NUMBER;

BEGIN
sCall := 'SELECT COUNT(*) INTO nTotal FROM vw_Scores WHERE
UserName=''' || user || '''';
sCall := sCall || --dynamic sql continues here...

EXECUTE IMMEDIATE sCall;
ret := nTotal;

END getTotalEntries;

Can anyone help me with this issue?

Thanks,
Robert Scheer

Jul 19 '05 #2
A quick look of your code shows two things that need revising:
(1) You need to use the INTO clause of EXECUTE IMMEDIATE when you want
to get the results of a single-row query. In your case, the "count(*)"
value.
(2) Use bind arguments whenever possible (USING clause). That's the
"where username" condition for you.

So try something like this:

....
sCall := 'SELECT COUNT(*) FROM vw_Scores WHERE UserName = :username';

EXECUTE IMMEDIATE sCall INTO nTotal USING user;
....

Do read the PL/SQL guide for more detailed info. HTH.

rb******@my-deja.com (Robert Scheer) wrote in message news:<cf*************************@posting.google.c om>...
Hi.

I have a stored procedure on a Oracle 8.1.6 database that generates a
dynamic sql statement. This stored procedure has an output parameter
that needs to return a count from a view. I can generate and run the
sql successfuly, but when I try to return the count I get errors. I am
showing the relevant part of the procedure, since the rest of
concatenations are used to compose the sql.

CREATE OR REPLACE PROCEDURE getScoreEntries (user VARCHAR2, level
NUMBER, ret OUT NUMBER)
AS

sCall VARCHAR2(500);
nTotal NUMBER;

BEGIN
sCall := 'SELECT COUNT(*) INTO nTotal FROM vw_Scores WHERE
UserName=''' || user || '''';
sCall := sCall || --dynamic sql continues here...

EXECUTE IMMEDIATE sCall;
ret := nTotal;

END getTotalEntries;

Can anyone help me with this issue?

Thanks,
Robert Scheer

Jul 19 '05 #3
rb******@my-deja.com (Robert Scheer) wrote in message news:<cf*************************@posting.google.c om>...
Hi.

I have a stored procedure on a Oracle 8.1.6 database that generates a
dynamic sql statement. This stored procedure has an output parameter
that needs to return a count from a view. I can generate and run the
sql successfuly, but when I try to return the count I get errors. I am
showing the relevant part of the procedure, since the rest of
concatenations are used to compose the sql.

CREATE OR REPLACE PROCEDURE getScoreEntries (user VARCHAR2, level
NUMBER, ret OUT NUMBER)
AS

sCall VARCHAR2(500);
nTotal NUMBER;

BEGIN
sCall := 'SELECT COUNT(*) INTO nTotal FROM vw_Scores WHERE
UserName=''' || user || '''';
sCall := sCall || --dynamic sql continues here...

EXECUTE IMMEDIATE sCall;
ret := nTotal;

END getTotalEntries;

Can anyone help me with this issue?

Thanks,
Robert Scheer


Don't see an INTO clause after the execute immediate statement.

Other than that: do you think anyone here can guess what your
unspecified errors are?

Sybrand Bakker
Senior Oracle DBA
Jul 19 '05 #4
Hi Romeo,

thanks, it worked!

Robert Scheer
ro******@hotmail.com (Romeo Olympia) wrote in message news:<42**************************@posting.google. com>...
A quick look of your code shows two things that need revising:
(1) You need to use the INTO clause of EXECUTE IMMEDIATE when you want
to get the results of a single-row query. In your case, the "count(*)"
value.
(2) Use bind arguments whenever possible (USING clause). That's the
"where username" condition for you.

So try something like this:

...
sCall := 'SELECT COUNT(*) FROM vw_Scores WHERE UserName = :username';

EXECUTE IMMEDIATE sCall INTO nTotal USING user;
...

Do read the PL/SQL guide for more detailed info. HTH.

rb******@my-deja.com (Robert Scheer) wrote in message news:<cf*************************@posting.google.c om>...
Hi.

I have a stored procedure on a Oracle 8.1.6 database that generates a
dynamic sql statement. This stored procedure has an output parameter
that needs to return a count from a view. I can generate and run the
sql successfuly, but when I try to return the count I get errors. I am
showing the relevant part of the procedure, since the rest of
concatenations are used to compose the sql.

CREATE OR REPLACE PROCEDURE getScoreEntries (user VARCHAR2, level
NUMBER, ret OUT NUMBER)
AS

sCall VARCHAR2(500);
nTotal NUMBER;

BEGIN
sCall := 'SELECT COUNT(*) INTO nTotal FROM vw_Scores WHERE
UserName=''' || user || '''';
sCall := sCall || --dynamic sql continues here...

EXECUTE IMMEDIATE sCall;
ret := nTotal;

END getTotalEntries;

Can anyone help me with this issue?

Thanks,
Robert Scheer

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bob | last post by:
Everybody, I've been doing a lot of on-line research and cannot find any reference to the exact problem I'm having. Let me preface this question with the fact that I'm coming from an Oracle...
7
by: LineVoltageHalogen | last post by:
Greetings All, I have a very large query that uses dynamic sql. The sql is very large and it requires it to be broken into three components to avoid the nvarchar(4000) issue: SET @v_SqlString(...
6
by: Patrik | last post by:
I know this has been dealt with a lot, but I would still really appreciate help. Thanks. I am trying to transform this table YY--ID-Code-R1-R2-R3-R4...R40 2004-1-101--1--2-3-4...
11
by: Axel | last post by:
Hi, I am currently creating an ASP page that returns a recordset of search result based on multiple keywords. The where string is dynamically built on the server page and that part work quite...
8
by: FS Liu | last post by:
Hi, I am writing ATL Service application (XML Web service) in VS.NET C++. Are there any sample programs that accept XML as input and XML as output in the web service? Thank you very much.
0
by: Martin | last post by:
Hi. I had a very frustrating afternoon and evening but I have got it all under control now so all of a sudden I am in a good mood. I want to share some insights on output caching with you lot. ...
4
by: Todd Perkins | last post by:
Hello all, surprisingly enough, this is my first newsgroup post, I usually rely on google. So I hope I have enough info contained. Thank you in advance for any help! Problem: I am getting...
2
by: Nemisis | last post by:
Hi everyone, I am saving a record to SQL and want to return the ID of the record added as an output parameter, can you do this in dynamic SQL, without the use of a stored procedure?? i.e. ...
4
by: Robert Scheer | last post by:
Hi. I have a stored procedure on a Oracle 8.1.6 database that generates a dynamic sql statement. This stored procedure has an output parameter that needs to return a count from a view. I can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.