SunQuest
           Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old July 20th, 2004, 06:48 AM
gudiya_78 gudiya_78 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 6 gudiya_78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Red face inserting default values into a table

Hi,
I want to populate a table T_CON with default values after its created. It has a column called Id. The number of rows to be inserted into T_CON depends on the number of localID's in another table T_NODES. That is, I have to insert values into Id field of T_CON and these have of Id field have to be taken from localID field of T_NODES.

Other fields of T_CON have fixed default values.

Simple insert does not work here since structure of 2 tables is different. Pls help me...i have been struck for some time now.

Reply With Quote
  #2  
Old July 20th, 2004, 09:19 AM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,307 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 4 h 28 m 57 sec
Reputation Power: 48
Your idea of default and mine are not the same. This is what I think you are saying
Code:
insert into tcon (Id, fld2, fld3 ,fld4 , fld5)
select Local_id, 'fixed value1', fixed value2', 'fixed value3', 'fixed value4'
from T_NODES;


But I think your idea of default is a value from T_CON or another table.
'fixed value1' is just a constant.

Reply With Quote
  #3  
Old July 20th, 2004, 01:10 PM
gudiya_78 gudiya_78 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 6 gudiya_78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
hi,
Thank you for your response.
I had tried

insert into tcon (Id, fld2, fld3 ,fld4 , fld5) values ((select Local_id from T_NODES), 'fixed value1', fixed value2', 'fixed value3', 'fixed value4');

where 'fixed value1', ... are fixed trings, numbers, etc.

Thank you so much. I will try the answer given by u.

Reply With Quote
  #4  
Old July 20th, 2004, 02:03 PM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,307 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 4 h 28 m 57 sec
Reputation Power: 48
You had a SQL syntax problem - 'values'
can't be there with a select statement doing the insert.

Reply With Quote
  #5  
Old July 20th, 2004, 10:46 PM
gudiya_78 gudiya_78 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 6 gudiya_78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
unique constraint (T_CON_PK)violated

Hi,
I tried using that query:
insert into tcon (Id, fld2, fld3 ,fld4 , fld5)
select Local_id, 'fixed value1', fixed value2', 'fixed value3', 'fixed value4'
from T_NODES;

but got message ORA-00001: unique constraint (T_CON_PK)violated.

The strcuture of T_CON is
CREATE TABLE T_CON
(
NodeId NUMBER NOT NULL,
SpUserList VARCHAR2(200),
CountAlarm NUMBER ,
CONSTRAINT T_CON_PK PRIMARY KEY(NodeId),
CONSTRAINT T_CON_ck1 CHECK (CountAlarm > 0 )
);


I tried using the query:
insert into tcon (Id, fld2, fld3 ,fld4 , fld5)
select unique Local_id, 'fixed value1', fixed value2', 'fixed value3', 'fixed value4'
from T_NODES;
It did not show any message on execution, but no rows were inserted.

The local_ID Field in T_NODES is unique and is its PK.
Do I need to write a function that takes the values of all the local_ID Field in T_NODES in an array and then insert values into T_CON?
But I do not know how to do that.

Please advice.

Reply With Quote
  #6  
Old July 20th, 2004, 11:17 PM
gudiya_78 gudiya_78 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 6 gudiya_78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
no rows are inserted

Hi,
the access violation I got was because I was trying to insert the same value for NodeId that was already present in the table. I deted that row and fired the query gain.
I got the output as 2, but when I did a select * on T_CON, no rows had been inserted.
What to do?

Reply With Quote
  #7  
Old July 23rd, 2004, 01:45 AM
gudiya_78 gudiya_78 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 6 gudiya_78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thank you the answer for the query worked perfectly.
Thanks again!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > inserting default values into a table


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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 On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway