/*

ORA-01400: 无法将 NULL 插入 ("JXKH"."SYS_MENU"."MENU_ID")

解决:
为该表加上序列和触发器

-- 菜单
CREATE TABLE sys_menu (
  menu_id NUMBER(20, 0) NOT NULL,
  parent_id NUMBER(20, 0) NOT NULL,
  name varchar2(50),
  url varchar2(200),
  perms varchar2(500),
  type NUMBER(2, 0),
  icon varchar2(50),
  order_num NUMBER(8, 0),
  PRIMARY KEY (menu_id)
);
-- Create sequence
create sequence SYS_MENU_SEQ
minvalue 1    -- 最小值=1
maxvalue 999999999999999999999999999  -- 指定最大值
-- 或nomaxvalue      -- 没有最大值
-- NOCYCLE;      -- 不循环
start with 1   -- 从1开始
increment by 1  -- 每次递增1
cache 20;

--触发器
create or replace trigger SYS_MENU_TRI
  before insert on SYS_MENU
REFERENCING OLD AS "OLD" NEW AS "NEW" FOR EACH ROW
begin
    SELECT SYS_MENU_SEQ.NEXTVAL INTO :NEW.menu_id FROM DUAL;
end;
posted @ 2020-06-12 17:11  Enthusiast  阅读(900)  评论(0编辑  收藏  举报