/******************************************************************************/
/***           Generated by IBExpert 2.5.0.22 07/03/2003 18:57:49           ***/
/******************************************************************************/



/******************************************************************************/
/***                                Domains                                 ***/
/******************************************************************************/
SET SQL DIALECT 3;

CREATE DATABASE '..\..\..\bin\Data\employee.gdb' USER 'SYSDBA' PASSWORD 'masterkey' DEFAULT CHARACTER SET WIN1252;

CREATE DOMAIN ADDRESSLINE AS
VARCHAR(30) CHARACTER SET NONE;

CREATE DOMAIN BUDGET AS
NUMERIC(15,2)
DEFAULT 50000
CHECK (VALUE > 10000 AND VALUE <= 2000000);

CREATE DOMAIN COUNTRYNAME AS
VARCHAR(15) CHARACTER SET NONE;

CREATE DOMAIN CUSTNO AS
INTEGER
CHECK (VALUE > 1000);

CREATE DOMAIN DEPTNO AS
CHAR(3) CHARACTER SET NONE
CHECK (VALUE = '000' OR (VALUE > '0' AND VALUE <= '999') OR VALUE IS NULL);

CREATE DOMAIN EMPNO AS
SMALLINT;

CREATE DOMAIN FIRSTNAME AS
VARCHAR(15) CHARACTER SET NONE;

CREATE DOMAIN JOBCODE AS
VARCHAR(5) CHARACTER SET NONE
CHECK (VALUE > '99999');

CREATE DOMAIN JOBGRADE AS
SMALLINT
CHECK (VALUE BETWEEN 0 AND 6);

CREATE DOMAIN LASTNAME AS
VARCHAR(20) CHARACTER SET NONE;

CREATE DOMAIN PHONENUMBER AS
VARCHAR(20) CHARACTER SET NONE;

CREATE DOMAIN PONUMBER AS
CHAR(8) CHARACTER SET NONE
CHECK (VALUE STARTING WITH 'V');

CREATE DOMAIN PRODTYPE AS
VARCHAR(12) CHARACTER SET NONE
DEFAULT 'software'
NOT NULL
CHECK (VALUE IN ('software', 'hardware', 'other', 'N/A'));

CREATE DOMAIN PROJNO AS
CHAR(5) CHARACTER SET NONE
CHECK (VALUE = UPPER (VALUE));

CREATE DOMAIN SALARY AS
NUMERIC(15,2)
DEFAULT 0
CHECK (VALUE > 0);



/******************************************************************************/
/***                               Generators                               ***/
/******************************************************************************/

CREATE GENERATOR CUST_NO_GEN;
SET GENERATOR CUST_NO_GEN TO 1015;

CREATE GENERATOR EMP_NO_GEN;
SET GENERATOR EMP_NO_GEN TO 145;



/******************************************************************************/
/***                               Exceptions                               ***/
/******************************************************************************/

CREATE EXCEPTION CUSTOMER_CHECK 'Overdue balance -- can not ship.';

CREATE EXCEPTION CUSTOMER_ON_HOLD 'This customer is on hold.';

CREATE EXCEPTION ORDER_ALREADY_SHIPPED 'Order status is "shipped."';

CREATE EXCEPTION REASSIGN_SALES 'Reassign the sales records before deleting this employee.';

CREATE EXCEPTION UNKNOWN_EMP_ID 'Invalid employee number or project id.';



SET TERM ^ ; 



/******************************************************************************/
/***                           Stored Procedures                            ***/
/******************************************************************************/

CREATE PROCEDURE ADD_EMP_PROJ (
    EMP_NO SMALLINT,
    PROJ_ID CHAR(5) CHARACTER SET NONE)
AS
BEGIN
  EXIT;
END^


CREATE PROCEDURE ALL_LANGS
RETURNS (
    CODE VARCHAR(5) CHARACTER SET NONE,
    GRADE VARCHAR(5) CHARACTER SET NONE,
    COUNTRY VARCHAR(15) CHARACTER SET NONE,
    LANG VARCHAR(15) CHARACTER SET NONE)
AS
BEGIN
  EXIT;
END^


CREATE PROCEDURE DELETE_EMPLOYEE (
    EMP_NUM INTEGER)
AS
BEGIN
  EXIT;
END^


CREATE PROCEDURE DEPT_BUDGET (
    DNO CHAR(3) CHARACTER SET NONE)
RETURNS (
    TOT NUMERIC(15,2))
AS
BEGIN
  EXIT;
END^


CREATE PROCEDURE GET_EMP_PROJ (
    EMP_NO SMALLINT)
RETURNS (
    PROJ_ID CHAR(5) CHARACTER SET NONE)
AS
BEGIN
  EXIT;
END^


CREATE PROCEDURE MAIL_LABEL (
    CUST_NO INTEGER)
RETURNS (
    LINE1 CHAR(40) CHARACTER SET NONE,
    LINE2 CHAR(40) CHARACTER SET NONE,
    LINE3 CHAR(40) CHARACTER SET NONE,
    LINE4 CHAR(40) CHARACTER SET NONE,
    LINE5 CHAR(40) CHARACTER SET NONE,
    LINE6 CHAR(40) CHARACTER SET NONE)
AS
BEGIN
  EXIT;
END^


CREATE PROCEDURE ORG_CHART
RETURNS (
    HEAD_DEPT CHAR(25) CHARACTER SET NONE,
    DEPARTMENT CHAR(25) CHARACTER SET NONE,
    MNGR_NAME CHAR(20) CHARACTER SET NONE,
    TITLE CHAR(5) CHARACTER SET NONE,
    EMP_CNT INTEGER)
AS
BEGIN
  EXIT;
END^


CREATE PROCEDURE SHIP_ORDER (
    PO_NUM CHAR(8) CHARACTER SET NONE)
AS
BEGIN
  EXIT;
END^


CREATE PROCEDURE SHOW_LANGS (
    CODE VARCHAR(5) CHARACTER SET NONE,
    GRADE SMALLINT,
    CTY VARCHAR(15) CHARACTER SET NONE)
RETURNS (
    LANGUAGES VARCHAR(15) CHARACTER SET NONE)
AS
BEGIN
  EXIT;
END^


CREATE PROCEDURE SUB_TOT_BUDGET (
    HEAD_DEPT CHAR(3) CHARACTER SET NONE)
RETURNS (
    TOT_BUDGET NUMERIC(15,2),
    AVG_BUDGET NUMERIC(15,2),
    MIN_BUDGET NUMERIC(15,2),
    MAX_BUDGET NUMERIC(15,2))
AS
BEGIN
  EXIT;
END^



SET TERM ; ^


/******************************************************************************/
/***                                 Tables                                 ***/
/******************************************************************************/

CREATE TABLE COUNTRY (
    COUNTRY   COUNTRYNAME NOT NULL,
    CURRENCY  VARCHAR(10) CHARACTER SET NONE NOT NULL
);


CREATE TABLE CUSTOMER (
    CUST_NO         CUSTNO NOT NULL,
    CUSTOMER        VARCHAR(25) CHARACTER SET NONE NOT NULL,
    CONTACT_FIRST   FIRSTNAME,
    CONTACT_LAST    LASTNAME,
    PHONE_NO        PHONENUMBER,
    ADDRESS_LINE1   ADDRESSLINE,
    ADDRESS_LINE2   ADDRESSLINE,
    CITY            VARCHAR(25) CHARACTER SET NONE,
    STATE_PROVINCE  VARCHAR(15) CHARACTER SET NONE,
    COUNTRY         COUNTRYNAME,
    POSTAL_CODE     VARCHAR(12) CHARACTER SET NONE,
    ON_HOLD         CHAR(1) CHARACTER SET NONE DEFAULT NULL
);


CREATE TABLE DEPARTMENT (
    DEPT_NO     DEPTNO NOT NULL,
    DEPARTMENT  VARCHAR(25) CHARACTER SET NONE NOT NULL,
    HEAD_DEPT   DEPTNO,
    MNGR_NO     EMPNO,
    BUDGET      BUDGET,
    LOCATION    VARCHAR(15) CHARACTER SET NONE,
    PHONE_NO    PHONENUMBER DEFAULT '555-1234'
);


CREATE TABLE EMPLOYEE (
    EMP_NO       EMPNO NOT NULL,
    FIRST_NAME   FIRSTNAME NOT NULL,
    LAST_NAME    LASTNAME NOT NULL,
    PHONE_EXT    VARCHAR(4) CHARACTER SET NONE,
    HIRE_DATE    DATE DEFAULT 'NOW' NOT NULL,
    DEPT_NO      DEPTNO NOT NULL,
    JOB_CODE     JOBCODE NOT NULL,
    JOB_GRADE    JOBGRADE NOT NULL,
    JOB_COUNTRY  COUNTRYNAME NOT NULL,
    SALARY       SALARY NOT NULL,
    FULL_NAME    COMPUTED BY (last_name || ', ' || first_name)
);


