0
我想聲明一個變量,然後爲該特定變量分配一個select查詢的值,然後我需要在insert
語句中傳遞該變量。所以,我想下面的代碼,如何在mysql中聲明變量存儲過程?
DROP PROCEDURE IF EXISTS `pro_damagestockdao` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `pro_damagestockdao`(
IN damage_date date,
IN damage_inv_no varchar(12),
IN damage_inv_date date,
IN damage_dist_name varchar(30),
IN damage_contact_no varchar(15),
IN damage_item_code varchar(30),
IN damage_item_name varchar(30),
IN damage_batch_no varchar(15),
IN damage_mfr_name varchar(50),
IN damage_expiry_date date,
IN damage_pur_qty int(11),
IN damage_qty int(11),
IN damage_unit_price double(10,2),
IN damage_unit_vat double(4,2),
IN damage_unit_discount double(4,2),
IN damage_sub_total double(10,2),
IN damage_total_amount double(10,2),
IN damage_remarks varchar(1000),
IN functionality varchar(20),
out flag int
)
BEGIN
DECLARE selCnt int;
DECLARE dqty int;
SET dqty = (SELECT free FROM purchase_invoice p WHERE p.invoice_no = damage_inv_no);
DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK;
SET flag=0;
START TRANSACTION;
if(functionality='save') then
INSERT INTO damage_stocks
(damage_stock_date,invoice_no,invoice_date,dist_name,contact_no,item_code,item_name,batch_no,qty,damaged_qty,unit_price,unit_vat,unit_discount,sub_total,total_amount,remarks) VALUES
(damage_date,damage_inv_no,damage_inv_date,damage_dist_name,damage_contact_no,0,damage_item_name,damage_batch_no,dqty,damage_qty,damage_unit_price,damage_unit_vat,damage_unit_discount,damage_sub_total,damage_total_amount,damage_remarks);
但它沒有。你看,我聲明的變量dqty
,然後我把它傳遞給insert
聲明。
使用從purchase_invoice中免費輸入dqty ... –