SQL Plus 无法识别 Oracle PL/SQL 语句

Posted

技术标签:

【中文标题】SQL Plus 无法识别 Oracle PL/SQL 语句【英文标题】:Oracle PL/SQL statements not being recognised by SQL Plus 【发布时间】:2014-04-20 17:10:57 【问题描述】:

我在 64 位笔记本电脑上安装了 11g 32 位 Oracle Express。 sql plus 将任何 pl/sql 语句/语法视为错误,并且仅识别 sql 代码。

一定是某个地方的 Oracle 配置问题。这是在上一次安装遇到相同问题后全新安装的 Oracle Express。

其他人有这个问题吗?我已经在谷歌上搜索死了,但没有提出解决方案。

Set serveroutput on
Set echo off
Remark  *** Set up the SQL*Plus environment ***

Set Pagesize 24
Set Feedback Off

Remark  *** Format the Columns ***
Column  ctype   Format A5       Heading Car|Type
Column  A       Format A3       Heading A
Column  B       Format A3       Heading B
Column  C       Format A3       Heading C
Column  D       Format A3       Heading D
Column  E       Format A3       Heading E
Column  F       Format A3       Heading F
Column  G       Format A3       Heading G

break on ctype

Remark  *** The Query ***
DECLARE
    v_cid   VARCHAR2(3);
    v_grade CHAR(1);
BEGIN
    FOR ct IN (SELECT c_type# as ct FROM consultant)
    LOOP
        v_cid := ct;
        SELECT      c_type# as ctype,
            TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'A')) as A,
            TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'B')) as B,
            TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'C')) as C,
            TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'D')) as D,
            TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'E')) as E,
            TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'F')) as F,
            TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'G')) as G
        FROM        consultant
        WHERE       consultant.c_type# = v_cid
        GROUP BY    c_type#
        ORDER BY    ctype;
    END LOOP;
END;
/

SELECT      car_type.c_type# as ctype,
            TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'A')) as A,
            TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'B')) as B,
            TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'C')) as C,
            TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'D')) as D,
            TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'E')) as E,
            TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'F')) as F,
            TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'G')) as G
FROM        consultant
INNER JOIN  grade
ON          consultant.grade = grade.grade
INNER JOIN  car_type
ON          consultant.c_type# = car_type.c_type#
GROUP BY    car_type.c_type#
ORDER BY    ctype
/
Remark  *** Reset the environment ***
Clear columns
Ttitle Off
Btitle Off
Set Feedback on
Set Pagesize 20 
Set Echo on

Error code :  ERROR at line 1:
ORA-00922: missing or invalid option

【问题讨论】:

发布声明和确切错误消息。 编辑了我的原始帖子以反映代码。 和任何 pl sql 代码(如 DECLARE、BEGIN)都会引发错误。虽然没有 sql 错误。 如何在 SQLplus 中运行这些语句?我猜你不会每次尝试时都输入它们。 '任何 PL/SQL 语句/语法' - 引发 ORA-00922 的最少代码是什么?除了 jonearles 指出的不正确的光标引用之外,您在循环中的选择没有选择 into 任何东西。 【参考方案1】:

替换

v_cid := ct;

v_cid := ct.ct;

代码必须引用cursor_name.column_name,即使游标和列名相同。此外,它总是有助于将问题减少到尽可能小的规模。

【讨论】:

谢谢你,但是在错误上没有区别。 SQL Plus 似乎对 PL SQL 产生了厌恶,并拒绝承认它的存在。自从移到新机器上,代码一切正常。 在 SQL*Plus 中即使是像这样的微不足道的 PL/SQL 块也会失败:exec null;【参考方案2】:

免费的 Oracle Express 不支持 PlSql

【讨论】:

以上是关于SQL Plus 无法识别 Oracle PL/SQL 语句的主要内容,如果未能解决你的问题,请参考以下文章

SQL Plus 和 www.apex.oracle.com

OracleLinux上配置新建用户访问SQL*Plus

SQL PLUS 如何远程连接ORACLE数据库

SQL Plus 将字符转换为字节以用于 Oracle 复制命令

pl/sql developer中写SQL时出现ORA-06550和PLS-00553

Oracle保存带&的数据