DEFAULT constraint not working in SQL Oracle? [closed] - sql

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I'm trying to get a constraint (this is just test code) but when I add the data (complete the whole table) and run it with leaving out Apptime data in the values it doesn't default to hello in the table it's just '-'. I'm using Oracle Live SQL. Any clue as to how this is done? Would be good if I could do it in the schema and not a constraint but if it has to be a constraint outside that's okay.
Thank you and apologies if I did anything wrong in this question, I'm new haha.
DROP TABLE Bok;
CREATE TABLE Bok (
BokID number(3) NOT NULL PRIMARY KEY,
Appdate varchar2(4),
Apptime varchar2(5) DEFAULT 'hello'
);

In order to default to work the insert query has to use DEFAULT keyword or skip the column
INSERT INTO Bok(BokID, Appdate, appTime)
VALUES (1, 'a', DEFAULT);
INSERT INTO Bok(BokID, Appdate)
VALUES (1, 'a');
One more option when DEFAULT ON NULL is defined:
CREATE TABLE Bok (
BokID number(3) NOT NULL PRIMARY KEY,
Appdate varchar2(4),
Apptime varchar2(5) DEFAULT ON NULL 'hello'
);
INSERT INTO Bok(BokID, Appdate, appTime)
VALUES (1, 'a', NULL);

Related

