Oracle字符串如何连接单引号
今天写了个存储过程,需要在字符串变量前后加单引号。貌似简单的事情折腾了我一下午,好在天无绝人之路。终于被我弄明白甲骨文的变态规则。Oracle 字符串连接单引号:
1. 首尾单引号为字符串识别标识,不做转译用
2. 首尾单引号里面如果出现的单引号,并且有多个,则相连两个单引号转译为一个字符串单引号
3. 单引号一定成对出现,否者这个字符串出错,因为字符串不知道哪个单引号负责结束
select to_char('aaa')from dual;
select '' || to_char('aaa') || ''from dual;
select '''' || to_char('aaa') || '''' from dual;
select '''''' || to_char('aaa') || '''''' from dual;
select '''''''' || to_char('aaa') || '''''''' from dual;
select ' '' ' ||' ' || ' '' ' || to_char('aaa') || ' '' '' ' from dual;
拼接示例:
create or replace procedure proc_createnewcardversion(srcunitcode varchar2, srccardbillcodes varchar2)
as
dstcardrecid raw(16) := null;
cursor c_srccard is (SELECT recid, billcode
FROM (SELECT a.recid, a.orgunit, a.year, a.period, a.billcode, a.islocked, a.isvalid, a.lockrecid, a.lockdefid, a.validtime, a.invalidtime,
ROW_NUMBER() OVER (PARTITION BY a.orgunit, a.billcode ORDER BY a.invalidtime desc) AS RN
FROM am_card a
where a.orgunit = (select recid from md_org where stdcode = srcunitcode)
and a.billcode in ('''' || replace(srccardbillcodes, ',' , ''',''') || ''''))
WHERE RN = 1);
begin
DBMS_OUTPUT.PUT_LINE('执行:');
for srccard in c_srccard loop --获取这些卡片编号下的最后一个版本数据
dstcardrecid := sys_guid();
DBMS_OUTPUT.PUT_LINE(srccard.recid || srccard.billcode || dstcardrecid ||';');
end loop;
end;
call proc_createnewcardversion('010101','4701-0001,4701-0002');
来源:CSDN
作者:尼古拉斯.小王
链接:https://blog.csdn.net/wjh5240313226/article/details/51955268