0

我将 SQL*Plus 与 Oracle8i 企业版 8.1.7.4.0 一起使用。

我有一张桌子customer_address

no - customer number

type - 0 main, 1 delivery, 2 invoice

email - customer e-mail address

每个客户都有一个设置为类型 0 的电子邮件地址,例如:

SELECT no, type, email FROM customer_address WHERE cunu = '1';

1,0,customer@domain.com

我需要将每个客户的电子邮件地址从类型 0 复制到类型 1?

当我进行这样的测试时,INSERT INTO customer_address (no, type, email) VALUES ('1','1','test@domain.com');我会看到如下错误消息:

ORA-01400: cannot insert NULL into

有人可以提供一个正确的例子吗?

4

3 回答 3

0

如果您以正确的顺序包含所有字段,您还可以避免在表名之后指定它们

INSERT INTO customer_address
     SELECT no,
            '1',
            email, 
            otherfields
       FORM customer_address
      WHERE cunu ='1'
        AND type='0'
于 2013-10-29T13:54:56.220 回答
0

您收到错误消息,因为您没有填写所有非空列。表中必须至少有一列不可为空且没有默认值。

insert into customer_address (no, type, email, notnullcol1, notnullcol2)
  select no, 1 as type, email, notnullcol1, notnullcol2
  from customer_address
  where type = 0
;
于 2013-10-29T14:20:18.647 回答
0

也许是这样的?

insert into customer_address
   (no,type,email, primarykeyfieldofthetable, otherfields)
select
   no,'1',email, sequenceofprimarykey.nextval, otherfields
from
  customer_address
where type='0'
于 2013-10-29T13:49:15.537 回答