oracle存储过程中如何对一个变量累加赋值 最好有个例子 5
展开全部
图显IP:
下面是一个用游标的存储过程,v_shixiaqu := to_char(to_number(v_region_code)+1);为变量赋值
create or replace procedure test
as
CURSOR c1 IS select parent_id from region where region_name = '市辖区' and region_code = region_name;
v_parent_id region.parent_id%type;
v_region_code region.region_code%type;
v_shixiaqu region.region_code%type;
v_errcode number;
v_errmsg varchar2(1000);
v_count number;
begin
open c1;
LOOP
fetch c1 into v_parent_id;
exit when c1%notfound;
select count(*) into v_count from region where region_id = v_parent_id;
if v_count <> 0 then
select region_code into v_region_code from region where region_id = v_parent_id;
v_shixiaqu := to_char(to_number(v_region_code)+1);
DBMS_OUTPUT.PUT_LINE(v_parent_id||'---'||v_shixiaqu );
update region
set region_code = v_shixiaqu
where parent_id = v_parent_id
and region_name = '市辖区';
commit;
end if;
--fetch c1 into v_parent_id;
end loop;
close c1;
exception
when others then
v_errcode := sqlcode;
v_errmsg := sqlerrm;
dbms_output.put_line( 'error code is ' || v_errcode || ' error message is ' || v_errmsg);
rollback;
end test;
下面是一个用游标的存储过程,v_shixiaqu := to_char(to_number(v_region_code)+1);为变量赋值
create or replace procedure test
as
CURSOR c1 IS select parent_id from region where region_name = '市辖区' and region_code = region_name;
v_parent_id region.parent_id%type;
v_region_code region.region_code%type;
v_shixiaqu region.region_code%type;
v_errcode number;
v_errmsg varchar2(1000);
v_count number;
begin
open c1;
LOOP
fetch c1 into v_parent_id;
exit when c1%notfound;
select count(*) into v_count from region where region_id = v_parent_id;
if v_count <> 0 then
select region_code into v_region_code from region where region_id = v_parent_id;
v_shixiaqu := to_char(to_number(v_region_code)+1);
DBMS_OUTPUT.PUT_LINE(v_parent_id||'---'||v_shixiaqu );
update region
set region_code = v_shixiaqu
where parent_id = v_parent_id
and region_name = '市辖区';
commit;
end if;
--fetch c1 into v_parent_id;
end loop;
close c1;
exception
when others then
v_errcode := sqlcode;
v_errmsg := sqlerrm;
dbms_output.put_line( 'error code is ' || v_errcode || ' error message is ' || v_errmsg);
rollback;
end test;
更多追问追答
追问
我是想这样的!!!
就java中的 String str ="";
str+="123";
追答
什么意思?
参考资料: 老k博客
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
declare
num number;
begin
num := 1;
num := num + 1;
dbms_output.put_line(num);
end;
/
num number;
begin
num := 1;
num := num + 1;
dbms_output.put_line(num);
end;
/
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的补充
declare
v_bianliang varchar2(1000);
begin
v_bianliang := 'test';
for r in 1 .. 5 loop
v_bianliang := v_bianliang || ',';
end loop;
dbms_output.put_line(v_bianliang);
end;
declare
v_bianliang varchar2(1000);
begin
v_bianliang := 'test';
for r in 1 .. 5 loop
v_bianliang := v_bianliang || ',';
end loop;
dbms_output.put_line(v_bianliang);
end;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询