Override PL-SQL condition

Asked

Viewed 79 times

1

I have a condition, like this one below, in a query.

If you receive the empty parameter or with 0, I would like this condition to cease to exist, or be nullified, so that the query search for all doctors.

where CD_MEDICO_CIRURGIAO = :medico

How to do?

1 answer

0


The right thing would be for you to check before if there’s a doctor’s code (:medico) and then insert the condition.

But that should do it, in case you don’t get it by the first option (NVL)

where CD_MEDICO_CIRURGIAO = NVL(:medico, CD_MEDICO_CIRURGIAO)
  • Would you have an example of this check, to see if the :doctor parameter receives values? The other way you quoted below I could not, because it always brings all the values, and is not what I wish.

  • Isn’t that what you wanted? if :doctor is empty bring all doctors? This code will bring all doctors. Post your code that gives to improve the example.

  • select NR_CIRURGIA from surgery Where CD_MEDICO_CIRURGIAO = :doctor

  • What language are you using? Post the code that will generate this output because it doesn’t look like pure PL/SQL. Another thing which database you are using?

  • This is pl sql yes. E :medico is a parameter passed when you run the code. If I pass as a parameter a doctor’s code will correctly return the values corresponding to the code. What I need, is in case this parameter comes empty, this condition ceases to exist, to fetch all values.

  • Which database? Oracle?

  • oracle database

  • Just to be sure, hehehe. I modified the answer.

  • Works well, thank you very much :D

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.