IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to fix SQLCODE -811?


IBM Mainframe Forums -> ABENDS & Debugging
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
madlui56

New User


Joined: 08 Aug 2006
Posts: 61
Location: Philippines

PostPosted: Tue Jun 26, 2007 12:28 pm
Reply with quote

What does this mean SQLCODE -811 and solution for this?
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1209
Location: Bangalore,India

PostPosted: Tue Jun 26, 2007 12:39 pm
Reply with quote

Hi There,

It means that u try to insert a row which is violating unique index clause

Code:
-811 THE RESULT OF AN EMBEDDED SELECT STATEMENT OR A SUBSELECT IN THE     
       SET CLAUSE OF AN UPDATE STATEMENT IS A TABLE OF MORE THAN ONE ROW,
       OR THE RESULT OF A SUBQUERY OF A BASIC PREDICATE IS MORE THAN ONE 
       VALUE   


Please download abend assist from the site
Back to top
View user's profile Send private message
ParagChouguley

Active User


Joined: 03 Feb 2007
Posts: 175
Location: PUNE(INDIA)

PostPosted: Tue Jun 26, 2007 1:29 pm
Reply with quote

Hi,
you can even get -811 in an embedded SQL SELECT, if your query returns more than one row. The description is as follows.

Execution of an embedded SELECT statement has resulted in a result table containing more than one row. Alternatively, a subquery contained in a basic predicate has produced more than one value.

Understanding SQLCODE -811:

Definition:

SQLCODE -811, also known as "More than one row retrieved in SELECT INTO," occurs in DB2 when a SELECT INTO statement is executed, but the result set contains multiple rows instead of a single row.

Common Causes:

Incorrect WHERE Clause: The SELECT statement may not have a precise WHERE clause, causing it to retrieve multiple rows.
Uniqueness Violation: The target column(s) specified in the SELECT INTO statement may not be unique, leading to multiple matches.
Subquery Issues: If the SELECT INTO statement includes a subquery, ensure that the subquery returns a single row.

Steps to Resolve SQLCODE -811:

Review SQL Statement:
Analyze the SQL statement that triggered the SQLCODE -811 error. Check the SELECT INTO statement, including the WHERE clause, column specifications, and subqueries.

Ensure Uniqueness:
Ensure that the target column(s) specified in the SELECT INTO statement uniquely identify a single row in the result set. Use primary keys or unique constraints where applicable.

Refine WHERE Clause:
Modify the WHERE clause in the SELECT statement to ensure it retrieves only a single row that matches the criteria.
Use additional criteria or join conditions to narrow down the result set if needed.

Use FETCH FIRST 1 ROWS ONLY:
Instead of SELECT INTO, consider using a FETCH FIRST 1 ROWS ONLY clause in your SELECT statement if you only need one row from the result set.
Example: SELECT column1 INTO :host_variable FROM table_name WHERE conditions FETCH FIRST 1 ROWS ONLY;
Back to top
View user's profile Send private message
edsellouie

New User


Joined: 13 Sep 2007
Posts: 1
Location: toronto

PostPosted: Sat Sep 15, 2007 1:47 am
Reply with quote

In your application, you may have to declare a CURSOR to resolve this issue. If you're expecting more than 1 row during a SELECT, then you need to have a CURSOR declared before you FETCH each record until there are no more records.

If you don't expect more than one row, then you have to make sure your WHERE clause would retrieve unique records from the specified columns.

...hope this helps...
Back to top
View user's profile Send private message
senthilssg

New User


Joined: 09 Dec 2005
Posts: 64
Location: USA

PostPosted: Tue Sep 25, 2007 8:03 pm
Reply with quote

Hi ,

If you want only row , you can use FETCH FIRST ROW ONLY to your Query , so that you can avoid -811 also reduce the CPU cost by avoiding of unncessary rows were fetched from table .

Code:
Eg :

Select column1 , column2
From tablename
where column3 = 'value'
Fetch first  row only
Back to top
View user's profile Send private message
Raghavendra P K

New User


Joined: 24 Aug 2007
Posts: 24
Location: bangalore

PostPosted: Tue Oct 23, 2007 4:37 pm
Reply with quote

Hi ,

Change your where clause to fetch the records based on the Primary key.This will not give you -811 error. If you read a table based on the primary key you will not get multiple records.
Back to top
View user's profile Send private message
View previous topic : : View next topic  
Post new topic   Reply to topic All times are GMT + 6 Hours
Forum Index -> ABENDS & Debugging

 


Similar Topics
Topic Forum Replies
No new posts SQLCODE=-311 in Cobol SP-DB2. COBOL Programming 2
No new posts SQLCODE = -122 while using the scalar... DB2 4
No new posts SQLCODE = -16002 when using XMLEXISTS DB2 1
No new posts Is SQLCODE -811 possible while fetchi... DB2 1
No new posts SQLCODE=-204 SQLSTATE=42704 DB2 4
Search our Forums:


Back to Top