How to use union with nextval in SQL

Just think of a situation where we have to use nextval in a SQL query with UNION, but the question here is how?Let’s see with a example:-

select mwreport_seq.nextval as RECORD_ID,inv.DEVICE_ID,inv.DEVICE_NAME,inv.DEVICE_USID, inv.DEVICE_SERIAL_NUM,inv.DEVICE_PORT,inv.DEVICE_VENDOR,inv.DEVICE_TYPE,inv.DEVICE_MODEL,from Device_Demo_table inv
union all
select gdid.DEVICE_ID,gdid.DEVICE_NAME,gdid.DEVICE_USID,
gdid.device_serial_no as DEVICE_SERIAL_NUM,gdid.DEVICE_PORT,
from Generic_device_demo_table gdid;

If you try to run this above Query you will an error like this:-

So here directly come to the point:-

So for the above Query how will get it executed, lets see:-

For more information , you can check the full details here in the below links:-



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Prem prakash Srivastava

I’m a software developer and computer programmer with an avid interest in Data Structures, Algorithms and Optimization.