Repository: tobymao/sqlglot

Issue:
Failure to parse `to_timestamp` func in Oracle SQL query
**Fully reproducible code snippet**
* sqlglot version = 26.16.4
```
    q = """
                select
                    to_timestamp(a_varchar) a_time
                from
                    t
    """
    sqlglot.parse(sql=q, dialect=sqlglot.Dialects.ORACLE)
```
Expected result: successful parse.
Actual: Failure with this error
```Required keyword: 'format' missing for <class 'sqlglot.expressions.StrToTime'>. Line 3, Col: 24. ...```

The parsing works as expected when `to_timestamp(` is replaced with `to_timestamp_tz(` or with `to_date(`.

**Official Documentation**
https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/TO_TIMESTAMP.html

Discussion:

Solution patch:
diff --git a/sqlglot/dialects/oracle.py b/sqlglot/dialects/oracle.py
index 1608cf35ba..766977f2e9 100644
--- a/sqlglot/dialects/oracle.py
+++ b/sqlglot/dialects/oracle.py
@@ -31,6 +31,13 @@ def _trim_sql(self: Oracle.Generator, expression: exp.Trim) -> str:
     return trim_sql(self, expression)
 
 
+def _build_to_timestamp(args: t.List) -> exp.StrToTime | exp.Anonymous:
+    if len(args) == 1:
+        return exp.Anonymous(this="TO_TIMESTAMP", expressions=args)
+
+    return build_formatted_time(exp.StrToTime, "oracle")(args)
+
+
 class Oracle(Dialect):
     ALIAS_POST_TABLESAMPLE = True
     LOCKING_READS_SUPPORTED = True
@@ -106,7 +113,7 @@ class Parser(parser.Parser):
             "NVL": lambda args: build_coalesce(args, is_nvl=True),
             "SQUARE": lambda args: exp.Pow(this=seq_get(args, 0), expression=exp.Literal.number(2)),
             "TO_CHAR": build_timetostr_or_tochar,
-            "TO_TIMESTAMP": build_formatted_time(exp.StrToTime, "oracle"),
+            "TO_TIMESTAMP": _build_to_timestamp,
             "TO_DATE": build_formatted_time(exp.StrToDate, "oracle"),
             "TRUNC": lambda args: exp.DateTrunc(
                 unit=seq_get(args, 1) or exp.Literal.string("DD"),


Test patch:
diff --git a/tests/dialects/test_oracle.py b/tests/dialects/test_oracle.py
index 7ff7d8b0ec..945bf8a5fd 100644
--- a/tests/dialects/test_oracle.py
+++ b/tests/dialects/test_oracle.py
@@ -320,6 +320,7 @@ def test_oracle(self):
             },
         )
         self.validate_identity("CREATE OR REPLACE FORCE VIEW foo1.foo2")
+        self.validate_identity("TO_TIMESTAMP('foo')")
 
     def test_join_marker(self):
         self.validate_identity("SELECT e1.x, e2.x FROM e e1, e e2 WHERE e1.y (+) = e2.y")