SQL * Plus中的语法错误

时间:2012-01-09 23:01:42

标签: sql oracle oracle11g

我正在尝试在SQL * Plus中运行以下查询,但是我收到了一个错误。但是,同样的确切查询适用于Aqua Data Studio。

SQL> CREATE OR REPLACE VIEW VIEW_WARREPORT
  2  AS
  3  WITH WGS (WORKGROUPID, Root) AS (
  4     SELECT WorkgroupID, CONNECT_BY_ROOT WORKGROUPID "Root"
  5        FROM TPM_WORKGROUPS
  6        START WITH PARENTWORKGROUPID=0
  7        CONNECT BY PRIOR WORKGROUPID = PARENTWORKGROUPID)
  8
SQL>     SELECT
  2            WG.NAME as Workgroup,
  3            WG.WORKGROUPID,
  4            TP.AREAID,
  5            WGS.Root as RootWorkgroup,
  6            DM.NAME as DeliveryMethod,
  7            D.TASKID,
  8            --D.ISMARKERCOMPLETION,
  9            T.NAME as TaskName,
 10            T.DESCRIPTION as TaskDescription,
 11            T.SHORTNAME,
 12            COALESCE(T.COURSECODE, 'N/A') as CourseCode,
 13            (U.FIRSTNAME || ' ' || U.LASTNAME) as HQOwner,
 14            ((T.DELIVERABLELENGTHHOUR * 60) + T.DELIVERABLELENGTHMINUTE) as TaskMinutes,
 15            TP.STARTDATE, TP.ENDDATE
 16          FROM TPM_TRAININGPLAN TP
 17          INNER JOIN TPM_WORKGROUPS WG ON TP.WORKGROUPID = WG.WORKGROUPID
 18          INNER JOIN TPM_DELIVERYMETHODS DM ON TP.METHODID = DM.METHODID
 19          INNER JOIN TPM_TRAININGPLANDELIVERABLES D ON TP.TRAININGPLANID = D.TRAININGPLANID
 20          INNER JOIN TPM_TASK T ON D.TASKID = T.TASKID
 21          INNER JOIN TPM_PROJECTVERSION V ON (T.PROJECTID = V.PROJECTID AND T.VERSIONID = V.VERSIONID AND V.STAGEID !
= 11 AND V.STAGEID != 12 AND V.STAGEID != 13 AND V.STAGEID != 15)
 22          INNER JOIN TPM_USER U ON V.BUSINESSSPONSOR = U.USERID
 23          INNER JOIN WGS ON WGS.WORKGROUPID = TP.WORKGROUPID
 24          WHERE TP.SCHEDULED=1 AND TP.TRAININGPLANTYPE='actual'
 25          ORDER BY STARTDATE;
        INNER JOIN WGS ON WGS.WORKGROUPID = TP.WORKGROUPID
                   *
ERROR at line 23:
ORA-00942: table or view does not exist

据我所知,错误是WGS不存在。但正如你所看到的,我在第3行创建了这个。

我的睡眠不足而咖啡因不够,所以我做一些愚蠢的事情远远超过了一些奇怪的SQL * Plus解析错误的可能性,但我仍然很好奇为什么这在Aqua中起作用。哦,如果我只运行查询而不是视图创建,我会得到同样的错误。

谢谢!

更新

好吧我觉得我看到了问题。在WITH子句之后,它会启动一个新查询。所以我想我的问题是可以在SQL * Plus中防止这种情况吗?我尝试过做一些事情,比如在WORKGROUPID = PARENTWORKGROUPID之后加一个分号,但这没有用。

2 个答案:

答案 0 :(得分:6)

有一个换行符导致SQL * Plus启动新语句。删除第7行后的换行符,它应该没问题

答案 1 :(得分:2)

你需要告诉SQL * Plus它应该允许带有

的空行
SQL> set sqlblanklines on

一切都会正常。