To day i was struggling to catch a error inside a stored procedure using MySQL. Faced lot of difficulties and still not found good result. There is no equal function in MySql to RAISERROR in MSSQL.
As a solution for this what we can we do is, we can call a function as this way
CALL RaiseError();
There for because of the none existence of this function this will be raise an error.
So it is very logical..:-)
So procedure will be work very fine.....Great...
Example:
DROP PROCEDURE IF EXISTS `dbname`.`procedureName` $$
CREATE DEFINER=`root`@`%` PROCEDURE `edbname`.`procedureName`(
pId bigint,
pName varchar(50)
BEGIN
IF EXISTS
(SELECT
1
FROM
tableName
WHERE
((Id = pId)
)
THEN
UPDATE
tableName
SET
Name = pName,
WHERE
(Id = pId);
ELSE
CALL RaiseError();
/*There is no RaiseError metho in MySql.
Because of that reason here call nonexistent method which is 'RaiseError()'.There for this will produce an error*/
END IF;
END $$
DELIMITER ;
As a solution for this what we can we do is, we can call a function as this way
CALL RaiseError();
There for because of the none existence of this function this will be raise an error.
So it is very logical..:-)
So procedure will be work very fine.....Great...
Example:
DROP PROCEDURE IF EXISTS `dbname`.`procedureName` $$
CREATE DEFINER=`root`@`%` PROCEDURE `edbname`.`procedureName`(
pId bigint,
pName varchar(50)
BEGIN
IF EXISTS
(SELECT
1
FROM
tableName
WHERE
((Id = pId)
)
THEN
UPDATE
tableName
SET
Name = pName,
WHERE
(Id = pId);
ELSE
CALL RaiseError();
/*There is no RaiseError metho in MySql.
Because of that reason here call nonexistent method which is 'RaiseError()'.There for this will produce an error*/
END IF;
END $$
DELIMITER ;
Comments