PostgreSQL 

PostgreSQL has a different syntax from MySQL for creating a function, but generally works the same way, as shown in the following query: 

CREATE FUNCTION hittinglevel(g_all SMALLINT)
RETURNS VARCHAR(10)
AS $hitlevel$
DECLARE hitlevel varchar(10);
BEGIN
IF g_all BETWEEN 0 and 10 THEN
SET hitlevel = 'barely any';
ELSEIF g_all BETWEEN 11 and 50 THEN
SET hitlevel = 'some';
ELSEIF g_all BETWEEN 51 and 100 THEN
SET hitlevel = 'many';
ELSEIF g_all > 100 THEN
SET hitlevel = 'tons';
END IF;
RETURN hitlevel;
END;
$hitlevel$
LANGUAGE plpgsql;

You can call the function and drop the function the same way that you do in MySQL. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.130.201