Manager " keyword not on a valid Position" [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 days ago.
Improve this question
I have working on a project. i found that SQL code on internet. i have not familiar with SQL. anyone help me regarding this. I have facing difficulties to execute this query in SQL work bench after login as administration.
Line number 1, 4, 5 and 6 getting error. Please correct this code what things I need to correct or change.
create user reservation identified by manager;
grant dba to reservation;
commit;
connect reservation/manager;
create table admin6(uname varchar2(40) primary key,name varchar2(40),
pword varchar2(50),mail_id varchar2(60),phone_no varchar2(12));
create table train6(tr_no number(10) primary key,tr_name varchar2(70),
from_stn varchar2(20),to_stn varchar2(20),available number(5),fare number(5));
create table register(uname varchar2(40) primary key,pword varchar2(50),
fname varchar2(40),lname varchar2(40),
addr varchar2(100), phno varchar2(12), mailid varchar2(60));
insert into admin6 values('admin','admin','admin','admin#train.com','9874561230');
insert into admin6 values('shashi','shashi','admin','shashi#train.com','98323561230');
insert into train6 values(10101,'Jodhpur Exp','Howrah','Jodhpur',152,450);
insert into train6 values(10102,'Mumbai Mail','Gaya','Mumbai',182,650);
insert into register values('shashi','shashi','Shashi','Raj','Tekari, Gaya, Bihar',954745222,'shashiraj.972#gmail.com');
commit;

i keep getting a "missing right parenthesis" error. But cannot see anything visibly wrong [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
Improve this question
I am new to SQL and I have been trying to make this table however when I put the duration of the tour as an integer that would last an hour and a half. however, it keeps showing up as red and giving the error message that it's "missing the right parentheses". I've only been taught how to use integers but not sure if this is the right one to use in this situation.
and for the table that will be referenced from that table is saying that there is nothing to reference and rightfully so because I have yet to make the table. but if anybody could help with this problem it would be much appreciated!
create table qualification
( tour_id varchar2(8) not null
, guide varchar2(8) null
, date_passed date null
, primary key (tour_id, guide)
, foreign key (guide) references guide(guide_no)
, foreign key (tour_id) references tour(tour_id)
);
create table tour
( tour_id varchar2(8) primary key
, tour_name varchar2(20) not null
, duration_of_tour integer (180) null
, standard_cost integer (6,2) not null
);
Oracle has the NUMBER datatype.
INTEGER(n,m) wouldn't work anywhere.
Standard SQL would be DECIMAL(n,m) then.
So this statement will work
create table tour
( tour_id varchar2(8) primary key
, tour_name varchar2(20) not null
, duration_of_tour number(38,0) null
, standard_cost number(6,2) not null
);
But the size of duration_of_tour might be too big.
At the best of my knowledge, you can't define a column with a type of integer WITH precision. The "int" or "integer" are just aliases for type number with already defined precision. I'm almost sure it is aliases for max allowed - "number(38)"
So, it's either "integer" or "number(x,y)"
However if you updated your col type from integer(180) to number(180) you'll hit another error because number can't be 180 digits long.
Check this doc, perhaps you'll find something useful there

I am trying to extract only date value from Oracle's SYSDATE but my query is giving me ORA-02290: check constraint violated [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I want to insert current date into my record, First I executed this query successfully.
insert into Member values (1, 'Richa Sharma', 'Pune', TO_DATE('10-Dec-05', 'DD-MM-YY'), 'Lifetime', '25000', 5, 50);
Then while executing the following query I'm getting the above error code.
insert into Member values (2, 'Garima Sen', 'Pune', SYSDATE, 'Annual', 100, 3, NULL);
EDIT: This is the query I used to create table.
create table Member (Member_Id number(5),
Member_Name varchar2(30),
Member_Address varchar2(50),
Acc_Open_Date date,
Membership_Type varchar2(20),
Fees_Paid number(6),
Max_Books_Allowed number(2),
Penalty_Amount number(7,2),
PRIMARY KEY(Member_Id),
CHECK (Membership_Type IN ('Lifetime',' Annual', 'Half Yearly',' Quarterly')));
Your check constraint has a leading space in ' Annual' change to 'Annual'

INSERT INTO suppliers casue Schema Creation Failed: ORA-00922: missing or invalid option [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
What's causing this error?
Schema Creation Failed: ORA-00922: missing or invalid option
.........................
CREATE TABLE suppliers
(
sid int,
sname varchar(20),
address varchar(30)
)
CREATE TABLE product
(
pid int,
pname varchar(20),
color varchar(30)
)
CREATE TABLE catalog
(
sid int,
pid int,
cost int
)
INSERT INTO suppliers
(sid, sname,address)
VALUES
(1, "name1","address1"),
(2, "name2","address2");
SQL Fiddle
Also, your INSERT statement will probably fail in Oracle (though this is not the reason why you are getting ORA-00922)
Change it to:
INSERT ALL
INTO suppliers(sid, sname,address) VALUES (1, 'name1','address1')
INTO suppliers(sid, sname,address) VALUES (2, 'name2','address2')
SELECT * FROM dual;

SQL Error: ORA-00947: not enough values [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Learning Oracle SQL. I have created a table that looks like this:
CREATE TABLE Kocury
(imie VARCHAR2(15) NOT NULL,
plec VARCHAR2(1) CONSTRAINT allowedValues CHECK (plec in ('M', 'D')),
pseudo VARCHAR2(15) Constraint PK_KOCURY PRIMARY KEY,
funkcja VARCHAR2(10) CONSTRAINT fk_checkF REFERENCES Funkcje (funkcja),
szef VARCHAR2(15) CONSTRAINT fk_checkS references Kocury (pseudo),
w_stadku_od DATE default sysdate,
przydzial_myszy NUMBER(3),
myszy_extra NUMBER(3),
nr_bandy NUMBER(2) CONSTRAINT fk_checkN REFERENCES Bandy(nr_bandy)
);`
and then I tried to insert some data:
INSERT INTO Kocury(imie, plec, pseudo, funkcja, szef, w_stadku_od, przydzial_myszy ,myszy_extra, nr_bandy)
VALUES ('JACEK', 'M', 'PLACEK', 'LOWCZY', 'LYSY', '2008-12-01, 67',NULL , 2);
as far as I am concerned the data types all match. But in Oracle SQL Developer I get this:
Error starting at line : 41 in command -
INSERT INTO Kocury(imie, plec, pseudo, funkcja, szef, w_stadku_od, przydzial_myszy ,myszy_extra, nr_bandy)
VALUES ('JACEK', 'M', 'PLACEK', 'LOWCZY', 'LYSY', '2008-12-01, 67',NULL , 2)
Error at Command Line : 42 Column : 1
Error report -
SQL Error: ORA-00947: not enough values
00947. 00000 - "not enough values"
*Cause:
*Action:
I am not sure what's happening and how to get my data inserted. What could I be doing wrong? These topics didn't help me:
ORA-00947 : Not Enough Values
ORA-00947: not enough values
You're missing some apostrophes in between '2008-12-01, 67':
INSERT INTO Kocury(imie, plec, pseudo, funkcja, szef, w_stadku_od, przydzial_myszy ,myszy_extra, nr_bandy)
VALUES ('JACEK', 'M', 'PLACEK', 'LOWCZY', 'LYSY', '2008-12-01', 67, NULL , 2)