0

好吧,我正在尝试在 PL/SQL 中运行此脚本。但是我经常遇到错误,我尝试用双引号替换单引号但没有用。

ACCEPT p_name PROMPT "Enter Customer Name: "
VARIABLE g_output VARCHAR2(200)
DECLARE
   v_street VARCHAR2(30);
   v_city VARCHAR2(20);
   v_prov VARCHAR2(20);
   v_postal VARCHAR2(10);
BEGIN
   SELECT cstreet, ccity, cprov, cpostal
     INTO v_address,v_city,v_state,v_zip
     FROM customer
    WHERE cname = "&p_name";
   :g_output := "&p_name" || " " ||v_street || " " || v_city;
   :g_output := :g_output " " || v_prov || " " || v_postal;
END;
/
PRINT g_output

错误:

Enter Customer Name: Ankur Kaushal
old  10:     WHERE cname = "&p_name";
new  10:     WHERE cname = "Ankur Kaushal";
old  11:    :g_output := "&p_name" || " " ||v_street || " " || v_city;
new  11:    :g_output := "Ankur Kaushal" || " " ||v_street || " " || v_city;
   :g_output := :g_output " " || v_prov || " " || v_postal;
                          *
ERROR at line 12:
ORA-06550: line 12, column 27:
PLS-00103: Encountered the symbol " " when expecting one of the following:
. ( * @ % & = - + ; < / > at in is mod remainder not rem
<an exponent (**)> <> or != or ~= >= <= <> and or like
between || indicator multiset member SUBMULTISET_
The symbol "." was substituted for " " to continue.


Input truncated to 14 characters

G_OUTPUT
--------------------------------------------------------------------------------

我在这里犯了什么错误?

4

3 回答 3

1

倒数第二行不应该是

  :g_output := :g_output || ' ' || v_prov || ' ' || v_postal; 

?

于 2012-07-10T12:28:21.880 回答
1

Oracle SQL 和 PL/SQL 使用单引号'来分隔字符串。双引号"用于表示标识符(表名、列名...)。

用单引号替换所有双引号。

另请注意,SQL*Plus 用作用户界面的工具很差。除了让用户手动输入两个单引号(“O''Reilly”)之外,没有办法让您的实际代码使用包含引号(“O'Reilly”)的名称。

于 2012-07-10T12:38:31.707 回答
0
 SELECT cstreet, ccity, cprov, cpostal
 INTO v_address, v_city, v_prov, v_zip

没有声明v_state.

于 2014-03-19T09:29:08.297 回答