db2 SQL3116W行和列中的字段值缺失,但目标列不可空如何指定使用列默认值

hsgswve4  于 2022-11-07  发布在  DB2
关注(0)|答案(2)|浏览(143)

我正在使用LOAD命令将数据放入一个表中,其中一列的默认值为当前时间戳。我在读取的数据中有NULL值,因为我认为这会导致表使用默认值,但根据上面的错误,情况并非如此。在这种情况下,我如何避免上面的错误?以下是完整的命令,输入文件是文本文件:从${LOADDIR}/${InputFile}.exp加载由COLDEL修改的DEL|插入到TEMP_TABLE中不可恢复

xdyibdwo

xdyibdwo1#

请尝试:

LOAD FROM ${LOADDIR}/${InputFile}.exp OF DEL MODIFIED BY USEDEFAULTS COLDEL| INSERT INTO TEMP_TABLE NONRECOVERABLE

自V7.x以来,只要Db2-LUW得到全面服务(即,正确应用了最终的修复包),就可以在Db2-LUW中使用此修改符usedefaults
请注意,某些Db2-LUW版本对usedefaults修饰符的使用有限制,如文档中所述。例如,与其他修饰符、模式或目标表类型一起使用的限制。
在请求帮助时,请始终指定您的Db2服务器版本和平台,因为答案可能取决于这些事实。

huwehgph

huwehgph2#

您可以使用METHOD P指定输入文件中的哪些列进入表中的哪些列-如果您省略了需要使用默认值的列,则会引发警告,但会填充默认值:

$ db2 "create table testtab1 (cola int, colb int, colc timestamp not null default)"
DB20000I  The SQL command completed successfully.
$ cat tt1.del
1,1,1
2,2,2
3,3,99
$ db2 "load from tt1.del of del method P(1,2) insert into testtab1 (cola, colb)"
SQL27967W  The COPY NO recoverability parameter of the Load has been converted
to NONRECOVERABLE within the HADR environment.

SQL3109N  The utility is beginning to load data from file
"/home/db2inst1/tt1.del".

SQL3500W  The utility is beginning the "LOAD" phase at time "07/12/2021
10:14:04.362385".

SQL3112W  There are fewer input file columns specified than database columns.

SQL3519W  Begin Load Consistency Point. Input record count = "0".

SQL3520W  Load Consistency Point was successful.

SQL3110N  The utility has completed processing.  "3" rows were read from the
input file.

SQL3519W  Begin Load Consistency Point. Input record count = "3".

SQL3520W  Load Consistency Point was successful.

SQL3515W  The utility has finished the "LOAD" phase at time "07/12/2021
10:14:04.496670".

Number of rows read         = 3
Number of rows skipped      = 0
Number of rows loaded       = 3
Number of rows rejected     = 0
Number of rows deleted      = 0
Number of rows committed    = 3

$ db2 "select * from testtab1"

COLA        COLB        COLC
----------- ----------- --------------------------
          1           1 2021-12-07-10.14.04.244232
          2           2 2021-12-07-10.14.04.244232
          3           3 2021-12-07-10.14.04.244232

  3 record(s) selected.

相关问题