Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > Oracle > Insert into a table with sequence and a value from other table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-11-08, 11:08
hgriva hgriva is offline
Registered User
 
Join Date: Nov 2007
Posts: 5
Insert into a table with sequence and a value from other table

Hi,

I have a table TARGET whose structure is

seq_no number -- should be populated with sequence SEQ_TAR
fsa varchar2(10)

Table SOURCE structure is
-------------------------
fsa varchar2(10)

my requirement is
i have to insert into the TARGET table the fsa value from
SOURCE table along with the sequence number using sequence SEQ_TAR.nextval.
Reply With Quote
  #2 (permalink)  
Old 01-11-08, 11:18
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 3,566
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
Reply With Quote
  #3 (permalink)  
Old 01-11-08, 11:21
hgriva hgriva is offline
Registered User
 
Join Date: Nov 2007
Posts: 5
its me only.i have postaed it on the forum
Reply With Quote
  #4 (permalink)  
Old 01-11-08, 11:34
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 654
Code:
INSERT INTO target_table (seq_no, fsa) SELECT seq_tar.nextval, fsa FROM source_table;
Reply With Quote
  #5 (permalink)  
Old 01-11-08, 12:57
hgriva hgriva is offline
Registered User
 
Join Date: Nov 2007
Posts: 5
insert into table with value from other table

hi,the code has been further modified as
test@ISNS>create table source (fsa varchar2(10),sal number);
Table created.
test@ISNS>create table target(seq_no number,fsa varchar2(10),rec_ct number);
Table created.
test@ISNS>insert into target(seq_no,fsa,rec_ct)
2 select SEQ_TAR.nextval, fsa, sum(sal)
3 from source group by fsa;

select SEQ_TAR.nextval, fsa, sum(sal)
*
ERROR at line 2:
ORA-02287: sequence number not allowed here
Kindly help me.
Reply With Quote
  #6 (permalink)  
Old 01-11-08, 13:12
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 654
Code:
INSERT INTO target_table (seq_no, fsa, rec_ct) SELECT seq_tar.nextval, t.fsa, t.sal FROM (SELECT fsa, sum(sal) as sal FROM source_table GROUP BY fas);
Reply With Quote
  #7 (permalink)  
Old 01-11-08, 13:17
hgriva hgriva is offline
Registered User
 
Join Date: Nov 2007
Posts: 5
insert into table with value from other table

Thanks .It worked now.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On