代码语言:javascript复制
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