`

plslq 语句编写规范

 
阅读更多

项目测试过程发现,公司测试无问题,客户测试报错,经过现场分析,发现为plsql中编写批量插入语句,

没有明确指明表的字段导致。

因为客户端数据表的字段顺序和公司数据库表字段顺序不一致导致。

-1400- 位置=,ORA-01400: cannot insert NULL into ("PMSDATA"."TFZ_GRADE_DETAIL_REC_HIS"."SCORE") stpb_id=3901430
原因:公司tfz_grade_detail_rec_his字段的顺序和平安不一致,导致不能插入正确值。
insert into tfz_grade_detail_rec_his
select v_id,
x.grin_id,
x.supply_id,
x.user_id,
x.score,
x.remark,
sysdate
from tfz_grade_user_result x
where x.stpb_id = i_stpb_id
and x.stpr_id = i_stpr_id
and x.bundle_code = i_bundle_code
and x.user_id = v.user_id;


公司

batch_id NUMBER(9) not null,
grin_id NUMBER(9) not null,
supply_id NUMBER(9) not null,
user_id NUMBER(9) not null,
score NUMBER(5,2) not null,
remark VARCHAR2(4000),
cdate DATE default sysdate not null

平安

(
BATCH_ID NUMBER(9) not null,
GRIN_ID NUMBER(9) not null,
SUPPLY_ID NUMBER(9) not null,
USER_ID NUMBER(9) not null,
REMARK VARCHAR2(4000),
SCORE NUMBER(5,2) not null,
CDATE DATE default sysdate not null
)

更改:

insert into tfz_grade_detail_rec_his
(batch_id,grin_id,supply_id,user_id,score,remark,cdate)
select v_id,
x.grin_id,
x.supply_id,
x.user_id,
x.score,
x.remark,
sysdate
from tfz_grade_user_result x
where x.stpb_id = i_stpb_id
and x.stpr_id = i_stpr_id
and x.bundle_code = i_bundle_code
and x.user_id = v.user_id;

指明要插入的表字段,是个好习惯,更规范。

 

深入分析:

导致公司和客户端表字段顺序不一致的原因是tfz_grade_detail_rec_his表之前已经客户数据库中,通过后续ddl更改,导致

表字段两边顺序不一致。因此如果对原始表更改较大,或许先drop掉重新建表会好点。

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics