我正在尝试在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
--------------------------------------------------------------------------------
我在这里犯的任何错误?
答案 0 :(得分:1)
倒数第二行不应该是
:g_output := :g_output || ' ' || v_prov || ' ' || v_postal;
答案 1 :(得分:1)
Oracle SQL和PL / SQL使用单引号'
来分隔字符串。双引号"
用于表示标识符(表名,列名......)。
用单引号替换所有双引号。
另请注意,SQL * Plus是一个很差的工具,可用作用户界面。除了让用户手动输入两个单引号(“O''Reilly”)之外,没有办法让你的实际代码使用包含引号的名称(“O'Reilly”)。
答案 2 :(得分:0)
SELECT cstreet, ccity, cprov, cpostal
INTO v_address, v_city, v_prov, v_zip
没有声明v_state
。