如何在oracle过程中使用python变量作为动态变量



I have sql procedure and I have some python variables I want to run this procedure along with using this variables as dynamic

`  I have sql procedure and I have some python variables I want to run this procedure along with using this variables as dynamic ` 
CREATRE OR REPLACE PROCEDUE SQURT_EN_UR(
v_ere       IN MIGRATE_CI_RF %TYPE,
V_efr       IN MIGRATE_CI_ID%TYPE,
v_SOS       IN MIGRATE_CI_NM %TYPE,
V_DFF       IN MIGRATE_CI_RS%TYPE, )
BEGIN
UPDATE MIGRATE_CI
SET RF= v_ere 
ID=V_efr  ///I WANT YOU VARIABLE HERE 
NM= v_SOS   ///I WANT YOU VARIABLE HERE
RS= V_DFF ///I WANT YOU VARIABLE HERE
WHERE CO_ID=V_efr_id;
if(sql%rowcount=0)
THEN
INSERT INTO MIGRATE_CI 
(ere,
efr,
SOS,
DFF,
VALUES(v_ere ,
V_efr,
v_SOS,       
V_DFF,
upper(assign_tr),
upper(assign_mod),
END IF;
END SP_MIGRATIE_DE;
/
`i want to create a function like this to use my varablie as dynamic ones in procedure`
try:
# create a connection to the Oracle Database
with cx_Oracle.connect(cfg.username,
cfg.password,
cfg.dsn,
encoding=cfg.encoding) as connection:
# create a new cursor
with connection.cursor() as cursor:

# call the stored procedure
cursor.callproc('SQURT_EN_UR')
return cursor.callproc('SQURT_EN_UR')
except cx_Oracle.Error as error:
print(error)
#my variables is 
V_efr ="r55" #I WANT YOU VARIABLE HERE 
NM= "dree"   #I WANT YOU VARIABLE HERE
RS= "ssyt" #I WANT YOU VARIABLE HERE

您可以直接将参数传递给过程,如下所示:

cursor.callproc("SQURT_EN_UR", [arg1, arg2, arg3, arg4])

将arg1、arg2、arg3和arg4的值替换为您自己的变量名或常量——无论您需要什么!

最新更新