Set Multiple constrains for JSON column in Oracle - oracle

How to create a column to save json data and have constraints "strict" JSON and "with unique Keys"?
Below code works only when a single constraint is present, but errors out with two constraints.
ALTER TABLE NOTIFICATIONS
ADD RECEIVER VARCHAR2(4000 CHAR)
CONSTRAINT strict_json
CHECK (RECEIVER IS JSON STRICT) ,
CONSTRAINT unique_json_keys
CHECK (RECEIVER IS JSON WITH UNIQUE KEYS);
Error report - ORA-01735: invalid ALTER TABLE option 01735. 00000 - "invalid ALTER TABLE option" *Cause: *Action:

If you follow the syntax diagrams closely, you will find that (1) your constraints are "inline constraints", and (2) when defining multiple constraints on a single column, they should not be separated by comma.
Drop the comma between the constraints and try again.

Related

How to change the name of constraint or drop it that has dot (.) inside its name?

I have created a constraint named version.pk while back ago on some table. Now, I want to drop it using the following query
alter table user.some_table drop constraint version.pk
However it's giving me an error saying ORA-01735: invalid ALTER TABLE option. I think it's because the constraint has dot (.) inside it and oracle does not recognize the query as a valid one. I wanted to change the name of the constraint to version_pk with the following query
alter table user.some_table rename constraint version.pk to version_pk
But again the same issue this time with different error ORA-00946: missing TO keyword . But I think the reason is the same, as it is not a valid query.
One solution that I have found for primary key type of constraints is this
alter table user.some_table drop primary key
But my constraint is foreign key type. Is there any way to refer constraint name as a literal text, something like 'version.pk', so that query remains valid?
Use a quoted identifier:
alter table user.some_table drop constraint "VERSION.PK";
Note: when you use quoted identifiers, you MUST use the correct case for all characters in the identifier as "VERSION.PK", "version.pk" and "VeRsIoN.pK" are three different identifiers.
Note: Single quotes are for text literals and double quotes are for quoted identifiers.

Why can I not add a check constraint that makes the user enter an email ending in a specific address

Implementing: An employee email address should use the company domain. That is, the
email address should end with 'abcco.com'.
alter table employee
add constraint emp_email_check check (co_email in ('%abcco.com'));
but I get this error
ORA-02293: cannot validate (ITAM.EMP_EMAIL_CHECK) - check constraint violated
02293. 00000 - "cannot validate (%s.%s) - check constraint violated"
*Cause: an alter table operation tried to validate a check constraint to
populated table that had nocomplying values.
*Action: Obvious
The IN() predicate tests for exact string matches only. It does not support wildcards.
You should use
check (co_email like '%abcco.com')
Or alternatively:
check (left(co_email, 9) = 'abcco.com')

Adding NOT NULL Constraint with ALTER TABLE statement (Oracle)

this is my PL-SQL statement
ALTER TABLE regions MODIFY (region_name VARCHAR(40) DEFAULT 'Euro') CONSTRAINT region_nn NOT NULL;
The column 'region_name' has NULL values I want to replace with 'Euro'. I get an error with this, and I'm wondering if I have the syntax wrong or if it's impossible to place a default value when adding the NOT NULL constraint and I have to do it as two separate SQL statements
Thank you for your help'
adding a constrain does not modify any existing data, it only modifies the definition of your table. Fix your data first, then add the constraint - or add the constraint with the defererred keyword and then fix the data. Either way, you'll manually have to update the data.

Add enum type column to table

im trying to add a new column to my existing table 'Results', and it seems to be very easy but I cant see the mistake.
Here is my code:
SQL> Alter table results add column CAL ENUM('A','B');
ERROR at line 1: ORA-00904: : invalid identifier
What am I missing?
I've read this from w3 and this from java2s but cant see the difference to mine.
Thanks, and sorry for the dumb question.
OK, with an ORA- error I am assuming that this is an oracle database, and not mysql. you have both tags and you are linking to MySQL example, but the error is not a MySQL error.
Assuming that this IS an Oracle DB, then there is no native ENUM data type. You have to do this as follows: First - you add the column with a correctly defined data type, and second you create a constrained list of permitted values on that column as a check constraint.
Alter table results add (cal varchar2(1));
Alter table results add constraint chk_cal CHECK (cal in ('A','B')) ENABLE;
(EDITED to fix brackets in constraint creation line)

Getting an invalid ALTER TABLE option

This is my exact query which is erroring out
alter table INDIL_MCAR drop constraint ABOB.INDI_MCAR_PK;
I m trying to remove the unique key constring from the table. It gives me the following error.
ORA-01735: invalid ALTER TABLE option
You can't prefix the constraint name... the table name yes, but not the constraint name. Remove the ABOB.:
alter table INDIL_MCAR drop constraint INDI_MCAR_PK;

Resources