|
View previous topic :: View next topic
|
| Author |
Message |
madlui56
New User
Joined: 08 Aug 2006 Posts: 61 Location: Philippines
|
|
|
|
| What does this mean SQLCODE -811 and solution for this? |
|
| Back to top |
|
 |
guptae
Moderator

Joined: 14 Oct 2005 Posts: 1209 Location: Bangalore,India
|
|
|
|
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 |
|
 |
ParagChouguley
Active User
.jpg)
Joined: 03 Feb 2007 Posts: 175 Location: PUNE(INDIA)
|
|
|
|
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 |
|
 |
edsellouie
New User
Joined: 13 Sep 2007 Posts: 1 Location: toronto
|
|
|
|
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 |
|
 |
senthilssg
New User

Joined: 09 Dec 2005 Posts: 64 Location: USA
|
|
|
|
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 |
|
 |
Raghavendra P K
New User
Joined: 24 Aug 2007 Posts: 24 Location: bangalore
|
|
|
|
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 |
|
 |
|
|