 |
| Oracle General Oracle database discussions. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Oracle section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

July 28th, 2005, 06:52 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 224
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Select Into statement
hi all
Can i use Select Into statement in Oracle for creating a table?
Thnx
Ashu
|
|

July 28th, 2005, 07:36 AM
|
|
Authorized User
|
|
Join Date: Jul 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ashu,
Your query is not clear.
Do you want to insert the selected values into a table,if so you can use
Insert into destination_table (col_one,col_two,col_three) values(select col_one,col_two,col_three from source_table)
Regards,
Ram.
|
|

July 28th, 2005, 09:47 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 224
Thanks: 0
Thanked 1 Time in 1 Post
|
|
hi Ram
actually i wanna do 2 things,
1) Create Table with same structure and
2) Insert all the rows of frst table into the new table
thnx
Ashu
|
|

July 29th, 2005, 05:25 AM
|
|
Authorized User
|
|
Join Date: Jul 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ashu,
Create Source table:
create table source_table(colone number(9),coltwo varchar2(9));
Insert some data into the source_table:
Insert into source_table values(1,A)
Insert into source_table values(2,B)
Insert into source_table values(3,C)
Insert into source_table values(4,D)
Create Destination Table:
Create table Destination_Table(colone number(9),coltwo varchar2(9));
Inserting Source table data into Destination table:
Insert into Destination_Table values(select colone,coltwo from source_table)
Hope it will helps you.
Regards,
Ram.
|
|

July 29th, 2005, 12:51 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 224
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hi Ram
i also used the same method
but isn't is a way around
wht i m asking is can we create and populate a table as we can do in SQL Server
thnx
Ashu
|
|

July 30th, 2005, 02:15 AM
|
|
Registered User
|
|
Join Date: Jul 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi ashu!!
try the following statement
create table <t1> as select * from (t2>
t1 table'll create same structure and data as t2
|
|

August 1st, 2005, 07:36 AM
|
|
Registered User
|
|
Join Date: Jul 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You can also use the 'COPY' command from SQL Plus. Very powerful. Here is what the help file says about the 'COPY' command:
usage: COPY FROM <db> TO <db> <opt> <table> { (<cols>) } USING <sel>
<db> : database string, e.g., scott/tiger@d:chicago-mktg
<opt> : ONE of the keywords: APPEND, CREATE, INSERT or REPLACE
<table>: name of the destination table
<cols> : a comma-separated list of destination column aliases
<sel> : any valid SQL SELECT statement
|
|

October 9th, 2005, 09:09 AM
|
|
Registered User
|
|
Join Date: Oct 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
to create a new table with the same structure and data of old table use this statement
CREATE TABLE New_Table AS
SELECT * FROM Old_Table;
|
|

October 9th, 2005, 11:30 PM
|
|
Authorized User
|
|
Join Date: Aug 2005
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
You can use the same structure for Creating table. There is no problem.
Thanx
Adalarasu
|
|
 |