Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
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 AI support!

Copy Clear