【问题标题】:i want to trim last two characters in string with selected row in selected column我想用选定列中的选定行修剪字符串中的最后两个字符
【发布时间】:2014-11-07 09:15:40
【问题描述】:

我在下面的查询中使用了对选定行最后 2 个值的修剪功能,但该查询修剪了所有行的最后 2 个字符。但我想修剪选定的行字符

select substr(detail,0,length(detail)-2) from address where  detail_no=1;

例如。

  row 1 text added
  row 2 last value
  row 3 end value

我只想修剪第 2 行的最后 2 个字符,请解释如何使用该查询

【问题讨论】:

标签: sql database oracle oracle11g


【解决方案1】:

您想对某些行而不是其他行执行操作。为此使用 CASE:

select 
  case when detail_no = 1 then
    then substr(detail, 1, length(detail)-2) 
  else
    detail
  end as detail
from address;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-27
    • 1970-01-01
    相关资源
    最近更新 更多