Jump to content

Recommended Posts

Posted

insert into table_name
select distinct plan_id, 'choice' from table_name where plan_value = '3001';

Posted

insert into tablename values ((select distinct plan_id from tablename), "choice")

Posted

-- Creating the TEST table for the scenario.
-- Note: The Table was created with out any primary key column.
-- As it was not mentioned whether the PK is "AutoNumber" column to find it, check for triggers on the table
-- "SELECT XYZ.nextval INTO :new.id FROM dual;" --> should see this select statement in the trigger.
create table test
( primary_id number , plan_id number ,plan_value number,def_choi varchar2 (30 char),expiration_date date
);
--TRUNCATE TABLE TEST;
-- Inserting Sample Data into the Table.
INSERT INTO TEST VALUES(1, 1001, 3001,'default', TO_DATE ('20130713','yyyymmdd') );
INSERT INTO TEST VALUES(2, 1001, 4001,'default', TO_DATE ('20130713','yyyymmdd') ); -- This Record has the same plan_id as row 1, above row inserted.
insert into test values(3, 1002, 3001,'default', to_date ('20130712','yyyymmdd') );
insert into test values(4, 1003, 3002,'default', to_date ('20130712','yyyymmdd') );
INSERT INTO TEST VALUES(5, 1004, 3003,'default', TO_DATE ('20130712','yyyymmdd') );

-- Inserting Data with 'choice' option.
-- In your requirement, you didn't mention if a "plan_id" can have multiple "plan_value" , "expiration_date", if so which value
-- we need to use "plan_value" , "expiration_date" for the record being inserted.
-- Also you need to let us know the logic to populate the Primary Key column (primary_id), if no triggers involved in populating the column
INSERT INTO TEST
SELECT DISTINCT PRIMARY_ID , PLAN_ID ,PLAN_VALUE, CASE WHEN DEF_CHOI = 'default' THEN 'choice' END ,EXPIRATION_DATE FROM TEST;

-- Also the best placce to post and get prompt & accurate response is "https://forums.oracle.com/community/developer/english/oracle_database/sql_and_pl_sql
-- Also what Tesla mentioned is correct if you have only teo columns with no PK & want to insert records with plan_value = 3001
-- provided by "myusaoffers" is wrong. solutions provide by "faf" are not optimal, i think he has datawarehousing experience... in OLTP it depends on the DB design..
-- other info, i requested and if there is any detail table dependent on our table.. it's that we need more info to provide an accurate and optimal sol.

Posted

Bhayya idhi simple...

Insert into PLAN_TABLE(PLAN_ID,PLAN_VALUE)
select PLAN_ID,
'CHOICE' -- your value
FROM PLAN_TABLE where lower(PLAN_VALUE)='default';

I hope it answers your question. If not please post create table and insert statements and the results youwant from that data. i can help you or some one

Posted

[quote name='DARLING...' timestamp='1373759055' post='1303949242']
Dat depends on order which u r inserting. Neeku Ela insert chesinaaa adey order follow avvala?
[/quote]

Bhayya i think you don't mind if tell you something....

this is completly false assumption.... data will never be stored in a certain order... you never know in which order it can store the data. you may see the order that you want for small set, that doesn't mean that data will stored in that order.

Posted

[quote name='Googlite' timestamp='1373786622' post='1303949867']

Bhayya i think you don't mind if tell you something....

this is completly false assumption.... data will never be stored in a certain order... you never know in which order it can store the data. you may see the order that you want for small set, that doesn't mean that data will stored in that order.
[/quote]
I think his direction of thinking to provide a solution to requirement is not 100% accurate, sorting data in the table has nothing to do with it...

×
×
  • Create New...