DATE
?VARCHAR2
?我收到了一个错误:
ORA-06550:第8行,第60栏:
PLS-00201:标识符'N'必须声明为
ORA-06550:第8行,第19栏:
PL / SQL:项目被忽略
06550. 00000 - “行%s,列%s:\ n%s”
*原因:通常是PL / SQL编译错误。
我的代码是:
SET SERVEROUTPUT ON; --for Oracle SQL Developer working
DECLARE
--declaring variables for input datas
vegzams_number EXAM.egzams_number%TYPE := &input_number_of_egzam;
vid_student EXAM.ID_STUDENT%TYPE := &input_id_student;
vid_subject EXAM.id_subject%TYPE := &input_id_subject;
vid_teacher EXAM.id_teacher%TYPE := &input_id_teacher;
vid_place_of_exam EXAM.id_place_of_exam%TYPE := &input_id_place_of_exam;
--PROBLEM HERE WITH THIS TWO VARIABLES
vexams_date EXAM.exams_date%TYPE := TO_DATE(&input_date_of_egzam);
vgot_a_mark EXAM.got_a_mark%TYPE := TO_CHAR(&input_good_mark_T_of_bad_N);
--end declaring variables for input datas
Command_text VARCHAR2(200); --for INSERT INTO EXAM command
exams_rec EXAM%rowtype; --declaring table
--cursor declaration
CURSOR c_exams IS SELECT egzams_number, ID_STUDENT, id_subject,
id_teacher, exams_date, id_place_of_exam, got_a_mark FROM EXAM;
--procedure declaration
PROCEDURE Insert_row(pegzams_number IN number,
pId_student IN number,
pid_subject IN number,
pid_teacher IN number,
pexams_date IN DATE,
Pid_place_of_exam IN number,
Pgood IN varchar2)IS
BEGIN
Command_text := 'INSERT INTO EXAM VALUES (:v1, :v2, :v3, :v4, :v5, :v6, :v7)';
EXECUTE IMMEDIATE Command_text USING pegzams_number, pId_student, pid_subject,
pid_teacher, pexams_date, Pid_place_of_exam, Pgood;
COMMIT;
END;
--procedure end
BEGIN --main begin
OPEN c_exams;
FETCH c_exams INTO exams_rec;
Dbms_output.put_line('Date: ' ||exams_rec.exams_date);
CLOSE c_exams;
END;
答案 0 :(得分:2)
使用替换变量时,需要将字符串值(但不是数字)括在引号中:
vexams_date EXAM.exams_date%TYPE := TO_DATE('&input_date_of_egzam');
不引用您提供的任何值被解释为标识符,并且没有具有该名称的表/列/局部变量。对于某些日期格式,您也会看到计算错误,因为它们看起来像数字表达式(例如,03/11/2014,是0.000135 ...,这不是{{1的有效参数无论是,还是03/11月。
如果你转动to_date
,你可以看到它试图解释的前后值;从你看来提供set verify on
的错误作为日期值,无论如何都会失败......大概是数据录入或定义错误。
您还应该指定您期望的格式模型,而不是依赖于当前的NLS_DATE_FORMAT。
如果您的下一个变量应该是字符串,那么您不需要'N'
,只需要引号;
to_char