用PLSQL创建存储过程,为什么结果不显示插入的内容,只有影响的行数?
--创建存储过程,过程体中使用INCreateProcedureproc1asDECLAREaint;cursorcur1isselect*fromempwheresal...
--创建存储过程,过程体中使用IN
Create Procedure proc1 as
DECLARE
a int;
cursor cur1 is
select * from emp
where sal in (800,1600);
begin
open cur1;
fetch cur1 into a;
insert into tab(num) values(a);
close cur1;
end;
结果是:
--执行过程
call proc1;
PROC1
-------
(1 行)
select num from tab;
NUM
-----
(1 行)
创建的表如下:
CREATE TABLE emp (sal int);
insert into emp values (1000);
CREATE TABLE tab (num int); 展开
Create Procedure proc1 as
DECLARE
a int;
cursor cur1 is
select * from emp
where sal in (800,1600);
begin
open cur1;
fetch cur1 into a;
insert into tab(num) values(a);
close cur1;
end;
结果是:
--执行过程
call proc1;
PROC1
-------
(1 行)
select num from tab;
NUM
-----
(1 行)
创建的表如下:
CREATE TABLE emp (sal int);
insert into emp values (1000);
CREATE TABLE tab (num int); 展开
展开全部
你的游标都没有取到值,你确定你的表中 sal in (800,1600); sal 字段 有800,1600这两个数据吗?
------------------
你的可以改成这样,不然你只能插入一行
Create or replace Procedure proc1 as
DECLARE
begin
for rec1 IN ( select sal from emp_e1 where sal in (800,1600))
loop
insert into tab_t1(num) values(rec1.sal);
end loop;
end;
------------------
你的可以改成这样,不然你只能插入一行
Create or replace Procedure proc1 as
DECLARE
begin
for rec1 IN ( select sal from emp_e1 where sal in (800,1600))
loop
insert into tab_t1(num) values(rec1.sal);
end loop;
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询