ora-01400 无法将NULL插入 ID 解决方法

问题描述:由于工作原因,把部分 字段改了,大体这样

1 StatementCallback; uncategorized SQLException for SQL
2  [insert into test(schoolId,classId,teacherId,weekId,serialno,name) values(28529,23402,328717,7,8,'')]; 
3  SQL state [null]; error code [17081]; 批处理中出现错误: ORA-01400: 无法将 NULL 插入 ("XXX"."test"."ID")
4 ; nested exception is java.sql.BatchUpdateException: 批处理中出现错误: ORA-01400: 无法将 NULL 插入 ("ORAL"."test"."ID")
5  -(:71)

 

这个问题很多时候是没有为该表建立触发器导致的,或者是sequence没建立,或者是trigger没建立。

建立其中一个或两个即可。

这是建立sequence

 1 create sequence TEST_SEQ
 2 
 3 minvalue 1
 4 
 5 maxvalue 999999999999999999999999999
 6 
 7 start with 1
 8 
 9 increment by 1
10 
11 cache 20;

 

这是建立trigger的

 CREATE OR REPLACE TRIGGER " TEST_TRI" BEFORE

        INSERT ON TEST

        FOR EACH ROW       

BEGIN

          SELECT test_seq.NEXTVAL INTO :NEW.ID FROM DUAL;

        END;

 

转载于:https://www.cnblogs.com/newlooker/p/3631177.html

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Cause: java.sql.SQLIntegrityConstraintViolationException: ORA-01400: 无法NULL 插入是指在向数据库插入数据时,违反了非空约束,即将 NULL插入了不允许为空的列中。 这通常发生在插入或更新数据时,对某个列进行了赋值为 NULL 的操作,而该列在数据库中被定义为不允许为空。这样的操作会触发数据库引发 SQLIntegrityConstraintViolationException 异常。这个异常信息中包含了具体的错误信息 ORA-01400。在这种情况下,你需要检查你的代码或者数据库表结构,确保在插入数据时不会将 NULL 值赋值给不允许为空的列。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [java.sql.SQLIntegrityConstraintViolationException](https://blog.csdn.net/zhao2chen3/article/details/122875564)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [Cause: java.sql.SQLIntegrityConstraintViolationException: Column ‘businessName‘ cannot be null](https://blog.csdn.net/Silly011/article/details/119580160)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Caused by: java.sql.SQLIntegrityConstraintViolationException: Cannot delete or update a parent row:](https://download.csdn.net/download/weixin_38500572/13684759)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值