SELECT语句在PL / SQL块中不起作用

时间:2013-07-13 19:48:04

标签: sql plsql

我是PL / SQL的新手,我坚持这个查询!
当我运行此命令时,

SELECT COUNT(*),AVG(SI.TOTALCOST)
FROM S2.CAR C, S2.SERVINV SI 
WHERE C.SERIAL = SI.SERIAL 
AND MAKE = 'JAGUAR'
AND MODEL = 'PRO';

直接在SQLPlus提示符下,它可以正常工作并显示输出!

但是当我以PL / SQL块的一部分运行相同的查询时,这样

SELECT COUNT(*) INTO v_visits, AVG(SI.TOTALCOST) INTO v_avg 
FROM S2.CAR C, S2.SERVINV SI
WHERE C.SERIAL = SI.SERIAL
AND MAKE = '&p_make'
AND MODEL = '&p_model';

它不起作用!它给了我这个错误,

SELECT COUNT(*) INTO v_visits, AVG(SI.TOTALCOST) INTO v_avg
                               *
ERROR at line 7:
ORA-06550: line 7, column 32:
PL/SQL: ORA-00934: group function is not allowed here
ORA-06550: line 7, column 1:
PL/SQL: SQL Statement ignored

我不明白这里的问题是什么!
我查看了互联网,但找不到任何有用的东西!
任何帮助表示赞赏!

由于

1 个答案:

答案 0 :(得分:1)

只允许一个into语句。列出那里的变量。此版本还使用更现代的连接语法(您应该学习):

SELECT COUNT(*), AVG(SI.TOTALCOST)
INTO v_visits, v_avg 
FROM S2.CAR C join
     S2.SERVINV SI
     on C.SERIAL = SI.SERIAL
where MAKE = '&p_make' AND MODEL = '&p_model';