我从一个表中选择数据存储为nchar。我正在添加“在记录之前”|记录之后。我正在使用Oracle数据库。由于固定的宽度,我在记录之间得到了空格。我使用RTrim删除了一半。
Select distinct RTRIM(('"I-'||AA.Field)|| '"|') AS Unique_ID,
RTRIM('"' ||AA.Name)||'"|' AS Name
From Test1 AA, Test2 B
Where AA.ID= B.ID;
如何删除字段之间的所有空格?
选择转储返回
Typ=2 Len=3: c2,2,3d Typ=96 Len=80: 0,46,0,69,0,6e,0,61,0,6e,0,63,0,65,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20
Typ=2 Len=3: c2,2,42 Typ=96 Len=80: 0,48,0,40,0,57,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20
Typ=2 Len=3: c2,2,10 Typ=96 Len=80: 0,48,0,75,0,6d,0,61,0,6e,0,20,0,52,0,65,0,73,0,6f,0,75,0,72,0,63,0,65,0,73,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20
Typ=2 Len=3: c2,2,b Typ=96 Len=80: 0,49,0,6e,0,66,0,6f,0,72,0,6d,0,61,0,74,0,69,0,6f,0,6e,0,20,0,54,0,65,0,63,0,68,0,6e,0,6f,0,6c,0,6f,0,67,0,79,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20
Typ=2 Len=3: c2,2,1f Typ=96 Len=80: 0,4d,0,61,0,72,0,6b,0,65,0,74,0,69,0,6e,0,67,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20
Typ=2 Len=3: c2,2,2e Typ=96 Len=80: 0,4e,0,65,0,77,0,20,0,4c,0,69,0,6e,0,65,0,73,0,20,0,6f,0,66,0,20,0,42,0,75,0,73,0,69,0,6e,0,65,0,73,0,73,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20
Typ=2 Len=2: c2,2 Typ=96 Len=80: 0,4f,0,70,0,65,0,72,0,61,0,74,0,69,0,6f,0,6e,0,73,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20
Typ=2 Len=3: c2,2,29 Typ=96 Len=80: 0,50,0,72,0,6f,0,64,0,75,0,63,0,74,0,20,0,44,0,65,0,76,0,65,0,6c,0,6f,0,70,0,6d,0,65,0,6e,0,74,0,20,0,26,0,20,0,50,0,72,0,69,0,63,0,69,0,6e,0,67,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20
Typ=2 Len=3: c2,2,24 Typ=96 Len=80: 0,53,0,61,0,6c,0,65,0,73,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20
Typ=2 Len=3: c2,2,7 Typ=96 Len=80: 0,43,0,75,0,73,0,74,0,6f,0,6d,0,65,0,72,0,20,0,53,0,65,0,72,0,76,0,69,0,63,0,65,0,73,0,20,0,2d,0,20,0,43,0,75,0,73,0,74,0,6f,0,6d,0,65,0,72,0,20,0,53,0,75,0,70,0,70,0,6f,0,72,0,74,0,20,0,20,0,20,0,20
Typ=2 Len=3: c2,2,1a Typ=96 Len=80: 0,54,0,72,0,61,0,69,0,6e,0,69,0,6e,0,67,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20
Typ=2 Len=2: c2,b Typ=96 Len=80: 0,4c,0,61,0,77,0,72,0,65,0,6e,0,63,0,65,0,20,0,4a,0,61,0,6e,0,65,0,73,0,20,0,28,0,53,0,79,0,73,0,74,0,65,0,6d,0,20,0,44,0,79,0,6e,0,61,0,6d,0,69,0,63,0,73,0,29,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20
Typ=2 Len=2: c1,15 Typ=96 Len=80: 0,4c,0,61,0,79,0,61,0,20,0,48,0,65,0,61,0,6c,0,74,0,68,0,63,0,61,0,72,0,65,0,20,0,4c,0,69,0,6d,0,69,0,74,0,65,0,64,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20
Typ=2 Len=2: c1,b Typ=96 Len=80: 0,41,0,76,0,6f,0,6e,0,64,0,68,0,75,0,20,0,4c,0,69,0,6d,0,69,0,74,0,65,0,64,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20
Typ=2 Len=3: c2,40,29 Typ=96 Len=80: 0,4c,0,69,0,7a,0,20,0,4f,0,27,0,53,0,75,0,6c,0,6c,0,69,0,76,0,61,0,6e,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20
Typ=2 Len=2: c1,1f Typ=96 Len=80: 0,51,0,75,0,69,0,6e,0,6e,0,20,0,48,0,43,0,20,0,53,0,65,0,72,0,76,0,69,0,63,0,65,0,73,0,20,0,4c,0,69,0,6d,0,69,0,74,0,65,0,64,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20
Typ=2 Len=3: c2,a,64 Typ=96 Len=80: 0,54,0,61,0,78,0,20,0,41,0,75,0,74,0,68,0,6f,0,72,0,69,0,74,0,79,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20
Typ=2 Len=3: c2,4d,52 Typ=96 Len=80: 0,4b,0,65,0,76,0,69,0,6e,0,20,0,4b,0,65,0,6e,0,74,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20
示例记录 | “救护车服务”|
答案 0 :(得分:2)
我相信你想要:
select distinct '"I-' || TRIM(AA.Field) || '"|' AS Unique_ID,
'"' || TRIM(AA.Name) ||'"|' AS Name
from Test1 AA join
Test2 B
on AA.ID = B.ID;
TRIM()
删除字符串开头和结尾的空格。您应该在之前执行此操作附加其他字符。
此外,您应该学会使用正确的,明确的join
语法。简单的规则:从不在FROM
子句中使用逗号。
如果要删除所有空格,请使用REPLACE()
:
select distinct '"I-' || REPLACE(AA.Field, ' ', '') || '"|' AS Unique_ID,
'"' || REPLACE(AA.Name, ' ', '') ||'"|' AS Name
from Test1 AA join
Test2 B
on AA.ID = B.ID;