Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Beginner - copying data from one table to another

Re: Beginner - copying data from one table to another

From: Martin Doherty <martin.doherty_at_oorraaccllee.com>
Date: Fri, 06 Dec 2002 00:38:00 -0800
Message-ID: <cqZH9.2$C53.84@news.oracle.com>


The simplest answer is to simply write an INSERT statement with a subquery instead of a VALUES clause
e.g.
INSERT INTO tab2 (ID, NAME)
SELECT ID, NAME FROM tab1

Let us know if you are looking for an automated solution that will work for ANY two tables (i.e. the from and to table names are parameters). That will require a different approach and more thought.

Are you actually using CHAR column datatype everywhere or was that just for the arbitrary example? Using VARCHAR2 is much more common, CHAR is typically only used in special circumstances where the particular semantics of that data type are required.

Whenever you post a question it is very helpful to mention the version of Oracle you are using. In addition, you'll often benefit by describing the root requirement that underlies your question, since that allows people to evaluate your approach and suggest other options.

Welcome to Oracle!

Martin Doherty

Mark Muller wrote:

>Hi,
>
>I want to copy rows from one table to another table where column names are
>the same
>
>for example
>
>Tab1
> ID CHAR(10)
> NAME CHAR(30)
> PHONE CHAR(15)
>
>Tab2
> ID CHAR(10)
> FNAME CHAR(10)
> NAME CHAR(30)
>
>Can i write a script that will insert all rows from Tab1 into Tab2 for the
>identical column names
>
>
>
>
Received on Fri Dec 06 2002 - 02:38:00 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US