PL/SQL – How to make a check whether the attribute is positive or zero

610 pts.
Tags:
Oracle PL/SQL
PL/SQL
PL/SQL attributes
PL/SQL Variables
Hi Experts, How to make a check on attribute(NUMBER) is positive or zero?
ASKED: February 9, 2009  4:55 AM
UPDATED: November 27, 2013  2:18 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

You might want to provide more information about your question.

- Is this attribute a database table column ? Do you want to make this check when rows are inserted ?
- Is this a local variable, or a procedure parameter ? (you tagged your question ‘PL/SQL Variables’)

A simlpe answer would be:

if  >= 0 then
...
...
end if;
The other way is with SQL statement and CUSTOM OPERATOR:
SELECT CUSTOM_OPERATOR(field_name)
  FROM table;
Information how to create CUSTOM operator is HERE.

Discuss This Question: 4  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Inprise
    Yes it s a database table column,need to check this before DML operation(INSERT/DELETE) and it s of NUMBER datatype and it s a procedure parameter
    610 pointsBadges:
    report
  • carlosdl
    This is still unclear for me, since you say it is a table column, and you say it is a procedure parameter also. If you want this check to be made automatically when data is updated or inserted into the table, you could use a check constraint. You could create it like this:
    ALTER TABLE yourTable ADD CONSTRAINT YourChkconstraint CHECK (yourField >= 0 );
    This will make any insert or update fail when a negative value is being assigned to that column. You mentioned DELETEs also. Could you provide an example on how this check should work when deleting rows from the table ?
    65,110 pointsBadges:
    report
  • sulica
    In that cases I create CUSTOM operator. HERE is example.
    185 pointsBadges:
    report
  • carlosdl
    Why would you create a custom operator in this particular case, when a simple ">= 0" comparison is enough?
    65,110 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following