init.sql 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. --指标基础信息表
  2. CREATE TABLE ETA_API_QUOTA_INFO
  3. (
  4. quote_id NUMBER NOT NULL,
  5. edb_info_id NUMBER NOT NULL,
  6. edb_code VARCHAR2(200) NOT NULL, -- 假设最大长度为255,可根据实际需求调整
  7. edb_name VARCHAR2(255) NOT NULL,
  8. UNIQUE_CODE VARCHAR2(60) NOT NULL,-- 假设最大长度为255,可根据实际需求调整
  9. unit VARCHAR2(100) NOT NULL, -- 假设最大长度为100,可根据实际需求调整
  10. frequency VARCHAR2(30) NOT NULL, -- 假设最大长度为50,可根据实际需求调整
  11. start_date DATE NOT NULL,
  12. end_date DATE NOT NULL,
  13. last_date DATE NOT NULL,
  14. classify_id NUMBER NOT NULL,
  15. source NUMBER(10) NOT NULL,
  16. source_name VARCHAR2(120) NOT NULL, -- 假设最大长度为255,可根据实际需求调整
  17. no_update NUMBER(1) DEFAULT 0 NOT NULL, -- 假设为布尔值,用数字1表示是,0表示否
  18. is_delete NUMBER(1) DEFAULT 0 NOT NULL, -- 假设为布尔值,用数字1表示是,0表示否
  19. is_quality NUMBER(1) DEFAULT 0 NOT NULL, -- 假设为布尔值,用数字1表示是,0表示否
  20. data_create_time NUMBER DEFAULT 0, -- 如果是时间戳,需指定精度;若为日期类型,请改为 DATE
  21. data_update_time NUMBER DEFAULT 0, -- 如果是时间戳,需指定精度;若为日期类型,请改为 DATE
  22. ht_unique_code VARCHAR2(255), -- 假设最大长度为255,可根据实际需求调整
  23. CONSTRAINT ETA_API_QUOTA_INFO_PK PRIMARY KEY (quote_id)
  24. );
  25. CREATE SEQUENCE seq_eta_api_quota_info
  26. START WITH 1
  27. INCREMENT BY 1
  28. NOMAXVALUE;
  29. CREATE OR REPLACE TRIGGER trg_eta_api_quota_info_insert
  30. BEFORE INSERT ON eta_api_quota_info
  31. FOR EACH ROW
  32. BEGIN
  33. SELECT seq_eta_api_quota_info.NEXTVAL INTO :new.quota_id FROM dual;
  34. END;
  35. /
  36. CREATE INDEX ETA_API_QUOTA_UNIQUE_CODE ON ETA_API_QUOTA_INFO ("UNIQUE_CODE", "LATEST_DATE")
  37. --指标明细数据表
  38. CREATE TABLE ETA_API_QUOTA_DATA
  39. (
  40. data_id NUMBER NOT NULL,
  41. unique_code VARCHAR2(60) NOT NULL,
  42. value NUMBER NOT NULL, -- 假设最大长度为255,可根据实际需求调整
  43. data_time DATE NOT NULL,
  44. update_time TIMESTAMP (6) NOT NULL,
  45. is_delete NUMBER(1) DEFAULT 0 NOT NULL, -- 假设为布尔值,用数字1表示是,0表示否
  46. is_quality NUMBER(1) DEFAULT 0 NOT NULL, -- 假设为布尔值,用数字1表示是,0表示否
  47. data_create_time NUMBER, -- 如果是时间戳,需指定精度;若为日期类型,请改为 DATE
  48. data_update_time NUMBER, -- 如果是时间戳,需指定精度;若为日期类型,请改为 DATE
  49. ht_unique_code VARCHAR2(255) ,
  50. CONSTRAINT ETA_API_QUOTA_DATA_PK PRIMARY KEY (data_id),
  51. );
  52. CREATE SEQUENCE seq_eta_api_quota_data
  53. START WITH 1
  54. INCREMENT BY 1
  55. NOMAXVALUE;
  56. CREATE OR REPLACE TRIGGER trg_eta_api_quota_data_insert
  57. BEFORE INSERT ON eta_api_quota_data
  58. FOR EACH ROW
  59. BEGIN
  60. SELECT seq_eta_api_quota_data.NEXTVAL INTO :new.data_id FROM dual;
  61. END;
  62. /
  63. CREATE UNIQUE INDEX ETA_API_DATA_UNIQUE_CODE ON ETA_API_QUOTA_DATA ("UNIQUE_CODE", "DATA_TIME", "IS_DELETE")
  64. CREATE INDEX IDX_UNIQUE_CODE_DATA_TIME ON ETA_API_QUOTA_DATA ("UNIQUE_CODE", "DATA_TIME" DESC)
  65. CREATE INDEX ETA_API_DATA_UNIQUE_CODE_INDEX ON ETA_API_QUOTA_DATA ("UNIQUE_CODE")
  66. /*
  67. * 辅助表,用于建立指标与指标分类之间的映射关系
  68. */
  69. CREATE SEQUENCE SEQ_ETA_CLASSIFY_INDEX_MAPPING
  70. START WITH 1
  71. INCREMENT BY 1
  72. NOMAXVALUE;
  73. CREATE OR REPLACE TRIGGER trg_SEQ_ETA_CLASSIFY_insert
  74. BEFORE INSERT ON t_eta_CLASSIFY_INDEX_MAPPINGr
  75. FOR EACH ROW
  76. BEGIN
  77. SELECT SEQ_ETA_CLASSIFY_INDEX_MAPPING.NEXTVAL INTO :new.id FROM dual;
  78. END;
  79. /**
  80. 修改已更新的指标的频度单位
  81. */
  82. select * from T_DAMP_DW_INDEX where INDEX_CODE in (
  83. select INDEX_CODE from T_DAMP_DW_INDEX_LINK where LINK_CODE like 'ETA%') and FREQUENCY like '%度'
  84. UPDATE T_DAMP_DW_INDEX
  85. SET FREQUENCY = REPLACE(FREQUENCY, '度', '')
  86. WHERE INDEX_CODE IN (
  87. SELECT INDEX_CODE
  88. FROM T_DAMP_DW_INDEX_LINK
  89. WHERE LINK_CODE LIKE 'ETA%'
  90. )
  91. AND FREQUENCY LIKE '%度%';