Oracle数据库自增主键

create table TEAM_MAJOR_WORK
(
  pkid                NUMBER(7) not null,
  team_no            VARCHAR2(16) not null,
  ymonth              VARCHAR2(6) not null,
  iwork_plan             CLOB,
  iwork_desc             CLOB,
  iwork_result        CLOB,
  teamld_evluate      CLOB,
  depld_evluate      CLOB,
  cr_date             DATE default sysdate not null
);



--创建seq
create sequence TWORK_ID_SEQ start with 100000 increment by 1 maxvalue 999999;



--创建触发器
create or replace trigger TR_MAJOR_WORK
  before insert on TEAM_MAJOR_WORK
  for each row
  when (new.pkid is null)
begin
  select TWORK_ID_SEQ.NEXTVAL into:new.pkid from dual;
end;

--查询触发器
select * from all_triggers tr where tr.TRIGGER_NAME='TR_MAJOR_WORK';

数据库JOIN语句使用经验

SQL LEFT JOIN 关键字

LEFT JOIN 关键字会从左表 (table_name1) 那里返回所有的行,即使在右表 (table_name2) 中没有匹配的行。

LEFT JOIN 关键字语法

SELECT column_name(s)
  FROM table_name1
LEFT JOIN table_name2 
  ON table_name1.column_name=table_name2.column_name
一张cheatsheet