0

I need to create a table in PL/SQL and this table need to have a CONSTRAINT on two attribut. I explain:

One of this two objects "com_name" and "com_nickname" need to be checked, if the both are it's ok, but at least one need to be filled.

I'm a beginner and I can't understand how can I make it work

*

CONSTRAINT ch_com_name_nickname CHECK (com_name = NOT NULL OR com_nickname = NOT NULL)

*

This is not working.

2
  • 'Not working' isn't very helpful, it's better to say what you expect and what you actually get. But you need IS NOT NULL, not = NOT NULL. Also why have you mentioned PL/SQL? Commented Oct 5, 2018 at 16:24
  • Also see this, which is PostgreSQL not Oracle but same syntax' and this. Commented Oct 5, 2018 at 16:31

2 Answers 2

1

The correct syntax is column_name IS NOT NULL. You don't need the =.

Sign up to request clarification or add additional context in comments.

Comments

-1

Why do u want do it by CONSTRAINT?!

This kind of task solves not like that.

You can simply check it in your logic (in procedure or function).

2 Comments

+1 I just started to learning SQL that's why I don't know how use others stuff, I will try to improve my code during this week ! Thank you for your advice !
A check constraint is the correct thing to use for this. It's fine and good to have application logic make sure it inserts the right things, but it should be as well as a check constraint, not instead of one. Having a check constraint (a) saves you if the application logic is somehow broken, and (b) still applies if the application is bypassed - if someone inserts directly into the table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.