1

I'm trying to use data in sys_context form to perform a match in a WHERE clause.

What I put into the context is ('53','89'), which is what is returned when I select against dual.

My where statement is: where to_char(location_id) in sys_context('my_ctx','valoc')

Since I'm not getting the expected response, I'm guessing that what I think Oracle should see is not actually what it sees, but I don't know how to "look" at what's passed to the processor from TOAD.

The original form was where location_id in sys_context('my_ctx','valoc') with (53,89) in valoc, but that didn't return anything either. I'm sensing there may be no answer to my problem.

1 Answer 1

1

The problem is that the resulting WHERE clause is equivalent to this:

where to_char(location_id) in '('53','89')'

(didn't double the inner apostrophes for clarity)

The database sees what's retrieved from context as a single value, not as a list of values.

You can use the CONNECT BY trick to achieve your goal:

SELECT 1
  FROM dual
WHERE '53' IN ( -- replace '53' with TO_CHAR(location_id)
  SELECT regexp_substr('53,89', '[0-9]*', 1, level) -- replace '53,89' with sys_context('my_ctx','valoc')
    FROM dual
  CONNECT BY regexp_substr('53,89', '[0-9]*', 1, level) IS NOT NULL -- replace '53,89' with sys_context('my_ctx','valoc')
);
Sign up to request clarification or add additional context in comments.

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.