On 2021-11-25 12:58, Mr John wrote:
> thanks both of you
> I've created a stored procedure:
>
> create or alter procedure FnToBigin(num varchar(20))
> returns (result bigint)
> as
> declare i integer;
> declare res varchar(20);
>
> begin
>
> res='';
> result=null;
> i=1;
> while (i<=char_length(:num)) do
> begin
> if (substring(:num from i for 1) similar to '[[:DIGIT:]]') then
> res =res||substring(:num from i for 1);
> i=i+1;
> end
> if (res<>'') then result=cast(res as bigint);
> suspend;
> end
I would suggest using an extra local CHAR(1) variable to store the
result of the substring so you perform that only once instead of twice.
> and I use it:
>
> select max(res) from
> (SELECT (SELECT RESULT FROM FnToBigin(NRU)) as res FROM MYTABLE)
>
> I don't know about the performance over a big table,In this case I
> need also to run Max()
You may want to consider if it is worthwhile to add an extra column to
the table and populate it using an ON INSERT OR UPDATE trigger instead
of doing this on the fly. That really depends on how often you need to
do this though.
Mark