Home » SQL & PL/SQL » SQL & PL/SQL » Assigning Number values to varchar2 columns and viceversa
Assigning Number values to varchar2 columns and viceversa [message #286239] Fri, 07 December 2007 00:17 Go to next message
swapnajojo
Messages: 40
Registered: June 2007
Location: India
Member
Hi Team ,



Suppose i have created a table like this

SQL> create table ttest (pen char(2))
2 /

Table created.

SQL> desc ttest
Name Null? Type
----------------------------------------- -------- ----------------------------
PEN CHAR(2)

SQL> insert into ttest(123);
insert into ttest(123)
*
ERROR at line 1:
ORA-00928: missing SELECT keyword


SQL> insert into ttest values (12)
2 /

1 row created.

Does this mean if have a column in a table as varchar2 ,
it can accept Number values too .


System Info :

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options



Regards..
Binuja
Re: Assigning Number values to varchar2 columns and viceversa [message #286243 is a reply to message #286239] Fri, 07 December 2007 00:27 Go to previous messageGo to next message
BlackSwan
Messages: 25039
Registered: January 2009
Location: SoCal
Senior Member
You should learn & use valid & proper SQL syntax
Re: Assigning Number values to varchar2 columns and viceversa [message #286246 is a reply to message #286239] Fri, 07 December 2007 00:29 Go to previous messageGo to next message
Michel Cadot
Messages: 64111
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
And you should read and follow OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format. Use the "Preview Message" button.

Regards
Michel

[Updated on: Fri, 07 December 2007 00:29]

Report message to a moderator

Re: Assigning Number values to varchar2 columns and viceversa [message #286249 is a reply to message #286239] Fri, 07 December 2007 00:31 Go to previous messageGo to next message
rajavu1
Messages: 1574
Registered: May 2005
Location: Bangalore , India
Senior Member



Oracle can do it. It casts numbers and characters.

SQL> create table ttest (pen char(2),nep number);

Table created.

SQL> insert into ttest values (12,2);

1 row created.

SQL> insert into ttest values ('12',2);

1 row created.

SQL> insert into ttest values (12,'2');

1 row created.

SQL> insert into ttest values ('12','2');

1 row created.

SQL> select * from ttest;

PE        NEP
-- ----------
12          2
12          2
12          2
12          2

SQL> drop table ttest;

Table dropped.

SQL>


But it is Highly recommended to NOT to let Oracle do the casting and values should be inserted with proper syntax.

Thumbs Up
Rajuvan.
Re: Assigning Number values to varchar2 columns and viceversa [message #286250 is a reply to message #286249] Fri, 07 December 2007 00:36 Go to previous messageGo to next message
swapnajojo
Messages: 40
Registered: June 2007
Location: India
Member
Thanks friend
Re: Assigning Number values to varchar2 columns and viceversa [message #286254 is a reply to message #286249] Fri, 07 December 2007 00:44 Go to previous message
Michel Cadot
Messages: 64111
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
@Rajuvan

So why did you show a detailled example of what must no be done?
Didn't you promise (among many other things) to not do that?

Regards
Michel

[Updated on: Fri, 07 December 2007 00:44]

Report message to a moderator

Previous Topic: Correct calender expression ?
Next Topic: a simple job...ORA-06550 error
Goto Forum:
  


Current Time: Mon Dec 05 19:32:11 CST 2016

Total time taken to generate the page: 0.08540 seconds