View previous topic :: View next topic
|
Author |
Message |
poul_motiram Currently Banned New User
Joined: 05 Dec 2006 Posts: 13 Location: chennai
|
|
|
|
Hi,
Can anybody help me in finding the answers to the follwing questions
If more than one row is retrieved using singleton SELECT, what is the value present in INTO clause HOST variable of SELECT, when SQLCODE is -811 .
plz refer this table:
EMPTABLE
ENO ENAME SAL
1 A 2000
2 B 6000
3 C 5000
4 D 4000
QUERY:
EXEC SQL
SELECT ENO ENAME SAL INTO :ENO :ENAME :SAL FROM EMPTABLE
END-EXEC.
for this query what is the value of host variables ?
Regards,
Motiram |
|
Back to top |
|
|
shrinivas_3 Warnings : 1 New User
Joined: 05 Sep 2006 Posts: 34
|
|
|
|
poul_motiram wrote: |
Hi,
Can anybody help me in finding the answers to the follwing questions
If more than one row is retrieved using singleton SELECT, what is the value present in INTO clause HOST variable of SELECT, when SQLCODE is -811 .
|
Hi
As per my understanding the host variable will have 'THE FIRST QUALIFIED ROW '
So in your case you should get
ENO ENAME SAL
1 A 2000
in the host variables.
correct me if i am wrong
Thanks
Shrinivas D |
|
Back to top |
|
|
ravi17s Warnings : 1 New User
Joined: 15 Aug 2003 Posts: 57
|
|
|
|
Yes thats Correct.
First qualifying row. |
|
Back to top |
|
|
poul_motiram Currently Banned New User
Joined: 05 Dec 2006 Posts: 13 Location: chennai
|
|
|
|
ravi17s wrote: |
Yes thats Correct.
First qualifying row. |
Hi,
I read it It retrives First qualifying Row Therotically.......
But in my notes (practically) It shows Second Row
i.e. the confusion for me.
If anyone know practically....
Please Correct me.
Regards,
Mots |
|
Back to top |
|
|
kvivek
New User
Joined: 09 May 2005 Posts: 51 Location: Singapore
|
|
|
|
Yes it is first qualifying row and it may not be the same as first row.
Select statement maynot retreive the rows in the same order.
Correct me if I am wrong.
Regards,
Vivek |
|
Back to top |
|
|
poul_motiram Currently Banned New User
Joined: 05 Dec 2006 Posts: 13 Location: chennai
|
|
|
|
kvivek wrote: |
Yes it is first qualifying row and it may not be the same as first row.
Select statement maynot retreive the rows in the same order.
Correct me if I am wrong.
Regards,
Vivek |
Hi,
But which row value it contain?
First, Second, Last or any (or combination) |
|
Back to top |
|
|
kvivek
New User
Joined: 09 May 2005 Posts: 51 Location: Singapore
|
|
|
|
Select statement may retreive the rows in any order, not necessarily in the inserted order.
Quote: |
But which row value it contain?
First, Second, Last or any (or combination) |
Answer for the above question is "unpredicted".
Regards,
Vivek |
|
Back to top |
|
|
shrinivas_3 Warnings : 1 New User
Joined: 05 Sep 2006 Posts: 34
|
|
|
|
poul_motiram wrote: |
ravi17s wrote: |
Yes thats Correct.
First qualifying row. |
Hi,
I read it It retrives First qualifying Row Therotically.......
But in my notes (practically) It shows Second Row
i.e. the confusion for me.
If anyone know practically....
Please Correct me.
Regards,
Mots |
Hi Mots
You had the below data setup
ENO ENAME SAL
1 A 2000
2 B 6000
3 C 5000
4 D 4000
Now as per my guessing what might have happened is :
In the below query
EXEC SQL
SELECT ENO ENAME SAL INTO :ENO :ENAME :SAL FROM EMPTABLE
END-EXEC.
Internally 1 A 2000 got populated in corresponding Host Variables first time .
(here SQLcode will be = 0 )
Since there are multiple qualifying Rows for the above query it might have fetched the second row with value 2 B 6000 into host variables OVERRIDING THE PREVIOUS VALUES (i.e 1 A 2000 ) Now the SQLCODE = -811
So it might be showing the second row in host variables
Try out this
EXEC SQL
SELECT ENO ENAME SAL INTO :ENO :ENAME :SAL FROM EMPTABLE
END-EXEC.
If sqlcode = 0 or ?811
Move values of Host variables into corresponding working storage variables
Display corresponding working storage variables
Else
Abend
End-if.
THis is my guessing
Check out and let me know if it works.
THanks
Shrinivas D |
|
Back to top |
|
|
shrinivas_3 Warnings : 1 New User
Joined: 05 Sep 2006 Posts: 34
|
|
|
|
kvivek wrote: |
Select statement may retreive the rows in any order, not necessarily in the inserted order.
Quote: |
But which row value it contain?
First, Second, Last or any (or combination) |
Answer for the above question is "unpredicted".
Regards,
Vivek |
Hi
Run the same query with same data setup SEQUENCE in SPUFI or QMF
and see the result .
THis will give you an IDEA about the ROW SEQUENCE FETCHED
Thanks
Shrinivas D |
|
Back to top |
|
|
prakash271082
New User
Joined: 09 Sep 2005 Posts: 53
|
|
|
|
As said well by Shrinivas, make use of check ( IF SQLCODE = 0 ) so that you would be clear enough.... |
|
Back to top |
|
|
humpty Warnings : 1 New User
Joined: 01 May 2005 Posts: 23
|
|
|
|
dear,
in your case the data is in sorted manner, so first row will be selected.
in case you give the orderby clause, then the first qualifying row will be selected. in case you do not give any order by and the data is also not sorted, then in this case a temp table is built with data in the sorted manner and then the first row of this temp sorted table is fetched.
clear ??
cheers !! |
|
Back to top |
|
|
|