Python通過(guò)調(diào)用mysql存儲(chǔ)過(guò)程實(shí)現(xiàn)更新數(shù)據(jù)功能示例
本文實(shí)例講述了Python通過(guò)調(diào)用mysql存儲(chǔ)過(guò)程實(shí)現(xiàn)更新數(shù)據(jù)功能。分享給大家供大家參考,具體如下:
一、需求分析
由于管理費(fèi)率配置錯(cuò)誤,生成訂單的還本付息表和訂單表的各種金額,管理費(fèi)之間的計(jì)算都有錯(cuò)誤,需要進(jìn)行數(shù)據(jù)訂正。為此,為了造個(gè)輪子,以后省很多功夫,全部用程序去修正,不接入人工。
二、帶參數(shù)mysql 存儲(chǔ)過(guò)程創(chuàng)建
1、更新訂單付息表(t_order_rapay)
drop procedure if exists update_t_order_rapay;
delimiter $$
create procedure update_t_order_rapay(IN orderNo varchar(64))
begin
declare t_order_no varchar(64);
set t_order_no=orderNo;
UPDATE t_order_repay
SET total_amount=principal+interest+round(manage_amount*0.0808/0.052,3)+breach_amount,
left_amount=principal+interest+round(manage_amount*0.0808/0.052,3)+breach_amount,
left_repay_manager=round(manage_amount*0.0808/0.052,3),
manage_amount=round(manage_amount*0.0808/0.052,3)
WHERE order_no=t_order_no;
end $$
delimiter;
2、更新訂單表(t_order_info)
drop procedure if exists update_t_order_info; delimiter $$ create procedure update_t_order_info(IN orderNo varchar(64)) begin declare t_order_no varchar(64); set t_order_no=orderNo; SELECT left_amount into @m1 from t_order_repay WHERE order_no=t_order_no ORDER BY plan_time LIMIT 1; UPDATE t_order_info set manage_cost_rate=0.0808, manage_cost=round(manage_cost*0.0808/0.052,3), left_amount=borrow_amount+interest_amount+manage_cost, next_amount_need=@m1 WHERE order_no=t_order_no; end $$ delimiter;
3、python 調(diào)用mysql 中的存儲(chǔ)過(guò)程
# encoding: utf-8
import time
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
time1 = time.time()
import pandas as pd
import pymysql
############################################從數(shù)據(jù)庫(kù)讀數(shù)據(jù)###########################################
###########線(xiàn)上######################
# 加上字符集參數(shù),防止中文亂碼
# conn=pymysql.connect(
# host="##########",
# database="######",
# user="####",
# password="##########",
# port=#######,
# charset='utf8'
# )
# #############測(cè)試庫(kù)######################
# ## 加上字符集參數(shù),防止中文亂碼
# conn=pymysql.connect(
# host="172.16.34.32",
# database="#########",
# user="admin",
# password="##############",
# port=#########,
# charset='utf8'
# )
#sql語(yǔ)句(安徽)
# sqlcmd="""
# SELECT order_no from t_order_info WHERE offline_org_no in(
# 0032,0035,0036
#
#
# ) and substr(create_time,1,10)>="2017-10-31"
#
# and `status` in(105,106,107,108)
#
# and manage_cost_rate=0.052
#
#
# """
#################sql語(yǔ)句(江蘇)
# sqlcmd2="""
# SELECT order_no from t_order_info WHERE offline_org_no in(
# 0002,0005,0006,0007,0008,0009,0010,0011,0012,0013,0014,0017,0018,0019,0025,0026,0027,0028,0030,0031,0033,0034
# ) and substr(create_time,1,10)>="2017-10-31"
# and `status` in(105,106,107,108)
# and manage_cost_rate=0.052
#
# """
#利用pandas 模塊導(dǎo)入mysql數(shù)據(jù)
# data=pd.read_sql(sqlcmd2,conn)
# print data
#
#
# ###################更新order_rapay表
# for each in data["order_no"]:
# print each
# # 創(chuàng)建游標(biāo)
# cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)
# #有參數(shù)存儲(chǔ)過(guò)程
# cursor.execute('call update_t_order_rapay(%s)',(each))
# conn.commit()
#
# print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
# #####################更新order_info表###################
# for each in data["order_no"]:
# print each
#
# # 創(chuàng)建游標(biāo)
# cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)
# #有參數(shù)存儲(chǔ)過(guò)程
# cursor.execute('call update_t_order_info(%s)', (each))
# conn.commit()
#
#
# cursor.close()
# print '調(diào)用存儲(chǔ)過(guò)程完畢................'
# conn.close()
# time2=time.time()
# print u'總共耗時(shí):' + str(time2 - time1) + 's'
更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《Python+MySQL數(shù)據(jù)庫(kù)程序設(shè)計(jì)入門(mén)教程》、《Python常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總》、《Python數(shù)學(xué)運(yùn)算技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門(mén)與進(jìn)階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。
相關(guān)文章
python利用tkinter實(shí)現(xiàn)圖片格式轉(zhuǎn)換的示例
這篇文章主要介紹了python利用tkinter實(shí)現(xiàn)圖片格式轉(zhuǎn)換,幫助大家更好的理解和使用python,感興趣的朋友可以了解下2020-09-09
python開(kāi)發(fā)之list操作實(shí)例分析
這篇文章主要介紹了python開(kāi)發(fā)之list操作方法,結(jié)合實(shí)例形式分析了list操作的具體用法與相關(guān)注意事項(xiàng),需要的朋友可以參考下2016-02-02
python使用pywinauto驅(qū)動(dòng)微信客戶(hù)端實(shí)現(xiàn)公眾號(hào)爬蟲(chóng)
這個(gè)項(xiàng)目是通過(guò)pywinauto控制windows(win10)上的微信PC客戶(hù)端來(lái)實(shí)現(xiàn)公眾號(hào)文章的抓取。代碼分成server和client兩部分。server接收client抓取的微信公眾號(hào)文章,并且保存到數(shù)據(jù)庫(kù)。另外server支持簡(jiǎn)單的搜索和導(dǎo)出功能。client通過(guò)pywinauto實(shí)現(xiàn)微信公眾號(hào)文章的抓取。2021-05-05
python之PyAutoGui教你做個(gè)自動(dòng)腳本計(jì)算器的方法
這篇文章主要介紹了python之PyAutoGui教你做個(gè)自動(dòng)腳本計(jì)算器的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03
Python?PySpark案例實(shí)戰(zhàn)教程
PySpark是由Spark官方開(kāi)發(fā)的Python語(yǔ)言第三方庫(kù),Python開(kāi)發(fā)者可以使用pip程序快速的安裝PySpark并像其它三方庫(kù)那樣直接使用,本文給大家介紹Python?PySpark案例實(shí)戰(zhàn),感興趣的朋友一起看看吧2023-09-09
Pandas多個(gè)條件(AND,OR,NOT)中提取行
本文主要介紹了Pandas多個(gè)條件(AND,OR,NOT)中提取行,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02
零基礎(chǔ)寫(xiě)python爬蟲(chóng)之使用urllib2組件抓取網(wǎng)頁(yè)內(nèi)容
文章詳細(xì)介紹了在python2.5環(huán)境下,如何使用urllib2這個(gè)python自帶的組件進(jìn)行抓取指定網(wǎng)頁(yè)內(nèi)容的,整個(gè)過(guò)程記錄的非常的詳細(xì),也很簡(jiǎn)單,有需要的朋友可以參考下,寫(xiě)出自己的python爬蟲(chóng)2014-11-11

