SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table test(num text); insert into test values('6'),('70'),('4,1'),('342'),('5'),('30.84'),('98'),('78'),('Отриц.'),('95.3'),('4'),('67'),('14'),('1,4'),('5'),('42'),('3'),('-'),('398'),('347'),('0,3'),('26'),('Положит.'),('0'),('5'),('4'),('+'),('3'),('6'),('202'),('0'),('Положительно'),('40'),('2'),('20'),('91'),('Отр'); CREATE OR REPLACE FUNCTION tonum(num text) RETURNS numeric LANGUAGE plpgsql AS $$ DECLARE BEGIN BEGIN return regexp_replace(coalesce(num, '0'), '[^0-9,]+', '')::numeric; EXCEPTION WHEN OTHERS THEN return 0; END; END; $$; select tonum(num) from test;
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear