日期:2014-05-17  浏览次数:21168 次

oracle中date类型怎么插值。。
SQL code

触发器创建不成功啊。。问题出在那个date字段。。搞不明白。

-- 创建 "SDD"."EMP" 表
CREATE TABLE "SDD"."EMP"
(
  "EMPNO" NUMBER(4,0),
  "ENAME" VARCHAR2(10),
  "JOB" VARCHAR2(9),
  "MGR" NUMBER(4,0),
  "HIREDATE" DATE,
  "SAL" NUMBER(7,2),
  "COMM" NUMBER(7,2),
  "DEPTNO" NUMBER(2,0),
  CONSTRAINT "PK_EMP" PRIMARY KEY ("EMPNO")
)TABLESPACE "SDD";

create or replace procedure pro_insert_tab_emp(empno number, ename varchar2,
job varchar2, mgr number, hiredate varchar2,
 sal number, comm number, deptno number)
as
begin
  insert into emp(empno, ename, job, mgr, hiredate, sal, comm, deptno) 
  values(empno, ename, job, mgr, to_date(hirdate,'yyyy-mm-dd'), sal, comm, deptno);
  dbms_output.put_line('insert a record');
end;

---
select object_name, status from  user_objects where lower(object_name)='pro_insert_tab_emp';

显示status字段为invalid啊。。求教。







------解决方案--------------------
create or replace procedure pro_insert_tab_emp(empno number, ename varchar2,
job varchar2, mgr number, hiredate varchar2,
 sal number, comm number, deptno number)
as
begin
insert into emp(empno, ename, job, mgr, hiredate, sal, comm, deptno) 
values(empno, ename, job, mgr, to_date(hirdate,'yyyy-mm-dd'), sal, comm, deptno);
dbms_output.put_line('insert a record');
end;


hiredate varchar2,变量名和字段名重复,建议传递进来的变量加v_hiredate
create or replace procedure pro_insert_tab_emp(empno number, ename varchar2,
job varchar2, mgr number, v_hiredatevarchar2,
 sal number, comm number, deptno number)
as
begin
insert into emp(empno, ename, job, mgr, hiredate, sal, comm, deptno) 
values(empno, ename, job, mgr, to_date(v_hiredate,'yyyy-mm-dd'), sal, comm, deptno);
dbms_output.put_line('insert a record');
end;
------解决方案--------------------
所有的输入参数名字都要改成和表emp字段不同,比如V_XXX这样就很清楚!
还有你得check下你的数据库默认的日期格式,按照默认格式确定'yyyy-mm-dd'还是'DD-MON-RR'之类的格式!