SQL to copy one table to another
Using Oracle with c#.I have two tables
TABLE1:
ID,
name,
attribute
TABLE2
ID,
name,
attribute
I need to copy the fields name, attribute of all the rows in TABLE1 into TABLE2 where name =: name,.
However when you do what I must also define all fields being copied into TABLE2 id to: id (this constant rest value in all areas that are copied and will be stored in a variable binding).
So if: id = 1000, regardless of their value as in Table1.my_field is, all rows are copied into TABLE2 will be the id.value of 1000.
I know I need something like
INSERT INTO TABLE2 (id, name, attribute) SELECT (id, name, attribute) FROM TABLE1 WHERE name =: name
But just need to get this id value to set.
It really comes down to write the SQL code for you what yo want.
Insert into table2
Select 20, name, attribute from table1 where name =: name_bind;
The value default ID to 20 during the copy only lines that has a name in the name of the binding variable.
Without bind variable, it would be
Insert into table2
Select 20, name, attribute from table1 where name = "Name1"
Please use bind variable if it is run more than once.
Tags: Database
Similar Questions
-
The fastest way to copy one schema to another.
Hi guys
Oracle11gr2
OEL 5
I have a requirement to copy one schema to another. I don't have access to linux for the server hosting the database. So I guess that the datapump cannot be used. exp/imp conventional takes too long. Another way I can achieve the goal? What is the best way. is it possible to copy all the object using a dblink (triggers to tables, views, procedures etc.)
PS: Both the schema are in the same database.
Thank you
AnkurkThey are in the same database, so no db connection is necessary; Fatest? It depends on my factors;
Why no loop all the sources of the tables in the schema and do;insert into target_schema.target_table select * from source_schema.source_table;
You are 11 GR 2, datapump could be a solution...
Directory user/pwd Impdp = DMP_DIR dumpfile = source_schema_dmp.dmp logfile = impdp.log remap_schema = source_schema:target_schema
-
How to replace one table with another?
I need to replace one table with another. Both tables have the same structure, primary keys, indexes, constraints, but different data (about 50 million records).
I would like to make this replacement in line, with no passage of database in offline mode.
There is no clause CREATE or REPLACE TABLE in Oracle unfortunely.
I could use just DROP and ALTER TABLE RENAME instructions, but it is necessary that a user receive message error "table or view does not exist. It may be possible to block incoming requests at the moment, while old and new droppping table rename are performed?
Thanks in advance.Hi again!
You can detect normal users with session sessions $ v. A session of a normal user has a username (username of the column). Systemsessions PMON and SMON have no user name. So, you can use the following query to detect sessions, you need to kill:
SELECT sid, serial#, username FROM v$session WHERE type NOT LIKE 'BACKGROUND';
concerning
-
Shutter button to copy records from one table to another; ORA-04091:
Hello
I am trying to create a trigger that will move data from one table to the other.
I have two tables (Trial1, Trial2) two of them contains the same attributes (code, c_index)
I want to spend each new record inserted in (code Trial1) (code in Trial2)
It's my trigger:
Create or replace trigger trg_move_to_trial2
After Insert on Trial1
for each rowStart
insert into Trial2 (code)
Select: new.code of Trial1;end;
He compiled, but when I insert a new record (the code) in (Trial1), it shows this error:
Error report:
I know matter what it means error, but I did not how to fix the error.
SQL error: ORA-04091: table STU101. TRIAL1 is changing, function of triggering/can not see
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 changing, function of triggering/can not see.
* Cause: A trigger (or plsql user-defined function that is referenced in)
This statement) attempted to watch (or modify) a table that has been
in the Middle being modified by the statement that shot.
* Action: Rewrite the trigger (or function) so it does not read this table.
..................................................................................................
I tried to change the (insert after on Trial1) before (insert on Trial1); It worked, but not in a good way. When I insert value in (code Trial1) new and refreshed Trial2 table, just as much as the records I have 2 test they will be duplicated. For example
Trial2
when I insert in Trial1
code
111
222
333
Trial1
code
444Trial2 will be:
can you please tell me how to fix this?
code
111
222
333
444
444
444
Kind regards
Published by: 1002059 on April 23, 2013 17:36You should not select Trial1 - you already have data. Simply insert this 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;
Kind regards
David -
Copy all the BLOBs from one table to another
Hi all
I hope that I put in the right place. I am trying to copy from one table to the other BLOBs, but were usuccessful. Here is the script that I wrote to do, but it just loaded a field saying not supported. Is there something I'm missing, I'm using the APEX 3.1.2.
Thanks for your help.
DECLARE
number of v_id;
v_document blob.
v_filename varchar2 (200);
v_mimetype varchar2 (200);
CURSOR c_Document IS
SELECT id, name of the document file, mimetype
IN v_id, v_document, v_filename, v_mimetype
OF CAB_APPEAL_ACTIONS
WHEN THE DOCUMENT IS NOT NULL;
BEGIN
FOR r_Document in c_Document
LOOP
INSERT INTO CAB_APPEAL_DOCUMENTS
(APPEAL_ACTION_ID,
DOCUMENT,
FILE NAME,
MIMETYPE
)
VALUES
(v_id,
v_document,
v_filename,
v_mimetype
);
END LOOP;
END;In addition, what is wrong with just...
INSERT INTO CAB_APPEAL_DOCUMENTS (APPEAL_ACTION_ID, DOCUMENT, FILENAME, MIMETYPE) SELECT id, document, filename, mimetype FROM CAB_APPEAL_ACTIONS WHERE DOCUMENT IS NOT NULL;
APEX will end process page in a BEGIN block... END; block anyway.
See you soon
Ben
-
Copy from one table to another
Is there a simple way to copy/add all the records from one table to a master table?INSERT INTO master_table (Field1, Field2, field3)
SELECT field1, Field2, field3
From other_table
WHERE everything whatIf the data types, order and the column names are the same for both tables, then it would also work to copy all other_table lines in master_table:
INSERT INTO master_table
SELECT *.
From other_tablePhil
-
Moving to a row of one table to another Table
Hi I am using JDeveloper Release 2 for the development of the ADF.
My requirement is as below:
- I have two tables table A and table B, which has similar clues, keys, etc the column names.
- In table A, for each line, I have a button called MOVE.
- If I click the button move in any row of the table, the data available in the selected row to be copied in table B.
Please provide me with details/ideas technically to achieve this scenario using ADF.
Thank you
Vinoth.
Vinoth, here's what you need to do:
(1) table to make a selection of monkey
(2) since the button move in a picture you call a method in a managed bean when you access selected aware of table a
(3) create and insert a new row in table b
(4) set the attributes you want to copy from the table one at the new line b line
(5) delete the current line has (as says your MOVE button I guess you don't want to keep the line in the table a)
(6) validation to
Timo
-
Copy one file to another layer in PScc2014
I think I saw a way to copy a layer from one file to another, when I'm in the consolidate all to tabs mode. Visible image one slide, or otherwise a layer to one of the tabs at the top of the window and this copy the layer to the image on this tab.
I can't get it to work,
I don't know about the 'double layer' selection in the layers panel, but there seems to be another faster way. I imagine this?
I use iMac, Yosemite.
Thank you
Vince
Same thing here. Photoshop CC, Yosemite.
What you are to select the layer on the source document that you will move. Use Opt + eyeball to hide all other layers, so you can see clearly what you are moving. Do not do anything dragging them from the layer panel, open the document window.
Then select the tool travel, go in the document window and drag this layer on the other file document tab until it opens.
Then, drag and drop in your destination document. You could hold down the SHIFT key if you want to Center until you drop.
It works in CC and CC 2014.
Gene
-
What is the process to move the VCenter SQL DB from one server to another?
I read the threads for the displacement of vCenter Server and it's local database from one server to another. My situation is a little different.
VirtualCenter Server 2.5 build 174768 has it's SQL database on another server. We're going to retire that SQL server only and move just the DB to a new SQL Server - current vCenter server will not be affected.
I'm trying to figure out how knowledge current vCenter once used SQL server (DCMNMSSQL02) DB is now on the server DCMSQL07 - which all on stays of DB.
Hello.
You must update the DSN on the server vCenter. See the article kb 7960893 for more information.
Good luck!
-
Inserting data into one table to another table.
Hi all
I'm having a few problems when copying data from the 1 table to another table. I have a data 1 date in a table, and I want to insert data in a partition of the main table. As it is the dev database space by getting a problem. I don't have enough space that I can maintain the data for the same date in 2 places.
Here every way possible in oracle this 1 table may be made partition in the other table. (Just a question).
Please suggest me a way out and if possible should be fast that data are more than 50 million lines and size along 10 GB.
Thank youAre the columns of your source table identical to that of the destination partitioned table?
If so, you can create an empty partition in the partitioned table and then create a swap partition to swap the source with the new empty partition table.
-
Populating one table from another table
Hi Forum...
I'm trying to populate a table from another table using CFQUERY... I have no problem with the selection of data from the original table, but need help to get the data into the new table. I use MX 6.1 and access as the database server.
The two arrays have domain names identical to the same place, and I don't want to have to code all the column names in the selection and insert command. for example
< cfquery name = "GetData" datasource = 'somename' >
SELECT * FROM AssetTable1 WHERE BarCode = "123456".
< / cfquery >
< cfloop query = "GetData" >
< cfquery name = "InsData" datasource = 'somename' >
INSERT INTO AssetTable2 (xxxx...)
VALUES ("#xxxx... #'")
< / cfquery >
< / cfloop >
I hope this makes sense
Thanks in advance
DaveIf your tables are identical structures and their columns are of the same type and position, and both tables are in the same database, then put everything in a single query.
INSERT INTO AssetTable2
SELECT *.
OF AssetTable1
WHERE bar code = "123456".
If the columns were in different positions, then you should be listed explicitly in the INSERT and SELECT the parts, but you get the idea.
INSERT INTO table1 (col1, col2)
SELECT col1, col2
FROM table2
WHERE all that...Phil
-
Need a logic sql to insert from one table to another
I have a table (
TABLEA
) as follows:type_id level
-------------
1 7
2 4
I would like to insert above values in another table (
TABLEB
) through DML so it looks like so:seq_id type_id name order level
-----------------------------------
1 1 display 1 7
2 1 header 2
3
1 detail 34 2 display 1 4
5 2 header 2
6 2 detail 3
Looks like a very complex sql is necessary, for which I have no knowledge of :-).
Hello
97a5a09d-76e1-4fc7-8113-80b4705be7f4 wrote:
I have a table (
TABLEA
) as follows:type_id level
-------------1 7
2 4
I would like to insert above values in another table (
TABLEB
) through DML so it looks like so:seq_id type_id name order level
-----------------------------------1 1 display 1 7
2 1 header 2
3
1 detail 3 4 2 display 1 4 5 2 header 2 6 2 detail 3Looks like a very complex sql is necessary, for which I have no knowledge of :-).
So, for each line in tablea, you want to INSERT 3 rows in tableb, is that at the time?
One way to do that is to tablea to join of a table (or the result set) with 3 rows, like cntr below:
INSERT INTO tableb (seq_id type_id, row_name, row_order, lvl)
WITH cntr AS
(
SELECT LEVEL AS row_order
OF the double
CONNECT BY LEVEL<=>=>
)
SELECT ROW_NUMBER () OVER (ORDER BY a.type_id
c.row_order
) - or sequence_name. NEXTVAL
a.type_id
Case c.row_order
WHEN 1 THEN 'display '.
WHEN 2 THEN 'head '.
WHEN 3 THEN «details»
END
c.row_order
Case c.row_order
WHEN 1 THEN a.lvl
END
FROM tablea a
CROSS JOIN cntr c
;
If you would care to post CREATE TABLE and INSERT for your tables (as it exists before the UPDATE), then I could test this.
NAME is not a very good column name, but it is nowhere near as bad as the ORDER or LEVEL. I called ROW_NAME, ROW_ORDER and LVL columns instead.
-
How to copy columns from one table to another
Hai All
How to copy the contents of the array to another
For example, first name of the table is T1 and I have 10 columns and data are here and I need to create a table T2
But I don't need the header, but not the values of all the 10 columns of T1 to T2, but not values
Thanks and greetings
Srikkanth.MWhy not?
create table test1 as select * from emp where 1 = 2;
Kind regards.
LOULOU.
-
Moving text to a cell in one table to another
I don't know if I'm somehow missed something, but in earlier versions of the Pages I could click and keep text in a cell in a table of Pages, the text would be "lifting" off the page and I could move it to another cell. I now use 5.6.2 Pages and the text does not move. When I click and hold, nothing happens, and when I try to move it's just active adjacent cells that spans my mouse.
Any help is appreciated.
I have Pages here on OS X 10.11.6 v5.6.2. I have a table in text format cell or automatic, I can select text in a cell, click and drag this text in another cell of arbitrary table. Although Pages v5.6.2 is a completely different application of v4.3 Pages ' 09, this operation of copy of text in a cell to works for me - although not the levitate text when you click on it.
-
Copy one file to another email address
I have the address book for different groups.
Some of the addresses may be common to several groups.
I want to copy, not only move, an E-mail from one address book to another because the groups change members.
I don't want to have to recreate a new contact whenever the group changes.How to do this.
Standard computer skills.
Hold down the Ctrl key everything to drag and drop the contact with the other address book. You will see a sign more seem to indicate a copy and not move.
Maybe you are looking for
-
I can't restore a profile FEBE. I have FF 13.0 beta 1
I'm trying to restore an older profile of the FEBE and when I go to restore it, I get the screen and when I hit restore, it says it is restoring, but nothing happens. Any help would be greatly appreciated. FEBE is compatible with FF 13 Beta 1?
-
How to speed up my download speed?
My recently purchased 13 "MacBook is very slow in the download from the internet how speed, I can't at the moment BT infinity?
-
External hard drive does not allow me to backup large video files
Hi - I wonder if anyone can tell me why the Toshiba 1 TB 3.5 "external hard drive I recently bought does not allow me to backup large video files from my PC.The files are located in the region of 5 to 10 GB and when I try to save these I get the mess
-
Compact Z3 crashes when accessing music is attempted
Each application that attempts to access the music falls down or freezes and causes a reboot. Includes the Walkman, doubletwist and same settings to choose a ringtone. Battery up to 28% after only 3.5 hours. It is a new phone, sim installed 3.5 hours
-
CTL-alt-del is not launch task manager, but the fact Task Manager start from the taskbar. The 'Windows key' + n, where n is E, M, F, etc also fails to do anything? Teacher of Win7 64-bit. Malwarebytes found nothing, neither did a full scan with MS