View previous topic :: View next topic
|
Author |
Message |
knd_r Currently Banned New User
Joined: 18 Mar 2005 Posts: 48
|
|
|
|
hi,
In embedded sql, I am retrieving more than one row using select statement and i am getting -811 error. How to avoid this error and till I have to use that select with more than one row?
bye,
ks reddy. |
|
Back to top |
|
|
amolgijare
New User
Joined: 19 Mar 2005 Posts: 8 Location: Pune, India
|
|
|
|
try using cursors.....
hope this helps
- Amol |
|
Back to top |
|
|
MGIndaco
Active User
Joined: 10 Mar 2005 Posts: 432 Location: Milan, Italy
|
|
|
|
SQL abend error -811 usually denote a duplicate value as result of a query
This is from the manual:
Quote: |
-811 THE RESULT OF AN EMBEDDED SELECT STATEMENT IS A TABLE OF MORE THAN
ONE ROW, OR THE RESULT OF THE SUBQUERY OF A BASIC PREDICATE IS MORE
THAN ONE VALUE
|
To avoid this error you must to check the definition of the tables that you are joining and assure you that no duplicate value are produced by a subquery.
To assure your result, if it's possible, use in subquery a DISTINCT. |
|
Back to top |
|
|
knd_r Currently Banned New User
Joined: 18 Mar 2005 Posts: 48
|
|
|
|
hi amol,
I know how to use cursors, but here the situation is different. please understand the question.
hi mgindaco,
i am using distinct and i am retrieving more than one row in select statement using embedded sql, probably i will get -811 error. I dont want to face this error and i still want that sql statement retrieving more than one row. How to accomplish this?
for example: in cobol if we are reading out of range in a table we will face soc4 error, if we mention nossrange in compiler options then we wont get soc4 and still we can read out of range!
thanks,
ks reddy. |
|
Back to top |
|
|
chayanath
New User
Joined: 07 Mar 2005 Posts: 6 Location: vijayawda
|
|
|
|
hello,
cursors r the best way for one to retrieve more than one row at a time.dO FOLLWOING STEPS:
now declare cursor in WS-Section or procedure division as:
1) EXEC SQL
DECLARE <CURNAME> CURSOR FOR
//** < SQL QUERY ON WHICH U WANT TO GET THE DATA>****/
SELECT EMPNO,EMPNAME FROM EMP WHERE EMPN=='200'
END-EXEC.
2)EXEC SQL
OPEN <CURNAME>
END-EXEC.
3)EXEC SQL
FETCH <CURNAME>
END-EXEC.
4)EXEC SQL
CLOSE <CURNAME>
END-EXEC.
2,3 & 4 SHOULD BE IN PROCEDURE DIVISION.
BYE |
|
Back to top |
|
|
sreehari
New User
Joined: 07 Feb 2007 Posts: 1 Location: Chennai
|
|
|
|
Hi,
Try to add one more condition in the Where clause of your SQL query wihle joining the table then it will show Both the rows with out throwing the error.
Sreehari |
|
Back to top |
|
|
Santoshdorge
New User
Joined: 27 Jun 2006 Posts: 48 Location: Pune
|
|
|
|
Hi
IF you are interested in one row only then try to use fetch first 1 row only
clause.
thanks
Santosh |
|
Back to top |
|
|
skkp2006
New User
Joined: 14 Jul 2006 Posts: 93 Location: Chennai,India
|
|
|
|
Select can fetch only one row at a time....otherwise u have to go for cursors... there is no option as to fetch more than one row using a sql select(As in SSRANGE).
And to generalise include all the primary key variables(single/composite) in the where clause to avoid -811.
Regards,
Syam |
|
Back to top |
|
|
vini_srcna
Active User
Joined: 26 May 2005 Posts: 178 Location: Copenhagen, Denmark
|
|
|
|
Quote: |
Hi,
Try to add one more condition in the Where clause of your SQL query wihle joining the table then it will show Both the rows with out throwing the error. ...........???????
Sreehari
|
If you want to see how many rows are satisfied for that condition, then take COUNT(*). If you want to fetch the rows, then you have to go for CURSOR'S. This is a trade off for your scenario. No other option for you.
Singleton select can give one & only one row.[/b] |
|
Back to top |
|
|
kgumraj
Active User
Joined: 01 May 2006 Posts: 151 Location: Hyderabad
|
|
|
|
Hi,
When you handle Sqlerrors, you by pass -811 also, hope that solves. |
|
Back to top |
|
|
priyamnavada
New User
Joined: 24 Dec 2005 Posts: 52 Location: hyderabad
|
|
|
|
Just handle it seperately using WHEN -811 clause and later retrive all the rows using singleton selelct, moving into table.
later use the table for futher.
Hope i answered your doubt. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
vini_srcna,
Quote: |
Singleton select can give one & only one row.
|
that is true, but on versions before db2V8, your host variables will still be populated when you receive a -811. V8 supposedly will not populate the host variables. (have not tested it yet).
vsn7 and before:
ibm just says that even though the host variables are populated when receiving a -811, the result row used to populate is not known, nor can it be, since you can't use an order by clause on a singleton select. |
|
Back to top |
|
|
mbatta1
New User
Joined: 30 Jan 2008 Posts: 3 Location: chennai
|
|
|
|
if you want only a single variable then you can use distinct so that you will get only one value insted of multiple values
if you want to get multiple results then use cursor |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
mbatta1,
did you bother to notice that this thread is a little old.
also, since the op never did bother to show his/her sql, you really have no idea what the op was trying to do.
do you plan to try to up your post count by responding to all the old threads? |
|
Back to top |
|
|
|