简体   繁体   中英

PL/SQL equivalent of SELECT statement

What would be the PL/SQL equivalent of this SQL query:

SELECT * FROM table(OWNER.PACKAGE.get_exam('123456789'));

This is the Function that I am trying to call:

FUNCTION get_exam(id IN VARCHAR2)
    RETURN ab_assign_v1
    IS
        CURSOR c_exams(cid VARCHAR2) IS
        SELECT t_api_exam_v1(
                sei.person_id, --unique id
                l.description --loc description
            )
            FROM my_view sei
            JOIN loc l
            ON sei.loc_code = l.loc_code
        v_collection ab_assign_v1;
    BEGIN
        OPEN c_exams(id);
        FETCH c_exams BULK COLLECT INTO v_collection;
        CLOSE c_exams;
        RETURN v_collection;
      EXCEPTION
        WHEN OTHERS THEN
            error_a1.raise_error(SQLCODE, SQLERRM);
    END get_exam;

假设您要返回函数的结果:

  select owner.package.get_exam('123456789') from table 

Hope this helps.

DECLARE
lv <COLLECTION_NAME>;
BEGIN
lv:= OWNER.PACKAGE.get_exam('123456789');
dbms_output.put_line(lv.COUNT);
END;
/

Your function returns a nested table type. You simply need to declare a variable of that type, and assign to it as you would if it were a scalar:

declare
    l_coll your_collection_type;
begin
    l_coll := OWNER.PACKAGE.get_exam('123456789');
end;
/

In this example your_collection_type is a placeholder for whatever object your function actually returns.


" I am getting this error: PLS-00201: identifier 'ab_assign_v1' must be declared "

ab_assign_v1 is the type used by your function. From the code posted in your revised question it seems that type is in the same schema which owns the package with the function. However your original pseudo-code prefixes the call with the schema name. So, putting two and two together, you need to revise the variable declaration to include the schema too. (You may need to grant EXECUTE on it too, if you haven't done this already).

declare
    l_coll OWNER.ab_assign_v1;
begin
    l_coll := OWNER.PACKAGE.get_exam('123456789');
end;
/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM