[Python] Set echo ON in Python call to Oracle SQL is not working

Discussão em 'Python' iniciado por Stack, Agosto 16, 2025.

  1. Stack

    Stack Membro Participativo

    I am beginner in Python, I am trying to access an Oracle database from my Python program. I am able to get the output with the code shown here. However, I want the SQL query which I ran along with the output. I am only getting the output. I tried 'set echo on' but it's not working. Please help me.

    #!/usr/bin/python

    ## Imports
    from subprocess import Popen, PIPE
    import os
    import sys

    sql1='set echo ON; \n select name from v$database;'
    sqlplus = Popen(["sqlplus", "-S", "/", "as", "sysdba"], stdout=PIPE, stdin=PIPE)
    sqlplus.stdin.write(sql1);

    out, err = sqlplus.communicate()
    print out


    Current Output:

    =================
    Execution Details:
    ===========
    ./test_db.py
    NAME
    ---------
    testdb


    I want the SQL query also to be printed along with output as below

    Continue reading...

Compartilhe esta Página