#14 Functions And Procedures
#14.0 Introduction
Functions & Procedure - database object로 특정 작업을 수행하는 SQL 구문을 세트로 캡슐화 가능
#14.1 Functions
CREATE OR REPLACE FUNCTION hello_world() -- funcion은 value를 return함
RETURNS text AS
$$ -- BODY
SELECT 'hello_world';
$$
LANGUAGE SQL; -- 언어
SELECT title, hello_world() FROM movies;
CREATE OR REPLACE FUNCTION hello_world(user_name text)
RETURNS text AS
$$ -- BODY
SELECT 'hello ' || user_name;
$$
LANGUAGE SQL;
SELECT title, hello_world('nico') FROM movies;
SELECT title, hello_world() FROM movies; -- 실행시 위의 hello_world()가 실행된다
DROP FUNCTION hello_world(); -- 삭제
CREATE OR REPLACE FUNCTION hello_world(text, text) -- parameter
RETURNS text AS
$$ -- BODY
SELECT 'hello ' || $1 || ' and ' || $2;
$$
LANGUAGE SQL;
SELECT hello_world('kim', 'son');#14.2 Return Types
#14.3 Trigger Functions
#14.4 Procedures
#14.5 Python Extension
Last updated
Was this helpful?