jko n127
asked on
Shell script to compare data in Oracle databae
Below is a sample of data in TABLE_FORMAT tables. I want to Compare the actual table names in SCOTT schema with the data in TABLE_FORMAT. Insert into TEST123 table the names of tables not meeting the naming convention in TABLE_FORMAT table. I need help please.
The first query return a roll because "SCR_00083_UB_ALL_FNL_2" fall within the naming format. The second query didn't return any row because "SCR_00083_UB_ALL_FNL_2t" doesn't falls within the naming format. I want to insert the name of tables that do not fall in the naming conversion.
select * from (
select UPPER(TABLE_FORMAT) table_format, upper(replace(replace(repl ace(replac e(table_fo rmat,'${TB _STAMP}',' %'),'${SCE NARIO}','% '),'${END_ DATE}','%' ),'_','\_' )) new_table_format from AR9_EIP_TABLES_TEMPLATE) a
2 3 where 'SCR_00083_UB_ALL_FNL_2' like new_table_format escape '\'
4 ;
TABLE_FORMAT NEW_TABLE_FORMAT
-------------------------- ---------- ---- -------------------------- ---------- ----
SCR_${TB_STAMP}_UB_ALL_FNL _2 SCR\_%\_UB\_ALL\_FNL\_2
select * from (
2 select UPPER(TABLE_FORMAT) table_format, upper(replace(replace(repl ace(replac e(table_fo rmat,'${TB _STAMP}',' %'),'${SCE NARIO}','% '),'${END_ DATE}','%' ),'_','\_' )) new_table_format from AR9_EIP_TABLES_TEMPLATE) a
3 where 'SCR_00083_UB_ALL_FNL_2t' like new_table_format escape '\';
no rows selected
The first query return a roll because "SCR_00083_UB_ALL_FNL_2" fall within the naming format. The second query didn't return any row because "SCR_00083_UB_ALL_FNL_2t" doesn't falls within the naming format. I want to insert the name of tables that do not fall in the naming conversion.
select * from (
select UPPER(TABLE_FORMAT) table_format, upper(replace(replace(repl
2 3 where 'SCR_00083_UB_ALL_FNL_2' like new_table_format escape '\'
4 ;
TABLE_FORMAT NEW_TABLE_FORMAT
--------------------------
SCR_${TB_STAMP}_UB_ALL_FNL
select * from (
2 select UPPER(TABLE_FORMAT) table_format, upper(replace(replace(repl
3 where 'SCR_00083_UB_ALL_FNL_2t' like new_table_format escape '\';
no rows selected
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I have a bigger question: Why do this in a shell script at all?
I'm not exactly sure what you are doing but it seems that it can ALL be done in SQL. Likely in a single insert or merge statement.
Can you provide more about your requirements? Possible some sample data and expected results?
I'm not exactly sure what you are doing but it seems that it can ALL be done in SQL. Likely in a single insert or merge statement.
Can you provide more about your requirements? Possible some sample data and expected results?
ASKER
Here is a sample of data
ttt_${CASE}_${T_STAMP}_inv _lt_st
ttt_${CASE}_${T_STAMP}_ar_ lt_st
ttt_${CASE}_${T_STAMP}_ar_ lt_st_2
ttt_${CASE}_${T_STAMP}_ar_ lt_st_3
ttt_${CASE}_${T_STAMP}_ar_ inv_tot
ttt_${CASE}_${T_STAMP}_ar_ inv_tot_2
ttt_${T_STAMP}_recon_vs_TT T_recon
ttt_${T_STAMP}_recon_vs_TT T_diff
ttt_${T_STAMP}_recon_vs_TT T_fnl_df
ttt_${END_DATE}_recon_vs_T TT_df
TTT_12B_INV_ISSUE_&RUN_MON TH
TTT_12C_INV_ISSUE_&RUN_MON TH
TTT_15A_AR_INV_BASE_&RUN_M ONTH
TTT_15A_OMS_MISS_DP_&RUN_M ONTH
TTT_4A_6A_TILL_&RUN_MONTH
TTT_4B_11A_TILL_&RUN_MONTH
ttt98968_11A_CHRG_2_REQ_&R UN_MONTH
ttt98968_11B_CHRG_2_REQ_&R UN_MONTH
ttt98968_6A_CHRG_2_REQ_&RU N_MONTH
ttt98968_6B_CHRG_2_REQ_&RU N_MONTH
ttt_27A_AR_INPUT_&RUN_MONT H
nolong_yyy_xxxx_${END_DATE }
nolong_yyy_xxxx_req_${END_ DATE}
nolong_yyy_uuu_xxxx_${END_ DATE}
nolong_inv_xxxx_rel_${END_ DATE}
nolong_uuu_pyr_pop_${END_D ATE}
ttt_${CASE}_${T_STAMP}_inv
ttt_${CASE}_${T_STAMP}_ar_
ttt_${CASE}_${T_STAMP}_ar_
ttt_${CASE}_${T_STAMP}_ar_
ttt_${CASE}_${T_STAMP}_ar_
ttt_${CASE}_${T_STAMP}_ar_
ttt_${T_STAMP}_recon_vs_TT
ttt_${T_STAMP}_recon_vs_TT
ttt_${T_STAMP}_recon_vs_TT
ttt_${END_DATE}_recon_vs_T
TTT_12B_INV_ISSUE_&RUN_MON
TTT_12C_INV_ISSUE_&RUN_MON
TTT_15A_AR_INV_BASE_&RUN_M
TTT_15A_OMS_MISS_DP_&RUN_M
TTT_4A_6A_TILL_&RUN_MONTH
TTT_4B_11A_TILL_&RUN_MONTH
ttt98968_11A_CHRG_2_REQ_&R
ttt98968_11B_CHRG_2_REQ_&R
ttt98968_6A_CHRG_2_REQ_&RU
ttt98968_6B_CHRG_2_REQ_&RU
ttt_27A_AR_INPUT_&RUN_MONT
nolong_yyy_xxxx_${END_DATE
nolong_yyy_xxxx_req_${END_
nolong_yyy_uuu_xxxx_${END_
nolong_inv_xxxx_rel_${END_
nolong_uuu_pyr_pop_${END_D
That sample data really doesn't tell me anything.
What are the table names you have in the schema?
What are the table names you want to compare against?
What is the desired output?
What are the table names you have in the schema?
What are the table names you want to compare against?
What is the desired output?
Use this query to list down the tables not matching your patterns
Once you get the query correct. You can put it into an SQL script and call it from shell script if you require. But first thing is to get the query correct.
select table_name
from user_tables ut1
minus
select table_name
from user_tables ut
inner join AR9_EIP_TABLES_TEMPLATE t1
on ut.table_name like regexp_replace(UPPER(t1.TABLE_FORMAT), '(\$\{[^}]+})|(\&RUN\_MONTH)' , '%')
;
Once you get the query correct. You can put it into an SQL script and call it from shell script if you require. But first thing is to get the query correct.
ASKER
Sujith, Thanks a lot for you help. It is working
ASKER
Thanks again for your help
Fantastic. Glad to know.
If you want to insert the results into a table; add an insert in the beginning -
If you want to insert the results into a table; add an insert in the beginning -
insert into test123 (table_name)
select table_name
from user_tables ut1
minus
select table_name
from user_tables ut
inner join AR9_EIP_TABLES_TEMPLATE t1
on ut.table_name like regexp_replace(UPPER(t1.TABLE_FORMAT), '(\$\{[^}]+})|(\&RUN\_MONTH)' , '%')
;
What is that you are trying to achieve here?
Why are you using shell script to do it anyway?
From the looks of it, what you are trying to do can be done with a single SQL statement.