2016-12-29 114 views
-7

我工作的一個PLSQL腳本,但有一個錯誤 - 我不知道什麼是錯的做;(PLSQL:ORA-00933爲什麼INTO無法正常工作?

林爲這個愚蠢的問題很抱歉,但我真的不知道該解決方案 燦有人幫助我

這是我的代碼:??

DECLARE 
    tagnow webtags_20161221.editionid%TYPE; 
BEGIN 
    select editionid from webtags w, edition e 
    into tagnow *the word into is red underlined* 
    where editionid in (
    select editionid from (
    select editionid, tag, count(*) from webtags 
    group by editionid, tag 
    having count(*) > 1)) 
    and editionid = editionid 
    order by createdat desc; 

    DBMS_OUTPUT.put_line (
    tagnow); 
END; 

爲什麼沒有工作的錯誤是:

ORA-06550: Line 5, Column 3: 
PL/SQL: ORA-00933 
ORA-06550: Line 4, Column 3: 
PL/SQL: SQL Statement ignored 
06550. 00000 - "line %s, column %s:\n%s" 
*Cause: Usually a PL/SQL compilation error. 
*Action: 

請幫助我,我是初學者。

+1

「SELECT - INTO - FROM - etc ..」是正確的順序 – Thomas

+0

@Thomas非常感謝你!我錯了。 – Squareoot

+3

[因爲這不是正確的語法](http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/selectinto_statement.htm#CJADDIHJ)。 –

回答

2

INTO就在SELECT之後,FROM之前。

select e.editionid 
into tagnow 
from webtags w, edition e 

另外,儘量去學習,而不是使用這個老甲骨文路標準ANSI JOIN,並且在使用中joiur連接條件別名注意。 您的查詢就會變成:

SELECT e.editionid 
    INTO tagnow 
    FROM webtags w 
    INNER JOIN edition e 
    ON (w.editionid = e.editionid) 
WHERE e.editionid IN (...); 

的另一種方式,其中別名可能不是絕對必要的(但它是一個很好的做法但是使用它們):

SELECT editionid 
    INTO tagnow 
    FROM webtags w 
    INNER JOIN edition e 
    USING (editionid) 
WHERE editionid IN (...); 

而且,你不需要雙重嵌套查詢;你可以使用:

SELECT editionid 
FROM webtags 
GROUP BY editionid, tag 
HAVING COUNT(*) > 1 
+2

第二個看起來也錯了,你不應該注意使用別名? –

+1

還有一個沒有別名的editionid –

+1

太不留神了!謝謝 – Aleksej