1.描述
在Oracle的存储过程中,我们可以直接将游标遍历出来的数据,直接使用replace函数进行字符替换,无需将其写在select语句中
2.实战演练
(1)建表语句
create table t(id number, name varchar2(10),tel varchar2(11));
insert into t values(1, 'Jack01', '13923456789');
insert into t values(1, 'Jack01', '13932456789');
insert into t values(1, 'Jack01', '13999456789');
insert into t values(1, 'Jack01', '13699456789');
insert into t values(1, 'Jack01', '13899456789');
commit;
(2)存储过程
create or replace procedure test_rep
as
-- 定义游标
CURSOR t_cursor IS
select * from t;
tel_str varchar2(200);
begin
for cur_1 in t_cursor loop
tel_str := replace(cur_1.tel, '139', 'update');
dbms_output.put_line(tel_str);
end loop;
end;
(3)运行结果