如何通过附加" ..."?
来截断查询结果并指明它已被截断此示例截断超过2个字符的结果,但不幸的是要将 N when
子句截断为 N 字符。
select
case length(x)
when 1 then x
when 2 then x
else substr(x,1,2)||'...'
end x
from (select 'ab' x from dual union select 'abc' from dual);
X
------
ab
ab...
有没有办法在查询中添加length(x) > 25
等条件逻辑?
答案 0 :(得分:4)
也许你只想要这个?
select (case when length(x) <= 2 then x
else substr(x, 1, 2) || '...'
end) as x
。 。
也就是说,使用case
的条件形式,而不是常量形式。
以下是问题中表达的完整代码。
select
case when length(x) <= 2 then x
else substr(x, 1, 2) || '...'
end x
from (select 'ab' x from dual union select 'abc' from dual);
X
------
ab
ab...