java.sql.sqlexpcetion:ORA-00917:missing comma

user3340095

I am sorry that i ask a very stupid question but i cant find the place where i miss the comma in the code..

sqlStr.append("INSERT INTO DS_GOAL ");
sqlStr.append("(DS_SITE_CODE, DS_FINANCIAL_YEAR, DS_DEPARTMENT_CODE, DS_PLAN_ID, DS_GOAL_ID, ");
sqlStr.append("DS_DESC, TO_CHAR(DS_PLAN_END_DATE, \"dd/MM/YY\"),");
sqlStr.append("DS_CORP_OBJECTIVE, DS_CORP_OBJECTIVE_OTHER, DS_FOCUS, DS_FOCUS_OTHER, ");
sqlStr.append("DS_TOTAL, DS_EQUIPMENT, DS_RECRUIT, DS_FTE, ");
sqlStr.append("DS_CREATED_USER, DS_MODIFIED_USER, DS_GOAL_ORDER ) ");
sqlStr.append("VALUES ");
sqlStr.append("(?, ?, ?, ?, ?,");
sqlStr.append("?, ?,");
sqlStr.append("?, ?, ?, ?,");
sqlStr.append("?, ?, ?, ?,");
sqlStr.append("?, ?, ?)");
sqlStr_insertGoal = sqlStr.toString();

After the sqlStr.toString()

the console shows

 INSERT INTO DS_GOAL (DS_SITE_CODE, DS_FINANCIAL_YEAR, DS_DEPARTMENT_CODE, DS_PLAN_ID,
 DS_GOAL_ID, 
 DS_DESC, TO_CHAR(DS_PLAN_END_DATE, 'dd/MM/YYYY'), 
 DS_CORP_OBJECTIVE, DS_CORP_OBJECTIVE_OTHER, DS_FOCUS, DS_FOCUS_OTHER, 
 DS_TOTAL, DS_EQUIPMENT, DS_RECRUIT,
 DS_FTE, DS_CREATED_USER, DS_MODIFIED_USER, DS_GOAL_ORDER)
 VALUES (?, ?, ?, ?, ?,?, ?,?, ?, ?, ?,?, ?, ?, ?,?, ?, ?)

After Edited the code the console shows

INSERT INTO DS_GOAL (DS_SITE_CODE, DS_FINANCIAL_YEAR, DS_DEPARTMENT_CODE, DS_PLAN_ID,
 DS_GOAL_ID, 
 DS_DESC, DS_PLAN_END_DATE, 
 DS_CORP_OBJECTIVE, DS_CORP_OBJECTIVE_OTHER, DS_FOCUS, DS_FOCUS_OTHER, 
 DS_TOTAL, DS_EQUIPMENT, DS_RECRUIT,
 DS_FTE, DS_CREATED_USER, DS_MODIFIED_USER, DS_GOAL_ORDER)
 VALUES (?, ?, ?, ?, ?,?, TO_CHAR(DS_PLAN_END_DATE, 'dd/MM/YYYY'),?, ?, ?, ?,?, ?, ?,
 ?,?, ?, ?)

But the consoles shows invalid column index error Thanks for help

JonK

I suspect your problem isn't actually a case of a missing comma (in my experience ORA errors are notorious for telling you the wrong thing). My suspicion is that your real issue is the use of " around the format string in your TO_CHAR call. To demonstrate, try this:

SELECT TO_CHAR(SYSDATE, "dd/MM/YY")
  FROM DUAL;

If I run the above I get an ORA-00904: "dd/MM/YY": invalid identifier error. If I change the quotes to apostrophes instead:

SELECT TO_CHAR(SYSDATE, 'dd/MM/YY')
  FROM DUAL;

I get 16/04/14. Double quotes are for identifiers, not strings:

SELECT TO_CHAR(SYSDATE, 'dd/MM/YY') AS "The Date"
  FROM DUAL;                        // ^ This is an identifier

prints:

The Date
--------
16/04/14

EDIT:

Sorry, I should have spotted this one sooner! You're using TO_CHAR in your columns list, which you can't do. The below example nicely produces an ORA-00917: missing comma error:

CREATE TABLE JON_TEST (COL1 VARCHAR2(20));

COMMIT;

INSERT INTO JON_TEST (TO_CHAR(COL1, 'DD/MM/YYYY'))
VALUES (SYSDATE);

Whereas this works:

INSERT INTO JON_TEST (COL1)
VALUES (TO_CHAR(SYSDATE, 'dd/MM/YYYY'));

So you need to correct three things:

  • You need to change TO_CHAR to TO_DATE, and
  • You need to move the call to TO_DATE to your VALUES clause, and
  • You need to ensure that you use ' instead of " with the format string.

This is how Oracle define the syntax for INSERT statements:

This is how Oracle defines the syntax for INSERT statements

Notice that in the middle section that it only says column_name and not sql_expression.

Try changing your query to the following:

