---------------- 오라클 예제 ---------------
CREATE TABLE EMP (
SABUN NUMBER,
SAL NUMBER,
BONUS NUMBER,
TOTAL_SAL NUMBER GENERATED ALWAYS AS (sal*12 + bonus)
);
insert into emp(sabun, sal,bonus) values(1,3000,200);
select * from emp;
SABUN SAL BONUS TOTAL_SAL
---------- ---------- ---------- ----------
1 3000 200 36200
-----------------------------------------------------------------------------------
PostgreSQL 과 EPAS 는 아래와 같이 위 기능을 구현할수 있습니다.
CREATE TABLE EMP (
SABUN NUMBER,
SAL NUMBER,
BONUS NUMBER
);
CREATE FUNCTION TOTAL_SAL(EMP) RETURNS number AS $$
SELECT $1.sal*12 + $1.bonus
$$ LANGUAGE SQL;
insert into emp(sabun, sal,bonus) values(1,3000,200);
select * from emp;
+-------+------+-------+
| sabun | sal | bonus |
+-------+------+-------+
| 1 | 3000 | 200 |
+-------+------+-------+
(1 row)
select a.*, a.total_sal from emp a;
+-------+------+-------+-----------+
| sabun | sal | bonus | total_sal |
+-------+------+-------+-----------+
| 1 | 3000 | 200 | 36200 |
+-------+------+-------+-----------+
(1 row)