Informix - Insert a boolean attribute - insert

I have this table definition :
CREATE TABLE Usuarios
(
CI INT PRIMARY KEY,
primer_nombre varchar(25) NOT NULL CHECK (primer_nombre MATCHES '^[a-zA-Z]$' ),
segundo_nombre varchar(25),
primer_apellido varchar(25) NOT NULL,
segundo_apellido varchar(25),
grado INT CHECK ( grado > 0 AND grado < 8),
fecha_nacimiento DATE NOT NULL,
nota INT CHECK ( nota > 0 AND nota < 13),
email varchar(80),
hace_proyecto boolean,
tipo varchar(20) CHECK (tipo IN ('Admin', 'Docente', 'Alumno')),
encriptacion_hash varchar(250),
encriptacion_sal varchar(250),
baja boolean
);
And this insert statement :
INSERT INTO Usuarios (CI, primer_nombre,segundo_nombre,primer_apellido,segundo_apellido,grado,fecha_nacimiento,nota,email,hace_proyecto,tipo,encriptacion_hash,encriptacion_sal,baja)
VALUES (
999999,
"Gabriel"
"Matias",
"Barrios",
"Cabrera",
NULL,
"10/28/1986",
1,
"myemail#gmail.com"
true,
"Alumno",
NULL,
NULL,
false
);
No matter what I do, I always get :
Connected.
201: A syntax error has occurred.
Error in line 17
Near character position 8
Disconnected.
I think it is related to my boolean fields. Is this true? How can I insert a boolean into my table ?

You are missing a ',' after "Gabriel" and then again after "myemail#gmail.com", and lastly the booleans are inserted as 't' or 'f' I believe.
Once I made those changes I just get an error about one of the check constraint's failing.

Related

Missing right parenthesis error while creating a table with SQL code generated in Vertabelo

I want to create a Database for my school project. Some tables were created without an error, but when I wanted to create a more complex table, I had this error:
ORA-00907: missing right parenthesis
The code is following (the names of the table and attributes are in Romanian):
CREATE TABLE Curse (
id_cursa int NOT NULL,
id_tura int NULL,
moment_inceput_cursa timestamp NULL,
moment_sfarsit_cursa timestamp NULL,
adresa_initiala text NULL,
GPS_punct_start text NULL,
adresa_destinatie text NULL,
destinatie_GPS text NULL,
stare_cursa char NOT NULL DEFAULT 0,
modalitate_plata int NULL,
pret decimal NULL,
CONSTRAINT Curse_pk PRIMARY KEY (id_cursa)
);
The actual fault is the DEFAULT clause comes before the NOT NULL clause. So this the correct syntax:
stare_cursa char DEFAULT 0 NOT NULL
Beyond that you need to change the text datatype to something like varchar2(1000) or whatever length you need.
A few objections:
TEXT datatype is invalid; I used VARCHAR2(100); could be larger, or CLOB
correct order is DEFAULT 0 NOT NULL (not NOT NULL DEFAULT 0)
Although it is not an error, you don't have to specify that NULL values are allowed
SQL> CREATE TABLE curse(
2 id_cursa INT NOT NULL,
3 id_tura INT NULL,
4 moment_inceput_cursa TIMESTAMP NULL,
5 moment_sfarsit_cursa TIMESTAMP NULL,
6 adresa_initiala VARCHAR2(100)NULL,
7 gps_punct_start VARCHAR2(100)NULL,
8 adresa_destinatie VARCHAR2(100)NULL,
9 destinatie_gps VARCHAR2(100)NULL,
10 stare_cursa CHAR DEFAULT 0 NOT NULL,
11 modalitate_plata INT NULL,
12 pret DECIMAL,
13 CONSTRAINT curse_pk PRIMARY KEY(id_cursa)
14 );
Table created.
SQL>

Oracle - Creating Triggers

