- 정보공유
[SQL] mysql 사용자 함수 생성
-------------------------------------------------------------------------------
DELIMITER $$
DROP FUNCTION IF EXISTS FNC_GET_CATEGORY_NAME;
CREATE FUNCTION FNC_GET_CATEGORY_NAME(
ix INT,
flag TINYINT(4)
) RETURNS VARCHAR(100)
BEGIN
DECLARE CATEGORY_NAME VARCHAR(100);
SET CATEGORY_NAME = '';
SELECT dvc_text
INTO CATEGORY_NAME
FROM category_table
WHERE cate_ix = ix
AND cate_flag = flag;
RETURN CATEGORY_NAME;
END $$
DELIMITER ;
-------------------------------------------------------------------------------
# 사용방법
SELECT FNC_GET_CATEGORY_NAME(column1, 1) AS str, column2 FROM info_table
# 아래는 오류
SELECT FNC_GET_CATEGORY_NAME(column1, 1) AS str, * FROM info_table