我已经在Oracle中定义了以下过程:
CREATE OR REPLACE Procedure InsertCliente
(dni IN VARCHAR, nombre IN VARCHAR, apellidos IN VARCHAR, apellido2 IN VARCHAR, direccion IN VARCHAR,
CALLE IN VARCHAR, NUMERO IN NUMBER, PISO IN VARCHAR, CIUDAD IN VARCHAR, CODPOSTAL IN NUMBER,
telefono IN NUMBER, edad IN DATE, email IN VARCHAR)
IS
claveDireccion number;
BEGIN
IF apellido2 is null THEN
INSERT INTO Cliente(DNI,Telefono,Direccion,Email,Edad,Apellidos,Nombre)
VALUES (dni,telefono,direccion,email,TO_DATE(edad,'YYYY-MM-DD'),apellidos,nombre);
ELSE
claveDireccion := (SELECT ID_DIRECCION FROM DIRECCION@SCHEMA2BD2 WHERE ID_DIRECCION=Direccion);
IF claveDireccion is not null THEN
INSERT INTO TITULAR@SCHEMA2BD2(DNI,Nombre,Apellido1, Apellido2, Direccion,Telefono,Fecha_Nacimiento)
VALUES (DNI,Nombre,Apellidos, Apellido2, Direccion,Telefono,TO_DATE(Fecha_Nacimiento,'YYYY-MM-DD'));
ELSE
raise_application_error(-20001, 'La direccion proporcionada no existe');
END IF;
END IF;
END;
/
但是我从Oracle中收到以下错误:
LINE/COL ERROR
-------- -----------------------------------------------------------------
13/22 PLS-00103: Encountered the symbol "SELECT" when expecting one of
the following:
( - + case mod not null others <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current exists max min prior sql stddev sum variance
execute forall merge time timestamp interval date
<a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
13/96 PLS-00103: Encountered the symbol ")" when expecting one of the
following:
LINE/COL ERROR
-------- -----------------------------------------------------------------
. ( * @ % & - + ; / at for mod rem <an exponent (**)> and or
group having intersect minus order start union where connect
||
20/6 PLS-00103: Encountered the symbol "IF" when expecting one of the
following:
; <an identifier> <a double-quoted delimited-identifier>
delete exists prior <a single-quoted SQL string>
我不知道那里发生了什么。它只是被分配给变量的选择语句。有帮助吗?
答案 0 :(得分:2)
使用INTO
:
SELECT ID_DIRECCION INTO claveDireccion
FROM DIRECCION@SCHEMA2BD2
WHERE ID_DIRECCION = Direccion;
逻辑没有道理。为什么不只使用它呢?
claveDireccion := Direccion;
我建议您命名参数,以便与列名区分开来
CREATE OR REPLACE Procedure InsertCliente (
in_dni IN VARCHAR,
in_nombre IN VARCHAR,
in_apellidos IN VARCHAR,
in_apellido2 IN VARCHAR,
in_direccion IN VARCHAR,
in_CALLE IN VARCHAR,
in_NUMERO IN NUMBER,
in_PISO IN VARCHAR,
in_CIUDAD IN VARCHAR,
in_CODPOSTAL IN NUMBER,
in_telefono IN NUMBER,
in_edad IN DATE,
in_email IN VARCHAR
) IS
p_claveDireccion number;
BEGIN
. . .
END;
这有助于防止存储过程的主体出现问题。