开发者

Varchar2 and Oracle quick question

开发者 https://www.devze.com 2022-12-28 07:51 出处:网络
Hi guys I\'m using varchar2 for a product name field, but when I query the database from the run SQL command line it shows too many empty spaces, how can I fix this without changing the datatype

Hi guys I'm using varchar2 for a product name field, but when I query the database from the run SQL command line it shows too many empty spaces, how can I fix this without changing the datatype

here is the link to the ss

开发者_如何学Go

http://img203.imageshack.us/img203/20/varchar.jpg


The data that got inserted into the database (probably through some ETL process) had spaces which were not trimmed.

You could update using (pseudo code)

Update Table Set Column = Trim(Column)


If TRIM does not change the results, that tells you that there are not trailing spaces in the actual database rows; they're just being added as part of the formatted screen output.

By default, sqlplus (the command-line Oracle tool you appear to be using) uses the maximum length of the varchar2 column as the (fixed) width when displaying the results of a select statement.

If you want to change this, use the column format sqlplus command before running the select. For example:

column DEPT_NAME format a20



Hi

Try to use trim on both sides,
Update TableName set FieldName = RTrim(LTrim(FieldName))

Regards

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号