Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Illegal use of keyword fetch. Token with union except query

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
HABBIE

New User


Joined: 08 Jul 2014
Posts: 24
Location: INDIA

PostPosted: Fri Aug 28, 2015 5:20 pm    Post subject: Illegal use of keyword fetch. Token with union except query
Reply with quote

Hi,


I m trying to write a query,

INSERT INTO ERT_TY
(z_DB_NAME,z_TABLE_NAME,z_COLUMN_NAME,S_COLUMN_TYP E,z_DATA)
SELECT 'TRAIN12','ALBUM',
'DEPTNAME','CHAR',DEPTNAME
FROM TRAIN12.DEPT FETCH FIRST 5 ROWS ONLY;

Error:
ILLEGAL USE OF KEYWORD FETCH. TOKEN WITH UNION EXCEPT QUERYNO WAS EXPECTED. SQLCODE=-199, SQLSTATE=42601

My db2 : version8 Z/os
os: windows

From the docs I got that FETCH will not work inside a subquery.

Can some one kindly let me know , how i have to insert the first 5 rows of a table into some other table.
Back to top
View user's profile Send private message

Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1626
Location: NY,USA

PostPosted: Fri Aug 28, 2015 8:14 pm    Post subject:
Reply with quote

Look for a Cursor.
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 335
Location: USA

PostPosted: Fri Aug 28, 2015 9:50 pm    Post subject: Reply to: Illegal use of keyword fetch. Token with union except query
Reply with quote

How do you identify the 'first 5 rows' of a table?

Do you have any specific records to be inserted into the table OR you just want some random 5 rows from another table?

If you want specific rows then you can use a 'where' clause in your select query. Otherwise, you may have to write something like:

Code:
INSERT INTO ERT_TY
(z_DB_NAME,z_TABLE_NAME,z_COLUMN_NAME,S_COLUMN_TYP E,z_DATA)
SELECT 'TRAIN12','ALBUM',
'DEPTNAME','CHAR',DEPTNAME
FROM TRAIN12.DEPT where condition UNION ALL
SELECT 'TRAIN12','ALBUM',
'DEPTNAME','CHAR',DEPTNAME
FROM TRAIN12.DEPT where condition;


Repeat the Select query 5 times with Union All. So, there will be 5 select queries and each query should return one row to be added. I don't see if you can actually insert a fixed number of rows through a Select query in a single shot.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
No new posts syncsort: copy lines after the keyword shreya19 SYNCSORT 7 Fri Dec 02, 2016 9:47 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us