Last active
March 25, 2022 14:55
-
-
Save BirgittaHauser/42a2bb0afdb054dbaa0dace9be53fe9e to your computer and use it in GitHub Desktop.
Check String for numeric values
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 Function YourSchema/Checknum (Parstring Varchar(32)) | |
Returns Integer | |
Language Sql | |
Modifies Sql Data | |
Deterministic | |
Called On Null Input | |
Secured | |
Begin | |
Declare LocNum Decimal(31, 9) Not NUll Default 0; | |
Declare Continue Handler For SQLException Return -1; | |
Set LocNum = Cast(ParString as Dec(31, 9)); | |
Return 0; | |
End; | |
Label On Routine YourSchema/Checknum(Varchar()) | |
Is 'Check Numeric Values'; | |
Comment On Parameter Routine YourSchema/Checknum (Varchar()) | |
(Parstring Is 'String to be checked'); | |
commit; | |
/* Test */ | |
With x (String) as (Values('12345'), ('-32,456'), ('0,23456'), ('-0,1000'), ('ABCD'), ('XYU')) | |
Select String, CheckNum(String) | |
from x; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In case anyone gets an error when trying to create this function like I did:
The Secured attribute requires authority to Database Security Administrator Functions (QIBM_DB_SECADM).
Our system has the function usage for this as:
Default authority = *DENIED
*ALLOBJ specify authority = *NOTUSED
You have four options: