【问题标题】:Oracle declare select into update statement does not workOracle 将 select 声明为 update 语句不起作用
【发布时间】:2015-01-16 23:48:33
【问题描述】:

had an issue where due to database charset special characters would get weird codes assigned 给他们,然后通过获取 select ascii(substr(declinereasondesc, 30,1)) from DECLINEREASON t where declinereasonid = 7; 我在 db 字符集中获得了 £ 的代码 (49827)。然后我尝试更新数据库中的记录。

我遇到的问题是数据没有保存到 DB 或 selecting into 值以某种方式更改为 varchar2(6); 并且它不再匹配 REGEXP_REPLACE

当我尝试使用应该值的varchar2(1) 时出错,这可能是一个提示。

declare c varchar2(6);
begin 
select ascii(substr(declinereasondesc, 30,1)) into c from DECLINEREASON t
where declinereasonid = 7;
begin 
  update DECLINEREASON set declinereasondesc = REGEXP_REPLACE(declinereasondesc, '(.+)('||c||')(\d+)', '\1\3 (GBP)');
  commit;
  end;
end;
/
commit;

更新:尝试declare c number;没有错误但没有更新值ether

【问题讨论】:

  • where 语句中没有 where 子句?!?
  • @ammoQ 不需要它,不匹配的 regex_replace 返回它的输入值。
  • 但这仍然意味着更新语句仍然会影响DECLINEREASON 中的所有行,即使更新本身没有效果
  • @ammoQ 你说的很对

标签: regex oracle select-into regexp-replace


【解决方案1】:

这是我愚蠢造成的 - 忘记将 c 包裹在 chr(c) 中。

declare c number;
begin 
select ascii(substr(declinereasondesc, 30,1)) into c from DECLINEREASON t
where declinereasonid = 7;
begin 
  update DECLINEREASON set declinereasondesc = REGEXP_REPLACE(declinereasondesc, '(.+)('||chr(c)||')(\d+)', '\1\3 (GBP)');
  commit;
  end;
end;
/
  commit;

【讨论】:

    猜你喜欢
    • 2011-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-17
    • 1970-01-01
    • 2015-11-19
    • 1970-01-01
    • 2011-09-16
    相关资源
    最近更新 更多