I am using Apex Oracle to run a script file merging data/tables with an existing schema. Here is the complete script file.
The error is produced on Every Insert Command stating not a valid month.
One error is produced on Alter command stating Column Type incompatible with referenced column type
The Script File:
--A1_rr_upd.txt file
--dropping the table if already exists
DROP TABLE RRSTAFF;
--creating new table for RRSTAFF
CREATE TABLE RRSTAFF (
staff_num CHAR(4) PRIMARY KEY,
name VARCHAR(20),
gender CHAR(1),
date_join DATE,
date_resign DATE,
contact_num NUMBER(11),
address VARCHAR(255)
);
--Adding new hired staff
INSERT INTO RRSTAFF VALUES ('s001','Adrian','M','2021/07/02',null,'60122000000','6 Jalan BU6, Petaling Jaya,Selangor');
INSERT INTO RRSTAFF VALUES ('s002','Jewel','F','2021/07/12',null,'60123000000','2 Jalan PJS2, Sunway,Selangor');
INSERT INTO RRSTAFF VALUES ('s003','Sean','M','2021/07/12',null,'60166000000','100 Sunway South K,Selangor');
--Adding new customer details
INSERT INTO rrcustomer VALUES ('1011','Dr','Brendan');
INSERT INTO rrcustomer VALUES ('1012','Dr','Haya');
--Adding new records into models
INSERT INTO model VALUES ('LGC83','LG C1 83 in OLED 4K TV', '500');
INSERT INTO model VALUES ('LGG77','LG Gallery 77 in OLED 4K TV', '400');
INSERT INTO model VALUES ('SNY43','Sony 43 in X75 4K Ultra HD Android TV', '200');
INSERT INTO model VALUES ('SHA50','Sharp 50 in Full HD Basic TV ', '80');
--Adding new records into appliance
INSERT INTO appliance VALUES ('2010','LGC83','E',null);
INSERT INTO appliance VALUES ('2011','LGC83','E',null);
--Altering the HIRE table to link it with RRSTAFF using staff_id as Foriegn Key
ALTER TABLE
hire ADD(
staff_id VARCHAR(4),
FOREIGN KEY (staff_id) REFERENCES rrstaff(staff_num)
);
--Adding new hire records
INSERT INTO hire VALUES ('2010','2021/08/02','1011','2021/08/08','s001');
INSERT INTO hire VALUES ('2010','2021/08/22','1012','2021/08/28','s001');
INSERT INTO hire VALUES ('2011','2021/08/12','1013',null,'s001');
Use TO_DATE('2021/07/02', 'YYYY/MM/DD') to convert your date values to the standard database date format
Replace the above date value as your date columns
In Oracle, you express date constants using the date keyword and a string in the ISO standard YYYY-MM-DD format. For instance:
INSERT INTO RRSTAFF
VALUES ('s001', 'Adrian', 'M', DATE '2021-07-02', null, '60122000000', '6 Jalan BU6, Petaling Jaya,Selangor');
Here is a db<>fiddle.
using to_date makes the script robust and independent from an implicit format. It also makes the code more readable since to_date is quite obvious in its syntax.
I'm still learning SQL so this is really basic. Im trying to get the Project Inserts to go into the project table, but Column name or number of supplied values does not match table definition. keeps on coming up can someone point out whats wrong
CREATE TABLE ASSIGNMENT (
ASN_NUM CHAR (2) NOT NULL CHECK (ASN_NUM IN ('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20')),
ASN_DATE VARCHAR (9) NOT NULL,
ASN_PRO_NUM CHAR (3) NOT NULL CHECK (ASN_PRO_NUM IN ('123','124','125','126','127','128')) REFERENCES PROJECT (PRO_NUM),
ASN_EMP_NUM CHAR (1) NOT NULL CHECK (ASN_EMP_NUM IN ('1','2','3','4','5','6','7')) REFERENCES EMPLOYEE (EMP_NUM),
ASN_JOB_CODE CHAR (3) NOT NULL CHECK (ASN_JOB_CODE IN ('ACT','DAN','DSD','DSS','NAD','NIN','SAN','SMO')) REFERENCES JOB (JOB_CODE),
ASN_HOURS DECIMAL (4,2) DEFAULT 0,
ASN_CHG_HR MONEY DEFAULT 0,
ASN_CHARGE MONEY DEFAULT 0,
PRIMARY KEY (ASN_NUM)
)
INSERT INTO ASSIGNMENT VALUES ('1','20-Jun-99','127','3','DSD','2.60',175.00,435.00);
INSERT INTO ASSIGNMENT VALUES ('2','20-Jun-99','123','6','SMO','1.80',85.00,53.00);
INSERT INTO ASSIGNMENT VALUES ('3','20-Jun-99','123','6','SAN','2.00',145.00,290.00);
INSERT INTO ASSIGNMENT VALUES ('4','20-Jun-99','126','2','NAD','3.70',120.00,444.00);
INSERT INTO ASSIGNMENT VALUES ('5','20-Jun-99','128','7','DSS','3.20',79.50,254.40);
INSERT INTO ASSIGNMENT VALUES ('6','20-Jun-99','127','2','DSD','2.90',175.00,507.50);
INSERT INTO ASSIGNMENT VALUES ('7','20-Jun-99','123','7','DSD','2.90',175.00,507.50);
INSERT INTO ASSIGNMENT VALUES ('8','20-Jun-99','125','5','NAD','1.50',120.00,180.00);
INSERT INTO ASSIGNMENT VALUES ('9','20-Jun-99','124','3','DSD','2.30',175.00,402.50);
INSERT INTO ASSIGNMENT VALUES ('10','20-Jun-99','127','5','NAD','4.30',120.00,516.00);
INSERT INTO ASSIGNMENT VALUES ('11','20-Jun-99','123','3','DSD','3.80',175.00,665.00);
INSERT INTO ASSIGNMENT VALUES ('12','21-Jun-99','126','7','DAN','1.50',95.00,142.50);
INSERT INTO ASSIGNMENT VALUES ('13','21-Jun-99','127','6','SAN','5.00',145.00,725.00);
INSERT INTO ASSIGNMENT VALUES ('14','21-Jun-99','125','3','DSD','2.90',175.00,507.50);
INSERT INTO ASSIGNMENT VALUES ('15','21-Jun-99','123','6','SMO','3.80',85.00,323.00);
INSERT INTO ASSIGNMENT VALUES ('16','21-Jun-99','128','5','NAD','4.10',120.00,492.00);
INSERT INTO ASSIGNMENT VALUES ('17','21-Jun-99','123','7','DAN','6.30',95.00,598.50);
INSERT INTO ASSIGNMENT VALUES ('18','21-Jun-99','125','2','NAD','11.20',120.00,1,344.00);
INSERT INTO ASSIGNMENT VALUES ('19','21-Jun-99','125','3','DSD','2.80',175.00,490.00);
INSERT INTO ASSIGNMENT VALUES ('20','01-Feb-99','123','1','SMO','2.00',85.00,170.00);
CREATE TABLE CLIENT (
CLI_NUM CHAR (3) NOT NULL CHECK (CLI_NUM IN ('112','114','115','118','122','123')),
CLI_LNAME VARCHAR (20) NOT NULL,
CLI_FNAME VARCHAR (20) NOT NULL,
CLI_MINI VARCHAR (10),
CLI_ADD VARCHAR (30) NOT NULL,
CLI_CITY VARCHAR (12) NOT NULL,
CLI_STATE CHAR (2) NOT NULL,
CLI_ZIP CHAR (5) NOT NULL,
CLI_AREA CHAR (3) NOT NULL,
CLI_PHONE CHAR (8) NOT NULL CHECK (CLI_PHONE LIKE ('[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]')),
PRIMARY KEY (CLI_NUM)
)
INSERT INTO CLIENT VALUES ('112','Chasteen','Anne','R','1234 Rose Lane','Murfreesboro','TN','37130','615','123-2345');
INSERT INTO CLIENT VALUES ('114','Williamson','Kirby','T','2345 Grove Street','Nashville','TN','32001','615','234-5678');
INSERT INTO CLIENT VALUES ('115','Quahtoty','hrman','','3456 Waterford Rd.','Nashville','TN','32008','615','239-9876');
INSERT INTO CLIENT VALUES ('118','Smith','Mary','M','4567 Oleander Blvd.','Owensboro','KY','38345','652','456-6543');
INSERT INTO CLIENT VALUES ('122','Taylor','Christopher','F','5678 Treeline Rd.','Murfreesboro','TN','37130','615','238-3344');
INSERT INTO CLIENT VALUES ('123','Trevors','Anne','K','6789 Sweetwater Dr.','Louisville','KY','39932','654','654-9001');
CREATE TABLE EMPLOYEE (
EMP_NUM CHAR (1) NOT NULL CHECK (EMP_NUM IN ('1','2','3','4','5','6','7')),
EMP_LNAME VARCHAR (20) NOT NULL,
EMP_FNAME VARCHAR (15) NOT NULL,
EMP_MINI VARCHAR (10),
EMP_DOB VARCHAR (35) NOT NULL,
EMP_VETERAN VARCHAR (3) NOT NULL CHECK (EMP_VETERAN IN ('YES','NO')),
PRIMARY KEY (EMP_NUM)
)
INSERT INTO EMPLOYEE VALUES ('1','Dempsey','John','R','Wednesday, December 02, 1970','No');
INSERT INTO EMPLOYEE VALUES ('2','Smithson','Susan','B','Saturday, April 11, 1964','Yes');
INSERT INTO EMPLOYEE VALUES ('3','Smith','James','D','Sunday, September 23, 1973','No');
INSERT INTO EMPLOYEE VALUES ('4','McDermott','Anne','W','Friday, November 28, 1975','No');
INSERT INTO EMPLOYEE VALUES ('5','Cheng','George','','Friday, July 09, 1971','Yes');
INSERT INTO EMPLOYEE VALUES ('6','Jackson','Marie','J','Saturday, October 16, 1971','No');
INSERT INTO EMPLOYEE VALUES ('7','Hernandez','Carlos','M','Friday, April 23, 1965','No');
CREATE TABLE JOB (
JOB_CODE CHAR (3) NOT NULL CHECK (JOB_CODE IN ('ACT','DAN','DSD','DSS','NAD','NIN','SAN','SMO')),
JOB_DESCRIPTION VARCHAR (45) NOT NULL,
JOB_CHG_HOUR MONEY DEFAULT 0,
PRIMARY KEY (JOB_CODE)
)
INSERT INTO JOB VALUES ('ACT','Accountant',75.00);
INSERT INTO JOB VALUES ('DAN','Data Analyst',95.00);
INSERT INTO JOB VALUES ('DSD','Database Systems Designer',175.00);
INSERT INTO JOB VALUES ('DSS','Decision Support Systems Specialist',79.50);
INSERT INTO JOB VALUES ('NAD','Network Administrator',120.00);
INSERT INTO JOB VALUES ('NIN','Network Installer',110.00);
INSERT INTO JOB VALUES ('SAN','Systems Analyst',145.00);
INSERT INTO JOB VALUES ('SMO','Statistical Modeler',85.00);
CREATE TABLE PROJECT (
PRO_NUM CHAR (3) NOT NULL CHECK (PRO_NUM IN ('123','124','125','126','127','128')),
PRO_NAME VARCHAR (20) NOT NULL,
PRO_CLI_NUM CHAR (3) NOT NULL CHECK (PRO_CLI_NUM IN ('118','122','114','112','118','114')) REFERENCES CLIENT (CLI_NUM),
PRO_COST MONEY DEFAULT 0,
PRO_OPEN_DATE VARCHAR (30) NOT NULL,
PRO_MANAGER CHAR (1) NOT NULL,
PRO_COORDINATOR CHAR (1) NOT NULL,
PRIMARY KEY (PRO_NUM)
)
INSERT INTO PROJECT VALUES ('123','Rock Veil','118',2,707.00,'Monday, May 12, 1997','2','5');
INSERT INTO PROJECT VALUES ('124','Willow Branch','122',785,000.00,'Monday, August 24, 1998','7','3');
INSERT INTO PROJECT VALUES ('125','Tin Roof','114',4,557,500.00,'Tuesday, May 12, 1998','6','5');
INSERT INTO PROJECT VALUES ('126','Freeze','112',1,080,000.00,'Tuesday, March 30, 1999','5','2');
INSERT INTO PROJECT VALUES ('127','Rumble Seat','118',3,010,000.00,'Thursday, June 11, 1998','2','6');
INSERT INTO PROJECT VALUES ('128','Fancy Flight','114',6,805,000.00,'Tuesday, June 22, 1999','5','7');
CREATE TABLE SKILL (
SKILL_EMP_NUM CHAR (1) NOT NULL CHECK (SKILL_EMP_NUM IN ('2','2','3','5','6','6','7','7','7')) REFERENCES EMPLOYEE (EMP_NUM),
SKILL_JOB_CODE CHAR (3) NOT NULL CHECK (SKILL_JOB_CODE IN ('DSD','NAD','DSD','NAD','SAN','SMO','DAN','DSD','DSS')) REFERENCES JOB (JOB_CODE),
SKILL_DATE VARCHAR (35) NOT NULL,
PRIMARY KEY (SKILL_EMP_NUM, SKILL_JOB_CODE)
)
INSERT INTO SKILL VALUES ('2','DSD','Monday, November 09, 1998');
INSERT INTO SKILL VALUES ('2','NAD','Friday, February 14, 1997');
INSERT INTO SKILL VALUES ('3','DSD','Thursday, April 11, 1996');
INSERT INTO SKILL VALUES ('5','NAD','Tuesday, December 05, 1995');
INSERT INTO SKILL VALUES ('6','SAN','Monday, July 23, 1990');
INSERT INTO SKILL VALUES ('6','SMO','Wednesday, September 02, 1992');
INSERT INTO SKILL VALUES ('7','DAN','Friday, November 28, 1997');
INSERT INTO SKILL VALUES ('7','DSD','Tuesday, June 22, 1999');
INSERT INTO SKILL VALUES ('7','DSS','Monday, May 17, 1993');
This is a little long for a comment.
When using insert, you should always be in the habit of including all the column names. So your first insert should look like:
INSERT INTO ASSIGNMENT(ASN_NUM, ASN_DATE, ASN_PRO_NUM, ASN_EMP_NUM, ASN_JOB_CODE, ASN_HOURS, ASN_CHG_HR, ASN_CHARGE)
VALUES ('1','20-Jun-99','127','3','DSD','2.60',175.00,435.00);
This won't necessarily fix the problem, but it will make it easier to debug.
To find the problem, run the code one table at a time to isolate the issue.