[英]Insert JSON data into Oracle using Python
everybody.大家。 I'm having problems working with json files.我在处理 json 文件时遇到问题。 I have such a list of Json data, how can I insert this data to a table?我有这样一个 Json 数据列表,如何将这些数据插入到表中? Python code: Python代码:
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: JSON (object.json) 文件中的一些日期:
[{"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 DatabaseError:ORA-00904:“ID”:无效标识符
ORA-904 is "invalid identifier". ORA-904 是“无效标识符”。
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.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.