sqlStr.append("INSERT INTO DS_GOAL ")
    .append("(DS_SITE_CODE, DS_FINANCIAL_YEAR, DS_DEPARTMENT_CODE, DS_PLAN_ID, DS_GOAL_ID, ")
    .append("DS_DESC, DS_PLAN_END_DATE, ")
    .append("DS_CORP_OBJECTIVE, DS_CORP_OBJECTIVE_OTHER, DS_FOCUS, DS_FOCUS_OTHER, ")
    .append("DS_TOTAL, DS_EQUIPMENT, DS_RECRUIT, DS_FTE, ")
    .append("DS_CREATED_USER, DS_MODIFIED_USER, DS_GOAL_ORDER ) ")
    .append("VALUES ")
    .append("(?, ?, ?, ?, ?,")
    .append("?, TO_DATE(?, 'dd/MM/YY'),")
    .append("?, ?, ?, ?,")
    .append("?, ?, ?, ?,")
    .append("?, ?, ?)");
    sqlStr_insertGoal = sqlStr.toString();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

ORA-00917, missing comma

From Dev

ORA-00917, missing comma

From Dev

java.sql.SQLException: ORA-00917: missing comma while Inserting rows in a table

From Dev

java.sql.SQLException: ORA-00917: missing comma while Inserting rows in a table

From Dev

ORA-00917: Missing Comma SQL Oracle error

From Dev

ORA-00917: missing comma error

From Dev

Missing Comma, oracle ORA-00917

From Dev

ORA-00917 missing comma in Powershell

From Dev

sql oracle, error "PL/SQL: SQL Statement ignored" and "PL/SQL: ORA-00917: missing comma"

From Dev

Error: ORA-00917: missing comma 00917. 00000 - "missing comma"

From Dev

ORA-00917 Missing Comma, but it isn't missing?

From Dev

ORA-00917: missing comma when insert not exist in oracle

From Dev

C# {"ORA-00917: missing comma"} INSERT QUERY ERROR

From Dev

Please help - ORA-00917: missing comma insert error

From Dev

ORA-00917: missing comma when insert not exist in oracle

From Dev

Oracle SQL Missing Comma

From Dev

java.sql.SQLSyntaxErrorException: ORA-00905: missing keyword

From Dev

PL/SQL: ORA-00917 Compilation failed, line 49 (11:56:09) The line numbers associated with

From Dev

Oracle SQL missing comma error

From Dev

getting java.sql.SQLSyntaxErrorException: ORA-00936: missing expression error

From Dev

java.sql.SQLSyntaxErrorException:: ORA-00907: missing right parenthesis error

From Dev

Missing Keyword (ORA-00905) - Erreur SQL : ORA-00905

From Dev

ORA-00907: Missing right parenthesis in SQL

From Dev

SQL missing right parenthesis ORA-00907

From Dev

SQL Error -- ORA-00936: missing expression

From Dev

ORA-00936: missing expression, although there seems to be no missing expression (SQL)

From Dev

ORA-00936: missing expression, although there seems to be no missing expression (SQL)

From Dev

ORA-00936, Java and SQL

From Dev

JDBC resultset not working when using aliases I receive " java.sql.SQLSyntaxErrorException: ORA-00905: missing keyword"

Related Related

  1. 1

    ORA-00917, missing comma

  2. 2

    ORA-00917, missing comma

  3. 3

    java.sql.SQLException: ORA-00917: missing comma while Inserting rows in a table

  4. 4

    java.sql.SQLException: ORA-00917: missing comma while Inserting rows in a table

  5. 5

    ORA-00917: Missing Comma SQL Oracle error

  6. 6

    ORA-00917: missing comma error

  7. 7

    Missing Comma, oracle ORA-00917

  8. 8

    ORA-00917 missing comma in Powershell

  9. 9

    sql oracle, error "PL/SQL: SQL Statement ignored" and "PL/SQL: ORA-00917: missing comma"

  10. 10

    Error: ORA-00917: missing comma 00917. 00000 - "missing comma"

  11. 11

    ORA-00917 Missing Comma, but it isn't missing?

  12. 12

    ORA-00917: missing comma when insert not exist in oracle

  13. 13

    C# {"ORA-00917: missing comma"} INSERT QUERY ERROR

  14. 14

    Please help - ORA-00917: missing comma insert error

  15. 15

    ORA-00917: missing comma when insert not exist in oracle

  16. 16

    Oracle SQL Missing Comma

  17. 17

    java.sql.SQLSyntaxErrorException: ORA-00905: missing keyword

  18. 18

    PL/SQL: ORA-00917 Compilation failed, line 49 (11:56:09) The line numbers associated with

  19. 19

    Oracle SQL missing comma error

  20. 20

    getting java.sql.SQLSyntaxErrorException: ORA-00936: missing expression error

  21. 21

    java.sql.SQLSyntaxErrorException:: ORA-00907: missing right parenthesis error

  22. 22

    Missing Keyword (ORA-00905) - Erreur SQL : ORA-00905

  23. 23

    ORA-00907: Missing right parenthesis in SQL

  24. 24

    SQL missing right parenthesis ORA-00907

  25. 25

    SQL Error -- ORA-00936: missing expression

  26. 26

    ORA-00936: missing expression, although there seems to be no missing expression (SQL)

  27. 27

    ORA-00936: missing expression, although there seems to be no missing expression (SQL)

  28. 28

    ORA-00936, Java and SQL

  29. 29

    JDBC resultset not working when using aliases I receive " java.sql.SQLSyntaxErrorException: ORA-00905: missing keyword"

HotTag

Archive