简体   繁体   中英

Invalid number in SQL Developer to test queries

I am trying to test my queries based on this table:

--Create Person Table
CREATE TABLE Person
(
    Person_ID NUMBER(10) PRIMARY KEY,
    First_Name NUMBER(15) NULL,
    Last_Name VARCHAR2(15) NULL,
    Middle_Name VARCHAR2(15) NULL,
    Street_Address VARCHAR(35) NULL,
    City    VARCHAR2(10) NULL,
    State   VARCHAR2(2) NULL,
    Zipcode VARCHAR2(5) NULL, 
    Country CHAR(2) NOT NULL, 
    Birth_Date DATE NOT NULL,
    Gender CHAR(1) NOT NULL,
    Phone VARCHAR2(10) NULL,
    Email VARCHAR2(25) NULL,
    Is_Patient CHAR(1) NULL,
    Is_Physician CHAR(1) NULL,
    Is_Employee CHAR(1) NULL,
    Is_Volunteer CHAR(1) NULL 
);

And this is what I input:

INSERT INTO PERSON (Person_ID, First_Name, Last_Name, Middle_Name, Street_Address,
City, State, Zipcode, Country, Birth_Date, Gender, Phone,
Email, Is_Patient, Is_Physician, Is_Employee, Is_Volunteer)

VALUES
    (1234, 'Jill', 'Palmer', 'Wendy', '123 Apple Court',
     'Bronx', 'NY', '10472', 'USA', date '1956-09-15', 'F', '9178546215',
     'heygirl5@gmail.com', 'Y', 'N', 'N','N');

VALUES
    (2345, 'Charles', 'Connor', 'Vanny', '87455 Lemon Drive',
     'Queens', 'NY', '12047', 'USA', date '1953-10-08', 'M', '9178546200',
     'sugahsugah@gmail.com', 'N', 'N', 'Y','N');

VALUES
    (3456, 'Chaniece', 'Boone', 'Pia', '94102 Grape Meaows',
     'Brooklyn', 'NY', '12047', 'USA', date '1983-03-31', 'F', '3479845102',
     'byenow@gmail.com', 'N', 'Y', 'N','N');

VALUES
    (4567, 'James', 'Boone', 'Wayck', '2010 Orange Place',
     'Manhattan', 'NY', '10026', 'USA', date '1981-08-03', 'M', '7187884411',
     'howyoudoin@gmail.com', 'Y', 'N', 'N','N');

VALUES
    (5678, 'Charlton', 'Connor', 'Ethan', '94165 Mango Lane',
     'Staten Island', 'NY', '30124', 'USA', date '1988-12-10', 'M', '6469820145',
     'youcrazyboy@gmail.com', 'Y', 'N', 'N','Y');

SELECT *
FROM PERSON;

I am getting an error of invalid number and I don't see why. Nothing is coming up on my test also.

You defined First_Name as NUMBER(15) . You probably meant VARCHAR2(15) .

Also, you have a mix of CHAR , VARCHAR and VARCHAR2 . These should all be VARCHAR2 . ( CHAR will seem to work, but it just causes problems for no added benefit ).

create table person
( person_id         number(10) primary key
, first_name        varchar2(15)  -- Not number
, last_name         varchar2(15)
, middle_name       varchar2(15)
, street_address    varchar2(35)
, city              varchar2(30)  -- Increased from 10
, state             varchar2(2)
, zipcode           varchar2(5)
, country           varchar2(3) not null  -- increased size to 3 to fit 'USA'
, birth_date        date not null
, gender            varchar2(1)
, phone             varchar2(10)
, email             varchar2(25)
, is_patient        varchar2(1)
, is_physician      varchar2(1)
, is_employee       varchar2(1)
, is_volunteer      varchar2(1)
);

insert into person
( person_id
, first_name, last_name, middle_name
, street_address, city, state, zipcode, country
, birth_date
, gender, phone, email
, is_patient, is_physician, is_employee, is_volunteer )
values
( 1234  -- Not '1234'
, 'Jill', 'Palmer', 'Wendy'
, '123 Apple Court', 'Bronx', 'NY', '10472', 'USA'
, to_date('09/15/1956', 'MM/DD/YYYY')  -- Corrected format mask (alternatively: date '1956-09-15')
, 'F'
, '9178546215'
, 'heygirl5@gmail.com'
, 'Y', 'N', 'N', 'N'  -- Not 'YES'/'NO' because the columns are 1 character
);

Maybe some more of the columns should be declared NOT NULL. Is it really OK for a person not to have a name or address or anything else besides a country and birth date? (You don't need to specify NULL for a nullable column, and doing so makes it harder to tell which ones are mandatory.)

Probably most of the name columns should be longer.

Ideally Y/N columns should be mandatory and enforced by check constraints, eg

is_patient  varchar2(1) not null  constraint is_patient_yn_chk check (is_patient in ('Y','N'))

The exact error you are seeing is probably being caused by that you are trying to insert a string value into the Person_ID column, which you have defined as numeric. Beyond this, you should always explicitly list the columns for the insert:

INSERT INTO PERSON (Person_ID, First_Name, Last_Name, Middle_Name, Street_Address,
    City, State, Zipcode, Country, Birth_Date, Gender, Phone,
    Email, Is_Patient, Is_Physician, Is_Employee, Is_Volunteer)
VALUES
    (1234, 'Jill', 'Palmer', 'Wendy', '123 Apple Court',
     'Bronx', 'NY', '10472', 'USA', date '1956-09-15', 'F', '9178546215',
     'heygirl5@gmail.com', 'Y', 'N', 'N','N');

Also note that for the Is_xxx columns, you should only be inserting a 'Y' or 'N' value, as you have defined these columns to be CHAR(1) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM