Code Listing 5: Creating a DUAL-like table

 1  CREATE TABLE onerow (dummy VARCHAR2(1))
 2  /
 3  GRANT SELECT ON onerow TO PUBLIC
 4  /
 5  CREATE PUBLIC SYNONYM onerow FOR onerow
 6  /
 7  CREATE OR REPLACE TRIGGER enforce_onerow
 8     BEFORE INSERT
 9     ON onerow
10  DECLARE
11     PRAGMA AUTONOMOUS_TRANSACTION;
12     l_count PLS_INTEGER;
13  BEGIN
14     SELECT COUNT (*)
15       INTO l_count
16       FROM onerow;
17   
18     IF l_count = 1
19     THEN
20        raise_application_error
21                        (-20000
22                       , 'The onerow table can have only one row.'
23                        );
24     END IF;
25  END;
26 /