ORA-00936缺少表达错误

时间:2018-07-25 14:32:57

标签: oracle sqlplus

我正在尝试运行以下查询进行登录审核,但是出现以下错误:

  

第13行出现错误:ORA-00936:缺少表达式。

这是脚本。我对此并不陌生,尚不清楚缺少哪种表达方式。任何帮助将不胜感激。

whenever sqlerror exist rollback
set feed on
set head on
set arraysize 1
set space 1
set verify on
set pages 25
set lines 80
set termout on
clear screen

spool aud_last_logon.lis

undefine number_of_days

col username for a10
col os_username for a10
col timestamp for a9
col logoff_time for a9
col returncode for 9999
col terminal for a10
col userhost for a10


select  a.username,
    os_username,
    a.timestamp,
    a.logoff_time,
    a.returncode,
    terminal,
    userhost
from dba_audit_session a
where (a.username,a.timestamp) in 
    (select b.username,max(b.timestamp)
        from dba_audit_session b
        group by b.username)
and a.timestamp<(sysdate-&&number_of_days)
/

spool off

1 个答案:

答案 0 :(得分:0)

问题可能出在您的运行方式上;说您必须运行以下代码:

spool d:\temp\spool.txt
undefine x
select &&x from dual
/

spool off

如果仅将此代码剪切并粘贴到SQLPLUS中,则会得到:

SQL> spool d:\temp\spool.txt
SQL> undefine x
SQL> select &&x from dual
  2  /
Enter value for x:
old   1: select &&x from dual
new   1: select  from dual
select  from dual
        *
ERROR at line 1:
ORA-00936: missing expression


SQL> spool off
SQL>

原因是在交互模式下,/之后的换行符被用作x的“值”,因此会出错。

如果将此代码保存到文件中并运行,您将获得所需的内容:

SQL> start d:\temp\test.sql
Enter value for x: 9
old   1: select &&x from dual
new   1: select 9 from dual

         9
----------
         9