[英]Insert JSON data into Oracle using Python
大家。 我在處理 json 文件時遇到問題。 我有這樣一個 Json 數據列表,如何將這些數據插入到表中? 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 (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”:無效標識符
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.