PL/SQL 实际返回行数超出请求行数
这是我写的代码(想输出每一行记录的三个字段):DECLAREv_enameemp.ename%TYPE;v_jobemp.job%TYPE;v_salemp.sal%TY...
这是我写的代码(想输出每一行记录的三个字段):
DECLARE
v_ename emp.ename%TYPE;
v_job emp.job%TYPE;
v_sal emp.sal%TYPE;
v_count NUMBER(2);
BEGIN
SELECT COUNT(*) INTO v_count FROM emp;
-- dbms_output.put_line(v_count);
WHILE v_count >= 1 LOOP
--dbms_output.put_line(v_count);
SELECT ename, job ,sal
INTO v_ename, v_job ,v_sal
FROM emp
WHERE rownum<v_count+1
Minus
SELECT ename , job ,sal
FROM emp
WHERE rownum<v_count; --查询出每行数据进行
v_count := v_count-1;
dbms_output.put_line(v_count);
dbms_output.put_line(v_ename);
dbms_output.put_line(v_job);
dbms_output.put_line(v_sal);
END LOOP;
END; 展开
DECLARE
v_ename emp.ename%TYPE;
v_job emp.job%TYPE;
v_sal emp.sal%TYPE;
v_count NUMBER(2);
BEGIN
SELECT COUNT(*) INTO v_count FROM emp;
-- dbms_output.put_line(v_count);
WHILE v_count >= 1 LOOP
--dbms_output.put_line(v_count);
SELECT ename, job ,sal
INTO v_ename, v_job ,v_sal
FROM emp
WHERE rownum<v_count+1
Minus
SELECT ename , job ,sal
FROM emp
WHERE rownum<v_count; --查询出每行数据进行
v_count := v_count-1;
dbms_output.put_line(v_count);
dbms_output.put_line(v_ename);
dbms_output.put_line(v_job);
dbms_output.put_line(v_sal);
END LOOP;
END; 展开
1个回答
展开全部
想的太复杂了,用简单的游标就能实现,如下:
DECLARE
i number(2);
BEGIN
i:=1;
for bus in (SELECT * FROM emp)
loop
dbms_output.put_line('Record: '||i);
dbms_output.put_line(bus.ename);
dbms_output.put_line(bus.job);
dbms_output.put_line(bus.sal);
i:=i+1;
END LOOP;
END;
DECLARE
i number(2);
BEGIN
i:=1;
for bus in (SELECT * FROM emp)
loop
dbms_output.put_line('Record: '||i);
dbms_output.put_line(bus.ename);
dbms_output.put_line(bus.job);
dbms_output.put_line(bus.sal);
i:=i+1;
END LOOP;
END;
追问
我只是想知道 如果我把v_count 固定到特定值的时候不报错。随着循环变化的时候报错
追答
报什么错?emp里有多少条记录?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询