将null值传递给Mysql中的存储过程

时间:2014-02-11 07:54:22

标签: mysql stored-procedures sqlyog

我在Mysql中创建一个存储过程。如何传递接受null的值?

我知道在SQL Server 2008 R2中,我确实喜欢这个

@name varchar(10) = null

但我怎么能在Mysql中做到这一点?

    DELIMITER $$
         CREATE PROCEDURE `ipm_website`.`uspInsertFuelBuyDetails`( promotion_code VARCHAR(45)=NULL,eventid INT,Erid INT, first_name VARCHAR(255)=NULL,last_Name)
     BEGIN
       INSERT INTO ipm_fuel.TBL_EVENT_PAYMENTS 
      (promotion_code, EVENT_ID, EVENT_RATE_ID, FIRST_NAME, LAST_NAME, PHONE_NUMBER, EMAIL, ADDRESS1, ADDRESS2,
       CITY, STATE, ZIPCODE, card_type, card_number, exmonth, exyear, total_amount,
        admin_fee, license_plate, guid, date_added) 
VALUES (promotion_code, eventid, Erid ,first_name ,last_Name ,phoneNo , email, address1, address2, city , state, ZIPCODE, card_type, card_no, exmonth, exyear, total_amount, admin_fee, licanse_plate,
         guid, date_added);
       END$$
    DELIMITER ;

我该怎么做,以及如何在参数中允许空值?

1 个答案:

答案 0 :(得分:2)

在您的查询中,无需传递 NULL ,您只需跳过要在insert子句中放置 NULL 的列。