473,606 Members | 2,200 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

2 New Member
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),s alary 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 3127
rski
700 Recognized Expert Contributor
This is how CTAS works.
Maybe take a look at dbms_metadata.g et_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 Recognized Expert Expert
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
2236
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) as FIRST_ITEM,
2
2755
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 field-2 of table-2 then value of field-1 of table-1 will be the default value other wise 0 will be the default value Can I use this type of conditional default value if yes please tell me how. I tried to set this expression in default property of a...
3
3565
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, which can then be set by the user. My thinking was I could set the default value of Unprompted to be =IIF(=Yes,Yes, No). I would then be able to override it for any Purchased=No, Unprompted = Yes results. If I can't achieve this directly within...
4
2339
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 this is possible... and if so..how? Thanks!
2
23405
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 2005. am not getting any prob when i exec ALTER TABLE TABLE_NAME ADD COLUMN DATATYPE SIZE CONSTRAINT VALUE. but getting probs when exec ALTER TABLE TABLE_NAME ALTER COLUMN_NAME DATATYPE SIZE VALUE. Help me, thanx in advance
1
4199
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 Time, ConcertPlace AS Place FROM Concerts UNION SELECT EventName AS Name, EventDate AS Date, EventTime AS Time, EventPlace AS Place FROM Events ORDER BY Date, Time now i'd like to add two things to this statement: 1. a column that indicates...
8
12588
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 table's default values, I want to create a user-friendly form that allows them to change the default values in the linked table. Let's say I have a form field "office" on my form that is linked to the table field in my table. The field has a...
8
2087
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 an error. e.g. if I give "select * from SERVC_MGR_REPT_V_CELL where EMPLOYEES_NAME='Ma, Stephen';", I am getting all the values. But if I give "select MANAGERS_NAME from SERVC_MGR_REPT_V_CELL where EMPLOYEES_NAME='Ma, Stephen';", it gives an...
2
12833
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 change it into mm/dd/yyyy format while fetching. Thanks in advance.
1
1720
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 as the selection criteria in a SQL.Attach is my code but incomplete..Dear experts kindly help Private Sub coReasonCode_Click() Dim Sreasoncode As String Dim sSQL As String Dim oSQL As clsSQL Dim cRow As FwAttributes Dim...
0
8439
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8094
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8305
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6770
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5966
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5465
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3977
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2448
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1553
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.