I need a bash script that will run on rhel server. The script will do 7 things. These things are sql queries. I need sql queries for each scenario. I have a function named func_db_connection to run oracle sql queries. It requeres db_connection_query variable. I need you to create db_connection_query for each scenario and also check inputs are valid.

script can take up to 4 input. It can be 1 , 2, 3 or 4.
first one is either a phone_number or "help". second one is date1, date2, day_number or "today" . third one is date2 or day_number if date1 is given at 2. 4th one can only be day_number.

if "help" input is given, ignore other inputs and only take help.

phone_number input must be 1st input if "help" is not given. 
phone_number should be made of digits only. 
phone_number input's length is minimum 10 and maximum 12.
if phone_number starts with 5 and length is 10 then add 90 to the beginning.
If it starts with 0 and length is 11 then add 9 to the beginning.
Store phone_number in digit variable.

date1 and date2 must be given in YYYY-MM-DD or DD-MM-YYYY format. Only digits and - as seperator is accepted.
It will be stored in date_var_first and date_var_last like YYYY-MM-DD format.
if date1 is later than date2 than store date1 to date_var_last. Also if date2 is later than date1 than store date2 to date_var_last.

day_number is an integer from 1 to 30 and will be stored in day_interval variable.

To use script 1st input must be given and it must be either "help" or phone_number. If not given act like "help" is given.

scenario 1: if 1st input is "help" or empty show the user what kind of inputs can he/she gives.

scenario 2: if 3 input is given like 1st is phone_number, 2nd is date1 and 3rd is date2. Then give a select * from db_mine where (DEST_ADDRESS LIKE '$digit' OR ORIG_ADDRESS LIKE '$digit') and insert_date BETWEEN TO_DATE ('$date_var_first','DD/MM/YYYY') AND TO_DATE ('$date_var_last','DD/MM/YYYY') order by insert_date desc;.

scenario 3: if 3 input is given like 1st is phone_number, 2nd is date1 and 3rd is day_number. Then give a select * from db_mine where (DEST_ADDRESS LIKE '$digit' OR ORIG_ADDRESS LIKE '$digit') and insert_date between TO_DATE ('$date_var_first','DD/MM/YYYY') AND TO_DATE ('$date_var_first - $day_interval','DD/MM/YYYY') order by insert_date desc;.

scenario 4: if only 1st input given. here day_interval=7 and date_var_first=today .Then give a select * from db_mine where (DEST_ADDRESS LIKE '$digit' OR ORIG_ADDRESS LIKE '$digit') and insert_date between today and today - $day_interval order by insert_date desc;.

scenario 5: if 1st input phone_number and 2nd input date1 is given. Then take day_interval=7 and give a select * from db_mine where (DEST_ADDRESS LIKE '$digit' OR ORIG_ADDRESS LIKE '$digit') and insert_date between TO_DATE ('$date_var_first','DD/MM/YYYY') AND TO_DATE ('$date_var_first - day_interval','DD/MM/YYYY') order by insert_date desc;.

scenario 6: if 1st input phone_number and 2nd input day_number is given. Then date_var_first=today date and give a select * from db_mine where (DEST_ADDRESS LIKE '$digit' OR ORIG_ADDRESS LIKE '$digit') and insert_date between today and today - day_interval order by insert_date desc;.

scenario 7: if 1st input phone_number and 2nd input "today" is given. Then select * from db_mine PARTITION FOR (TO_DATE('$today_date', 'YYYY-MM-DD')) where (DEST_ADDRESS LIKE '$digit' OR ORIG_ADDRESS LIKE '$digit') order by insert_date desc;.

for other than above scenarios show the user what kind of inputs can he/she gives.