我在Oracle中遇到此代码的问题:
create or replace procedure InsertarEntertNotica (IDSUBTOPIC out varchar,
TEXT out varchar,IMAGE out varchar,STADE out varchar,TITT out varchar)
is
idS varchar2(3) := IDSUBTOPIC;
txt varchar2(4000) := TEXT;
img varchar2(100) := IMAGE;
st varchar2(2) := STADE;
fech varchar2(30);
tit varchar2(300) := TITT;
hor date;
begin
SELECT TO_CHAR(SYSDATE,'DD/MM/YY') into fech FROM DUAL;
SELECT SYSDATE into hor FROM DUAL;
insert into ENTERTAIMENT (IDSUBTEMA,TEXTO,IMAGEN,ESTADO,FECHA,TITULO,HORA)
values (idS,txt,img,st,fech,tit,hor);
end;
当我创建这个SP时,我没有问题,但是当我执行它时,我遇到了这个问题
Error starting at line : 377 in command -
execute InsertarEntertNotica('ET','Texto de la Noticia Proc','','No','Noticia con Procedimiento')
Error report -
ORA-06550: line 1, column 28:
PLS-00363: expression 'ET' cannot be used as an assignment target
ORA-06550: line 1, column 33:
PLS-00363: expression 'Texto de la Noticia Proc' cannot be used as an assignment target
ORA-06550: line 1, column 60:
PLS-00363: expression '<null>' cannot be used as an assignment target
ORA-06550: line 1, column 63:
PLS-00363: expression 'No' cannot be used as an assignment target
ORA-06550: line 1, column 68:
PLS-00363: expression 'Noticia con Procedimiento' cannot be used as an assignment target
ORA-06550: line 1, column 7:
答案 0 :(得分:0)
您已将所有形式参数声明为OUT
,这意味着在调用过程时必须传递可更新变量,而不是固定字符串值。 The documentation shows how IN/OUT
works.
您只需将其更改为IN
即可。您也不需要任何局部变量:
create or replace procedure InsertarEntertNotica (IDSUBTOPIC in varchar,
TEXT in varchar,IMAGE in varchar,STADE in varchar,TITT in varchar)
is
begin
insert into ENTERTAIMENT (IDSUBTEMA, TEXTO, IMAGEN, ESTADO, FECHA, TITULO, HORA)
values (IDSUBTOPIC, TEXT, IMAGE, STADE, TO_CHAR(SYSDATE,'DD/MM/YY'),
TITT, SYSDATE);
end;
如果您要使用局部变量,那么区别于参数名称的名称就会很好。通常使用前缀来区分,例如, p_text
表示参数,l_text
表示局部变量。
由于几个原因,使用TO_CHAR(SYSDATE,'DD/MM/YY')
看起来不对。两位数的年份可能导致意想不到的结果,以及臭名昭着的Y2K问题。如果FECHA
是DATE列而不是VARCHAR2(8),那么您将使用会话NLS设置隐式地将该字符串转换回日期 - 这很危险,并且只有在会话发生也是DD / MM / YY。如果您真的想将今天的日期与午夜时间存储在一起,那么您应该使用TRUNC(SYSDATE)
代替。虽然不确定为什么要将它作为单独的列存储到HORA
。