如何返回存储过程的值

时间:2017-03-27 07:27:24

标签: mysql stored-procedures

CREATE PROCEDURE deleteDealer 
(**In dealerCode Varchar(100),In userId VARCHAR(100**))
BEGIN
  `UPDATE tbl_dealer SET status='INACTIVE' where dealerCode=dealerCode';
  `UPDATE tbl_dealer_contact SET status='INACTIVE' where dealerCode=dealerCode';
  'UPDATE tbl_login set status='INACTIVE' where userId=userId';


END;

这是我的程序如何返回布尔值 任何人都给我快速回答

4 个答案:

答案 0 :(得分:0)

您可以在过程中使用OUT参数来返回值。

CREATE PROCEDURE deleteDealer 
(In dealerCode Varchar(100),In userId VARCHAR(100), OUT result INT)
BEGIN
  `UPDATE tbl_dealer SET status='INACTIVE' where dealerCode=dealerCode';
  `UPDATE tbl_dealer_contact SET status='INACTIVE' where dealerCode=dealerCode';
  'UPDATE tbl_login set status='INACTIVE' where userId=(select userId from tbl_dealer_contact where dealerCode=dealerCode)';

   set result = 1; // your value
END;

打电话时,

call deleteDealer('dealerCode', 'userId', @result);

可以从

查看结果
select @result;

请尝试此选项。

答案 1 :(得分:0)

CREATE PROCEDURE deleteDealer 
(**In dealerCode Varchar(100),
In userId VARCHAR(100**))
BEGIN
  `UPDATE tbl_dealer SET status='INACTIVE' where dealerCode=dealerCode';
  `UPDATE tbl_dealer_contact SET status='INACTIVE' where dealerCode=dealerCode';
  'UPDATE tbl_login set status='INACTIVE' where userId=userId';


SELECT 1;

END;

答案 2 :(得分:0)

CREATE PROCEDURE deleteDealer 
(**In dealerCode Varchar(100),In userId VARCHAR(100**))
BEGIN
  `UPDATE tbl_dealer SET status='INACTIVE' where dealerCode=dealerCode';
  `UPDATE tbl_dealer_contact SET status='INACTIVE' where dealerCode=dealerCode';
  'UPDATE tbl_login set status='INACTIVE' where userId=userId';

  select 1;


END;

答案 3 :(得分:0)

public boolean deleteDealer(DealerDto dealerDto){         logger.info(" DealerDto> {}" + dealerDto)

final String procedureCall = "{call deleteDealer(?,?)}";


    logger.trace("procedure call funtion {}" + procedureCall);
    logger.info("get dealerCode"+dealerDto.getDealerCode());
    Connection connection = null;

    try {

        // Get Connection instance from dataSource
        connection = dataSource.getConnection();
        CallableStatement callableSt = connection.prepareCall(procedureCall);

        callableSt.setString("dealerCode", dealerDto.getDealerCode());
        logger.info("dealerCode"+dealerDto.getDealerCode());
        callableSt.registerOutParameter("result", Types.INTEGER);

        // Call Stored Procedure
        callableSt.executeUpdate();

        if( callableSt.getInt("result")==1){
            return true;
        }
        return false;
    } catch (SQLException e) {
        return false;
    }

}