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 YYYYMMDD or DDMMYYYY or 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 where Phone = date_var_first','DD/MM/YYYY') AND TO_DATE ('$date_var_last','DD/MM/YYYY') order by insert_date desc;.
Assistant
User
I changed oracle sql query a bit. Now change your code when you see Phone = digitchangeitto(DESTdigit' OR ORIG_ADDRESS LIKE '$digit')
Assistant
d
i
g
i
t
an
d
in
ser
td
a
t
e
B
E
T
W
E
E
N
T
OD
A
T
E
(′
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 where Phone = digitandinsertdatebetweenTODATE(′date_var_first','DD/MM/YYYY') AND TO_DATE ('datevarfirst−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 where Phone = digitandinsertdatebetweentodayandtoday−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 where Phone = digitandinsertdatebetweenTODATE(′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 where Phone= $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 PARTITION FOR (TO_DATE('todaydate′,′YYYY−MM−DD′))wherePhone=digit order by insert_date desc;.
Certainly! Here's a bash script that implements your requirements. It handles input validation, normalizes phone numbers, parses dates and day numbers, selects the scenario and creates the appropriate db_connection_query for your func_db_connection function.
bash
#!/bin/bash
# Function placeholders (replace with actual implementations)
func_db_connection() {
# Example usage of db_connection_query variable
echo "Executing SQL Query:"
echo "$db_connection_query"
# Here should be your actual code to connect and run query against Oracle DB
}
# Helper: Print help message
print_help() {
cat <<EOF
Usage:
script.sh [phone_number | help] [date1 | day_number | today] [date2 | day_number] [day_number]
Inputs:
phone_number: digits only, 10 to 12 characters
- if starts with 5 and length 10 prepend '90'
- if starts with 0 and length 11 prepend '9'
help: show this help message
Dates: supported formats - YYYYMMDD, DDMMYYYY, YYYY-MM-DD, DD-MM-YYYY
day_number: integer from 1 to 30
today: literal string meaning today's date
Examples:
# Show help
script.sh help
# Scenario 2: phone_number, date1, date2
script.sh 905551234567 2023-06-01 2023-06-07
# Scenario 3: phone_number, date1, day_number
script.sh 5551234567 01062023 5
# Scenario 4: phone_number only
script.sh 905551234567
# Scenario 5: phone_number and date1
script.sh 905551234567 2023-06-01
# Scenario 6: phone_number and day_number
script.sh 905551234567 7
# Scenario 7: phone_number and "today"
script.sh 905551234567 today
EOF
}
# Normalize phone number following the rules & validate
normalize_phone_number() {
local input="$1"
# Remove any spaces if any
input="${input// /}"
# Check all are digits only
if ! [[ "$input" =~ ^[0-9]+$ ]]; then
echo "Error: Phone number must be digits only." >&2
return 1
fi
local len=${#input}
if [[ $len -lt 10 || $len -gt 12 ]]; then
echo "Error: Phone number length must be between 10 and 12." >&2
return 1
fi
# Apply rules
if [[ $len -eq 10 && ${input:0:1} == "5" ]]; then
# prepend 90
input="90$input"
elif [[ $len -eq 11 && ${input:0:1} == "0" ]]; then
# prepend 9
input="9$input"
fi
echo "$input"
}
# Parse date and convert to YYYY-MM-DD format
parse_date() {
local raw="$1"
# Validate format - only digits and optional '-'
if ! [[ "$raw" =~ ^[0-9-]+$ ]]; then
echo "Error: Date contains invalid characters." >&2
return 1
fi
# Remove dashes for easier processing
local clean_date="${raw//-/}"
# Detect format and parse:
# Accepted:
# YYYYMMDD -> length 8, first four digits year
# DDMMYYYY -> length 8, first two digits day
if [[ ${#clean_date} -ne 8 ]]; then
echo "Error: Date must be 8 digits (valid formats: YYYYMMDD or DDMMYYYY)." >&2
return 1
fi
local part1=${clean_date:0:2}
local part2=${clean_date:2:2}
local part3=${clean_date:4:4}
local year=""
local month=""
local day=""
# Check if format is YYYYMMDD or DDMMYYYY
# If first 4 digits numeric > 1900 assume YYYYMMDD otherwise DDMMYYYY
local first_4="${clean_date:0:4}"
if [[ "$first_4" =~ ^[0-9]{4}$ && "$first_4" -ge 1900 ]]; then
# YYYYMMDD
year=${clean_date:0:4}
month=${clean_date:4:2}
day=${clean_date:6:2}
else
# DDMMYYYY
day=${clean_date:0:2}
month=${clean_date:2:2}
year=${clean_date:4:4}
fi
# Validate date components (simple check)
if ! [[ "$year" =~ ^[0-9]{4}$ && "$month" =~ ^(0[1-9]|1[0-2])$ && "$day" =~ ^(0[1-9]|[12][0-9]|3[01])$ ]]; then
echo "Error: Date parts not valid." >&2
return 1
fi
# Return normalized date YYYY-MM-DD
echo "$year-$month-$day"
}
# Compare two dates YYYY-MM-DD, print later one first, then earlier
date_compare_order() {
local d1="$1"
local d2="$2"
local dt1=$(date -d "$d1" +%s 2>/dev/null)
local dt2=$(date -d "$d2" +%s 2>/dev/null)
if [[ -z "$dt1" || -z "$dt2" ]]; then
echo "Error: Invalid date for comparison." >&2
return 1
fi
if (( dt1 > dt2 )); then
# dt1 later, so print dt2 (earlier), dt1 (later)
echo "$d2 $d1"
else
echo "$d1 $d2"
fi
}
# Validate day_number 1..30
validate_day_number() {
local val="$1"
if ! [[ "$val" =~ ^[0-9]+$ ]]; then
echo "Error: Day number must be an integer." >&2
return 1
fi
if (( val < 1 || val > 30 )); then
echo "Error: Day number must be between 1 and 30." >&2
return 1
fi
echo "$val"
}
# Main script starts here
# Read inputs
input1="$1"
input2="$2"
input3="$3"
input4="$4"
# If no inputs or first input is empty, treat as help
if [[ -z "$input1" || "$input1" == "help" ]]; then
print_help
exit 0
fi
# If first input is help, ignore others and print help
if [[ "$input1" == "help" ]]; then
print_help
exit 0
fi
# First input must be phone_number now
digit=$(normalize_phone_number "$input1") || exit 1
# Variables for later use
date_var_first=""
date_var_last=""
day_interval=""
# Helper: Get today's date in YYYY-MM-DD
today_date=$(date +%F)
# Determine scenario by inputs count and type checking
input_count=$#
if (( input_count > 4 )); then
echo "Error: Maximum 4 inputs allowed." >&2
exit 1
fi
# Function to subtract days from a date and return YYYY-MM-DD
subtract_days() {
date -d "$1 -$2 days" +%F
}
# Parse inputs and decide scenario
# Scenario 4: only phone_number given (input_count==1)
if (( input_count == 1 )); then
day_interval=7
date_var_first="$today_date"
date_var_last=$(subtract_days "$today_date" "$day_interval")
# SQL Scenario 4
db_connection_query="select * from db where Phone = $digit and insert_date between TO_DATE ('$date_var_last','YYYY-MM-DD') AND TO_DATE ('$date_var_first','YYYY-MM-DD') order by insert_date desc;"
func_db_connection
exit 0
fi
# If 2 inputs are given, determine if input2 is date, day_number, or today
if (( input_count == 2 )); then
# Check if input2 == today
if [[ "$input2" == "today" ]]; then
# Scenario 7
db_connection_query="select * from db PARTITION FOR (TO_DATE('$today_date', 'YYYY-MM-DD')) where Phone= $digit order by insert_date desc;"
func_db_connection
exit 0
fi
# Check if input2 is day number
day_interval=$(validate_day_number "$input2" 2>/dev/null || echo "")
if [[ -n "$day_interval" ]]; then
# Scenario 6
date_var_first="$today_date"
date_var_last=$(subtract_days "$today_date" "$day_interval")
db_connection_query="select * from db where Phone= $digit and insert_date between TO_DATE ('$date_var_last','YYYY-MM-DD') AND TO_DATE ('$date_var_first','YYYY-MM-DD') order by insert_date desc;"
func_db_connection
exit 0
fi
# Try parse date1
date_var_first=$(parse_date "$input2") || exit 1
# Scenario 5 day_interval=7, date_var_last = date_var_first - 7 days
day_interval=7
date_var_last=$(subtract_days "$date_var_first" "$day_interval")
db_connection_query="select * from db where Phone = $digit and insert_date between TO_DATE ('$date_var_last','YYYY-MM-DD') AND TO_DATE ('$date_var_first','YYYY-MM-DD') order by insert_date desc;"
func_db_connection
exit 0
fi
# For input_count=3 or 4, parse input2 is either date1 or day_number or today
# We also need to parse input3 accordingly & input4 if given
if (( input_count >= 3 )); then
# Categorize input2
case "$input2" in
today)
# input2 is today -> scenario 7 if input_count=2, else invalid?
if (( input_count == 3 )) || (( input_count == 4 )); then
echo "Error: Input count not valid with 'today' as second argument and more args." >&2
exit 1
fi
;;
*)
# Check if input2 is day number
day_interval_candidate=$(validate_day_number "$input2" 2>/dev/null || echo "")
if [[ -n "$day_interval_candidate" ]]; then
# input2 is day_number
day_interval="$day_interval_candidate"
else
# must be date1
date_var_first=$(parse_date "$input2") || exit 1
fi
;;
esac
# Categorize input3
# input3 either date2 or day_number or invalid
day_interval_candidate=$(validate_day_number "$input3" 2>/dev/null || echo "")
if [[ -n "$day_interval_candidate" ]]; then
input3_is_daynumber=1
else
input3_is_daynumber=0
# try parse as date
date_var_last=$(parse_date "$input3" 2>/dev/null || echo "")
if [[ -z "$date_var_last" ]]; then
echo "Error: Third input invalid as date or day_number." >&2
exit 1
fi
fi
# input4 if given must be day_number
if (( input_count == 4 )); then
day_interval_candidate=$(validate_day_number "$input4" 2>/dev/null || echo "")
if [[ -z "$day_interval_candidate" ]]; then
echo "Error: Fourth input must be day_number between 1 and 30." >&2
exit 1
fi
day_interval="$day_interval_candidate"
fi
# Now decide scenario:
# Scenario 2: phone_number, date1(input2), date2(input3)
if [[ -n "$date_var_first" && $input3_is_daynumber -eq 0 && -n "$date_var_last" ]]; then
# Order dates so date_var_first < date_var_last
read dfirst dlast < <(date_compare_order "$date_var_first" "$date_var_last") || exit 1
# assign normalized variables again
date_var_first="$dfirst"
date_var_last="$dlast"
db_connection_query="select * from db where Phone = $digit and insert_date BETWEEN TO_DATE ('$date_var_first','YYYY-MM-DD') AND TO_DATE ('$date_var_last','YYYY-MM-DD') order by insert_date desc;"
func_db_connection
exit 0
fi
# Scenario 3: phone_number, date1 (input2), day_number (input3)
if [[ -n "$date_var_first" && $input3_is_daynumber -eq 1 ]]; then
day_interval="$input3"
date_var_last=$(subtract_days "$date_var_first" "$day_interval")
# Ensure date_var_last < date_var_first for query
db_connection_query="select * from db where Phone = $digit and insert_date between TO_DATE ('$date_var_last','YYYY-MM-DD') AND TO_DATE ('$date_var_first','YYYY-MM-DD') order by insert_date desc;"
func_db_connection
exit 0
fi
# Scenario 5: If input_count=3, phone_number and date1 only
# This was handled above
# Scenario 6: phone_number and day_number
if [[ -z "$date_var_first" && $input3_is_daynumber -eq 1 ]]; then
day_interval="$input3"
date_var_first="$today_date"
date_var_last=$(subtract_days "$date_var_first" "$day_interval")
db_connection_query="select * from db where Phone= $digit and insert_date between TO_DATE ('$date_var_last','YYYY-MM-DD') AND TO_DATE ('$date_var_first','YYYY-MM-DD') order by insert_date desc;"
func_db_connection
exit 0
fi
echo "Error: Input combination did not match any scenario." >&2
exit 1
fi
echo "Error: Inputs not valid for any scenario." >&2
exit 1
SQL queries are constructed in db_connection_query variable.
Function func_db_connection is called with the query.
Dates in queries are represented as TO_DATE('YYYY-MM-DD','YYYY-MM-DD') to match the format.
Dates in BETWEEN use the earlier date first.
Make sure your actual func_db_connection uses the db_connection_query variable for the Oracle DB calls. The date format in TO_DATE uses 'YYYY-MM-DD' as place-holder. You may want to further adapt the date format based on your database settings.
Test thoroughly on your system before production. Let me know if you want me to enhance or adjust anything!
A
D
D
R
E
S
S
L
I
K
E′
also for date inputs only let YYYY-MM-DD and DD-MM-YYYY.
Got it! I've updated the script with your new requirements:
The SQL WHERE Phone = $digit clause is replaced with (DEST_ADDRESS LIKE '$digit' OR ORIG_ADDRESS LIKE '$digit').
Date inputs only accept YYYY-MM-DD or DD-MM-YYYY formats (with - separators), strictly.
Date parsing adjusted accordingly.
Also fixed the TO_DATE format string in queries to 'DD-MM-YYYY' as you used in your original example.
Here's the updated script section with all changes incorporated:
bash
#!/bin/bash
# Function placeholders (replace with actual implementations)
func_db_connection() {
# Example usage of db_connection_query variable
echo "Executing SQL Query:"
echo "$db_connection_query"
# Here should be your actual code to connect and run query against Oracle DB
}
print_help() {
cat <<EOF
Usage:
script.sh [phone_number | help] [date1 | day_number | today] [date2 | day_number] [day_number]
Inputs:
phone_number: digits only, 10 to 12 characters
- if starts with 5 and length 10 prepend '90'
- if starts with 0 and length 11 prepend '9'
help: show this help message
Dates: supported formats - YYYY-MM-DD or DD-MM-YYYY only
day_number: integer from 1 to 30
today: literal string meaning today's date
Examples:
# Show help
script.sh help
# Scenario 2: phone_number, date1, date2
script.sh 905551234567 2023-06-01 2023-06-07
# Scenario 3: phone_number, date1, day_number
script.sh 5551234567 01-06-2023 5
# Scenario 4: phone_number only
script.sh 905551234567
# Scenario 5: phone_number and date1
script.sh 905551234567 2023-06-01
# Scenario 6: phone_number and day_number
script.sh 905551234567 7
# Scenario 7: phone_number and "today"
script.sh 905551234567 today
EOF
}
normalize_phone_number() {
local input="$1"
input="${input// /}"
if ! [[ "$input" =~ ^[0-9]+$ ]]; then
echo "Error: Phone number must be digits only." >&2
return 1
fi
local len=${#input}
if [[ $len -lt 10 || $len -gt 12 ]]; then
echo "Error: Phone number length must be between 10 and 12." >&2
return 1
fi
if [[ $len -eq 10 && ${input:0:1} == "5" ]]; then
input="90$input"
elif [[ $len -eq 11 && ${input:0:1} == "0" ]]; then
input="9$input"
fi
echo "$input"
}
# Updated parse_date: only accept YYYY-MM-DD or DD-MM-YYYY (with hyphens)
parse_date() {
local raw="$1"
if ! [[ "$raw" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ || "$raw" =~ ^[0-9]{2}-[0-9]{2}-[0-9]{4}$ ]]; then
echo "Error: Date must be in YYYY-MM-DD or DD-MM-YYYY format." >&2
return 1
fi
# Determine which format, convert to YYYY-MM-DD for internal use
if [[ "$raw" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
# Already YYYY-MM-DD
echo "$raw"
else
# DD-MM-YYYY to YYYY-MM-DD
local dd=${raw:0:2}
local mm=${raw:3:2}
local yyyy=${raw:6:4}
echo "$yyyy-$mm-$dd"
fi
}
date_compare_order() {
local d1="$1"
local d2="$2"
local dt1=$(date -d "$d1" +%s 2>/dev/null)
local dt2=$(date -d "$d2" +%s 2>/dev/null)
if [[ -z "$dt1" || -z "$dt2" ]]; then
echo "Error: Invalid date for comparison." >&2
return 1
fi
if (( dt1 > dt2 )); then
echo "$d2 $d1"
else
echo "$d1 $d2"
fi
}
validate_day_number() {
local val="$1"
if ! [[ "$val" =~ ^[0-9]+$ ]]; then
echo "Error: Day number must be an integer." >&2
return 1
fi
if (( val < 1 || val > 30 )); then
echo "Error: Day number must be between 1 and 30." >&2
return 1
fi
echo "$val"
}
subtract_days() {
date -d "$1 -$2 days" +%F
}
# Main starts here:
input1="$1"
input2="$2"
input3="$3"
input4="$4"
if [[ -z "$input1" || "$input1" == "help" ]]; then
print_help
exit 0
fi
digit=$(normalize_phone_number "$input1") || exit 1
day_interval=""
date_var_first=""
date_var_last=""
today_date=$(date +%F)
input_count=$#
if (( input_count > 4 )); then
echo "Error: Max 4 inputs allowed." >&2
exit 1
fi
# Scenario 4: only phone number
if (( input_count == 1 )); then
day_interval=7
date_var_first="$today_date"
date_var_last=$(subtract_days "$today_date" "$day_interval")
db_connection_query="select * from db where (DEST_ADDRESS LIKE '$digit' OR ORIG_ADDRESS LIKE '$digit') and insert_date between TO_DATE ('$date_var_last','DD-MM-YYYY') AND TO_DATE ('$date_var_first','DD-MM-YYYY') order by insert_date desc;"
func_db_connection
exit 0
fi
if (( input_count == 2 )); then
if [[ "$input2" == "today" ]]; then
db_connection_query="select * from db PARTITION FOR (TO_DATE('$today_date', 'YYYY-MM-DD')) where (DEST_ADDRESS LIKE '$digit' OR ORIG_ADDRESS LIKE '$digit') order by insert_date desc;"
func_db_connection
exit 0
fi
day_interval=$(validate_day_number "$input2" 2>/dev/null || echo "")
if [[ -n "$day_interval" ]]; then
date_var_first="$today_date"
date_var_last=$(subtract_days "$today_date" "$day_interval")
db_connection_query="select * from db where (DEST_ADDRESS LIKE '$digit' OR ORIG_ADDRESS LIKE '$digit') and insert_date between TO_DATE ('$date_var_last','DD-MM-YYYY') AND TO_DATE ('$date_var_first','DD-MM-YYYY') order by insert_date desc;"
func_db_connection
exit 0
fi
date_var_first=$(parse_date "$input2") || exit 1
day_interval=7
date_var_last=$(subtract_days "$date_var_first" "$day_interval")
db_connection_query="select * from db where (DEST_ADDRESS LIKE '$digit' OR ORIG_ADDRESS LIKE '$digit') and insert_date between TO_DATE ('$date_var_last','DD-MM-YYYY') AND TO_DATE ('$date_var_first','DD-MM-YYYY') order by insert_date desc;"
func_db_connection
exit 0
fi
if (( input_count >= 3 )); then
# Check input2
case "$input2" in
today)
echo "Error: Invalid input combination with 'today' as second argument and more inputs." >&2
exit 1
;;
*)
day_interval_candidate=$(validate_day_number "$input2" 2>/dev/null || echo "")
if [[ -n "$day_interval_candidate" ]]; then
day_interval="$day_interval_candidate"
else
date_var_first=$(parse_date "$input2") || exit 1
fi
;;
esac
day_interval_candidate=$(validate_day_number "$input3" 2>/dev/null || echo "")
if [[ -n "$day_interval_candidate" ]]; then
input3_is_daynumber=1
day_interval="$day_interval_candidate"
else
input3_is_daynumber=0
date_var_last=$(parse_date "$input3" 2>/dev/null || echo "")
if [[ -z "$date_var_last" ]]; then
echo "Error: Third input invalid as date or day_number." >&2
exit 1
fi
fi
if (( input_count == 4 )); then
day_interval_candidate=$(validate_day_number "$input4" 2>/dev/null || echo "")
if [[ -z "$day_interval_candidate" ]]; then
echo "Error: Fourth input must be day_number between 1 and 30." >&2
exit 1
fi
day_interval="$day_interval_candidate"
fi
# Scenario 2
if [[ -n "$date_var_first" && $input3_is_daynumber -eq 0 && -n "$date_var_last" ]]; then
read dfirst dlast < <(date_compare_order "$date_var_first" "$date_var_last") || exit 1
date_var_first="$dfirst"
date_var_last="$dlast"
db_connection_query="select * from db 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;"
func_db_connection
exit 0
fi
# Scenario 3
if [[ -n "$date_var_first" && $input3_is_daynumber -eq 1 ]]; then
date_var_last=$(subtract_days "$date_var_first" "$day_interval")
db_connection_query="select * from db where (DEST_ADDRESS LIKE '$digit' OR ORIG_ADDRESS LIKE '$digit') and insert_date between TO_DATE ('$date_var_last','DD-MM-YYYY') AND TO_DATE ('$date_var_first','DD-MM-YYYY') order by insert_date desc;"
func_db_connection
exit 0
fi
# Scenario 6
if [[ -z "$date_var_first" && $input3_is_daynumber -eq 1 ]]; then
date_var_first="$today_date"
date_var_last=$(subtract_days "$date_var_first" "$day_interval")
db_connection_query="select * from db where (DEST_ADDRESS LIKE '$digit' OR ORIG_ADDRESS LIKE '$digit') and insert_date between TO_DATE ('$date_var_last','DD-MM-YYYY') AND TO_DATE ('$date_var_first','DD-MM-YYYY') order by insert_date desc;"
func_db_connection
exit 0
fi
echo "Error: Input combination did not match any scenario." >&2
exit 1
fi
echo "Error: Inputs not valid for any scenario." >&2
exit 1
Summary of changes:
All WHERE Phone = $digit replaced by WHERE (DEST_ADDRESS LIKE '$digit' OR ORIG_ADDRESS LIKE '$digit')
Date accepted formats only: YYYY-MM-DD or DD-MM-YYYY
Date parsing simplified to only those formats.
TO_DATE format strings changed to 'DD-MM-YYYY' to align with your example.
Small validation improvements with error messages.
Run and test this updated script on your RHEL server. Adjust func_db_connection as needed to run the actual Oracle queries.
If you want me to provide the full script again or help on anything else, just ask!