[英]How to use oracle sequence in Python dataframe - Python (Pandas)
I have a sequence in oracle that I want to use to insert my data from a data frame in Python into an oracle database.我在 oracle 中有一个序列,我想用它来将我的数据从 Python 的数据框中插入到 oracle 数据库中。 I have already a sequence in oracle that I want to use.
我已经在 oracle 中有一个想要使用的序列。
I have a python data frame below that I want to consider a specific column as "ID" in order to put sequence:我在下面有一个 python 数据框,我想将特定列视为“ID”以便放置序列:
ID ![]() |
Name![]() |
NN![]() |
---|---|---|
1 ![]() |
Sara![]() |
1234 ![]() |
2 ![]() |
Mina![]() |
6547 ![]() |
I have already a sequence in oracle which I call "SQ_test"我已经在 oracle 中有一个序列,我称之为“SQ_test”
PS: I found how to create the sequence but I do not know how to use that or use that in my panda's data frame. PS:我找到了如何创建序列,但我不知道如何使用它或在我的熊猫数据框中使用它。 here is the function that I can use:
这是我可以使用的 function:
def get_change_id():
id = cursor.var(cx_Oracle.NUMBER)
sql_query_sq = """
BEGIN
:next_id := SQ_TEST.nextval;
END;
"""
cursor.execute(sql_query, {"next_id":id})
change_id = id.getvalue()
return change_id
I found a way to create a sequence by creating a table, after that whenever I want to insert my, automatically sequences are created and inserted in their column.我找到了一种通过创建表来创建序列的方法,之后每当我想插入我的序列时,就会自动创建序列并将其插入到它们的列中。 How: When I create my table when I consider the type of my column, I also write down the sequence creation, Like this:
如何:当我在考虑列的类型时创建表时,我还会记下序列创建,如下所示:
CREATE TABLE TABLE_NAME
(
ID NUMBER(38,0) generated by default as identity primary key,
...
);
We need to be careful that till we insert the data into a table, the sequence will be continued, but if we want to restart the sequence, we need to drop the table.我们需要注意的是,直到我们将数据插入到表中,序列才会继续,但是如果我们想重新开始序列,我们需要删除表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.