__IF_EXISTS__
SELECT 1
  FROM CI_UT_INSTL_DTL
WHERE SCRIPT_FILE_NAME = 'FW45010_POSTDATA_UGBUPD-11209.SQL'
   AND END_DTTM IS NOT NULL
/
__THEN__
__EXIT__
__ENDIF__

INSERT INTO CI_MD_IDX(IDX_CD,TBL_NAME,UNIQUE_SW,OWNER_FLG,VERSION)  
SELECT A.INDEX_NAME,A.TABLE_NAME,(CASE WHEN A.UNIQUENESS = 'UNIQUE' then 'Y' ELSE 'N' END),B.OWNER_FLG, 1
FROM USER_INDEXES A, CI_MD_TBL B
where (UPPER(A.INDEX_NAME) not like 'SYS%' and UPPER(A.INDEX_NAME) not LIKE 'ZZ%' AND UPPER(A.INDEX_NAME) not like 'CM%')
AND RTRIM(A.TABLE_NAME) = RTRIM(B.TBL_NAME)
AND B.TBL_NAME NOT LIKE 'ZZ%'
AND B.OWNER_FLG <> 'CM'
AND NOT EXISTS (SELECT 1 FROM CI_MD_IDX B WHERE (UPPER(TRIM(B.IDX_CD))) = UPPER(A.INDEX_NAME))
/

INSERT INTO CI_MD_IDX_FLD (IDX_CD,SEQ_NUM,FLD_NAME,OWNER_FLG,VERSION)  
SELECT A.INDEX_NAME,A.COLUMN_POSITION,A.COLUMN_NAME,b.owner_flg, 1
FROM USER_IND_COLUMNS A , CI_MD_TBL B
where UPPER(A.INDEX_NAME) NOT LIKE 'SYS%' AND UPPER(A.INDEX_NAME) NOT LIKE 'ZZ%' AND UPPER(A.INDEX_NAME) not like 'CM%'
AND RTRIM(A.TABLE_NAME) = RTRIM(B.TBL_NAME)
AND B.TBL_NAME NOT LIKE 'ZZ%'
AND B.OWNER_FLG <> 'CM'
AND NOT EXISTS (SELECT 1 FROM CI_MD_IDX_FLD B WHERE (UPPER(TRIM(B.IDX_CD))) = UPPER(A.INDEX_NAME) AND B.SEQ_NUM = A.COLUMN_POSITION)
/