CREATE GLOBAL TEMPORARY TABLE ACTION_LIST
(
  ACTION_ID NUMBER NOT NULL,
  ACTION    T_ACTION NOT NULL
)
ON COMMIT DELETE ROWS;

ALTER TABLE ACTION_LIST  
  ADD CONSTRAINT PK_ACTION_LIST PRIMARY KEY (ACTION_ID);

COMMENT ON TABLE action_list IS 'System object actions queue';
COMMENT ON COLUMN action_list.action_id IS 'Action identifier';
COMMENT ON COLUMN action_list.action IS 'Action (any object under t_action)';

CREATE SEQUENCE s_action_id;

CREATE OR REPLACE TRIGGER ti_action_list_id 
  BEFORE INSERT ON action_list
  FOR EACH ROW
BEGIN
  /* autoincrement identifier of action */
  SELECT s_action_id.NEXTVAL INTO :NEW.action_id FROM dual;
END TI_ACTION_LIST_ID;
/

create sequence S_MDB_REPORT
minvalue 1
maxvalue 999999999999999999999999999
start with 1
increment by 1
cache 20;
/

CREATE FUNCTION SID RETURN NUMBER IS
  RESULT$ NUMBER;
BEGIN
  SELECT SID INTO RESULT$ FROM V$MYSTAT WHERE ROWNUM = 1;
  RETURN(RESULT$);
END;
/

alter table ACTION_LIST add DOCUMENT_ID number
/
 
create index INX_DOCUMENT_ID on ACTION_LIST (document_id)
/
