Oracle声明select into update语句不起作用

时间:2014-11-19 12:46:25

标签: regex oracle select-into regexp-replace

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 charset中获得£的代码(49827)。然后我尝试更新数据库中的记录。

我得到的问题是数据未保存到数据库或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

1 个答案:

答案 0 :(得分:0)

这个是我愚蠢造成的 - 忘了在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;