I am trying to create a trigger in Oracle whereby we move deleted records to another table. So when deleted column is set to 1, it should move the records from the patient_table to the deleted_patient_table.
Can you please help :)
CREATE TABLE Patient_Table(
PatientID NUMBER(6) Primary Key,
Title char(4) NOT NULL,
Forename varchar2(20) NOT NULL,
Surname varchar2(20) NOT NULL,
Gender char(1) NOT NULL CHECK (Gender in ('M','F')),
DOB date NOT NULL,
TelNo varchar(12) NOT NULL,
Conditions varchar(200) NOT NULL,
Deleted Number(1) NOT NULL CHECK (Deleted in ('0','1'));
-- Table that should contain deleted records --
Create Table Deleted_Patient_table(
PatientID NUMBER(6) Primary Key,
Title char(4) NOT NULL,
Forename varchar2(20) NOT NULL,
Surname varchar2(20) NOT NULL,
Gender char(1) NOT NULL CHECK (Gender in ('M','F')),
DOB date NOT NULL,
TelNo varchar(12) NOT NULL,
Conditions varchar(200) NOT NULL,
Deleted Number(1));
Create or replace trigger trg_del
Before delete on Patient_Table
for each row
Begin
Insert into Deleted_Patient_table value (:old.PatientID,...)
End;
It seems you're soft-deleting your rows. i.e. not deleting but updating related column(Deleted) from 0 to 1. The values of column can be one of two and not null, so you only need to compare only two values of them without nvl operator. During this update operation you can use below trigger to produce log records :
Create or Replace Trigger Trg_Del_Patient
After Update on Patient_Table
For Each Row
Begin
If ( :old.Deleted = 0 and :new.Deleted = 1 ) Then
Insert into Deleted_Patient_table
values(:old.PatientID,:old.Title,:old.Forename,:old.Surname,
:old.Gender,:old.DOB,:old.TelNo,:old.Conditions);
Delete Patient_Table where PatientID = :old.PatientID;
-- Include this Delete statement, if you want to remove after the row has been inserted to the Deleted_Patient_Table
End If;
End;

SQL Error: ORA-00906: missing left parenthesis

CREATE TABLE Customer_TBL
(CustomerID INTEGER NOT NULL PRIMARY KEY,
CustomerName VARCHAR NOT NULL,
JobPosition VARCHAR,
CompanyName VARCHAR NOT NULL,
USState VARCHAR NOT NULL,
ContactNo BIGINTEGER NOT NULL);
Error starting at line : 1 in command -
Error report - SQL Error: ORA-00906: missing left parenthesis
00906. 00000 - "missing left parenthesis"
*Cause:
*Action:
Biginteger is not supported in Oracle, use number instead. And you need to use varchar2(number of char/bytes) or varchar(number of char/bytes).
Why the error missing left parenthesis?
Because Oracle was expecting ( after VARHCHAR but it was not there.
CREATE TABLE Customer_TBL (CustomerID INTEGER NOT NULL PRIMARY KEY,
CustomerName VARCHAR2(20) NOT NULL,
JobPosition VARCHAR2(20),
CompanyName VARCHAR2(20) NOT NULL,
USState VARCHAR2(20) NOT NULL,
ContactNo NUMBER NOT NULL);
You need to specify a maximum size for VARCHAR fields, e.g: field_name VARCHAR(40),

SQL Error: ORA-00906: missing left parenthesis 00906. 00000 - "missing left parenthesis"

i have been trying to make a simple table and i it keeps coming up with SQL Error: ORA-00906: missing left parenthesis 00906. 00000 - "missing left parenthesis"
CREATE TABLE USER_TABLE(
USER_ID int NOT NULL,
Username varchar NULL,
Password varchar NULL,
Email varchar NOT NULL,
DOB Date NULL,
Address VARCHAR NOT NULL,
First_name VARCHAR NOT NULL,
Telephone_number int NULL,
PRIMARY KEY (User_ID));
You simply need to add the size of VARCHAR colums:
CREATE TABLE USER_TABLE
(
USER_ID INT NOT NULL,
Username VARCHAR(1) NULL,
Password VARCHAR(1) NULL,
Email VARCHAR(1) NOT NULL,
DOB DATE NULL,
Address VARCHAR(1) NOT NULL,
First_name VARCHAR(1) NOT NULL,
Telephone_number INT NULL,
PRIMARY KEY(User_ID)
);
Notice that VARCHAR is deprecated, better use VARCHAR2

SQL Error: ORA-01722: invalid number

Here is my table.
CREATE TABLE SCHEDULE (
SCHEDULE_ID INT NOT NULL
,ARRV_TIME INT NOT NULL
,DEP_TIME INT NOT NULL
,BUS_TRANSFERS VARCHAR2(40) NOT NULL
,BUS_ID NUMERIC NOT NULL
,TRAVEL_DIRECTION VARCHAR(10) NOT NULL
,WEEK_DAY INTEGER NOT NULL
);
I run this insert statement
INSERT INTO SCHEDULE (SCHEDULE_ID, ARRV_TIME, DEP_TIME, BUS_TRANSFERS, BUS_ID, TRAVEL_DIRECTION, WEEK_DAY)
VALUES (SEQ_SCHEDULE.NEXTVAL,'10', '11', 'White Oak', '2', 'North', '4');
and I get this error message:
Error starting at line : 1 in command - INSERT INTO SCHEDULE
(SCHEDULE_ID, ARRV_TIME, DEP_TIME, BUS_TRANSFERS, BUS_ID,
TRAVEL_DIRECTION, WEEK_DAY) VALUES (SEQ_SCHEDULE.NEXTVAL,'10', '11',
'White Oak', '2', 'North', '4')
Error report - SQL Error: ORA-01722: invalid number
01722. 00000 - "invalid number"
*Cause: The specified number was invalid.
*Action: Specify a valid number.
Try This :-
CREATE TABLE SCHEDULE(
SCHEDULE_ID INTEGER NOT NULL ,
ARRV_TIME INTEGER NOT NULL ,
DEP_TIME INTEGER NOT NULL ,
BUS_TRANSFERS VARCHAR2(40) NOT NULL ,
BUS_ID INTEGER NOT NULL ,
TRAVEL_DIRECTION VARCHAR2(10) NOT NULL ,
WEEK_DAY INTEGER NOT NULL );
INSERT INTO SCHEDULE(SCHEDULE_ID, ARRV_TIME, DEP_TIME,BUS_TRANSFERS,BUS_ID, TRAVEL_DIRECTION, WEEK_DAY)
VALUES(SEQ_SCHEDULE.NEXTVAL,10,11, 'White Oak',2,'North',4);
This error is because you have declared arrived_time as int and you are trying to insert '10' value for that. Which is a string please remove the quotes for non string data types

Resources