1

Simple table:

CREATE TABLE Users (
  PersonID int,
  Name varchar(255),
  Salary int
);

I have to write a cursor that will be used in a procedure. Cursor is supposed to return records whose Name field belongs to the array.

CREATE OR REPLACE TYPE namesArray AS TABLE OF int;
/

CURSOR luckyPeople(names IN namesArray) IS
select PersonID from Users
where Name IN(namesArray); //how this can be solved?

How can I use the array in the select clause?

thanks

2 Answers 2

3

One of your problem is that you are defining namesArray type as Int but you are querying the name column which is varchar. The other problem is that you should change your where clause and cursor parameter part.

If you want to check Name column you should try the code below :

CREATE OR REPLACE TYPE namesArray AS TABLE OF varchar(255);

/

CURSOR luckyPeople(names namesArray) IS
select PersonID from Users
where Name IN(select Name from table(namesArray));
Sign up to request clarification or add additional context in comments.

1 Comment

The int vs varchar was a copy paste error. Provided solution works. Thank you
1

Surely

CREATE OR REPLACE TYPE namesArray AS TABLE OF varchar(255);

and

CURSOR luckyPeople(names IN namesArray) IS
select PersonID from Users, table(names) tnames
where Name = tnames.column_value;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.