Home » SQL & PL/SQL » SQL & PL/SQL » Converting a varchar2 to a char (10g)
Converting a varchar2 to a char [message #298563] Wed, 06 February 2008 07:34 Go to next message
amardilo
Messages: 37
Registered: February 2007
Member
Hi there.

I have a field passed into a Stored procedure as a varchar2 and I want to convert that to a char.

i.e. how do I convert the following....

vString varchar2(10) := 'abc'
vChar char(5)

In the above example I need to change vString to 'abc ' so I can insert/update a row into a table.

Anyone know how to do this?

Re: Converting a varchar2 to a char [message #298565 is a reply to message #298563] Wed, 06 February 2008 07:46 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
RPAD

Regards
Michel
Re: Converting a varchar2 to a char [message #298566 is a reply to message #298563] Wed, 06 February 2008 07:47 Go to previous messageGo to next message
joy_division
Messages: 4640
Registered: February 2005
Location: East Coast USA
Senior Member
Just simply set vString to
vString || '  '
Re: Converting a varchar2 to a char [message #298569 is a reply to message #298565] Wed, 06 February 2008 07:54 Go to previous messageGo to next message
amardilo
Messages: 37
Registered: February 2007
Member
Thanks for your help.
Re: Converting a varchar2 to a char [message #298609 is a reply to message #298563] Wed, 06 February 2008 14:51 Go to previous messageGo to next message
Bill B
Messages: 1482
Registered: December 2004
Senior Member
YOu do not need to right pad. The column will do it automatically. A char field is by definition padded.


>create table xx (x char(5));

Table created.

>insert into xx values('ABC');

1 row created.

>select '['||x||']' from xx;

'['||X|
-------
[ABC ]

>drop table xx;

Table dropped.
Re: Converting a varchar2 to a char [message #298653 is a reply to message #298609] Thu, 07 February 2008 00:27 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Where do you see OP talks about column in a table.
He "clearly" showed PL/SQL variables.
He said "I have a field passed into a Stored procedure as a varchar2 and I want to convert that to a char", so the column (field) is VARCHAR2 and then the variable has to be CHAR.

In addition, please 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.
Indent the code.
Use the "Preview Message" button to verify.
Spaces are not visible (even with []) without formatting.

Regards
Michel
Re: Converting a varchar2 to a char [message #298813 is a reply to message #298563] Thu, 07 February 2008 15:24 Go to previous message
Bill B
Messages: 1482
Registered: December 2004
Senior Member
Sorry, I should have wrapped the code in the code tags.
Previous Topic: update/replace in pl/sql block
Next Topic: Db link name problem
Goto Forum:
  


Current Time: Sat Dec 03 04:11:55 CST 2016

Total time taken to generate the page: 0.10083 seconds