orale 创建表

来源:互联网 发布:unity3d ios 录屏处理 编辑:程序博客网 时间:2024/04/29 22:21
declare  tm_i integer;       begin  select count(*) into tm_i from user_tables where lower(table_name)=lower('表名');    if tm_i>0 then      execute immediate 'drop table  表名 ';      end if;end;/-- Create tablecreate table 表名(  I_SERIAL_NO      NUMBER(22) not null,  I_INST_NO        NUMBER(22) not null,  i_DATE           NUMBER(8) not null,  VC_STOCKHOLDER   VARCHAR2(12)  default ' ' not null,  I_FUND_ACCOUNT   NUMBER(22) not null,  VC_EXCHANGE      VARCHAR2(20) not null,   VC_SEAT          VARCHAR2(20) not null,  VC_STORAGE_KEY1  VARCHAR2(20) not null,  VC_STORAGE_KEY2  VARCHAR2(20) not null,  VC_STORAGE_KEY3  VARCHAR2(20) not null,  VC_STOCK_CODE     VARCHAR2(8) not null,  EN_VIRTUAL_AMOUNT NUMBER(22,2) default 0 not null);-- Create/Recreate primary, unique and foreign key constraints alter table 表名  add constraint PK_表名  primary key (I_SERIAL_NO);    -- Create sequence declare  tm_i integer;  begin  select count(*) into tm_i from User_Objects t where Lower(t.OBJECT_NAME) = Lower('SEQ_表名') And Lower(t.OBJECT_TYPE) = Lower('Sequence');    if tm_i=0 then      execute immediate 'create sequence SEQ_表名  minvalue 1 maxvalue 999999999999999999999999999 start with 1 increment by 1 cache 2';      end if;  end;/CREATE OR REPLACE TRIGGER TRIG_表名_IDBEFORE INSERT ON 表名FOR EACH ROWBEGINSelect SEQ_表名 .NEXTVAL INTO :NEW.i_serial_noFROM DUAL;END;

0 0
原创粉丝点击