我正在尝试根据分隔符解析sqlscript文件“;”然后调用Cx_Oracle连接并执行DB服务器上的语句。我遇到了与游标相关的代码块的问题。我的通话结构是:
ScriptHandle = open(filepath)
SqlScript = ScriptHandle.read()
SqlCommands = SqlScript.split(';')
for sqlcommand in SqlCommands:
print sqlcommand,'\n'*3
if sqlcommand:
ODBCCon.ExecuteWithCx_Oracle(cursor, sqlcommand)
我遇到的问题是以下sql块:
DECLARE CURSOR date_cur IS (select calendar_date
from cg_calendar dates
where dates.calendar_date between '30-Jun-2014' and '31-Jul-2015'
and global_business_or_holiday = 'B');
BEGIN
FOR date_rec in date_cur LOOP
insert into fc_pos
SELECT PP.acctid,
PP.mgrid,
PP.activitydt,
PP.secid,
PP.shrparamt,
PP.lclmktval,
PP.usdmktval,
SM.asset_name_1,
SM.asset_name_2,
SM.cg_sym,
SM.fc_local_crncy_cd,
SM.fc_local_crncy_id,
SM.fc_trade_cd,
substr(SM.asset_name_1, 17,3) as against_crncy_cd
FROM FC_acct_mgr AM, asset SM, ma_mktval PP
WHERE PP.dw_asset_id = SM.dw_asset_id
AND PP.secid = SM.asset_id
AND PP.activitydt = date_rec.calendar_date
AND AM.acctid = PP.acctid
AND AM.mgrid = PP.mgrid
AND SM.asset_categ_cd = 'FC';
END LOOP;
END;
上面的python解析步骤基于分隔符“;”解除了上述代码的关联。我需要将上面的内容视为从DECLARE开始并在END结束的一个块;
如何从python端完成它。我一直无法取得任何进展,这是我自动化的遗留流程。
提前致谢。