Untitled

 avatar
unknown
plain_text
a year ago
1.0 kB
2
Indexable
# ... (previous code)

# Inside your main function, update the code where you construct insert_values
for column_name, source_val in source_row.items():
    if source_val is not None:
        if isinstance(source_val, str) and source_val.startswith('TO_DATE'):
            # If it already starts with TO_DATE, don't add TO_DATE again
            insert_values.append(source_val)
        elif is_datetime(source_val):  # Add a function to check if the value is a datetime
            # Format datetime values using TO_DATE
            insert_values.append(f"TO_DATE('{source_val}', 'YYYY-MM-DD HH24:MI:SS')")
        else:
            insert_values.append(f"'{source_val}'")
    else:
        insert_values.append('NULL')

# ... (the rest of your code remains the same)

# Add a function to check if a value is a datetime
def is_datetime(value):
    try:
        # Attempt to parse the value as a datetime
        datetime.datetime.strptime(value, '%Y-%m-%d %H:%M:%S')
        return True
    except ValueError:
        return False