473,386 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how to set default value for column of new created table from select statement in 11g

I create a table in oracle 11g with the default value for one of the columns. Systax is "create table xyz(emp number,ename varchar2(100),salary number default 0);". This created successfully. For some reasons I need to create another table with same old table structure and data. So i created a new table with name "abc" as "create table abc as select * from xyz". Here "abc" created successfully with same structure and data as old table "xyz". But for the column "salary" in old table "xyz" default value was set to "0". But in the newly created table "abc" the default value is not set. This is all in Oracle 11g. Please tell me the reason why the default value was not set and how we can set this using select statement.
May 4 '11 #1
2 3111
rski
700 Expert 512MB
This is how CTAS works.
Maybe take a look at dbms_metadata.get_ddl function. It will return the query used to create a table in this output query you need only to change table name and run.
Get a definition of TEST table
Expand|Select|Wrap|Line Numbers
  1. select dbms_metadata.get_ddl('TABLE','TEST') from dual
  2.  
In the output you will se something like
Expand|Select|Wrap|Line Numbers
  1.  
  2.   CREATE TABLE "RSKI"."TEST" 
  3.    (    "I" NUMBER(*,0) DEFAULT 100
  4.    ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  5.   STORAGE(INITIAL 163840 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  6.   PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  7.   TABLESPACE "USERS" 
  8.  
Just edit this query (rename table name) and run.
May 5 '11 #2
debasisdas
8,127 Expert 4TB
Yes you need to do as suggested by rski.

CREATE TABLE AS SELECT..... syntax

creates only the basic structure of the table without any contstraints.
May 8 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: grok | last post by:
I have a column called SEGMENTED_BLOCK sample data: X,X,X XX,XX,XX, TYZC123456,X,X, TOYZ654321,1234,777777 I need to do something that has the effect of SELECT (stuff before first comma)...
2
by: mukesh | last post by:
Can we use expression in default value for a table field for example – IIf(Table-1.field-1=table-2 . field-1, table-1.field-2, 0) Interpretation – If field-1 of table -1 is like/equal to...
3
by: treborstetsam | last post by:
amongst the columns in my table are 2 - "Purchased" and "Unprompted", what I would like to do is: If Purchased = Yes then Unprompted = Yes If Purchased = No then Unprompted could be Yes or No,...
4
by: Torilyn73 | last post by:
I have a combo box set up off a query. I want the default value to be the column heading so I don't have to put a label over it. So far I haven't been able to figure this out. Can anyone tell me if...
2
by: vijaialphonse | last post by:
i have a table which has 3 columns, one of three is set to default value 0. Now i have to change data type of that particular column and its default value using sql query. am working with sql server...
1
by: BlackMustard | last post by:
hi all, i am currently using the following union select statement to select records from two of my tables to a gridview in asp.net: SELECT ConcertName AS Name, ConcertDate AS Date, ConcertTime AS...
8
by: peterkennett | last post by:
I am designing a database that will be used by many different offices, and each office may want to change the defaults I have in a table. Rather than teach each user how to go in and change a...
8
by: Vinarashi | last post by:
Hi, I have given a "select *" statement for a view. It gives all the values for the "where" condition mentioned. But when I give "select column_name " for the same "where" condition, I am getting...
2
by: anoop s | last post by:
Hi, In my web application I want fetch data from fixed width text file. I am using OLEDB connection for retrieving data. But the problem is the date format is dd/mm/yyyy in text file. Can I...
1
kirubagari
by: kirubagari | last post by:
My form displays a combo box populated by a SQL SELECT statement. The user will select a row from the combo box. I then want the value in a field of the row selected in the combo box to be used...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.