oracle - How to insert a value with '&' in sqlplus with python -
import urllib import requests bs4 import * subprocess import popen,pipe import os connectstring = 'system/mediadot123' def runsqlquery(sqlcommand, connectstring): session = popen(['sqlplus', '-s', connectstring], stdin=pipe, stdout=pipe, stderr=pipe) session.stdin.write(sqlcommand) return session.communicate() session = popen(['c:\\app\khize_000\product\\11.2.0\dbhome_1\bin\sqlplus.exe','-s','hr/hr'], stdin=pipe, stdout=pipe, stderr=pipe) stdout, stderr = session.communicate() sqlcommand = "set define off;" queryresult, errormessage = runsqlquery(sqlcommand, connectstring) print queryresult titledb = "retrieved somewhere else & in it" sqlcommand = "insert food(title) values ('" + str(titledb.encode('utf-8')) + "');" queryresult, errormessage = runsqlquery(sqlcommand, connectstring) print queryresult
i saw 'set define off' query on oracle website not working me code. working in command line not here. gives me following error:
bacon, potato & egg breakfast casserole
enter value egg:
sp2-0546: user requested interrupt or eof detected.
the set define off
command not persist between sqlplus sessions. each time call runsqlquery
opening new instance of sqlplus. need execute set define off
in same session actual insert command have desired effect.
if confident won't ever need substitution functionality in context, send command sqlplus in runsqlquery
function, before sending statement passed parameter.
you redesign entire logic keep single sqlplus session open , write multiple commands it.
or, locate proper library connecting directly oracle python, rather executing external sqlplus process.
Comments
Post a Comment