Created
January 23, 2014 09:20
-
-
Save pokoli/8575512 to your computer and use it in GitHub Desktop.
PostgreSQL Function to calculate IBAN the given a Spanish Acount Number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE OR REPLACE FUNCTION calculate_iban(account varchar) | |
| RETURNS varchar AS $$ | |
| DECLARE num numeric; | |
| DECLARE DC varchar(2); | |
| BEGIN | |
| SELECT CAST(replace(account, ' ', '')|| '142800' AS numeric) INTO num; | |
| SELECT LPAD(CAST(98 - MOD(num, 97) AS varchar(2)), 2, '0') INTO DC; | |
| RETURN 'ES' || DC || replace(account, ' ', ''); | |
| END; | |
| $$ LANGUAGE plpgsql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment