如何修剪teradata表列中的尾随空格

时间:2018-05-18 11:27:26

标签: teradata trim

我想修剪teradata表列的尾随空格

我是这样做的,

trim(trailing from dictionary_managed_databases.dbname),

或直接使用修剪,

trim(dictionary_managed_databases.dbname),

但结果显示: enter image description here

看起来修剪不起作用, 不知道如何在teradata中做到这一点,

2 个答案:

答案 0 :(得分:1)

create volatile table test ( dbname varchar(128) CHARACTER SET UNICODE ) on commit preserve rows;
insert into test values ( 'Database-Name' );
-- you don't need to trim a varchar column
select dbname || '~'  from test;
(dbname||'~')
---------------------------------------------------------------------------------------------------------------------------------
Database-Name~
-- it is always max length, so not to loose any possible content
select trim(dbname) || '~'  from test;
(Trim(BOTH FROM dbname)||'~')
---------------------------------------------------------------------------------------------------------------------------------
Database-Name~
-- you may cast it to shorten the resulting column
select cast(trim(dbname) as varchar(30)) from test;
Trim(BOTH FROM dbname)
------------------------------
Database-Name
-- it will never be less then the header, even if the content is less
select cast(trim(dbname) as varchar(10)) from test;
Trim(BOTH FROM dbname)
----------------------
Database-N
-- but it will truncate the result
select cast(trim(dbname) as varchar(10)) as dbname from test;
dbname
----------
Database-N

答案 1 :(得分:0)

sel 
dictionary_object_map.moId,
trim(dictionary_managed_databases.dbname)|| '~',
dictionary_deployed_info.dictionaryId,
dictionary_deployed_info.dictionaryName,
dictionary_managed_objects.moname
from dictionary_object_map,
dictionary_deployed_info,
dictionary_managed_objects ,
dictionary_managed_databases
where 
dictionary_object_map.dictionaryId=dictionary_deployed_info.dictionaryId 
and dictionary_object_map.moid=dictionary_managed_objects.moid
and dictionary_managed_databases.moDBId=dictionary_managed_objects.moDBId
and dictionary_managed_databases.dbname = 'customerservice';

结果

enter image description here

不明白为什么字段dbname的输出仍然如此,