您好,登錄后才能下訂單哦!
目的:刪除數據庫各個系統his庫里的測試soe與故障數據;
一、sql執行錯誤:
執行sql:SELECT FROM SOE WHERE sDevCode = 012400000001
報錯:
[SQL Server]將 varchar 轉換為數據類型 numeric 時出現算術溢出錯誤。
原因:查看表設計,sDevCode列的類型為varchar(字符串),
修改:SELECT FROM SOE WHERE sDevCode = '012400000001' 。
二、腳本;
import os
import pymssql
import pprint
sql_name = [
qqqqq
]
print('****程序正在啟動****')
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
os.environ['NLS_LANG'] = 'AMERICAN_AMERICA.AL32UTF8'
for SJK in sql_name:
IP_HIS = SJK[0] # 獲取數據庫IP
us_HIS = SJK[1]
PW_HIS= SJK[2]
HIS = SJK[3]
print(HIS)
conn = pymssql.connect(host=IP_HIS, user=us_HIS, password=PW_HIS, database=HIS)
cur1 = conn.cursor()
check_sql1 = "DELETE FROM SOE WHERE sDevCode = '012400000001'"
cur1.execute(check_sql1)
cur2 = conn.cursor()
check_sql2 = "DELETE FROM Fault_Record WHERE LOWER(sLineName) LIKE '%cs%' or sLineName LIKE '%測試%' or sLineName LIKE '%模擬%'"
cur2.execute(check_sql2)
conn.close()
解析:主要在sql上,
DELETE FROM Fault_Record WHERE LOWER(sLineName) LIKE '%cs%' or sLineName LIKE '%測試%' or sLineName LIKE '%模擬%
其中,模糊查詢用like ,忽略大小寫用lower或者upper都可以。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。