【问题标题】:how to insert records from one table to another selecting only the common columns如何仅选择公共列将记录从一个表插入到另一个表
【发布时间】:2015-06-04 11:41:38
【问题描述】:

我想用公共列将记录从一个表插入另一个表

desc fp_mast        null?     type

emp_id              not null  varchar2(4) 
emp_nm              not null  varchar2(35) 
typ                 not null  varchar2(1) 
flag                not null  varchar2(1) 
st_dt               not null  DATE 
end_dt                        DATE
wk_dt               not null  DATE 

desc emp_mast 为空?输入

emp_id              not null  varchar2(4) 
emp_nm              not null  varchar2(35) 
grd_cd              not null  varchar2(3) 
desg_cd             not null  varchar2(2) 
cost_sl             not null  varchar2(2)                 
flag                not null  varchar2(1) 
join_dt             not null  DATE 
resig_dt                      DATE
wk_dt               not null  DATE

我试过这个查询来插入记录,但没有用

insert into fp_mast(emp_id,emp_nm,st_dt,end_dt,wk_dt)
select(emp_no,emp_nm,join_dt,resig_dt,wk_dt)
from emp_mast
where emp_id in ('7996','7942','5251','7999','8249','6464','8220',
'8221')

它一直显示以下错误

缺少右括号

谢谢。

【问题讨论】:

    标签: sql oracle select


    【解决方案1】:

    缺少右括号

    因为您在 SELECT 语句中有语法错误。

    改变这个:

    select(emp_no,emp_nm,join_dt,resig_dt,wk_dt)
    

    到这里:

    select emp_no,emp_nm,join_dt,resig_dt,wk_dt
    

    选择列表中的列名不需要括号。我认为您对 VALUES 关键字的使用方式感到困惑。

    【讨论】:

    • 我更改了查询并删除了括号,现在它向我显示了这个错误 SQL> insert into fp_mast(EMP_ID,EMP_NM,ST_DT,END_DT,WK_DT) 2 select EMP_ID,emp_nm,join_dt,resig_dt,wk_dt 3 from emp_mast 4 where emp_id in ('7996','7942','5251','7999','8249','6464', 5 '8220','8221','8220','7106','7220','7187','8183','7423', 6 '8192','8184','8219','8070','8120','8053' 7 ,'8033','8154') 8 / insert into fp_mast(EMP_ID,EMP_NM,ST_DT,END_DT,WK_DT) * ERROR at line 1: ORA- 01400: 无法将 NULL 插入 ("AGROVET"."FP_MAST"."TYP") `SQL>
    • 提到的列 ("AGROVET"."FP_MAST"."TYP"),必须对它们没有空约束,并且由于您没有向其中插入任何内容,因此会出现此错误。
    猜你喜欢
    • 2012-01-23
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-01
    • 2016-01-17
    • 1970-01-01
    相关资源
    最近更新 更多