import os from subprocess import Popen,PIPE sqlplus = Popen(["sqlplus", "-S", "andy/root"], stdout=PIPE, stdin=PIPE) sqlplus.stdin.write("select sysdate from dual;"+os.linesep) sqlplus.stdin.write("insert into t_python values(1,‘chenlong‘);"+os.linesep) sqlplus.stdin.write("insert into t_python values(2,‘xiao‘);"+os.linesep) sqlplus.stdin.write("select count(*) from t_python;"+os.linesep) sqlplus0.stdin.write("select count(*) from emp;"+os.linesep) out, err = sqlplus.communicate() print out sqlplus0 = Popen(["sqlplus", "-S", "scott/root"], stdout=PIPE, stdin=PIPE) out0, err0 = sqlplus0.communicate() print out0
本文出自 “天空海阔” 博客,请务必保留此出处http://ether007.blog.51cto.com/8912105/1539652