61 lines
1.1 KiB
SQL
61 lines
1.1 KiB
SQL
DELIMITER $$
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`accountNumberToIban`(
|
|
vAccount VARCHAR(20)
|
|
)
|
|
RETURNS varchar(4) CHARSET utf8mb3 COLLATE utf8mb3_general_ci
|
|
DETERMINISTIC
|
|
BEGIN
|
|
/**
|
|
* Calcula y genera el código IBAN correspondiente
|
|
* a un número de cuenta bancaria español.
|
|
*
|
|
* @param vAccount Número de cuenta bancaria
|
|
* @return vIban Código IBAN de 4 caracteres.
|
|
*/
|
|
DECLARE vIban VARCHAR(4);
|
|
|
|
SELECT
|
|
CONCAT('ES',
|
|
RIGHT(
|
|
CONCAT(0,
|
|
98-MOD(
|
|
CONCAT(
|
|
MOD(
|
|
CONCAT(
|
|
MOD(
|
|
CONCAT(
|
|
MOD(
|
|
SUBSTRING(vAccount, 1, 8),
|
|
97
|
|
),
|
|
SUBSTRING(vAccount,9,8)
|
|
),
|
|
97
|
|
),
|
|
SUBSTRING(
|
|
CONCAT(vAccount, 142800),
|
|
17,
|
|
8
|
|
)
|
|
),
|
|
97
|
|
),
|
|
SUBSTRING(
|
|
CONCAT(vAccount, 142800),
|
|
25,
|
|
2
|
|
)
|
|
),
|
|
97
|
|
)
|
|
),
|
|
2
|
|
)
|
|
) INTO vIban;
|
|
|
|
RETURN vIban;
|
|
END$$
|
|
DELIMITER ;
|
|
|
|
GRANT EXECUTE ON FUNCTION util.accountNumberToIban TO hr, financial;
|