0

everybody. I'm having problems working with json files. I have such a list of Json data , how can I insert this data to a table? Python code:

with open('object.json') as f:
    json_obj = json.load(f)
print(json_obj)

for i in enumerate(json_obj):
    id = validate_string(item.get("id", None))
    LAST_NAME = validate_string(item.get("LAST_NAME", None))
    FIRST_NAME = validate_string(item.get("FIRST_NAME", None))
cursor.execute("insert into EMPLOYEES (id,LAST_NAME,FIRST_NAME) VALUES (:1,:2,:3)", (id,LAST_NAME,FIRST_NAME))
conn.close

JSON some dates in the (object.json) file:

[{"ID": 1, "LAST_NAME": "Alex", "FIRST_NAME": "Pip"}, 
{"ID": 2, "LAST_NAME": "John", "FIRST_NAME": "Alan"},
{"ID": 3, "LAST_NAME": "Dehan", "FIRST_NAME": "Luck"},
{"ID": 4, "LAST_NAME": "Nick", "FIRST_NAME": "Adem"},
{"ID": 5, "LAST_NAME": "Aspen", "FIRST_NAME": "Turit"}]

DatabaseError: ORA-00904: "ID": invalid identifier

1
  • Once you've resolved the error (see the answer already proposed), then you should look at using executemany() to improve performance. See the cx_Oracle documentation. Commented May 24, 2020 at 23:00

1 Answer 1

2

ORA-904 is "invalid identifier".

  • Are you sure the column id exists ?
  • Could it be you created the employee table with case sensititive column names, I see that in your insert statement you have "id" in lower case and "LAST_NAME" in upper case. If your column names are case sensitive you have to surround them with double quotes. Example:
create table test ("id" NUMBER, "Name" VARCHAR2(100));
INSERT INTO test (id, name) VALUES (1,'KOEN'); 
> gives ORA-00904: "NAME": invalid identifier 
INSERT INTO test ("id", "Name") VALUES (1,'KOEN');
1 row(s) inserted.

More details here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.