Skip to content
Advertisement

Can “value in list or list is empty” be written shorter?

Given this SQL:

Is there a way to write the “in list or list is empty” part shorter? Preferably in a way that contains the list only once (see the Don’t_repeat_yourself principle )

I’m interested for Oracle SQL or PL/SQL, but other information is also welcome.

As requested, a MRE that works in SQL*Plus:

Advertisement

Answer

From Oracle 12, you could use a LATERAL join with conditional aggregation:

Or a similar technique using EXISTS:

db<>fiddle here

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement