懂Oracle的SQL语句的请帮忙:(100分)

  • 主题发起人 主题发起人 wukw
  • 开始时间 开始时间
W

wukw

Unregistered / Unconfirmed
GUEST, unregistred user!
懂Oracle的SQL语句的请帮忙:

INSERT INTO DAILY_TB2(FD, SDD, FOD, WV, TH) SELECT FD, SDD, FOD, WV, TH FROM DAILY_TB3
WHERE
DAILY_TB2.STA_ID=DAILY_TB3.STA_ID AND
DAILY_TB2.YEAR=DAILY_TB3.YEAR AND
DAILY_TB2.MONTH=DAILY_TB3.MONTH AND
DAILY_TB2.DAY=DAILY_TB3.DAY

提示说:无效列名
但是我觉得列名肯定没错,估计是语句本身写的有问题,帮忙:)
 
语句应该没问题 会不会是表的原因??
 
insert into table1(col1,col2) Select b.col1,b.col2 from table1 a,table2 b where a.col1=b.col2;

INSERT INTO DAILY_TB2(FD, SDD, FOD, WV, TH) SELECT a.FD, a.SDD, a.FOD, a.WV, a.TH FROM DAILY_TB3 a,DAILY_TB2 b
WHERE
b.STA_ID=a.STA_ID AND
b.YEAR=a.YEAR AND
b.MONTH=a.MONTH AND
b.DAY=a.DAY
 
SELECT FD, SDD, FOD, WV, TH FROM DAILY_TB3
WHERE
DAILY_TB2.STA_ID=DAILY_TB3.STA_ID AND
DAILY_TB2.YEAR=DAILY_TB3.YEAR AND
DAILY_TB2.MONTH=DAILY_TB3.MONTH AND
DAILY_TB2.DAY=DAILY_TB3.DAY
先把这句单独执行,没错再说吧
 
啊不好意思,原来yzhshi已经给出正确的方案,没仔细看啊,
 
to yzhshi
多谢大哥,你的方法好像可以哦!
只是小弟不理解,这样为什么不行??
INSERT INTO DAILY_TB2(FD, SDD, FOD, WV, TH) SELECT DAILY_TB3.FD, DAILY_TB3.SDD, DAILY_TB3.FOD, DAILY_TB3.WV, DAILY_TB3.TH FROM DAILY_TB3 WHERE
DAILY_TB2.STA_ID=DAILY_TB3.STA_ID AND
DAILY_TB2.YEAR=DAILY_TB3.YEAR AND
DAILY_TB2.MONTH=DAILY_TB3.MONTH AND
DAILY_TB2.DAY=DAILY_TB3.DAY
 
to yzhshi

The following error has occurred:
ORA-01400: 无法将NULL 插入 ("DEV"."DAILY_TB2"."STA_ID")

怎么办?我确定daily_tb3不会有sta_id为null的情况。
 
你的DAILY_TB2表中的字段不只是那么几个,所以要插入的纪录必须指定要更改的字段名
 
SELECT DAILY_TB3.FD, DAILY_TB3.SDD, DAILY_TB3.FOD, DAILY_TB3.WV, DAILY_TB3.TH FROM DAILY_TB3 WHERE
DAILY_TB2.STA_ID=DAILY_TB3.STA_ID AND
DAILY_TB2.YEAR=DAILY_TB3.YEAR AND
DAILY_TB2.MONTH=DAILY_TB3.MONTH AND
DAILY_TB2.DAY=DAILY_TB3.DAY
这句先执行后,看结果,没有NULL????
 
接受答案了.
 
后退
顶部