How to insert from one table to another (multiple columns to single column)
I want to insert data from table1 into table2 and the data looks in 3 columns as below
Table1
RepNm ObjNm DbNm
123 abc def
456 def xyz
789 123 456
and the data in table2 should be display as
Table 2
ObjNm
123
456
789
abc
def
xyz
the dupes should get eliminated and only the distinct values should be inserted into a single column in table2 from multiple columns in table1
How do you want to handle nulls? If there is a null in any value of a column, do you want to insert it?
Then,
WITH T
AS (SELECT LEVEL colnum
FROM DUAL
CONNECT BY LEVEL <= 3)
SELECT DECODE (colnum, 1, RepNm, 2, ObjNm, 3, DbNm) as ObjNm
FROM table1, T;if you dont want to insert nulls then,
WITH T
AS (SELECT LEVEL colnum
FROM DUAL
CONNECT BY LEVEL <= 3)
SELECT DECODE (colnum, 1, RepNm, 2, ObjNm, 3, DbNm) AS ObjNm
FROM table1, T
WHERE DECODE (colnum, 1, RepNm, 2, ObjNm, 3, DbNm) = DECODE (colnum, 1, RepNm, 2, ObjNm, 3, DbNm)G.
Similar Messages
-
How to map from one table to another dependable on data from lookup?
I'm new in warehouse builder and i wonder how to do something what is very easily done by sql..
I want to map data from table_a to table_b, but not all rows - only those for which one of attributes in table_a have reference in table_c (is not null)...
I suppose it should go somehow with lookup operator, but playing with it, I wasn't able to achieve goal..
Thanks in advance for any help..Hi Zeljko,
On of the easier ways (in my experience) of accomplishing this is to define a view which does a SELECT DISTINCT on table A and uses an EXISTS clause to exactly filter those records that you want to get into your target table (i.e. the ones that already have an occurrence in table C).
And if performance is an issue, you could experiment with FIRST_ROWS hint or rownum=1 in the EXISTS clause.
Cheers, Patrick -
Its very urgent:How to insert data one table to another table
Hi all,
i am very new to oaf.
i have employee_number(per_all_people_f) lov is there.once select the employee number and click on the submit button
what ever select the employee number it ll move to new_operation_manager in custom table.
plz help me how to move.
its very urgent.
Thanks
Latha.
Edited by: Latha on Dec 21, 2011 9:33 PMHi Gyan,
Sorry, i will not repate.how to close the thread.
Gyan i have no knowledge on this issue.
plz help me.and where to mention,data is which table to insert.
plz send one sample code.
its very urgent gyan.
i wrote the am,co codes
in am:
public void NewoperationManagerLogic()
ManagerCustomTableVOImpl vo1=getManagerCustomTableVO1();----> here which vo take
OADBTransaction oadbt=getOADBTransaction();
if(!vo1.isPreparedForExecution())
vo1.executeQuery();
Row row=vo1.createRow();
vo1.insertRow(row);
in Co processrequest:
public void processRequest(OAPageContext pageContext, OAWebBean webBean)
super.processRequest(pageContext, webBean);
ManagerInformationAMImpl am=(ManagerInformationAMImpl)pageContext.getApplicationModule(webBean);
am.invokeMethod("NewoperationManagerLogic");
in co processform request:
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
super.processFormRequest(pageContext, webBean);
if(pageContext.getParameter("Submit")!=null)
ManagerInformationAMImpl am=(ManagerInformationAMImpl)pageContext.getApplicationModule(webBean);
am.getOADBTransaction().commit();
throw new OAException("Records Saved Sucessfully",OAException.INFORMATION);
thanks
latha
Edited by: Latha on Dec 22, 2011 1:26 AM -
How to insert records with LONG RAW columns from one table to another
Does anybody know how to use subquery to insert records with columns of LONG RAW datatype from one table to another? Can I add a WHERE clause in the subquery statement? Thanks.
Insert into ... Select statements are not supported for long or long raw. You will have to either use PL/SQL or convert your long raw to blobs.
-
How to copy data from one table to another (in other database)
Hi. I would like to copy all rows from one table to another (and not use BC4J). Tables can be in various databases. I have already 2 connections and I am able to browse source table using
ResultSet rset = stmt.executeQuery("select ...");
But I would not like to create special insert statement for every row . There will be problems with date formats etc and it will be slow. Can I use retrieved ResultSet somehow ? Maybe with method insertRow, but how, if ResultSet is based on select statement and want to insert into target table? Please point me in the right direction. Thanks.No tools please, it must be common solution. We suceeded in converting our BC4J aplication to PostgreSQL, the MSSQL will be next. So we want to write simple aplication, which could transfer data from our tables between these 3 servers.
-
How to convert data when transferring from one table to another
I have two tables and these are the structure of the tables
create table E1(
ID NUMBER
,NAME VARCHAR2(30)
, DESIGNATION VARCHAR2(30)
,GENDER VARCHAR2(10));
create table E2(
ID NUMBER
,NAME VARCHAR2(30)
, DESIGNATION VARCHAR2(3)
,GENDER NUMBER); Now I want to transfer records from one table to another using a master tables where data are compared because the datatypes in tables are different
The first one is a gender table to match the gender and convert
create table Gender(
E1 varchar2(10),
E2 number);The second is for the designation
create table Designation(
E1 varchar2(30),
E2 varchar2(3);How to match and convert the data so that it can be transfered.Peeyush wrote:
Can we do it with the help of a cursor.
All SQL executed by the database are parsed as cursors and executed as cursors.
I mean I have to insert data in bulk and I want to use cursor for it.The read and write (select and insert) are done by the SQL engine. The read part reads data and passes it to the write part that inserts the data.
Now why would using PL/SQL and bulk processing make this faster? It will reside in-between the read part and the write part being done by the SQL engine.
So the SQL engine reads the data. This then travels all the way to the PL/SQL engine as a bulk collect. PL./SQL then issues an insert (the write part to be done by the SQL engine). And now this very same data travels all the way from the PL/SQL engine to the SQL engine for insertion.
So just how is this approach, where you add extra travel time to data, faster?
and i want to commit the transaction after every 50 recordsWhy? What makes you think this is better? What makes you think you have a problem with not committing every 50 rows? -
Insert old missing data from one table to another(databaase trigger)
Hello,
i want to do two things
1)I want to insert old missing data from one table to another through a database trigger but it can't be executed that way i don't know what should i do in case of replacing old data in table_1 into table_2
2)what should i use :NEW. OR :OLD. instead.
3) what should i do if i have records exising between the two dates
i want to surpress the existing records.
the following code is what i have but no effect occured.
CREATE OR REPLACE TRIGGER ATTENDANCEE_FOLLOWS
AFTER INSERT ON ACCESSLOG
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
V_COUNT NUMBER(2);
V_TIME_OUT DATE;
V_DATE_IN DATE;
V_DATE_OUT DATE;
V_TIME_IN DATE;
V_ATT_FLAG VARCHAR2(3);
V_EMP_ID NUMBER(11);
CURSOR EMP_FOLLOWS IS
SELECT EMPLOYEEID , LOGDATE , LOGTIME , INOUT
FROM ACCESSLOG
WHERE LOGDATE
BETWEEN TO_DATE('18/12/2008','dd/mm/rrrr')
AND TO_DATE('19/12/2008','dd/mm/rrrr');
BEGIN
FOR EMP IN EMP_FOLLOWS LOOP
SELECT COUNT(*)
INTO V_COUNT
FROM EMP_ATTENDANCEE
WHERE EMP_ID = EMP.EMPLOYEEID
AND DATE_IN = EMP.LOGDATE
AND ATT_FLAG = 'I';
IF V_COUNT = 0 THEN
INSERT INTO EMP_ATTENDANCEE (EMP_ID, DATE_IN ,DATE_OUT
,TIME_IN ,TIME_OUT,ATT_FLAG)
VALUES (TO_NUMBER(TO_CHAR(:NEW.employeeid,99999)),
TO_DATE(:NEW.LOGDATE,'dd/mm/rrrr'), -- DATE_IN
NULL,
TO_DATE(:NEW.LOGTIME,'HH24:MI:SS'), -- TIME_IN
NULL ,'I');
ELSIF V_COUNT > 0 THEN
UPDATE EMP_ATTENDANCEE
SET DATE_OUT = TO_DATE(:NEW.LOGDATE,'dd/mm/rrrr'), -- DATE_OUT,
TIME_OUT = TO_DATE(:NEW.LOGTIME,'HH24:MI:SS'), -- TIME_OUT
ATT_FLAG = 'O'
WHERE EMP_ID = TO_NUMBER(TO_CHAR(:NEW.employeeid,99999))
AND DATE_IN <= (SELECT MAX (DATE_IN )
FROM EMP_ATTENDANCEE
WHERE EMP_ID = TO_NUMBER(TO_CHAR(:NEW.employeeid,99999))
AND DATE_OUT IS NULL
AND TIME_OUT IS NULL )
AND DATE_OUT IS NULL
AND TIME_OUT IS NULL ;
END IF;
END LOOP;
EXCEPTION
WHEN OTHERS THEN RAISE;
END ATTENDANCEE_FOLLOWS ;
Regards,
Abdetu..INSERT INTO SALES_MASTER
( NO
, Name
, PINCODE )
SELECT SALESMANNO
, SALESMANNAME
, PINCODE
FROM SALESMAN_MASTER;Regards,
Christian Balz -
Inserting data from one table into another table using PL/SQL
HI,
I am trying to insert values from one table into another using PL procedure, the values I want to retrieve from the table riverside1 are charac_id and charac_type and insert these values into another table called riverside2 , the stored procedure zorgs_gorfs(x,y) accepts two parameters which are 2 charac_id's of d characters in riverside1 then using insert statements inserts these characters from riverside1 into riverside2.
CREATE OR REPLACE PROCEDURE zorgs_gorfs(x IN NUMBER, y IN NUMBER) AS
BEGIN
INSERT INTO riverside2
(charac_id)
VALUES
(x);
INSERT INTO riverside2
(charac_id)
VALUES
(y);
END zorgs_gorfs;
/This works but the problem im having is that when I also try to insert the charac_type as well as the charac_id it doesnt work below is the code:
CREATE OR REPLACE PROCEDURE zorgs_gorfs(x IN NUMBER, y IN NUMBER) AS
BEGIN
INSERT INTO riverside2
(charac_id,charac_tye)
VALUES
(Select
charac_id,
charc_type
FROM
riverside1
WHERE
charac_id = x);
END zorgs_gorfs;
/can someone kindly sort me outmodify this sql
INSERT INTO riverside2
(charac_id,charac_tye)
VALUES
(Select
charac_id,
charc_type
FROM
riverside1
WHERE
charac_id = x);as
INSERT INTO riverside2
(charac_id,charac_tye)
VALUES
(Select
charac_id,
charc_type
FROM
riverside1
WHERE
charac_id in ( x,y));But my suggestion would be consider revising your approach. It does not look that good.
Thanks,
karthick. -
How to move BLOBs from one table to another ??
Hi All,
I am trying to move blobs from one table to another, however my insert statement is not working. What i mean is its running, but records are not being inserted into the table.
This is my first time moving blobs, so please bear with me.
here is my insert statement:
INSERT INTO CASES.FILESTORAGE
SELECT DID,
DRENDITIONID,
DLASTMODIFIED,
DFILESIZE,
DISDELETED,
BFILEDATA // this attribute is the BLOB
FROM USSC_CASES_TMP.FILESTORAGE
WHERE DID NOT IN (SELECT DID FROM CASES.FILESTORAGE);here is the DDL for the table.
CREATE TABLE "USSC_CASES_TMP"."FILESTORAGE"
"DID" NUMBER(*,0) NOT NULL ,
"DRENDITIONID" VARCHAR2(30 CHAR) NOT NULL ,
"DLASTMODIFIED" TIMESTAMP (6),
"DFILESIZE" NUMBER(*,0),
"DISDELETED" VARCHAR2(1 CHAR),
"BFILEDATA" BLOB,
CONSTRAINT "PK_FILESTORAGE" PRIMARY KEY ("DID", "DRENDITIONID")
);CASES.FILESTORAGE table has the same DDL, but in a different schema.
Thanks in advance.If this seems rather straight forward. If the schema are exact simply execute:
inset into [destination] select * from [source] ;if something is amiss you should be throwing errors someplace* but try this:
create table [scratch table name] as select * from [source table] where [place some limit here] ;If this does not work then something someplace is very wrong and if you are not the DBA you need to get this persons attention, fairly quickly. I would do the above from sqlplus and then after each statement would:
commit;then check to see if it succeeded. -
Create Trigger to insert records from one table to another
I created the below trigger to move data from one table to another after records have been inserted from another table to that table. What I need done is that each time records have been inserted into TEST_TBL, one of these actions codes should be implimented: U-update, N-insert, D-delete and inserted into TEST_TBL1. But each time I run the script, I get bunch of errors. Please see the script below: - Your help will be appreciated.
create or replace
trigger POWER_tr
after update or insert or delete ON test_tbl
for each row
begin
if updating then
insert into test_tbl1
(idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, action_code, date_added
VALUES
(idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, 'U', sysdate);
ELSif INSERTING then
insert insert into test_tbl1
(idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, action_code, date_added
VALUES
(idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, 'N', sysdate);
ELSIF deleting then
insert into test_tbl1
(idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, action_code, date_added
VALUES
(idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, 'D', sysdate);
END IF;
END POWER_tr;
Thank you,
Albert Zaza
Edited by: azaza on Mar 1, 2009 4:14 PMHello
At the end of trigger show errors / and post what errors are you getting exactly?
Here is a simple example for your reference, this will save old values in history table; you can replace it with new values if that's what do you want.
CREATE OR REPLACE TRIGGER TRG_DU
AFTER DELETE OR UPDATE
ON EMPLOYEE REFERENCING NEW AS New OLD AS Old
FOR EACH ROW
DECLARE
BEGIN
IF UPDATING
THEN
INSERT INTO employee_hist
VALUES ('UPDATE',
:OLD.empid,
:OLD.name,
:OLD.deptid);
ELSIF DELETING
THEN
INSERT INTO employee_hist
VALUES ('UPDATE',
:OLD.empid,
:OLD.name,
:OLD.deptid);
END IF;
EXCEPTION
WHEN OTHERS
THEN
-- Consider logging the error and then re-raise
RAISE;
END TRG_DU;
/Regards
Edited by: OrionNet on Mar 1, 2009 7:27 PM -
How to move records from one table to another?
Is there a way to copy data and column names from one table to another table?
I am trying to copy one production database table onto the development database. we are using Oracle 10g. I tried exporting to an xls file and importing to the other table but this needs to create destination table with the column names. Is there any better approach to achieve this?Hello,
You can create dblink between production and dev and from dev just
*1. create table mytable as select * from mytable@dblink;**2. Use of export/import or datapump*
Example
On prod
exp username/password tables=mytable1,mytable2 file=mytableexport.dmp log=mytableexport.log
On dev
imp username/password tables=mytable1,mytable2 file=mytableexport.dmp log=mytableimport.log*3. Datapump*
http://www.oracle-base.com/articles/10g/OracleDataPump10g.php
*4. Generate csv formatted file and use sqlldr or external*
External Table: http://www.adp-gmbh.ch/ora/misc/ext_table.html
Sqlldr: http://www.psoug.org/reference/sqlloader.html
Regards
Edited by: OrionNet on Feb 13, 2009 6:52 PM -
Trigger to copy records from one table to another; ORA-04091:
Hello,
I'm trying to create a trigger that will move data from one table to another.
I have two tables (Trial1, Trial2) Both of them contains the same attributes (code, c_index)
I want to move each new record inserted in (code in Trial1) to (code in Trial2)
This is my trigger:
Create or replace trigger trg_move_to_trial2
After insert on Trial1
for each row
begin
insert into Trial2 (code)
select :new.code from Trial1;
end;It compiled, but when I insert new (code) record into (Trial1) it display this error:
Error report:
SQL Error: ORA-04091: table STU101.TRIAL1 is mutating, trigger/function may not see it
ORA-06512: at "STU101.TRG_MOVE_TO_TRIAL2", line 3
ORA-04088: error during execution of trigger 'STU101.TRG_MOVE_TO_TRIAL2'
04091. 00000 - "table %s.%s is mutating, trigger/function may not see it"
*Cause: A trigger (or a user defined plsql function that is referenced in
this statement) attempted to look at (or modify) a table that was
in the middle of being modified by the statement which fired it.
*Action: Rewrite the trigger (or function) so it does not read that table.I know what does this error mean, but I don't how to fix the error.
I tried to change the (After insert on Trial1) to be (Before insert on Trial1); that worked, but not in the right way. When I insert new value into (code in Trial1) and refreshed Trial2 table, as much as records I have in Trial 2 they will be duplicated. E.g.
Trial2
code
111
222
333when I insert in Trial1
Trial1
code
444
Trial2 will be:
code
111
222
333
444
444
444Can you please tell me how to solve this issue?
Regards,
Edited by: 1002059 on Apr 23, 2013 5:36 PMYou should not select from Trial1 - you have the data already. Just insert that value.
Create or replace trigger trg_move_to_trial2
After insert on Trial1
for each row
begin
insert into Trial2 (code)
values (:new.code);
end; regards,
David -
MySQL move date from one table to another
I was wondering if there is a MySQL command that will let me move a selected row of data from one table to another. both tables have the same columns and declaration type (one table is actually an archived table on old data)
example
I wasnt to move all data in Table1 where the date is greater than 30 days old to Table 2
-- so the result should be...import all rows to Table 2 where the date is greater than 30 days old..and delete all date from Table 1 that is greater than 30 days.
currently..I'm doing three process
1) get all row that is greater than 30 days
"SELECT * FROM Table1 WHERE TO_DAYS(NOW()) - TO_DAYS(dateField) > 30"
2) insert data into Table2
while (res.hasNext())
TableData data = ..... // .get row
dataList.add(data);
for (int i = 0; i < dataList.size(); i++){
pstm.setString.....
pstm.addBatch()
pstm.executeBatch();
3) delete data from Table1
"DELETE FROM Table 1 WHERE TO_DAYS(NOW()) - TO_DAYS(dateField) > 30"for this app..losing a few rows does not
impact on how we analyze the data.That's what everyone always tells me too. But 99% of the time they come back and want to know why the cannot balance and/or validate the data between two runs taken only minutes from each other.
I've seen people puzzle over data for days that they swear they ran the exact same utility for their tests, but they were in fact using live data, and additional data had accrued but since all they had to do was execute the a script without parameters (they didn't put in a stop time), they got two different answers and it always, and I mean always confuses people. Be safe, and put the option in for and end date/time, then when they waste days trying to figure out why the two different observations gave them different numbers, they cannot blame you (because you gave them the option)!
My 2 cents for the day... -
Adding Data From One Table to Another
Now, this doesn't strike me as a particularly complex problem, but I've either strayed outside the domain of Numbers or I'm just not looking at the problem from the right angle. In any case, I'm sure you guys can offer some insight.
What I'm trying to do is, essentially, move data from one table to another. One table is a calendar, a simple two column 'date/task to be completed' affair, the other is a schedule of jogging workouts, i.e, times, distances. Basically, I'm trying to create a formula that copies data from the second table onto the first but only for odd days of the week, excepting Sundays (and assuming Monday as the start of the week). Now, this isn't the hard part, I can do that. The problem comes when I replicate the formula down the calendar. Even on the days when the 'if' statement identifies it as an 'even day', the cell reference to the appropriate workout on the second table is incremented, so when it comes to the next 'odd day', it has skipped a workout.
I can't seem to see any way of getting it to specifically copy the NEXT line in the second table, and not the corresponding line.
This began as a distraction to try and organise my running so I could see at a glance what I had to do that day and track my progress, but now it's turned into an obsession. SURELY there's a solution?
Cheers.Hi Sealatron,
Welcome to Apple Discussions and the Numbers '09 forum.
Several possible ways to move the data occur to me, but the devil's in the details of how the data is currently arranged.
Is it
• a list of three workouts, one for each of Monday, Wednesday and Friday, then the same three repeated the following week?
• an open-ended list that does not repeat?
• something else?
Regards,
Barry -
Moving time-dependant data from one table to another (archiving)
Hello all
I would like to know if there's an easier solution or a "best practice" to move data from one table to another. The context of this issue can be found within "archiving".
More concretely: we have an application that uses several tables to log information to.
These tables are growing like crazy, and we would like to keep only "relevant" data in those tables, so I was thinking about moving data from these tables that have been in there for, say 2 months, to "archiving" tables.
I figured there must be some kind of "best practice" to get this done.
I have already written a procedure that loops the table that has the time indicator and inserts the records from the normal tables into the archive tables (and afterwards delete this data), but it seems to be taking ages to get it done.
Thanks in advance!
Message was edited by:
timschraepenThere is nothing to do with PL/SQL.
You can refer below links:
http://www.lc.leidenuniv.nl/awcourse/oracle/server.920/a96524/c12parti.htm
http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10739/partiti.htm#i1006727
Maybe you are looking for
-
Unicode Migration using National Characterset data types - Best Practice ?
I know that Oracle discourages the use of the national characterset and national characterset data types(NCHAR, NVARCHAR) but that is the route my company has decide to take and I would like to know what is the best practice regarding this specifical
-
Training and Event Management - 2 Specify Attendance Types
Hi Is it possible to assign 1 attendance types to each course type or an specific event. For example: There is a course that generates payed attendance and another course that generates non payed attendance. So to discriminate for the payroll we need
-
NI-Motion with Labview 5.0.1
Hi, I'm trying to setup my pci-flexmotion-6c board under Labview 5.0.1 on a Windows 98 box. When I go to the recommended drivers page on NI.com it directs me to the NI-Motion 5.0.1 driver. When I try to install the software on my system, it only seem
-
What's the deal with DVI and Thunderbolt displays?
I have up and until now only ever had a MacBook, I planned on getting an iMac desktop but that didn't work out. However, now I am set on getting a Mini, but I remember there was a lot of comotion with the display connector and was hoping someone coul
-
When I try to insert a burned disk with data on it, I get the message "this computer cannot read the disk" The options it gives me are "ignore" or "eject." I've tried changing the "hostconfig" file in the "etc" folder, as suggested by the support web