CREATE OR REPLACE PROCEDURE test
as
begin
for i in 1001..1003 loop
execute immediate 'update tableName set test1001=1001 where a=''000002'' and b=''20100816''';
end loop
end;exec test
大概就是这个样子 上面的东西执行了 就是提示影响了0行,但下面这个句子确实能执行的update tableName set test1001=1001 where a='000002' and b='20100816' 确显示影响1行其实本来嵌在循环内的应该是下面这样
'update tableName set test'||to_char(i)||'='||to_char(i)|| 'where a=''000002'' and b=''20100816'''
我已经精简到不用参数试试效果的 可为啥还是不能执行呢(影响0行)....
oracle的数据库
求高手
as
begin
for i in 1001..1003 loop
execute immediate 'update tableName set test1001=1001 where a=''000002'' and b=''20100816''';
end loop
end;exec test
大概就是这个样子 上面的东西执行了 就是提示影响了0行,但下面这个句子确实能执行的update tableName set test1001=1001 where a='000002' and b='20100816' 确显示影响1行其实本来嵌在循环内的应该是下面这样
'update tableName set test'||to_char(i)||'='||to_char(i)|| 'where a=''000002'' and b=''20100816'''
我已经精简到不用参数试试效果的 可为啥还是不能执行呢(影响0行)....
oracle的数据库
求高手
as
begin
for i in 1001..1003 loop
update tableName set test1001=1001 where a='000002' and b='20100816';----这里用不用execute immediate 都可以,但是必须要commit哦commit;
end loop
end;
使用下面语句执行存储过程,看看 sql%rowcount(影响行数)输出是否为 0set serveroutput onbegin
test;
dbms_output.put_line(sql%rowcount);
end;
直接在 sqlplus 下执行存储过程是不会产生“影响行数”的。
as
begin
for i in 1001..1003 loop
execute immediate 'update tableName set test1001=1001 where a=''000002'' and b=''20100816''';
commit; --提交
end loopend;
我光执行
begin
for i in 1001..1003 loop
execute immediate 'update tableName set test1001=1001 where a=''000002'' and b=''20100816''';
commit;
end loop
end;
是完全米有问题的...(不加commit也行)
就是加了
CREATE OR REPLACE PROCEDURE test
as
这2句就提示影响0行了...
那是不是创建了过程要另外调用啊?
还有那个commit到底什么时候要加啊?
你要
exec test
或者
begin
test;
end
for i in 4001..4010 loop
execute immediate
'update tableName set test'||to_char(i)||'='||to_char(i)|| 'where a=''000002'' and b=''20100816''';
commit;
end loop;比如test4001是varchar2类型的
当我在sqlserver里面执行这样的语句是必须要把i显示的转换成varchar的 cast(i as varchar(10))
但在oracle里面 当我去掉to_char()也是ok的,虽然i是在for里面定义的 但是我想找个i应该也是int类型吧
所以我想问 是不是在oracle里面 会自动转型啊?
不过,在 sql server 中优先低的类型会向优先级高的类型转换,而 int 类型的优先级高于 char 和 varchar 类型,因此在字符串联运算中 char 和 varchar 类型会隐式转换为 int 类型,从而导致错误。虽然 oracle 没有这样的限制,但是 oracle 推荐使用 to_char 显示转换。
那么按优先级高低的话 就是说在sql server中 char类型的1可以隐式转换成int 的1而不报错了?
在 sql server 中可以这样 select '1'+2