Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use the <a href="http://docs.oracle.com/cd/B28359_01/appdev.111/b28419/d_sql.htm#sthref7488">DBMS_SQL</a> package. This provides an alternative way to run dynamic SQL. It is perhaps a little more cumbersome to use, but it can be more flexible, especially with varying numbers of bind parameters.</p> <p>Here's how you could use it (warning: I haven't tested this):</p> <pre><code>FUNCTION player_search ( pName IN VARCHAR2, pHeight IN NUMBER, pTeam IN VARCHAR2 ) RETURN SYS_REFCURSOR IS cursor_name INTEGER; ignore INTEGER; id_var MyTable.ID%TYPE; name_var MyTable.Name%TYPE; height_var MyTable.Height%TYPE; team_var MyTable.Team%TYPE; BEGIN -- Put together SQLQuery here... -- Open the cursor and parse the query cursor_name := DBMS_SQL.OPEN_CURSOR; DBMS_SQL.PARSE(cursor_name, SQLQuery, DBMS_SQL.NATIVE); -- Define the columns that the query returns. -- (The last number for columns 2 and 4 is the size of the -- VARCHAR2 columns. Feel free to change them.) DBMS_SQL.DEFINE_COLUMN(cursor_name, 1, id_var); DBMS_SQL.DEFINE_COLUMN(cursor_name, 2, name_var, 30); DBMS_SQL.DEFINE_COLUMN(cursor_name, 3, height_var); DBMS_SQL.DEFINE_COLUMN(cursor_name, 4, team_var, 30); -- Add bind variables depending on whether they were added to -- the query. IF pName IS NOT NULL THEN DBMS_SQL.BIND_VARIABLE(cursor_name, ':pName', pName); END IF; IF pHeight &gt; 0 THEN DBMS_SQL.BIND_VARIABLE(cursor_name, ':pHeight', pHeight); END IF; IF pTeam IS NOT NULL THEN DBMS_SQL.BIND_VARIABLE(cursor_name, ':pTeam', pTeam); END IF; -- Run the query. -- (The return value of DBMS_SQL.EXECUTE for SELECT queries is undefined, -- so we must ignore it.) ignore := DBMS_SQL.EXECUTE(cursor_name); -- Convert the DBMS_SQL cursor into a PL/SQL REF CURSOR. RETURN DBMS_SQL.TO_REFCURSOR(cursor_name); EXCEPTION WHEN OTHERS THEN -- Ensure that the cursor is closed. IF DBMS_SQL.IS_OPEN(cursor_name) THEN DBMS_SQL.CLOSE_CURSOR(cursor_name); END IF; RAISE; END; </code></pre> <p>(Note: <a href="http://docs.oracle.com/cd/B28359_01/appdev.111/b28419/d_sql.htm#CHDFDCDE"><code>DBMS_SQL.TO_REFCURSOR</code></a> is new in Oracle 11g.)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload