Insert row with increasing numerical ID (e.g. rownum) using Oracle SQL? -


i insert new rows using oracle sql table, 1 field needs unique, e.g. rownum value. statement not work:

insert mytable ( id_, index_, type_, somevalue_  ) values ( "foobar", rownum, 1, 999 ); 

this result in error message:

00976. 00000 -  "specified pseudocolumn or operator not allowed here." *cause:    level, prior, rownum, connect_by_root, connect_by_isleaf or            connect_by_iscycle specified @ illegal location. 

i open efficient alternate solution, if using rownum not possible.

what need here create sequence.

follow sequence creation , usage document here.

for instance can create sequence like:

create sequence mytable_sq  start     1  increment   1  nocache  nocycle; 

then can this:

insert mytable ( id_, index_, type_, somevalue_  ) values ( "foobar", mytable_sq.nextval, 1, 999 ); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -