 |
| 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
|
|
|
|

March 24th, 2011, 06:46 AM
|
|
Authorized User
|
|
Join Date: Sep 2008
Posts: 54
Thanks: 8
Thanked 1 Time in 1 Post
|
|
Values are not inserting through 'Default' while creating tables.
The table has been created through the query below
CREATE TABLE customer
(First_Name char(50),
Last_Name char(50),
Address char(50) default 'Unknown',
City char(50) default 'Karachi',
Country char(25),
Birth_Date date)
but the default value is not inserting in their respective column, what's wrong with the query?
Thanks in advance.
__________________
How to do programming?
Last edited by arbab; March 24th, 2011 at 06:50 AM..
|
|

March 24th, 2011, 08:01 AM
|
|
Authorized User
|
|
Join Date: Jan 2011
Posts: 86
Thanks: 1
Thanked 12 Times in 12 Posts
|
|
Hi,
how does your insert sql look like?
Just a guess, but if your insert looks like this:
Code:
insert into customer
values ('SCOTT', 'TIGER4', null, null, 'US', to_date('19-10-1961', 'dd-mm-yyyy'));
You are deliberately overwriting the value for Address and City...
The default value only works if you do something like this:
Code:
insert into customer(First_Name ,Last_Name )
values ('SCOTT', 'TIGER');
Hope this helps.
|
|

March 28th, 2011, 03:01 AM
|
|
Authorized User
|
|
Join Date: Sep 2008
Posts: 54
Thanks: 8
Thanked 1 Time in 1 Post
|
|
You mean to say that 'Default' will not work to insert values.
@ disel2010: You mean to say that âDefaultâ does not work, we need to have insert query to fill the columns, I am learning Oracle/SQL commands from a website where I found this:
Sometimes, we want to provide a default value for each column. A default value is used when you do not specify a column's value when inserting data into the table. To specify a default value, add "Default [value]" after the data type declaration. In the above example, if we want to default column "Address" to "Unknown" and City to "Mumbai", we would type in
CREATE TABLE customer
(First_Name char(50),
Last_Name char(50),
Address char(50) default 'Unknown',
City char(50) default 'Mumbai',
Country char(25),
Birth_Date date)
Referece:
http://www.1keydata.com/sql/sqlcreate.html
Thanks in advance
__________________
How to do programming?
|
|

March 28th, 2011, 03:11 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Who said "default does not work"? Please show the query you are using to insert data where the default values are not inserted.
|
|

March 28th, 2011, 06:07 AM
|
|
Authorized User
|
|
Join Date: Jan 2011
Posts: 86
Thanks: 1
Thanked 12 Times in 12 Posts
|
|
Hi Arbab,
sorry to hear my post wasn't clear.
I was trying to show by example when (and when not) the default value comes into play.
To clarify, please note:
- that the default value only comes into play when a column isn't specified in an INSERT statement...
- that as soon as you do specify a column with a default value, you are overwriting the default value
Also, it's only when you are actually inserting records that the default value can come into play.. The moment you created your table with the DDL statement you only have the metadata describing your database object, not the data itself yet...
|
|
The Following User Says Thank You to disel2010 For This Useful Post:
|
|
|

April 8th, 2011, 06:39 AM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 31
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
The keyword default means values (default values ) will be inserted into the specified column of the table if no data is passed in the insert statement (column is ignored). But if data is passed the default value will be over written by the passed value.
__________________
Regards
Debasis
|
|
The Following User Says Thank You to debasisdas For This Useful Post:
|
|
|
 |