A
A
Alexander C.2019-04-18 13:13:03
Oracle
Alexander C., 2019-04-18 13:13:03

How to declare an array in PL/SQL so that it can be used later in IN?

Good afternoon. Suppose there is a query with an IN condition (below is a simple example). Can I declare a collection of items ('IBM', 'Hewlett Packard', 'Microsoft') ahead of time in DECLARE as a constant?

SELECT *
FROM customers
WHERE customer_name IN ('IBM', 'Hewlett Packard', 'Microsoft');

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Kolun, 2019-08-04
@at6p

Yes.
You can write your own utility type like:

create or replace type string_tab as table of varchar2(4000 char)
/

Declare a constant at method level, package body, or package spec
And use in select
-- Если константа пакетная, то <package_name>.c_customers
select *
from customers
where customer_name in (select column_value from table(c_customers));

alternative, but with its drawbacks :-)
select *
from customers
where customer_name member of c_customers;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question