|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
You had a SQL syntax problem - 'values'
can't be there with a select statement doing the insert. |
|
#5
|
|||
|
|||
|
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. |
|
#6
|
|||
|
|||
|
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? |
|
#7
|
|||
|
|||
|
Thank you the answer for the query worked perfectly.
Thanks again! |
![]() |
| Viewing: Dev Shed Forums > Databases > Oracle Development > inserting default values into a table |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|