如何将数据帧插入oracle表非法/可变oracle

2024-05-29 02:55:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下数据帧

df2 = {names: [PEPE, LUIS], id: [1,2], stages: [0,1], ord: [3, 2]}

但是这些是必需的字段,要插入的表,您有更多的字段,这些字段允许空值

其中dataframe相当于表中的这些字段

df2 = {labels= :1, id= :2, stages= :3, ord= :4}

桌子

CREATE TABLE customer_prf
(
  names      VARCHAR2(80) NOT NULL, 
  label      VARCHAR2(80) NOT NULL,
  type       VARCHAR2(80) NOT NULL,
  type_flag  INT,
  type_flag2 INT,
  conc       VARCHAR2(80), 
  id         INT NOT NULL,
  n_stage    INT NOT NULL,
  ctry       INT NOT NULL,
  "order"    INT NOT NULL
);

您是如何使用insert with values从数据中插入数据的​​已经在ora-01036发送给我的查询字符串中定义,我做错了。此外,id值本身是否自动递增

我的代码

import cx_Oracle
import pandas as pd

...
df2.to_dict(orient='records')
print(df2)

conn = cx_Oracle.connect(connection)
cur = conn.cursor()
id = 0
insert_qry = cur.execute("insert into customer_prf values(
'references',
:1,
'text',
'',
'',
:2,
:3,
2,
:4)"
   cursor.prepare(insert)

如何插入


Tags: 数据idnamestypenotcustomernullint

热门问题