Jeromy French
Jeromy French

Reputation: 12121

Using a subquery within PLSQL conditional logic; error PLS-00405

I am building an application that uses PHP to get data from an Oracle10g database server. My input form has a series of checkboxes that are submitted to the processing page via an array (code filtered down to the relevant elements):

<form>
   <input type="checkbox" name="p_queue_type[]" id="p_queue_type_CR" value="CR" class="subject_to_all toggle_subcategory required" required="">
   <input type="checkbox" name="p_queue_type[]" id="p_queue_type_HOLD" value="HOLD" class="subject_to_all toggle_subcategory required" required="">
</form>

The processing page calls an Oracle procedure that uses a custom data type "STRING_TABLE" (CREATE OR REPLACE TYPE STRING_TABLE AS TABLE OF VARCHAR (1000);) to translate the checkbox values, which PHP processes as an array, into a table.

My procedure takes those checkboxes as the incoming parameter "p_queue_type" (code filtered down to the relevant elements):

PROCEDURE get_TLFQ_results (
    p1                      OUT   SYS_REFCURSOR,
    p_queue_type            IN    STRING_TABLE
)
IS
    v_return_sql            VARCHAR2(32767) := '';
BEGIN
    IF ('HOLD' IN (SELECT COLUMN_VALUE AS queue_type FROM TABLE (p_queue_type))) THEN
        --compile query string
    END IF;
    IF ('CR' IN (SELECT COLUMN_VALUE AS queue_type FROM TABLE (p_queue_type))) THEN
        --compile query string
    END IF;

    -- Execute the query string and store the results in a cursor
    OPEN p1 FOR v_return_sql;
END get_TLFQ_results;

When I attempt to compile my procedure, I am getting this Oracle error:

[Error] PLS-00405 (4215: 23): PLS-00405: subquery not allowed in this context

What am I doing wrong? How can I use my string table within my PLSQL conditional logic?

Upvotes: 4

Views: 6779

Answers (1)

Tony Andrews
Tony Andrews

Reputation: 132580

You cannot use a SELECT statement within a PL/SQL IF condition in that way. However you can do this:

IF ('HOLD'  member of p_queue_type) THEN
...

Upvotes: 5

Related Questions