Oracle中表或视图不存在自动创建

布满荆棘的人生 2024-03-27 17:51 105阅读 0赞

文章目录

  • Oracle中表或视图不存在自动创建
      1. 【 表 】不存在自动创建:
      1. 【视图】不存在自动创建:

Oracle中表或视图不存在自动创建

1. 【 表 】不存在自动创建:

  1. declare
  2. tableExist number;
  3. begin
  4. select count(1)
  5. into tableExist
  6. from user_tables
  7. where table_name = upper('CA_CALLBACKDATA');
  8. if tableExist = 0 then
  9. execute immediate 'create table CA_CALLBACKDATA
  10. (
  11. ID VARCHAR2(50) not null,
  12. JSONDATA CLOB,
  13. CREATEDATE DATE,
  14. UPDATEDATE DATE,
  15. UPDATETIMES NUMBER
  16. )';
  17. execute immediate 'comment on table CA_CALLBACKDATA
  18. is ''Ca接口数据回写表''';
  19. execute immediate 'comment on column CA_CALLBACKDATA.ID
  20. is ''主键Id''';
  21. execute immediate 'comment on column CA_CALLBACKDATA.JSONDATA
  22. is ''Ca接口回写的Json数据''';
  23. execute immediate 'comment on column CA_CALLBACKDATA.CREATEDATE
  24. is ''创建时间''';
  25. execute immediate 'comment on column CA_CALLBACKDATA.UPDATEDATE
  26. is ''更新时间''';
  27. execute immediate 'comment on column CA_CALLBACKDATA.UPDATETIMES
  28. is ''更新的次数''';
  29. execute immediate 'alter table CA_CALLBACKDATA
  30. add constraint PK_CA_CALLBACKDATA_ID primary key (ID)';
  31. end if;
  32. end;

2. 【视图】不存在自动创建:

  1. declare viewExist number;
  2. begin
  3. select count(1) into viewExist from user_views where VIEW_NAME='REPORT_APPOINTMENTSBYLOCATORS';
  4. if viewExist=0 then
  5. execute immediate
  6. 'CREATE VIEW REPORT_APPOINTMENTSBYLOCATORS
  7. AS
  8. SELECT appointmentID, startDateTime, endDateTime, grid, locator,
  9. meetingAddress, contactNumber, company, contact, reasonForAppointment,
  10. DtFirstCall, DtSecondCall,CustomerAnswerFirstCall, CustomerAnswerSecondCall,
  11. IsMeetOnSite, DtLastModified, AppointmentStatus, IsLocatorArriveOnsite,
  12. DtCompletedAt,DtLocatorArriveOnsite, RescheduledOn, RescheduledAt, IsRescheduled, city
  13. FROM Appointment';
  14. end if;
  15. end;

发表评论

表情:
评论列表 (有 0 条评论,105人围观)

还没有评论,来说两句吧...

相关阅读