使用 pymssql 調用存儲過程


import pymssql

DBHOST = '127.0.0.1'
DBUSER = 'sa'
DBPASS = 'test'
DBNAME = 'test'

def retrieve():
    try:
        db = pymssql.connect(DBHOST, DBUSER, DBPASS, DBNAME)
        cur = db.cursor()

        cur.callproc('stored procedure name',('test0008','test','test','test','2020-10-14'))
        # cur.execute("exec P_ChangeLastStatus @BARCODE='test0004',@ACTIVITY='test',@COMMENT='test',@DETAIL_ACTIVITY='test',@CREATE_TIME='2020-10-14'")
        cur.nextset()  #獲取返回值
        results = cur.fetchall() #獲取返回值 
     db.commit()
     cur.close() d
     b.close()
    
print(results)

  except pymssql.Error as e: print('數據庫連接失敗'+str(e)) return "error"
retrieve()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM