Check list of values is NULL in PL/SQL

Alex

Is there a way to check is a list of values is NULL in PL/SQL?

I have something along the lines of:

SELECT * FROM myTable t WHERE t.dataId IN (:myList) OR :myList IS NULL

At run-time, the :myList symbol is substituted for a list of strings e.g.

SELECT * FROM myTable t WHERE t.dataId IN ('a', 'b', 'c') OR  ('a', 'b', 'c') IS NULL

I've realised that ('a', 'b', 'c') IS NULL is invalid PL/SQL, so I wondered if there is another way to check a list of values evaluate to NULL.

The behaviour I'm attempting to emulate would evaluate ('a', 'b', 'c') to NOT NULL. I'm trying to avoid creating another variable (e.g. :myListFlag) which would return '' if the list was empty.

trapicki

Maybe COALESCE will help you:

It evaluates a list of values left to right and returns the first value that is NOT NULL. If all values are NULL, it evaluates to NULL, which is a single value that you can check for IS NULL.

 SELECT * FROM myTable t WHERE t.dataId IN (:myList) OR COALESCE(:myList) IS NULL

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to check if 2 values IS NULL

分類Dev

Replacing null values in a list with values of another list

分類Dev

Check a list for specific values and if it finds replace with div

分類Dev

Which is better when check a list is null : not null or use Any

分類Dev

Linq to Dictionary <string、List <string >> with Null values

分類Dev

how to append values to a plsql table

分類Dev

Create a list of objects in plsql - postgresql

分類Dev

c# check the empty or null value in all datatable values

分類Dev

c# check the empty or null value in all datatable values

分類Dev

Why use null function instead of == [] to check for empty list in Haskell?

分類Dev

In Swift, How to check if the first element of an Array is equal to a list of values?

分類Dev

PLSQLでNULL値を比較する方法

分類Dev

Displaying checked and unchecked check box list after reading values from the database is not working

分類Dev

Check if CGRect null in getter

分類Dev

Check for NULL or empty '' in function?

分類Dev

If statement with a null check

分類Dev

Check, if a variable is null in a view

分類Dev

Check '!= null" not working

分類Dev

Conditional statement for null check

分類Dev

Check enum for multiple values

分類Dev

Check if item is in list

分類Dev

Check all properties in List

分類Dev

Check checkbox in a list dynamically

分類Dev

Check for NoneTypes in a list of iterables

分類Dev

Check if list is Flattened or not in Prolog

分類Dev

JPQL is not grouping null values

分類Dev

BigQuery - NULL values

分類Dev

Highcharts DataGrouping with Null values

分類Dev

LINQ Count null values

Related 関連記事

ホットタグ

アーカイブ