CREATE TABLE EMPLOYEE_PROJECT (
    EMP_NO   EMPNO NOT NULL,
    PROJ_ID  PROJNO NOT NULL
);


CREATE TABLE JOB (
    JOB_CODE         JOBCODE NOT NULL,
    JOB_GRADE        JOBGRADE NOT NULL,
    JOB_COUNTRY      COUNTRYNAME NOT NULL,
    JOB_TITLE        VARCHAR(25) CHARACTER SET NONE NOT NULL,
    MIN_SALARY       SALARY NOT NULL,
    MAX_SALARY       SALARY NOT NULL,
    JOB_REQUIREMENT  BLOB SUB_TYPE 1 SEGMENT SIZE 400,
    LANGUAGE_REQ     VARCHAR(15) [1:5] CHARACTER SET NONE
);


CREATE TABLE PROJ_DEPT_BUDGET (
    FISCAL_YEAR       INTEGER NOT NULL,
    PROJ_ID           PROJNO NOT NULL,
    DEPT_NO           DEPTNO NOT NULL,
    QUART_HEAD_CNT    INTEGER [1:4],
    PROJECTED_BUDGET  BUDGET
);


CREATE TABLE PROJECT (
    PROJ_ID      PROJNO NOT NULL,
    PROJ_NAME    VARCHAR(20) CHARACTER SET NONE NOT NULL,
    PROJ_DESC    BLOB SUB_TYPE 1 SEGMENT SIZE 800,
    TEAM_LEADER  EMPNO,
    PRODUCT      PRODTYPE
);


CREATE TABLE SALARY_HISTORY (
    EMP_NO          EMPNO NOT NULL,
    CHANGE_DATE     DATE DEFAULT 'NOW' NOT NULL,
    UPDATER_ID      VARCHAR(20) CHARACTER SET NONE NOT NULL,
    OLD_SALARY      SALARY NOT NULL,
    PERCENT_CHANGE  DOUBLE PRECISION DEFAULT 0 NOT NULL,
    NEW_SALARY      COMPUTED BY (old_salary + old_salary * percent_change / 100)
);


CREATE TABLE SALES (
    PO_NUMBER     PONUMBER NOT NULL,
    CUST_NO       CUSTNO NOT NULL,
    SALES_REP     EMPNO,
    ORDER_STATUS  VARCHAR(7) CHARACTER SET NONE DEFAULT 'new' NOT NULL,
    ORDER_DATE    DATE DEFAULT 'NOW' NOT NULL,
    SHIP_DATE     DATE,
    DATE_NEEDED   DATE,
    PAID          CHAR(1) CHARACTER SET NONE DEFAULT 'n',
    QTY_ORDERED   INTEGER DEFAULT 1 NOT NULL,
    TOTAL_VALUE   NUMERIC(9,2) NOT NULL,
    DISCOUNT      FLOAT DEFAULT 0 NOT NULL,
    ITEM_TYPE     PRODTYPE,
    AGED          COMPUTED BY (ship_date - order_date)
);


CREATE TABLE TBLOB (
    STREAM  BLOB SUB_TYPE 0 SEGMENT SIZE 80
);





/******************************************************************************/
/***                                 Views                                  ***/
/******************************************************************************/


/* View: PHONE_LIST */
CREATE VIEW PHONE_LIST(
    EMP_NO,
    FIRST_NAME,
    LAST_NAME,
    PHONE_EXT,
    LOCATION,
    PHONE_NO)
AS
SELECT
    emp_no, first_name, last_name, phone_ext, location, phone_no
    FROM employee, department
    WHERE employee.dept_no = department.dept_no;


INSERT INTO COUNTRY (COUNTRY, CURRENCY) VALUES ('USA', 'Dollar');
INSERT INTO COUNTRY (COUNTRY, CURRENCY) VALUES ('England', 'Pound');
INSERT INTO COUNTRY (COUNTRY, CURRENCY) VALUES ('Canada', 'CdnDlr');
INSERT INTO COUNTRY (COUNTRY, CURRENCY) VALUES ('Switzerland', 'SFranc');
INSERT INTO COUNTRY (COUNTRY, CURRENCY) VALUES ('Japan', 'Yen');
INSERT INTO COUNTRY (COUNTRY, CURRENCY) VALUES ('Italy', 'Lira');
INSERT INTO COUNTRY (COUNTRY, CURRENCY) VALUES ('France', 'FFranc');
INSERT INTO COUNTRY (COUNTRY, CURRENCY) VALUES ('Germany', 'D-Mark');
INSERT INTO COUNTRY (COUNTRY, CURRENCY) VALUES ('Australia', 'ADollar');
INSERT INTO COUNTRY (COUNTRY, CURRENCY) VALUES ('Hong Kong', 'HKDollar');
INSERT INTO COUNTRY (COUNTRY, CURRENCY) VALUES ('Netherlands', 'Guilder');
INSERT INTO COUNTRY (COUNTRY, CURRENCY) VALUES ('Belgium', 'BFranc');
INSERT INTO COUNTRY (COUNTRY, CURRENCY) VALUES ('Austria', 'Schilling');
INSERT INTO COUNTRY (COUNTRY, CURRENCY) VALUES ('Fiji', 'FDollar');

COMMIT WORK;

INSERT INTO CUSTOMER (CUST_NO, CUSTOMER, CONTACT_FIRST, CONTACT_LAST, PHONE_NO, ADDRESS_LINE1, ADDRESS_LINE2, CITY, STATE_PROVINCE, COUNTRY, POSTAL_CODE, ON_HOLD) VALUES (1001, 'Signature Design', 'Dale J.', 'Little', '(619) 530-2710', '15500 Pacific Heights Blvd.', NULL, 'San Diego', 'CA', 'USA', '92121', NULL);
INSERT INTO CUSTOMER (CUST_NO, CUSTOMER, CONTACT_FIRST, CONTACT_LAST, PHONE_NO, ADDRESS_LINE1, ADDRESS_LINE2, CITY, STATE_PROVINCE, COUNTRY, POSTAL_CODE, ON_HOLD) VALUES (1002, 'Dallas Technologies', 'Glen', 'Brown', '(214) 960-2233', 'P. O. Box 47000', NULL, 'Dallas', 'TX', 'USA', '75205', '*');
INSERT INTO CUSTOMER (CUST_NO, CUSTOMER, CONTACT_FIRST, CONTACT_LAST, PHONE_NO, ADDRESS_LINE1, ADDRESS_LINE2, CITY, STATE_PROVINCE, COUNTRY, POSTAL_CODE, ON_HOLD) VALUES (1003, 'Buttle, Griffith and Co.', 'James', 'Buttle', '(617) 488-1864', '2300 Newbury Street', 'Suite 101', 'Boston', 'MA', 'USA', '02115', NULL);
INSERT INTO CUSTOMER (CUST_NO, CUSTOMER, CONTACT_FIRST, CONTACT_LAST, PHONE_NO, ADDRESS_LINE1, ADDRESS_LINE2, CITY, STATE_PROVINCE, COUNTRY, POSTAL_CODE, ON_HOLD) VALUES (1004, 'Central Bank', 'Elizabeth', 'Brocket', '61 211 99 88', '66 Lloyd Street', NULL, 'Manchester', NULL, 'England', 'M2 3LA', NULL);
INSERT INTO CUSTOMER (CUST_NO, CUSTOMER, CONTACT_FIRST, CONTACT_LAST, PHONE_NO, ADDRESS_LINE1, ADDRESS_LINE2, CITY, STATE_PROVINCE, COUNTRY, POSTAL_CODE, ON_HOLD) VALUES (1005, 'DT Systems, LTD.', 'Tai', 'Wu', '(852) 850 43 98', '400 Connaught Road', NULL, 'Central Hong Kong', NULL, 'Hong Kong', NULL, NULL);
INSERT INTO CUSTOMER (CUST_NO, CUSTOMER, CONTACT_FIRST, CONTACT_LAST, PHONE_NO, ADDRESS_LINE1, ADDRESS_LINE2, CITY, STATE_PROVINCE, COUNTRY, POSTAL_CODE, ON_HOLD) VALUES (1006, 'DataServe International', 'Tomas', 'Bright', '(613) 229 3323', '2000 Carling Avenue', 'Suite 150', 'Ottawa', 'ON', 'Canada', 'K1V 9G1', NULL);
INSERT INTO CUSTOMER (CUST_NO, CUSTOMER, CONTACT_FIRST, CONTACT_LAST, PHONE_NO, ADDRESS_LINE1, ADDRESS_LINE2, CITY, STATE_PROVINCE, COUNTRY, POSTAL_CODE, ON_HOLD) VALUES (1007, 'Mrs. Beauvais', NULL, 'Mrs. Beauvais', NULL, 'P.O. Box 22743', NULL, 'Pebble Beach', 'CA', 'USA', '93953', NULL);
INSERT INTO CUSTOMER (CUST_NO, CUSTOMER, CONTACT_FIRST, CONTACT_LAST, PHONE_NO, ADDRESS_LINE1, ADDRESS_LINE2, CITY, STATE_PROVINCE, COUNTRY, POSTAL_CODE, ON_HOLD) VALUES (1008, 'Anini Vacation Rentals', 'Leilani', 'Briggs', '(808) 835-7605', '3320 Lawai Road', NULL, 'Lihue', 'HI', 'USA', '96766', NULL);
INSERT INTO CUSTOMER (CUST_NO, CUSTOMER, CONTACT_FIRST, CONTACT_LAST, PHONE_NO, ADDRESS_LINE1, ADDRESS_LINE2, CITY, STATE_PROVINCE, COUNTRY, POSTAL_CODE, ON_HOLD) VALUES (1009, 'Max', 'Max', NULL, '22 01 23', '1 Emerald Cove', NULL, 'Turtle Island', NULL, 'Fiji', NULL, '*');
INSERT INTO CUSTOMER (CUST_NO, CUSTOMER, CONTACT_FIRST, CONTACT_LAST, PHONE_NO, ADDRESS_LINE1, ADDRESS_LINE2, CITY, STATE_PROVINCE, COUNTRY, POSTAL_CODE, ON_HOLD) VALUES (1010, 'MPM Corporation', 'Miwako', 'Miyamoto', '3 880 77 19', '2-64-7 Sasazuka', NULL, 'Tokyo', NULL, 'Japan', '150', NULL);
INSERT INTO CUSTOMER (CUST_NO, CUSTOMER, CONTACT_FIRST, CONTACT_LAST, PHONE_NO, ADDRESS_LINE1, ADDRESS_LINE2, CITY, STATE_PROVINCE, COUNTRY, POSTAL_CODE, ON_HOLD) VALUES (1011, 'Dynamic Intelligence Corp', 'Victor', 'Granges', '01 221 16 50', 'Florhofgasse 10', NULL, 'Zurich', NULL, 'Switzerland', '8005', NULL);
INSERT INTO CUSTOMER (CUST_NO, CUSTOMER, CONTACT_FIRST, CONTACT_LAST, PHONE_NO, ADDRESS_LINE1, ADDRESS_LINE2, CITY, STATE_PROVINCE, COUNTRY, POSTAL_CODE, ON_HOLD) VALUES (1012, '3D-Pad Corp.', 'Michelle', 'Roche', '1 43 60 61', '22 Place de la Concorde', NULL, 'Paris', NULL, 'France', '75008', NULL);
INSERT INTO CUSTOMER (CUST_NO, CUSTOMER, CONTACT_FIRST, CONTACT_LAST, PHONE_NO, ADDRESS_LINE1, ADDRESS_LINE2, CITY, STATE_PROVINCE, COUNTRY, POSTAL_CODE, ON_HOLD) VALUES (1013, 'Lorenzi Export, Ltd.', 'Andreas', 'Lorenzi', '02 404 6284', 'Via Eugenia, 15', NULL, 'Milan', NULL, 'Italy', '20124', NULL);
INSERT INTO CUSTOMER (CUST_NO, CUSTOMER, CONTACT_FIRST, CONTACT_LAST, PHONE_NO, ADDRESS_LINE1, ADDRESS_LINE2, CITY, STATE_PROVINCE, COUNTRY, POSTAL_CODE, ON_HOLD) VALUES (1014, 'Dyno Consulting', 'Greta', 'Hessels', '02 500 5940', 'Rue Royale 350', NULL, 'Brussels', NULL, 'Belgium', '1210', NULL);
INSERT INTO CUSTOMER (CUST_NO, CUSTOMER, CONTACT_FIRST, CONTACT_LAST, PHONE_NO, ADDRESS_LINE1, ADDRESS_LINE2, CITY, STATE_PROVINCE, COUNTRY, POSTAL_CODE, ON_HOLD) VALUES (1015, 'GeoTech Inc.', 'K.M.', 'Neppelenbroek', '(070) 44 91 18', 'P.0.Box 702', NULL, 'Den Haag', NULL, 'Netherlands', '2514', NULL);

COMMIT WORK;

INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENT, HEAD_DEPT, MNGR_NO, BUDGET, LOCATION, PHONE_NO) VALUES ('000', 'Corporate Headquarters', NULL, 105, 1000000, 'Monterey', '(408) 555-1234');
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENT, HEAD_DEPT, MNGR_NO, BUDGET, LOCATION, PHONE_NO) VALUES ('100', 'Sales and Marketing', '000', 85, 2000000, 'San Francisco', '(415) 555-1234');
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENT, HEAD_DEPT, MNGR_NO, BUDGET, LOCATION, PHONE_NO) VALUES ('600', 'Engineering', '000', 2, 1100000, 'Monterey', '(408) 555-1234');
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENT, HEAD_DEPT, MNGR_NO, BUDGET, LOCATION, PHONE_NO) VALUES ('900', 'Finance', '000', 46, 400000, 'Monterey', '(408) 555-1234');
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENT, HEAD_DEPT, MNGR_NO, BUDGET, LOCATION, PHONE_NO) VALUES ('180', 'Marketing', '100', NULL, 1500000, 'San Francisco', '(415) 555-1234');
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENT, HEAD_DEPT, MNGR_NO, BUDGET, LOCATION, PHONE_NO) VALUES ('620', 'Software Products Div.', '600', NULL, 1200000, 'Monterey', '(408) 555-1234');
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENT, HEAD_DEPT, MNGR_NO, BUDGET, LOCATION, PHONE_NO) VALUES ('621', 'Software Development', '620', NULL, 400000, 'Monterey', '(408) 555-1234');
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENT, HEAD_DEPT, MNGR_NO, BUDGET, LOCATION, PHONE_NO) VALUES ('622', 'Quality Assurance', '620', 9, 300000, 'Monterey', '(408) 555-1234');
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENT, HEAD_DEPT, MNGR_NO, BUDGET, LOCATION, PHONE_NO) VALUES ('623', 'Customer Support', '620', 15, 650000, 'Monterey', '(408) 555-1234');
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENT, HEAD_DEPT, MNGR_NO, BUDGET, LOCATION, PHONE_NO) VALUES ('670', 'Consumer Electronics Div.', '600', 107, 1150000, 'Burlington, VT', '(802) 555-1234');
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENT, HEAD_DEPT, MNGR_NO, BUDGET, LOCATION, PHONE_NO) VALUES ('671', 'Research and Development', '670', 20, 460000, 'Burlington, VT', '(802) 555-1234');
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENT, HEAD_DEPT, MNGR_NO, BUDGET, LOCATION, PHONE_NO) VALUES ('672', 'Customer Services', '670', 94, 850000, 'Burlington, VT', '(802) 555-1234');
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENT, HEAD_DEPT, MNGR_NO, BUDGET, LOCATION, PHONE_NO) VALUES ('130', 'Field Office: East Coast', '100', 11, 500000, 'Boston', '(617) 555-1234');
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENT, HEAD_DEPT, MNGR_NO, BUDGET, LOCATION, PHONE_NO) VALUES ('140', 'Field Office: Canada', '100', 72, 500000, 'Toronto', '(416) 677-1000');
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENT, HEAD_DEPT, MNGR_NO, BUDGET, LOCATION, PHONE_NO) VALUES ('110', 'Pacific Rim Headquarters', '100', 34, 600000, 'Kuaui', '(808) 555-1234');
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENT, HEAD_DEPT, MNGR_NO, BUDGET, LOCATION, PHONE_NO) VALUES ('115', 'Field Office: Japan', '110', 118, 500000, 'Tokyo', '3 5350 0901');
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENT, HEAD_DEPT, MNGR_NO, BUDGET, LOCATION, PHONE_NO) VALUES ('116', 'Field Office: Singapore', '110', NULL, 300000, 'Singapore', '3 55 1234');
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENT, HEAD_DEPT, MNGR_NO, BUDGET, LOCATION, PHONE_NO) VALUES ('120', 'European Headquarters', '100', 36, 700000, 'London', '71 235-4400');
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENT, HEAD_DEPT, MNGR_NO, BUDGET, LOCATION, PHONE_NO) VALUES ('121', 'Field Office: Switzerland', '120', 141, 500000, 'Zurich', '1 211 7767');
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENT, HEAD_DEPT, MNGR_NO, BUDGET, LOCATION, PHONE_NO) VALUES ('123', 'Field Office: France', '120', 134, 400000, 'Cannes', '58 68 11 12');
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENT, HEAD_DEPT, MNGR_NO, BUDGET, LOCATION, PHONE_NO) VALUES ('125', 'Field Office: Italy', '120', 121, 400000, 'Milan', '2 430 39 39');
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENT, HEAD_DEPT, MNGR_NO, BUDGET, LOCATION, PHONE_NO) VALUES ('117', 'Field Office: Hong Kong', '110', NULL, 100000, NULL, '555-1234');
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENT, HEAD_DEPT, MNGR_NO, BUDGET, LOCATION, PHONE_NO) VALUES ('118', 'Field Office: Australia', '110', NULL, 100000, NULL, '555-1234');
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENT, HEAD_DEPT, MNGR_NO, BUDGET, LOCATION, PHONE_NO) VALUES ('119', 'Field Office: New Zealand', '110', NULL, 100000, NULL, '555-1234');

COMMIT WORK;

INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (2, 'Robert', 'Nelson', '250', '1988-12-28', '600', 'VP', 2, 'USA', 105900);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (4, 'Bruce', 'Young', '233', '1988-12-28', '621', 'Eng', 2, 'USA', 97500);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (5, 'Kim', 'Lambert', '22', '1989-02-06', '130', 'Eng', 2, 'USA', 102750);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (8, 'Leslie', 'Johnson', '410', '1989-04-05', '180', 'Mktg', 3, 'USA', 64635);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (9, 'Phil', 'Forest', '229', '1989-04-17', '622', 'Mngr', 3, 'USA', 75060);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (11, 'K. J.', 'Weston', '34', '1990-01-17', '130', 'SRep', 4, 'USA', 86292.9375);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (12, 'Terri', 'Lee', '256', '1990-05-01', '000', 'Admin', 4, 'USA', 53793);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (14, 'Stewart', 'Hall', '227', '1990-06-04', '900', 'Finan', 3, 'USA', 69482.625);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (15, 'Katherine', 'Young', '231', '1990-06-14', '623', 'Mngr', 3, 'USA', 67241.25);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (20, 'Chris', 'Papadopoulos', '887', '1990-01-01', '671', 'Mngr', 3, 'USA', 89655);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (24, 'Pete', 'Fisher', '888', '1990-09-12', '671', 'Eng', 3, 'USA', 81810.1875);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (28, 'Ann', 'Bennet', '5', '1991-02-01', '120', 'Admin', 5, 'England', 22935);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (29, 'Roger', 'De Souza', '288', '1991-02-18', '623', 'Eng', 3, 'USA', 69482.625);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (34, 'Janet', 'Baldwin', '2', '1991-03-21', '110', 'Sales', 3, 'USA', 61637.8125);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (36, 'Roger', 'Reeves', '6', '1991-04-25', '120', 'Sales', 3, 'England', 33620.625);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (37, 'Willie', 'Stansbury', '7', '1991-04-25', '120', 'Eng', 4, 'England', 39224.0625);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (44, 'Leslie', 'Phong', '216', '1991-06-03', '623', 'Eng', 4, 'USA', 56034.375);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (45, 'Ashok', 'Ramanathan', '209', '1991-08-01', '621', 'Eng', 3, 'USA', 80689.5);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (46, 'Walter', 'Steadman', '210', '1991-08-09', '900', 'CFO', 1, 'USA', 116100);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (52, 'Carol', 'Nordstrom', '420', '1991-10-02', '180', 'PRel', 4, 'USA', 42742.5);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (61, 'Luke', 'Leung', '3', '1992-02-18', '110', 'SRep', 4, 'USA', 68805);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (65, 'Sue Anne', 'O''Brien', '877', '1992-03-23', '670', 'Admin', 5, 'USA', 31275);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (71, 'Jennifer M.', 'Burbank', '289', '1992-04-15', '622', 'Eng', 3, 'USA', 53167.5);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (72, 'Claudia', 'Sutherland', NULL, '1992-04-20', '140', 'SRep', 4, 'Canada', 100914);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (83, 'Dana', 'Bishop', '290', '1992-06-01', '621', 'Eng', 3, 'USA', 62550);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (85, 'Mary S.', 'MacDonald', '477', '1992-06-01', '100', 'VP', 2, 'USA', 111262.5);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (94, 'Randy', 'Williams', '892', '1992-08-08', '672', 'Mngr', 4, 'USA', 56295);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (105, 'Oliver H.', 'Bender', '255', '1992-10-08', '000', 'CEO', 1, 'USA', 212850);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (107, 'Kevin', 'Cook', '894', '1993-02-01', '670', 'Dir', 2, 'USA', 111262.5);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (109, 'Kelly', 'Brown', '202', '1993-02-04', '600', 'Admin', 5, 'USA', 27000);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (110, 'Yuki', 'Ichida', '22', '1993-02-04', '115', 'Eng', 3, 'Japan', 6000000);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (113, 'Mary', 'Page', '845', '1993-04-12', '671', 'Eng', 4, 'USA', 48000);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (114, 'Bill', 'Parker', '247', '1993-06-01', '623', 'Eng', 5, 'USA', 35000);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (118, 'Takashi', 'Yamamoto', '23', '1993-07-01', '115', 'SRep', 4, 'Japan', 7480000);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (121, 'Roberto', 'Ferrari', '1', '1993-07-12', '125', 'SRep', 4, 'Italy', 99000000);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (127, 'Michael', 'Yanowski', '492', '1993-08-09', '100', 'SRep', 4, 'USA', 44000);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (134, 'Jacques', 'Glon', NULL, '1993-08-23', '123', 'SRep', 4, 'France', 390500);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (136, 'Scott', 'Johnson', '265', '1993-09-13', '623', 'Doc', 3, 'USA', 60000);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (138, 'T.J.', 'Green', '218', '1993-11-01', '621', 'Eng', 4, 'USA', 36000);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (141, 'Pierre', 'Osborne', NULL, '1994-01-03', '121', 'SRep', 4, 'Switzerland', 110000);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (144, 'John', 'Montgomery', '820', '1994-03-30', '672', 'Eng', 5, 'USA', 35000);
INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE, DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) VALUES (145, 'Mark', 'Guckenheimer', '221', '1994-05-02', '622', 'Eng', 5, 'USA', 32000);

COMMIT WORK;

INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (144, 'DGPII');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (113, 'DGPII');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (24, 'DGPII');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (8, 'VBASE');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (136, 'VBASE');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (15, 'VBASE');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (71, 'VBASE');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (145, 'VBASE');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (44, 'VBASE');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (4, 'VBASE');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (83, 'VBASE');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (138, 'VBASE');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (45, 'VBASE');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (20, 'GUIDE');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (24, 'GUIDE');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (113, 'GUIDE');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (8, 'GUIDE');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (4, 'MAPDB');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (71, 'MAPDB');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (46, 'MKTPR');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (105, 'MKTPR');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (12, 'MKTPR');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (85, 'MKTPR');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (110, 'MKTPR');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (34, 'MKTPR');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (8, 'MKTPR');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (14, 'MKTPR');
INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (52, 'MKTPR');

COMMIT WORK;

INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('CEO', 1, 'USA', 'Chief Executive Officer', 130000, 250000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('CFO', 1, 'USA', 'Chief Financial Officer', 85000, 140000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('VP', 2, 'USA', 'Vice President', 80000, 130000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('Dir', 2, 'USA', 'Director', 75000, 120000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('Mngr', 3, 'USA', 'Manager', 60000, 100000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('Mngr', 4, 'USA', 'Manager', 30000, 60000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('Admin', 4, 'USA', 'Administrative Assistant', 35000, 55000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('Admin', 5, 'USA', 'Administrative Assistant', 20000, 40000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('Admin', 5, 'England', 'Administrative Assistant', 13400, 26800);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('PRel', 4, 'USA', 'Public Relations Rep.', 25000, 65000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('Mktg', 3, 'USA', 'Marketing Analyst', 40000, 80000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('Mktg', 4, 'USA', 'Marketing Analyst', 20000, 50000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('Accnt', 4, 'USA', 'Accountant', 28000, 55000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('Finan', 3, 'USA', 'Financial Analyst', 35000, 85000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('Eng', 2, 'USA', 'Engineer', 70000, 110000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('Eng', 3, 'USA', 'Engineer', 50000, 90000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('Eng', 3, 'Japan', 'Engineer', 5400000, 9720000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('Eng', 4, 'USA', 'Engineer', 30000, 65000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('Eng', 4, 'England', 'Engineer', 20100, 43550);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('Eng', 5, 'USA', 'Engineer', 25000, 35000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('Doc', 3, 'USA', 'Technical Writer', 38000, 60000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('Doc', 5, 'USA', 'Technical Writer', 22000, 40000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('Sales', 3, 'USA', 'Sales Co-ordinator', 40000, 70000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('Sales', 3, 'England', 'Sales Co-ordinator', 26800, 46900);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('SRep', 4, 'USA', 'Sales Representative', 20000, 100000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('SRep', 4, 'England', 'Sales Representative', 13400, 67000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('SRep', 4, 'Canada', 'Sales Representative', 26400, 132000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('SRep', 4, 'Switzerland', 'Sales Representative', 28000, 149000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('SRep', 4, 'Japan', 'Sales Representative', 2160000, 10800000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('SRep', 4, 'Italy', 'Sales Representative', 33600000, 168000000);
INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY, MAX_SALARY) VALUES ('SRep', 4, 'France', 'Sales Representative', 118200, 591000);

COMMIT WORK;

INSERT INTO PROJECT (PROJ_ID, PROJ_NAME, TEAM_LEADER, PRODUCT) VALUES ('VBASE', 'Video Database', 45, 'software');
INSERT INTO PROJECT (PROJ_ID, PROJ_NAME, TEAM_LEADER, PRODUCT) VALUES ('DGPII', 'DigiPizza', 24, 'other');
INSERT INTO PROJECT (PROJ_ID, PROJ_NAME, TEAM_LEADER, PRODUCT) VALUES ('GUIDE', 'AutoMap', 20, 'hardware');
INSERT INTO PROJECT (PROJ_ID, PROJ_NAME, TEAM_LEADER, PRODUCT) VALUES ('MAPDB', 'MapBrowser port', 4, 'software');
INSERT INTO PROJECT (PROJ_ID, PROJ_NAME, TEAM_LEADER, PRODUCT) VALUES ('HWRII', 'Translator upgrade', NULL, 'software');
INSERT INTO PROJECT (PROJ_ID, PROJ_NAME, TEAM_LEADER, PRODUCT) VALUES ('MKTPR', 'Marketing project 3', 85, 'N/A');

COMMIT WORK;

INSERT INTO PROJ_DEPT_BUDGET (FISCAL_YEAR, PROJ_ID, DEPT_NO, PROJECTED_BUDGET) VALUES (1994, 'GUIDE', '100', 200000);
INSERT INTO PROJ_DEPT_BUDGET (FISCAL_YEAR, PROJ_ID, DEPT_NO, PROJECTED_BUDGET) VALUES (1994, 'GUIDE', '671', 450000);
INSERT INTO PROJ_DEPT_BUDGET (FISCAL_YEAR, PROJ_ID, DEPT_NO, PROJECTED_BUDGET) VALUES (1993, 'MAPDB', '621', 20000);
INSERT INTO PROJ_DEPT_BUDGET (FISCAL_YEAR, PROJ_ID, DEPT_NO, PROJECTED_BUDGET) VALUES (1994, 'MAPDB', '621', 40000);
INSERT INTO PROJ_DEPT_BUDGET (FISCAL_YEAR, PROJ_ID, DEPT_NO, PROJECTED_BUDGET) VALUES (1994, 'MAPDB', '622', 60000);
INSERT INTO PROJ_DEPT_BUDGET (FISCAL_YEAR, PROJ_ID, DEPT_NO, PROJECTED_BUDGET) VALUES (1994, 'MAPDB', '671', 11000);
INSERT INTO PROJ_DEPT_BUDGET (FISCAL_YEAR, PROJ_ID, DEPT_NO, PROJECTED_BUDGET) VALUES (1994, 'HWRII', '670', 20000);
INSERT INTO PROJ_DEPT_BUDGET (FISCAL_YEAR, PROJ_ID, DEPT_NO, PROJECTED_BUDGET) VALUES (1994, 'HWRII', '621', 400000);
INSERT INTO PROJ_DEPT_BUDGET (FISCAL_YEAR, PROJ_ID, DEPT_NO, PROJECTED_BUDGET) VALUES (1994, 'HWRII', '622', 100000);
INSERT INTO PROJ_DEPT_BUDGET (FISCAL_YEAR, PROJ_ID, DEPT_NO, PROJECTED_BUDGET) VALUES (1994, 'MKTPR', '623', 80000);
INSERT INTO PROJ_DEPT_BUDGET (FISCAL_YEAR, PROJ_ID, DEPT_NO, PROJECTED_BUDGET) VALUES (1994, 'MKTPR', '672', 100000);
INSERT INTO PROJ_DEPT_BUDGET (FISCAL_YEAR, PROJ_ID, DEPT_NO, PROJECTED_BUDGET) VALUES (1994, 'MKTPR', '100', 1000000);
INSERT INTO PROJ_DEPT_BUDGET (FISCAL_YEAR, PROJ_ID, DEPT_NO, PROJECTED_BUDGET) VALUES (1994, 'MKTPR', '110', 200000);
INSERT INTO PROJ_DEPT_BUDGET (FISCAL_YEAR, PROJ_ID, DEPT_NO, PROJECTED_BUDGET) VALUES (1994, 'MKTPR', '000', 100000);
INSERT INTO PROJ_DEPT_BUDGET (FISCAL_YEAR, PROJ_ID, DEPT_NO, PROJECTED_BUDGET) VALUES (1995, 'MKTPR', '623', 1200000);
INSERT INTO PROJ_DEPT_BUDGET (FISCAL_YEAR, PROJ_ID, DEPT_NO, PROJECTED_BUDGET) VALUES (1995, 'MKTPR', '672', 800000);
INSERT INTO PROJ_DEPT_BUDGET (FISCAL_YEAR, PROJ_ID, DEPT_NO, PROJECTED_BUDGET) VALUES (1995, 'MKTPR', '100', 2000000);
INSERT INTO PROJ_DEPT_BUDGET (FISCAL_YEAR, PROJ_ID, DEPT_NO, PROJECTED_BUDGET) VALUES (1995, 'MKTPR', '110', 1200000);
INSERT INTO PROJ_DEPT_BUDGET (FISCAL_YEAR, PROJ_ID, DEPT_NO, PROJECTED_BUDGET) VALUES (1994, 'VBASE', '621', 1900000);
INSERT INTO PROJ_DEPT_BUDGET (FISCAL_YEAR, PROJ_ID, DEPT_NO, PROJECTED_BUDGET) VALUES (1995, 'VBASE', '621', 900000);
INSERT INTO PROJ_DEPT_BUDGET (FISCAL_YEAR, PROJ_ID, DEPT_NO, PROJECTED_BUDGET) VALUES (1994, 'VBASE', '622', 400000);
INSERT INTO PROJ_DEPT_BUDGET (FISCAL_YEAR, PROJ_ID, DEPT_NO, PROJECTED_BUDGET) VALUES (1994, 'VBASE', '100', 300000);
INSERT INTO PROJ_DEPT_BUDGET (FISCAL_YEAR, PROJ_ID, DEPT_NO, PROJECTED_BUDGET) VALUES (1995, 'VBASE', '100', 1500000);
INSERT INTO PROJ_DEPT_BUDGET (FISCAL_YEAR, PROJ_ID, DEPT_NO, PROJECTED_BUDGET) VALUES (1996, 'VBASE', '100', 150000);

COMMIT WORK;

INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (28, '1992-12-15', 'admin2', 20000, 10);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (2, '1992-12-15', 'admin2', 98000, 8.06122448979592);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (4, '1992-12-15', 'admin2', 90000, 8.33333333333333);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (5, '1992-12-15', 'admin2', 95000, 8.1578947368421);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (11, '1992-12-15', 'admin2', 70000, 7.5);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (12, '1992-12-15', 'admin2', 48000, 7.5);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (14, '1992-12-15', 'admin2', 62000, 7.5);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (15, '1992-12-15', 'admin2', 60000, 7.5);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (20, '1992-12-15', 'admin2', 80000, 7.5);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (24, '1992-12-15', 'admin2', 73000, 7.5);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (29, '1992-12-15', 'admin2', 62000, 7.5);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (34, '1992-12-15', 'admin2', 55000, 7.5);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (36, '1992-12-15', 'admin2', 30000, 7.5);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (37, '1992-12-15', 'admin2', 35000, 7.5);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (44, '1992-12-15', 'admin2', 50000, 7.5);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (45, '1992-12-15', 'admin2', 72000, 7.5);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (8, '1993-09-08', 'elaine', 62000, 4.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (9, '1993-09-08', 'elaine', 72000, 4.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (11, '1993-09-08', 'elaine', 75250, 4.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (12, '1993-09-08', 'elaine', 51600, 4.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (14, '1993-09-08', 'elaine', 66650, 4.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (15, '1993-09-08', 'elaine', 64500, 4.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (20, '1993-09-08', 'elaine', 86000, 4.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (24, '1993-09-08', 'elaine', 78475, 4.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (28, '1993-09-08', 'elaine', 22000, 4.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (29, '1993-09-08', 'elaine', 66650, 4.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (34, '1993-09-08', 'elaine', 59125, 4.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (36, '1993-09-08', 'elaine', 32250, 4.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (37, '1993-09-08', 'elaine', 37625, 4.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (44, '1993-09-08', 'elaine', 53750, 4.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (45, '1993-09-08', 'elaine', 77400, 4.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (52, '1993-09-08', 'elaine', 41000, 4.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (61, '1993-09-08', 'elaine', 60000, 4.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (65, '1993-09-08', 'elaine', 30000, 4.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (71, '1993-09-08', 'elaine', 51000, 4.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (72, '1993-09-08', 'elaine', 88000, 4.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (83, '1993-09-08', 'elaine', 60000, 4.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (94, '1993-09-08', 'elaine', 54000, 4.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (46, '1993-12-20', 'tj', 120000, -3.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (85, '1993-12-20', 'tj', 115000, -3.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (105, '1993-12-20', 'tj', 220000, -3.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (107, '1993-12-20', 'tj', 115000, -3.25);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (11, '1993-12-20', 'elaine', 78448.125, 10);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (61, '1993-12-20', 'elaine', 62550, 10);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (72, '1993-12-20', 'elaine', 91740, 10);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (118, '1993-12-20', 'elaine', 6800000, 10);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (121, '1993-12-20', 'elaine', 90000000, 10);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (127, '1993-12-20', 'elaine', 40000, 10);
INSERT INTO SALARY_HISTORY (EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY, PERCENT_CHANGE) VALUES (134, '1993-12-20', 'elaine', 355000, 10);

COMMIT WORK;

INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V91E0210', 1004, 11, 'shipped', '1991-03-04', '1991-03-05', NULL, 'y', 10, 5000, 0.100000001490116, 'hardware');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V92E0340', 1004, 11, 'shipped', '1992-10-15', '1992-10-16', '1992-10-17', 'y', 7, 70000, 0, 'hardware');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V92J1003', 1010, 61, 'shipped', '1992-07-26', '1992-08-04', '1992-09-15', 'y', 15, 2985, 0, 'software');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V93J2004', 1010, 118, 'shipped', '1993-10-30', '1993-12-02', '1993-11-15', 'y', 3, 210, 0, 'software');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V93J3100', 1010, 118, 'shipped', '1993-08-20', '1993-08-20', NULL, 'y', 16, 18000.4, 0.100000001490116, 'software');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V92F3004', 1012, 11, 'shipped', '1992-10-15', '1993-01-16', '1993-01-16', 'y', 3, 2000, 0, 'software');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V93F3088', 1012, 134, 'shipped', '1993-08-27', '1993-09-08', NULL, 'n', 10, 10000, 0, 'software');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V93F2030', 1012, 134, 'open', '1993-12-12', NULL, NULL, 'y', 15, 450000.49, 0, 'hardware');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V93F2051', 1012, 134, 'waiting', '1993-12-18', NULL, '1994-03-01', 'n', 1, 999.98, 0, 'software');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V93H0030', 1005, 118, 'open', '1993-12-12', NULL, '1994-01-01', 'y', 20, 5980, 0.200000002980232, 'software');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V94H0079', 1005, 61, 'open', '1994-02-13', NULL, '1994-04-20', 'n', 10, 9000, 0.0500000007450581, 'software');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V9324200', 1001, 72, 'shipped', '1993-08-09', '1993-08-09', '1993-08-17', 'y', 1000, 560000, 0.200000002980232, 'hardware');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V9324320', 1001, 127, 'shipped', '1993-08-16', '1993-08-16', '1993-09-01', 'y', 1, 0, 1, 'software');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V9320630', 1001, 127, 'open', '1993-12-12', NULL, '1993-12-15', 'n', 3, 60000, 0.200000002980232, 'hardware');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V9420099', 1001, 127, 'open', '1994-01-17', NULL, '1994-06-01', 'n', 100, 3399.15, 0.150000005960464, 'software');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V9427029', 1001, 127, 'shipped', '1994-02-07', '1994-02-10', '1994-02-10', 'n', 17, 422210.97, 0, 'hardware');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V9333005', 1002, 11, 'shipped', '1993-02-03', '1993-03-03', NULL, 'y', 2, 600.5, 0, 'software');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V9333006', 1002, 11, 'shipped', '1993-04-27', '1993-05-02', '1993-05-02', 'n', 5, 20000, 0, 'other');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V9336100', 1002, 11, 'waiting', '1993-12-27', '1994-01-01', '1994-01-01', 'n', 150, 14850, 0.0500000007450581, 'software');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V9346200', 1003, 11, 'waiting', '1993-12-31', NULL, '1994-01-24', 'n', 3, 0, 1, 'software');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V9345200', 1003, 11, 'shipped', '1993-11-11', '1993-12-02', '1993-12-01', 'y', 900, 27000, 0.300000011920929, 'software');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V9345139', 1003, 127, 'shipped', '1993-09-09', '1993-09-20', '1993-10-01', 'y', 20, 12582.12, 0.100000001490116, 'software');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V93C0120', 1006, 72, 'shipped', '1993-03-22', '1993-05-31', '1993-04-17', 'y', 1, 47.5, 0, 'other');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V93C0990', 1006, 72, 'shipped', '1993-08-09', '1993-09-02', NULL, 'y', 40, 399960.5, 0.100000001490116, 'hardware');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V9456220', 1007, 127, 'open', '1994-01-04', NULL, '1994-01-30', 'y', 1, 3999.99, 0, 'hardware');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V93S4702', 1011, 121, 'shipped', '1993-10-27', '1993-10-28', '1993-12-15', 'y', 4, 120000, 0, 'hardware');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V94S6400', 1011, 141, 'waiting', '1994-01-06', NULL, '1994-02-15', 'y', 20, 1980.72, 0.400000005960464, 'software');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V93H3009', 1008, 61, 'shipped', '1993-08-01', '1993-12-02', '1993-12-01', 'n', 3, 9000, 0.0500000007450581, 'software');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V93H0500', 1008, 61, 'open', '1993-12-12', NULL, '1993-12-15', 'n', 3, 16000, 0.200000002980232, 'hardware');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V93F0020', 1009, 61, 'shipped', '1993-10-10', '1993-11-11', '1993-11-11', 'n', 1, 490.69, 0, 'software');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V93I4700', 1013, 121, 'open', '1993-10-27', NULL, '1993-12-15', 'n', 5, 2693, 0, 'hardware');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V93B1002', 1014, 134, 'shipped', '1993-09-20', '1993-09-21', '1993-09-25', 'y', 1, 100.02, 0, 'software');
INSERT INTO SALES (PO_NUMBER, CUST_NO, SALES_REP, ORDER_STATUS, ORDER_DATE, SHIP_DATE, DATE_NEEDED, PAID, QTY_ORDERED, TOTAL_VALUE, DISCOUNT, ITEM_TYPE) VALUES ('V93N5822', 1015, 134, 'shipped', '1993-12-18', '1994-01-14', NULL, 'n', 2, 1500, 0, 'software');

COMMIT WORK;



/* Check constraints definition */

ALTER TABLE JOB ADD CHECK (min_salary < max_salary);
ALTER TABLE EMPLOYEE ADD CHECK ( salary >= (SELECT min_salary FROM job WHERE
                        job.job_code = employee.job_code AND
                        job.job_grade = employee.job_grade AND
                        job.job_country = employee.job_country) AND
            salary <= (SELECT max_salary FROM job WHERE
                        job.job_code = employee.job_code AND
                        job.job_grade = employee.job_grade AND
                        job.job_country = employee.job_country));
ALTER TABLE PROJ_DEPT_BUDGET ADD CHECK (FISCAL_YEAR >= 1993);
ALTER TABLE SALARY_HISTORY ADD CHECK (percent_change between -50 and 50);
ALTER TABLE CUSTOMER ADD CHECK (on_hold IS NULL OR on_hold = '*');
ALTER TABLE SALES ADD CHECK (order_status in
                            ('new', 'open', 'shipped', 'waiting'));
ALTER TABLE SALES ADD CHECK (ship_date >= order_date OR ship_date IS NULL);
ALTER TABLE SALES ADD CHECK (date_needed > order_date OR date_needed IS NULL);
ALTER TABLE SALES ADD CHECK (paid in ('y', 'n'));
ALTER TABLE SALES ADD CHECK (qty_ordered >= 1);
ALTER TABLE SALES ADD CHECK (total_value >= 0);
ALTER TABLE SALES ADD CHECK (discount >= 0 AND discount <= 1);
ALTER TABLE SALES ADD CHECK (NOT (order_status = 'shipped' AND ship_date IS NULL));
ALTER TABLE SALES ADD CHECK (NOT (order_status = 'shipped' AND
            EXISTS (SELECT on_hold FROM customer
                    WHERE customer.cust_no = sales.cust_no
                    AND customer.on_hold = '*')));


/******************************************************************************/
/***                           Unique Constraints                           ***/
/******************************************************************************/

ALTER TABLE DEPARTMENT ADD UNIQUE (DEPARTMENT);
ALTER TABLE PROJECT ADD UNIQUE (PROJ_NAME);


/******************************************************************************/
/***                              Primary Keys                              ***/
/******************************************************************************/

ALTER TABLE COUNTRY ADD PRIMARY KEY (COUNTRY);
ALTER TABLE CUSTOMER ADD PRIMARY KEY (CUST_NO);
ALTER TABLE DEPARTMENT ADD PRIMARY KEY (DEPT_NO);
ALTER TABLE EMPLOYEE ADD PRIMARY KEY (EMP_NO);
ALTER TABLE EMPLOYEE_PROJECT ADD PRIMARY KEY (EMP_NO, PROJ_ID);
ALTER TABLE JOB ADD PRIMARY KEY (JOB_CODE, JOB_GRADE, JOB_COUNTRY);
ALTER TABLE PROJECT ADD PRIMARY KEY (PROJ_ID);
ALTER TABLE PROJ_DEPT_BUDGET ADD PRIMARY KEY (FISCAL_YEAR, PROJ_ID, DEPT_NO);
ALTER TABLE SALARY_HISTORY ADD PRIMARY KEY (EMP_NO, CHANGE_DATE, UPDATER_ID);
ALTER TABLE SALES ADD PRIMARY KEY (PO_NUMBER);


/******************************************************************************/
/***                              Foreign Keys                              ***/
/******************************************************************************/

ALTER TABLE CUSTOMER ADD FOREIGN KEY (COUNTRY) REFERENCES COUNTRY (COUNTRY);
ALTER TABLE DEPARTMENT ADD FOREIGN KEY (HEAD_DEPT) REFERENCES DEPARTMENT (DEPT_NO);
ALTER TABLE DEPARTMENT ADD FOREIGN KEY (MNGR_NO) REFERENCES EMPLOYEE (EMP_NO);
ALTER TABLE EMPLOYEE ADD FOREIGN KEY (DEPT_NO) REFERENCES DEPARTMENT (DEPT_NO);
ALTER TABLE EMPLOYEE ADD FOREIGN KEY (JOB_CODE, JOB_GRADE, JOB_COUNTRY) REFERENCES JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY);
ALTER TABLE EMPLOYEE_PROJECT ADD FOREIGN KEY (EMP_NO) REFERENCES EMPLOYEE (EMP_NO);
ALTER TABLE EMPLOYEE_PROJECT ADD FOREIGN KEY (PROJ_ID) REFERENCES PROJECT (PROJ_ID);
ALTER TABLE JOB ADD FOREIGN KEY (JOB_COUNTRY) REFERENCES COUNTRY (COUNTRY);
ALTER TABLE PROJECT ADD FOREIGN KEY (TEAM_LEADER) REFERENCES EMPLOYEE (EMP_NO);
ALTER TABLE PROJ_DEPT_BUDGET ADD FOREIGN KEY (DEPT_NO) REFERENCES DEPARTMENT (DEPT_NO);
ALTER TABLE PROJ_DEPT_BUDGET ADD FOREIGN KEY (PROJ_ID) REFERENCES PROJECT (PROJ_ID);
ALTER TABLE SALARY_HISTORY ADD FOREIGN KEY (EMP_NO) REFERENCES EMPLOYEE (EMP_NO);
ALTER TABLE SALES ADD FOREIGN KEY (CUST_NO) REFERENCES CUSTOMER (CUST_NO);
ALTER TABLE SALES ADD FOREIGN KEY (SALES_REP) REFERENCES EMPLOYEE (EMP_NO);


/******************************************************************************/
/***                                Indices                                 ***/
/******************************************************************************/

CREATE INDEX CUSTNAMEX ON CUSTOMER (CUSTOMER);
CREATE INDEX CUSTREGION ON CUSTOMER (COUNTRY, CITY);
CREATE DESCENDING INDEX BUDGETX ON DEPARTMENT (BUDGET);
CREATE INDEX NAMEX ON EMPLOYEE (LAST_NAME, FIRST_NAME);
CREATE DESCENDING INDEX MAXSALX ON JOB (JOB_COUNTRY, MAX_SALARY);
CREATE INDEX MINSALX ON JOB (JOB_COUNTRY, MIN_SALARY);
CREATE UNIQUE INDEX PRODTYPEX ON PROJECT (PRODUCT, PROJ_NAME);
CREATE DESCENDING INDEX CHANGEX ON SALARY_HISTORY (CHANGE_DATE);
CREATE INDEX UPDATERX ON SALARY_HISTORY (UPDATER_ID);
CREATE INDEX NEEDX ON SALES (DATE_NEEDED);
CREATE DESCENDING INDEX QTYX ON SALES (ITEM_TYPE, QTY_ORDERED);
CREATE INDEX SALESTATX ON SALES (ORDER_STATUS, PAID);


/******************************************************************************/
/***                                Triggers                                ***/
/******************************************************************************/


SET TERM ^ ;




/* Trigger: POST_NEW_ORDER */
CREATE TRIGGER POST_NEW_ORDER FOR SALES
ACTIVE AFTER INSERT POSITION 0
AS
BEGIN
    POST_EVENT 'new_order';
END
^

/* Trigger: SAVE_SALARY_CHANGE */
CREATE TRIGGER SAVE_SALARY_CHANGE FOR EMPLOYEE
ACTIVE AFTER UPDATE POSITION 0
AS
BEGIN
    IF (old.salary <> new.salary) THEN
        INSERT INTO salary_history
            (emp_no, change_date, updater_id, old_salary, percent_change)
        VALUES (
            old.emp_no,
            'NOW',
            user,
            old.salary,
            (new.salary - old.salary) * 100 / old.salary);
END
^

/* Trigger: SET_CUST_NO */
CREATE TRIGGER SET_CUST_NO FOR CUSTOMER
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
    new.cust_no = gen_id(cust_no_gen, 1);
END
^

/* Trigger: SET_EMP_NO */
CREATE TRIGGER SET_EMP_NO FOR EMPLOYEE
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
    new.emp_no = gen_id(emp_no_gen, 1);
END
^


SET TERM ; ^


/******************************************************************************/
/***                           Stored Procedures                            ***/
/******************************************************************************/


SET TERM ^ ;

ALTER PROCEDURE ADD_EMP_PROJ (
    EMP_NO SMALLINT,
    PROJ_ID CHAR(5) CHARACTER SET NONE)
AS
BEGIN
 BEGIN
 INSERT INTO employee_project (emp_no, proj_id) VALUES (:emp_no, :proj_id);
 WHEN SQLCODE -530 DO
  EXCEPTION unknown_emp_id;
 END
 SUSPEND;
END
^

ALTER PROCEDURE ALL_LANGS
RETURNS (
    CODE VARCHAR(5) CHARACTER SET NONE,
    GRADE VARCHAR(5) CHARACTER SET NONE,
    COUNTRY VARCHAR(15) CHARACTER SET NONE,
    LANG VARCHAR(15) CHARACTER SET NONE)
AS
    BEGIN
 FOR SELECT job_code, job_grade, job_country FROM job 
  INTO :code, :grade, :country

 DO
 BEGIN
     FOR SELECT languages FROM show_langs 
       (:code, :grade, :country) INTO :lang DO
         SUSPEND;
     /* Put nice separators between rows */
     code = '=====';
     grade = '=====';
     country = '===============';
     lang = '==============';
     SUSPEND;
 END
    END
^

ALTER PROCEDURE DELETE_EMPLOYEE (
    EMP_NUM INTEGER)
AS
 DECLARE VARIABLE any_sales INTEGER;
BEGIN
 any_sales = 0;

 /*
  * If there are any sales records referencing this employee,
  * can't delete the employee until the sales are re-assigned
  * to another employee or changed to NULL.
  */
 SELECT count(po_number)
 FROM sales
 WHERE sales_rep = :emp_num
 INTO :any_sales;

 IF (any_sales > 0) THEN
 BEGIN
  EXCEPTION reassign_sales;
  SUSPEND;
 END

 /*
  * If the employee is a manager, update the department.
  */
 UPDATE department
 SET mngr_no = NULL
 WHERE mngr_no = :emp_num;

 /*
  * If the employee is a project leader, update project.
  */
 UPDATE project
 SET team_leader = NULL
 WHERE team_leader = :emp_num;

 /*
  * Delete the employee from any projects.
  */
 DELETE FROM employee_project
 WHERE emp_no = :emp_num;

 /*
  * Delete old salary records.
  */
 DELETE FROM salary_history
 WHERE emp_no = :emp_num;

 /*
  * Delete the employee.
  */
 DELETE FROM employee
 WHERE emp_no = :emp_num;

 SUSPEND;
END
^

ALTER PROCEDURE DEPT_BUDGET (
    DNO CHAR(3) CHARACTER SET NONE)
RETURNS (
    TOT NUMERIC(15,2))
AS
 DECLARE VARIABLE sumb DECIMAL(12, 2);
 DECLARE VARIABLE rdno CHAR(3);
 DECLARE VARIABLE cnt INTEGER;
BEGIN
 tot = 0;

 SELECT budget FROM department WHERE dept_no = :dno INTO :tot;

 SELECT count(budget) FROM department WHERE head_dept = :dno INTO :cnt;

 IF (cnt = 0) THEN
  SUSPEND;

 FOR SELECT dept_no
  FROM department
  WHERE head_dept = :dno
  INTO :rdno
 DO
  BEGIN
   EXECUTE PROCEDURE dept_budget :rdno RETURNING_VALUES :sumb;
   tot = tot + sumb;
  END

 SUSPEND;
END
^

ALTER PROCEDURE GET_EMP_PROJ (
    EMP_NO SMALLINT)
RETURNS (
    PROJ_ID CHAR(5) CHARACTER SET NONE)
AS
BEGIN
 FOR SELECT proj_id
  FROM employee_project
  WHERE emp_no = :emp_no
  INTO :proj_id
 DO
  SUSPEND;
END
^

ALTER PROCEDURE MAIL_LABEL (
    CUST_NO INTEGER)
RETURNS (
    LINE1 CHAR(40) CHARACTER SET NONE,
    LINE2 CHAR(40) CHARACTER SET NONE,
    LINE3 CHAR(40) CHARACTER SET NONE,
    LINE4 CHAR(40) CHARACTER SET NONE,
    LINE5 CHAR(40) CHARACTER SET NONE,
    LINE6 CHAR(40) CHARACTER SET NONE)
AS
 DECLARE VARIABLE customer VARCHAR(25);
 DECLARE VARIABLE firstone  VARCHAR(15);
 DECLARE VARIABLE lastone  VARCHAR(20);
 DECLARE VARIABLE addr1  VARCHAR(30);
 DECLARE VARIABLE addr2  VARCHAR(30);
 DECLARE VARIABLE city  VARCHAR(25);
 DECLARE VARIABLE state  VARCHAR(15);
 DECLARE VARIABLE country VARCHAR(15);
 DECLARE VARIABLE postcode VARCHAR(12);
 DECLARE VARIABLE cnt  INTEGER;
BEGIN
 line1 = '';
 line2 = '';
 line3 = '';
 line4 = '';
 line5 = '';
 line6 = '';

 SELECT customer, contact_first, contact_last, address_line1,
  address_line2, city, state_province, country, postal_code
 FROM CUSTOMER
 WHERE cust_no = :cust_no
 INTO :customer, :firstone, :lastone, :addr1, :addr2,
  :city, :state, :country, :postcode;

 IF (customer IS NOT NULL) THEN
  line1 = customer;
 IF (firstone IS NOT NULL) THEN
  line2 = firstone || ' ' || lastone;
 ELSE
  line2 = lastone;
 IF (addr1 IS NOT NULL) THEN
  line3 = addr1;
 IF (addr2 IS NOT NULL) THEN
  line4 = addr2;

 IF (country = 'USA') THEN
 BEGIN
  IF (city IS NOT NULL) THEN
   line5 = city || ', ' || state || '  ' || postcode;
  ELSE
   line5 = state || '  ' || postcode;
 END
 ELSE
 BEGIN
  IF (city IS NOT NULL) THEN
   line5 = city || ', ' || state;
  ELSE
   line5 = state;
  line6 = country || '    ' || postcode;
 END

 SUSPEND;
END
^

ALTER PROCEDURE ORG_CHART
RETURNS (
    HEAD_DEPT CHAR(25) CHARACTER SET NONE,
    DEPARTMENT CHAR(25) CHARACTER SET NONE,
    MNGR_NAME CHAR(20) CHARACTER SET NONE,
    TITLE CHAR(5) CHARACTER SET NONE,
    EMP_CNT INTEGER)
AS
 DECLARE VARIABLE mngr_no INTEGER;
 DECLARE VARIABLE dno CHAR(3);
BEGIN
 FOR SELECT h.department, d.department, d.mngr_no, d.dept_no
  FROM department d
  LEFT OUTER JOIN department h ON d.head_dept = h.dept_no
  ORDER BY d.dept_no
  INTO :head_dept, :department, :mngr_no, :dno
 DO
 BEGIN
  IF (:mngr_no IS NULL) THEN
  BEGIN
   mngr_name = '--TBH--';
   title = '';
  END

  ELSE
   SELECT full_name, job_code
   FROM employee
   WHERE emp_no = :mngr_no
   INTO :mngr_name, :title;

  SELECT COUNT(emp_no)
  FROM employee
  WHERE dept_no = :dno
  INTO :emp_cnt;

  SUSPEND;
 END
END
^

ALTER PROCEDURE SHIP_ORDER (
    PO_NUM CHAR(8) CHARACTER SET NONE)
AS
 DECLARE VARIABLE ord_stat CHAR(7);
 DECLARE VARIABLE hold_stat CHAR(1);
 DECLARE VARIABLE cust_no INTEGER;
 DECLARE VARIABLE any_po CHAR(8);
BEGIN
 SELECT s.order_status, c.on_hold, c.cust_no
 FROM sales s, customer c
 WHERE po_number = :po_num
 AND s.cust_no = c.cust_no
 INTO :ord_stat, :hold_stat, :cust_no;

 /* This purchase order has been already shipped. */
 IF (ord_stat = 'shipped') THEN
 BEGIN
  EXCEPTION order_already_shipped;
  SUSPEND;
 END

 /* Customer is on hold. */
 ELSE IF (hold_stat = '*') THEN
 BEGIN
  EXCEPTION customer_on_hold;
  SUSPEND;
 END

 /*
  * If there is an unpaid balance on orders shipped over 2 months ago,
  * put the customer on hold.
  */
 FOR SELECT po_number
  FROM sales
  WHERE cust_no = :cust_no
  AND order_status = 'shipped'
  AND paid = 'n'
  AND ship_date < CAST('NOW' AS DATE) - 60
  INTO :any_po
 DO
 BEGIN
  EXCEPTION customer_check;

  UPDATE customer
  SET on_hold = '*'
  WHERE cust_no = :cust_no;

  SUSPEND;
 END

 /*
  * Ship the order.
  */
 UPDATE sales
 SET order_status = 'shipped', ship_date = 'NOW'
 WHERE po_number = :po_num;

 SUSPEND;
END
^

ALTER PROCEDURE SHOW_LANGS (
    CODE VARCHAR(5) CHARACTER SET NONE,
    GRADE SMALLINT,
    CTY VARCHAR(15) CHARACTER SET NONE)
RETURNS (
    LANGUAGES VARCHAR(15) CHARACTER SET NONE)
AS
DECLARE VARIABLE i INTEGER;
BEGIN
  i = 1;
  WHILE (i <= 5) DO
  BEGIN
    SELECT language_req[:i] FROM joB
    WHERE ((job_code = :code) AND (job_grade = :grade) AND (job_country = :cty)
           AND (language_req IS NOT NULL))
    INTO :languages;
    IF (languages = ' ') THEN  /* Prints 'NULL' instead of blanks */
       languages = 'NULL';         
    i = i +1;
    SUSPEND;
  END
END
^

ALTER PROCEDURE SUB_TOT_BUDGET (
    HEAD_DEPT CHAR(3) CHARACTER SET NONE)
RETURNS (
    TOT_BUDGET NUMERIC(15,2),
    AVG_BUDGET NUMERIC(15,2),
    MIN_BUDGET NUMERIC(15,2),
    MAX_BUDGET NUMERIC(15,2))
AS
BEGIN
 SELECT SUM(budget), AVG(budget), MIN(budget), MAX(budget)
  FROM department
  WHERE head_dept = :head_dept
  INTO :tot_budget, :avg_budget, :min_budget, :max_budget;
 SUSPEND;
END
^


SET TERM ; ^
