2017-07-15 75 views
1
--script2.sql 
--Krishan Billa 
ACCEPT p_make PROMPT 'ENTER MAKE OF THE CAR'; 
ACCEPT p_model PROMPT 'ENTER MODEL OF THE CAR'; 
ACCEPT p_year PROMPT 'ENTER YEAR OF THE CAR'; 
ACCEPT p_color PROMPT 'ENTER COLOR OF THE CAR'; 
VARIABLE g_output VARCHAR2(500); 
DECLARE 
    CURSOR allprospects 
    IS 
    SELECT b.cname, 
     TRIM(b.cstreet), 
     TRIM(b.ccity), 
     TRIM(b.cprov), 
     TRIM(b.cpostal) 
    FROM s9.prospect a 
    INNER JOIN s9.customer b 
    ON(a.cname   =b.cname) 
    WHERE UPPER(a.make)=UPPER('&p_make') 
    AND UPPER(a.model) =UPPER('&p_model') 
    AND a.cyear  ='&p_year' 
    AND UPPER(a.color) =UPPER('&p_color'); 
BEGIN 
    :g_output := '&p_make'||CHR(10); 
    FOR v_prospect IN allprospects LOOP 
    :g_output := :g_output||'test'; 
    --:g_output := :g_output || v_prospect.cname || CHR(10)|| v_prospect.ccity || CHR(10); 
    --:g_output := :g_output || v_prospect.ccity ||','|| v_prospect.cprov || ' ' || v_prospect.cpostal || CHR(10); 
    END LOOP; 
END; 
PRINT g_output; 
--select make,model,cyear,color,count(*)from s9.prospect group by model,make,cyear,color; 
--desc s9.prospect; 
--desc s9.customer; 

--JAGUAR  XL  2016 RED   2 

請在運行此代碼時看到下面的錯誤。它對我來說看起來很好。任何人都可以幫忙嗎? Thankyou
ORA-06550:第24行,第7列: PLS-00103:遇到符號「G_OUTPUT」時遇到下列之一::=。 (@%; 06550. 00000 - 「line%s,column%s:\ n%s」PLS-00103:遇到下列其中一項時遇到符號「G_OUTPUT」::=

+0

順便說一句,你應該添加一些標點符號並在你的提示字符串末尾留出空格,例如''ENTER MAKE OF THE CAR:''否則輸入一個值將看起來像''CARBMW'的製造商' –

回答

1

您錯過了終止符SQLPlus正在查看plsql塊的末尾,因此「print g_output」被包括在發送到PLSQL「編譯」的編譯器不知道如何處理它,並沒有預料到這是錯誤塊嘗試:。

END; 
/
PRINT g_output; 
+0

非常感謝。現在好了! –

相關問題