Dynamic SQL in Forms

I' d like to use dynamic SQL in Form, but i'm attacking a access database(ODBC OCA).
Is there any way to do that?
Thanks.
null

SEE ALL EXAMPLES
=============
Example 1
** Built-in: FORMS_DDL
** Example: The expression can be a string literal.
BEGIN
Forms_DDL('create table temp(n NUMBER)');
IF NOT Form_Success THEN
Message ('Table Creation Failed');
ELSE
Message ('Table Created');
END IF;
END;
Example 2
** Built-in: FORMS_DDL
** Example: The string can be an expression or variable.
** Create a table with n Number columns.
** TEMP(COL1, COL2, ..., COLn).
PROCEDURE Create_N_Column_Number_Table (n NUMBER) IS
my_stmt VARCHAR2(2000);
BEGIN
my_stmt := 'create table tmp(COL1 NUMBER';
FOR I in 2..N LOOP
my_stmt := my_stmt| |',COL'| |TO_CHAR(i)| |' NUMBER';
END LOOP;
my_stmt := my_stmt| |')';
** Now, create the table...
Forms_DDL(my_stmt);
IF NOT Form_Success THEN
Message ('Table Creation Failed');
ELSE
Message ('Table Created');
END IF;
END;
Example 3:
** Built-in: FORMS_DDL
** Example: The statement parameter can be a block
** of dynamically created PL/SQL code.
DECLARE
procname VARCHAR2(30);
BEGIN
IF :global.flag = 'TRUE' THEN
procname := 'Assign_New_Employer';
ELSE
procname := 'Update_New_Employer';
END IF;
Forms_DDL('Begin '| | procname | |'; End;');
IF NOT Form_Success THEN
Message ('Employee Maintenance Failed');
ELSE
Message ('Employee Maintenance Successful');
END IF;
END;
Example 4:
** Built-in: FORMS_DDL
** Example: Issue the SQL statement passed in as an argument,
** and return a number representing the outcome of
** executing the SQL statement.
** A result of zero represents success.
FUNCTION Do_Sql (stmt VARCHAR2, check_for_locks BOOLEAN := TRUE)
RETURN NUMBER
IS
SQL_SUCCESS CONSTANT NUMBER := 0;
BEGIN
IF stmt IS NULL THEN
Message ('DO_SQL: Passed a null statement.');
RETURN SQL_SUCCESS;
END IF;
IF Check_For_Locks AND :System.Form_Status = 'CHANGED' THEN
Message ('DO_SQL: Form has outstanding locks pending.');
RETURN SQL_SUCCESS;
END IF;
Forms_DDL(stmt);
IF Form_Success THEN
RETURN SQL_SUCCESS;
ELSE
RETURN Dbms_Error_Code;
END IF;
END;

Similar Messages

  • Dynamic SQL in Form Builder 6.0

    Hai,
    I would like to know how to create Dynamic SQL in Form Builder 6.0. I'am using oracle 9i database...Please help me.....

    I studied the EXEC_SQL and i wrote these syntax(below), but it gives me error...Could you help me please......:
    PROCEDURE Dynamic_sql IS
    connection_id EXEC_SQL.CONNTYPE;
    cursorID EXEC_SQL.CURSTYPE;
    sql_string VARCHAR2(1000);
    v_pc varchar2 (4);
    v_pd varchar2 (30);
    v_poc varchar2(4);
    v_pvd DATE;
    v_pid DATE;
    exec_id PLS_INTEGER;
    out_file TEXT_IO.FILE_TYPE;
    linebuf varchar2(7000);
    vchFileName VARCHAR2(100);
    Vchfolder VARCHAR2(100);
    AppID      PLS_INTEGER;
    nmbAlert          varchar2(50);
    BEGIN
    SET_APPLICATION_PROPERTY(CURSOR_STYLE,'BUSY');
    vchFileName := 'dynamic_sql_'||sysdate||'.txt';
    Vchfolder := 'D:\KONS\Damar\';
    host('mkdir '||Vchfolder,NO_SCREEN);
    out_file := text_io.fopen(vchfolder||vchFileName,'w');
    TEXT_IO.PUT_LINE (out_file,'PRODUCT CODE PRODUCT DESC PRODUCT OBJECT CODE PRODUCT VALID DATE PRODUCT INVALID DATE ');
    connection_id := EXEC_SQL.OPEN_CONNECTION('FIFDBA/F1FDBA@REPL_DAILY');
    cursorID := EXEC_SQL.OPEN_CURSOR(connection_id);
    sql_string := 'SELECT PROD_CODE, PROD_DESC, PROD_OBJT_CODE, PROD_VALID_DATE, PROD_INVALID_DATE
    FROM HOUS_PRODUCT_TYPE ';
    EXEC_SQL.PARSE(connection_id, cursorID, sql_string, exec_sql.V7);
    --EXEC_SQL.BIND_VARIABLE(connection_id, cursorID, '', input_empno);
    EXEC_SQL.DEFINE_COLUMN(connection_id, cursorID, 1,v_pc, 4);
    EXEC_SQL.DEFINE_COLUMN(connection_id, cursorID, 2, v_pd, 30);
    EXEC_SQL.DEFINE_COLUMN(connection_id, cursorID, 3, v_poc, 4);
    EXEC_SQL.DEFINE_COLUMN(connection_id, cursorID, 4, v_pvd);
    EXEC_SQL.DEFINE_COLUMN(connection_id, cursorID, 5, v_pid);
    exec_id := EXEC_SQL.EXECUTE(connection_id, cursorID);
    WHILE (EXEC_SQL.FETCH_ROWS(connection_id, cursorID) > 0 ) LOOP
    EXEC_SQL.COLUMN_VALUE(connection_id, cursorID, 1, v_pc, 4);
    EXEC_SQL.COLUMN_VALUE(connection_id, cursorID, 2, v_pd);
    EXEC_SQL.COLUMN_VALUE(connection_id, cursorID, 3, v_poc);
    EXEC_SQL.COLUMN_VALUE(connection_id, cursorID, 4, v_pvd);
    EXEC_SQL.COLUMN_VALUE(connection_id, cursorID, 5, v_pid);
    TEXT_IO.PUT_LINE(out_file,v_pc || v_pd ||v_poc||v_pvd||v_pid);
    --Forms_DDL('INSERT INTO TEMP VALUES('||''''||nRows||' '||v_state_id||''''||')');
    --COMMIT_FORM();
    END LOOP;
    EXEC_SQL.CLOSE_CURSOR(connection_id, cursorID);
    EXEC_SQL.CLOSE_CONNECTION(connection_id);
    SET_APPLICATION_PROPERTY(CURSOR_STYLE,'DEFAULT');
    TEXT_IO.FCLOSE(out_FILE);

  • Using database link  with a dynamic SQL in Forms 5

    I have a Form 5 application where a database link is specified in a client version of dynamic SQL. The function that the application is designed to perform is to access data in a table in a remote database and use it to populate another table in a local database with the same structure as the source table. Dynamic SQL is used because the name of the table can only be resolved during run time.
    The problem is that it gives error with code 'ORA-03113' and text 'End-of-file on communication channel' when you try to run it.
    Is it not possible to use a database link with a dynamic SQL? What can I do to overcome the problem ?

    Try to create a local view based ao the remote table and use the view.

  • Using Native Dynamic SQL in Forms

    Can Native Dynamic SQL be used in Forms 5.0 or Forms 6.0? (Database 8.1.6.0.0)
    I have tried the following code (examples below) from the PL/SQL User's Guide and Reference Release 8.1.6 and the Metalinks Note: 62592.1 and the trigger/procedure (in Forms) will not compile. I appreciate any help given.
    Example1:
    (I have a table named temp_jane with a column named companies and a value 'Hello'. When compiling, I receive the error: 'Error 103 at line 8, column 11 Encountered the symbol ''IMMEDIATE" when expecting one of the following :=.(@%; ')
    declare
    str varchar2( 200 );
    val varchar2( 20 );
    ret temp_jane%rowtype;
    begin
    str := 'select company from temp_jane where company = :b1';
    val := 'Hello';
    execute immediate str into ret using val;
    message('Value fetched from table: '| |ret.company);
    end;
    Example2:
    (Here is the real issue, I don't know what the select statement, so I need to be able to assign a variable. When compiling, I receive the error: 'Error 103 at line 28, column 21 Encountered the symbol "VSQLSTATEMENT" when expecting one of the following: select ').
    declare
    type ItemsControlCurTyp is ref cursor;
    ItemsCur ItemsControlCurTyp;
    ItemsRec Items%rowtype;
    vSQLStatement varchar2( 5000 );
    vExecuteSQL varchar2( 5000 );
    vNumRows integer;
    vValue varchar2( 2000 );
    vFirstOne varchar2( 1 ) := 'Y';
    vRetval varchar2( 2000 );
    begin
    -- Display the column prompts with the right text.
    set_item_property( 'ITEMS_AVAILABLE.NDB_VALUE', PROMPT_TEXT, :ITEMS_CONTROL.AVAILABLE_LABEL );
    set_item_property( 'ITEMS_CHOSEN.NDB_VALUE', PROMPT_TEXT, :ITEMS_CONTROL.CHOSEN_LABEL );
    -- Save the original version of CHOSEN_STRING in case the user reverts or cancels.
    :ITEMS_CONTROL.CHOSEN_STRING_ORIG := :ITEMS_CONTROL.CHOSEN_STRING;
    vSQLStatement := :ITEMS_CONTROL.SELECT_STATEMENT;
    vExecuteSQL := vSQLStatement;
    -- Open the cursor
    open ItemsCur for vSQLStatement;

    Hi JTaylor
    You cannot use NDS in Client side (Developer). You have to use DBMS_SQL only.
    Regards
    A K Srinivasan
    Oracle.

  • Using Dynamic SQL in Forms

    Does anyone know anything about Dynamic SQL not being available in Forms v. 6.0.8.11.3? I trying to use Dynamic SQL for the first time and am having some difficulty. When I try to put my SQL in a function and run it straight into the database through SQLPlus, it works fine, but when trying to compile the code in Forms Builder (in a library), I get compiler errors. Any help would be appreciated...
    Thanks!
    Vanessa

    When I tried to compile the following code in Forms, the compiler error I got was Encountered the symbol "STMT_STR" when expecting one of the following: select. However, when I run it in SQLPlus, it creates the function without any errors.
    FUNCTION my_func
    return number
    is
    TYPE DiaryCurTyp IS REF CURSOR;
    cur DiaryCurTyp;
    stmt_str VARCHAR2(200);
    dmonth NUMBER;
    dday NUMBER;
    BEGIN
    stmt_str := 'SELECT dmonth, dday FROM p2_diary
    WHERE dmonth = :1';
    OPEN cur FOR stmt_str USING '12';
    LOOP
    FETCH cur INTO dmonth, dday;
    EXIT WHEN cur%NOTFOUND;
    -- <process data>
    END LOOP;
    CLOSE cur;
    END;

  • Dynamic SQL an Form values in formatted Search

    Hi all,
    Can I create Dynamically the where clause of a query (for a Formatted Search) finding that into a UDF of another table, and then store all in a Varchar(300) variable and use that variable as parameter of an EXEC?
    Sorry for my bad explanation, it takes less time attach the query ...
    so here it is:
    declare  @pol as varchar(8)
    set @pol = $[ORDR.U_PolProj]
    declare @internal_q NVARCHAR(300)
    select  @internal_q = T0.U_CondPol
    from [@PRG_CEN_POL_PROJ] T0
    where Code = @pol
    declare  @itcode as varchar(100)
    set @itcode = $[RDR1.ItemCode]
    declare @sql NVARCHAR(300)
    select @sql = 'select  result =  count(ItemCode)
    from OITM T0
    where T0.ItemCode = ''' + @itcode +
    ''' and ' + @internal_q
    exec(@sql)
    Could someone tell me what's wrong with this formatted search?

    resolved!!! It works

  • Help w/ dynamic sql in form based on proc.

    First, I'm not the most brilliant at this so I might be missing something basic.
    I have a form based off a stored procedure. In that procedure, I have an update statement that is built dynamically from session variables. It won't work because I am putting the update statement together from variables. How can I get around this?
    example:
    Here is the problematic code in my procedure:
    update my_schema.my_table_synonym
    set
    v_myfield = v_myvar
    where myid = v_myid;
    I am pulling the variables from session storage I created earlier in the application. It doesn't seem to like that the field is a variable... is there a way to do this? I would prefer to use this in my application dozens of times rather than copy it dozens of times with slight changes.

    ok, nevermind... I figured my problem out.
    All I needed was something like this:
    v_sql := 'update mytable set ' || myfield || ' = ''HELLO';
    EXECUTE IMMEDIATE v_sql;

  • How to execute dynamic sql in forms 6i?

    Cursor_Handle     Integer     := DBMS_SQL.OPEN_CURSOR;
         Out_Put          Integer;
    BEGIN
         DBMS_SQL.PARSE(Cursor_Handle, Sql_Stmt , dbms_sql.v7);
         Out_Put := DBMS_SQL.EXECUTE(Cursor_Handle);
         DBMS_SQL.CLOSE_CURSOR(Cursor_Handle);
    return true;
    END;
    this is the procedure i have used. it works fine in server side but not in client side. pls help me to solve this problem.
    Advance tanx

    The reason your process won't compile is that you are using a package variable, dbms_sql.v7. (Why aren't you using dbms_sql.native?) If you change that variable to a value of 1 it will probably work.
    However, Francois is correct -- In Forms, you should be using the Exec_SQL package. It is built for Forms; Oracle does not support using DBMS_SQL from Forms. In fact, if you use Forms Builder 10g connected to Oracle 9i and try to compile, the compiler fails with internal errors. They say it works again if you connect to Oracle 10.
    Exec_SQL is identical to DBMS_SQL, except for exception handling. You have to make an additional call to catch the error if an exception occurs: Exec_SQL.Last_Error_Code

  • How can I execute Dynamic SQL statement in Forms?

    Hi All,
    I have to execute dynamic SQL statement from Forms
    Below statement I have to execute
    "EXECUTE IMMEDIATE v_stmt INTO v_return;".
    Googled for the same got results saying, Better use Database function or procedures to execute these Dynamic Statements but We want to execute in forms only.
    Can any one help me..
    Thanks,
    Madhu

    So in short you are trading code obfuscation for maintainability and the ability to share code between tools? If from somewhere else you need a procedure already implemented in database PL/SQL (and now ported to forms) this would mean you'd need to implement it in every other tool. In times where you might want to integrate your forms with $other_technology and putting stuff on the database is the first step to share functionality you just go the opposite way? And all that because someone is afraid that somebody might steal your source code? I am sorry to be blunt, but this is just plain stupid.
    Leaving aside that some things like Analytic Functions, Bulk processing or execute immediate are not even available in forms your software consists of how many LOC? How long does it take to bring a new developer up to speed with your source code? Imagine how long that would take for a developer who doesn't have coleagues who know their way around.
    And just so you know: I work for a ISV selling a closed-source product as well. We have 200+ customers all over the planet. We are well aware that wrapped packages can be reverse engineered. The premise is: stored procedures can be reused in every tool we have, if it makes sense to put stuff on the database by all means do it. If someone would want to reverse engineer our software I'd wish him good luck as some parts are implemented in such a hilarious complicated way I have troubles understanding them (and quite frankly I refuse to understand certain parts, but that's another story). I do work for almost 10 years for that ISV.
    In any case the possible solutions have already been mentioned: you have exec_sql, create_group_from_query and forms_ddl to execute dynamic SQL in forms whereas forms_ddl is a one way street and most certainly not the thing you need or want. Take a look at the documentation for the other 2 things.
    cheers

  • Solve this Dynamic sql problem

    hi i am sending the table and the contents in the table and what i want from the table.
    SQL> descr sswms_rule_components;
    Name Null? Type
    RULE_COMPONENT_ID NOT NULL NUMBER
    RULE_COMPONENT_CODE NOT NULL VARCHAR2(30)
    RULE_COMPONENT_NAME NOT NULL VARCHAR2(100)
    ENABLED_FLAG NOT NULL VARCHAR2(1)
    DB_TABLE VARCHAR2 (100)
    DB_COLUMN VARCHAR2 (100)
    DB_FUNCTION VARCHAR2(100)
    WHERE_CLAUSE VARCHAR2 (2000)
    FROM_CLAUSE VARCHAR2 (2000)
    The table contains the following data
    db_table
    sswms_shipment_lines
    wsh_carrier_ship_method --- the data inside the db_table column is a table
    db_column
    Ship to
    Carrier_id
    Where_clause
    Oe_order_headers_all.header_id = sswms_shipment_lines.order_header_id
    From_clause
    Oe_order_headers_all, sswms_shipment_lines -- the data inside the From_clause is a table
    Now my requirement is to build a dynamic sql in forms 6i.when I click the build sql it should update the sql
    So --- I have to write a procedure --
    Select db_table || . || db_column || ‘’ || group_key
    ---group_key is an alias
    From db_table, From_clause
    --- Here the logic should be
    1. I should remove the commas from the “FROM_CLAUSE” column and check for duplicate values
    2. i should check for duplicate values for the “DB_TABLE “ column
    3. I should compare both the FROM_CLAUSE and DB_TABLE column for DUPLICATE VALUES
    4. After doing this I should add the result to the “FROM” in the select statement
    5.The table name should not be repeated from the "FROM"
    I am expecting the code and a positive reply from you.

    I'm waiting for the code the last 10 minutes and none arrived. What's happening? Developers, do my work, please! (ironic sentence)

  • Dynamic sql - built

    i have a table with say - rule_component
    which has two columns
    1.db_table
    2.from_clause
    The two columns contains tables for example
    db_table
    emp
    dept
    bonus
    emp
    def
    from_clause
    emp,dept,bonus,dept,emp,abc
    My requirement
    i want to find the duplicate tables in both the from_clause and db_table column
    and populate in my from clause which are unique to both the columns
    say example
    select ......
    from emp,dept,bonus,abc,def

    SQL> descr sswms_rule_components;
    Name Null? Type
    RULE_COMPONENT_ID NOT NULL NUMBER
    RULE_COMPONENT_CODE NOT NULL VARCHAR2(30)
    RULE_COMPONENT_NAME NOT NULL VARCHAR2(100)
    ENABLED_FLAG NOT NULL VARCHAR2(1)
    DB_TABLE VARCHAR2 (100)
    DB_COLUMN VARCHAR2 (100)
    DB_FUNCTION VARCHAR2(100)
    WHERE_CLAUSE VARCHAR2 (2000)
    FROM_CLAUSE VARCHAR2 (2000)
    The table contains the following data
    db_table
    sswms_shipment_lines
    wsh_carrier_ship_method --- the data inside the db_table column is a table
    db_column
    Ship to
    Carrier_id
    Where_clause
    Oe_order_headers_all.header_id = sswms_shipment_lines.order_header_id
    From_clause
    Oe_order_headers_all, sswms_shipment_lines -- the data inside the From_clause is a table
    Now my requirement is to build a dynamic sql in forms 6i.when I click the build sql it should update the sql
    So --- I have to write a procedure --
    Select db_table || . || db_column || ‘’ || group_key
    ---group_key is an alias
    From db_table, From_clause
    --- Here the logic should be
    1. I should remove the commas from the “FROM_CLAUSE” and check for duplicate values
    2. i should check for duplicate values for the “DB_TABLE “ column
    3. I should compare both the FROM_CLAUSE and DB_TABLE for DUPLICATE VALUES
    4. After doing this I should add the result to the “FROM” in the select statement
    where where_clause
    hope this is clear.
    regards
    sudharshan

  • Need help on Dynamic SQL Cursor in Forms

    Hi All,
    I am trying to execute Dynamic SQL Cursor in forms using EXEC_SQL built in.
    I have a cursor for example:
    'select * from supplier where supplier = '||p_supplier||' and processing_order = '||p_order
    My code is
    cur_num := Exec_SQL.Open_cursor;
    sql_order := 'select * from supplier where supplier = '||p_supplier||' and processing_order = '||p_order;
    EXEC_SQL.PARSE(cursor_number, sql_order);
      EXEC_SQL.DEFINE_COLUMN(cur_num ,1,ln_Supp_Id);
      EXEC_SQL.DEFINE_COLUMN(cur_num ,2,ls_Suppl_Name,30);
    EXEC_SQL.DEFINE_COLUMN(cur_num ,24,ls_exchange,20);
      sql_count := EXEC_SQL.EXECUTE(cur_num );
      While EXEC_SQL.FETCH_ROWS(cur_num ) > 0 Loop
            EXEC_SQL.COLUMN_VALUE(cur_num ,1,ln_Supp_Id);
            EXEC_SQL.COLUMN_VALUE(cur_num ,2,ls_Suppl_Name);
            EXEC_SQL.COLUMN_VALUE(cur_num ,24,ls_exchange);
    End Loop;
    EXEC_SQL.CLOSE_CURSOR(cur_num );
    In this case I have to write 24 Define Columns and 24 Column value. Is there any way to assign them to %rowtype at one time as I need all coulmn of the table.
    I had similar case on multiple tables.
    Please help me
    Thanks,
    Maddy

    I need this dynamic sql because p_supplier and p_order values changes at run time
    I do not understand. Is this a simplified sample or the real thing? You do know that you can pass variables to cursors:
    cursor test is
    select * from supplier where supplier = p_supplier and processing_order = p_order;
    or does e.g. p_supplier hold other parts of the query?
    cheers

  • Dynamic SQL and Bulk Bind... Interesting Problem !!!

    Hi Forum !!
    I've got a very interesting problem involving Dynamic SQL and Bulk Bind. I really Hope you guys have some suggestions for me...
    Table A contains a column named TX_FORMULA. There are many strings holding expressions like '.3 * 2 + 1.5' or '(3.4 + 2) / .3', all well formed numeric formulas. I want to calculate each formula, finding the number obtained as a result of each calculation.
    I wrote something like this:
    DECLARE
    TYPE T_FormulasNum IS TABLE OF A.TX_FORMULA%TYPE
    INDEX BY BINARY_INTEGER;
    TYPE T_MontoIndicador IS TABLE OF A.MT_NUMBER%TYPE
    INDEX BY BINARY_INTEGER;
    V_FormulasNum T_FormulasNum;
    V_MontoIndicador T_MontoIndicador;
    BEGIN
    SELECT DISTINCT CD_INDICADOR,
    TX_FORMULA_NUMERICA
    BULK COLLECT INTO V_CodIndicador, V_FormulasNum
    FROM A;
    FORALL i IN V_FormulasNum.FIRST..V_FormulasNum.LAST
    EXECUTE IMMEDIATE
    'BEGIN
    :1 := TO_NUMBER(:2);
    END;'
    USING V_FormulasNum(i) RETURNING INTO V_MontoIndicador;
    END;
    But I'm getting the following messages:
    ORA-06550: line 22, column 43:
    PLS-00597: expression 'V_MONTOINDICADOR' in the INTO list is of wrong type
    ORA-06550: line 18, column 5:
    PL/SQL: Statement ignored
    ORA-06550: line 18, column 5:
    PLS-00435: DML statement without BULK In-BIND cannot be used inside FORALL
    Any Idea to solve this problem ?
    Thanks in Advance !!

    Hallo,
    many many errors...
    1. You can use FORALL only in DML operators, in your case you must use simple FOR LOOP.
    2. You can use bind variables only in DML- Statements. In other statements you have to use literals (hard parsing).
    3. RETURNING INTO - Clause in appropriate , use instead of OUT variable.
    4. Remark: FOR I IN FIRST..LAST is not fully correct: if you haven't results, you get EXCEPTION NO_DATA_FOUND. Use Instead of 1..tab.count
    This code works.
    DECLARE
    TYPE T_FormulasNum IS TABLE OF VARCHAR2(255)
    INDEX BY BINARY_INTEGER;
    TYPE T_MontoIndicador IS TABLE OF NUMBER
    INDEX BY BINARY_INTEGER;
    V_FormulasNum T_FormulasNum;
    V_MontoIndicador T_MontoIndicador;
    BEGIN
    SELECT DISTINCT CD_INDICATOR,
    TX_FORMULA_NUMERICA
    BULK COLLECT INTO V_MontoIndicador, V_FormulasNum
    FROM A;
    FOR i IN 1..V_FormulasNum.count
    LOOP
    EXECUTE IMMEDIATE
    'BEGIN
    :v_motto := TO_NUMBER('||v_formulasnum(i)||');
    END;'
    USING OUT V_MontoIndicador(i);
    dbms_output.put_line(v_montoindicador(i));
    END LOOP;
    END;You have to read more about bulk- binding and dynamic sql.
    HTH
    Regards
    Dmytro
    Test table
    a
    (cd_indicator number,
    tx_formula_numerica VARCHAR2(255))
    CD_INDICATOR TX_FORMULA_NUMERICA
    2 (5+5)*2
    1 2*3*4
    Message was edited by:
    Dmytro Dekhtyaryuk

  • ORA-01008 with ref cursor and dynamic sql

    When I run the follwing procedure:
    variable x refcursor
    set autoprint on
    begin
      Crosstab.pivot(p_max_cols => 4,
       p_query => 'select job, count(*) cnt, deptno, row_number() over (partition by job order by deptno) rn from scott.emp group by job, deptno',
       p_anchor => Crosstab.array('JOB'),
       p_pivot  => Crosstab.array('DEPTNO', 'CNT'),
       p_cursor => :x );
    end;I get the following error:
    ^----------------
    Statement Ignored
    set autoprint on
    begin
    adsmgr.Crosstab.pivot(p_max_cols => 4,
    p_query => 'select job, count(*) cnt, deptno, row_number() over (partition by
    p_anchor => adsmgr.Crosstab.array('JOB'),
    p_pivot => adsmgr.Crosstab.array('DEPTNO', 'CNT'),
    p_cursor => :x );
    end;
    ORA-01008: not all variables bound
    I am running this on a stored procedure as follows:
    create or replace package Crosstab
    as
        type refcursor is ref cursor;
        type array is table of varchar2(30);
        procedure pivot( p_max_cols       in number   default null,
                         p_max_cols_query in varchar2 default null,
                         p_query          in varchar2,
                         p_anchor         in array,
                         p_pivot          in array,
                         p_cursor in out refcursor );
    end;
    create or replace package body Crosstab
    as
    procedure pivot( p_max_cols          in number   default null,
                     p_max_cols_query in varchar2 default null,
                     p_query          in varchar2,
                     p_anchor         in array,
                     p_pivot          in array,
                     p_cursor in out refcursor )
    as
        l_max_cols number;
        l_query    long;
        l_cnames   array;
    begin
        -- figure out the number of columns we must support
        -- we either KNOW this or we have a query that can tell us
        if ( p_max_cols is not null )
        then
            l_max_cols := p_max_cols;
        elsif ( p_max_cols_query is not null )
        then
            execute immediate p_max_cols_query into l_max_cols;
        else
            RAISE_APPLICATION_ERROR(-20001, 'Cannot figure out max cols');
        end if;
        -- Now, construct the query that can answer the question for us...
        -- start with the C1, C2, ... CX columns:
        l_query := 'select ';
        for i in 1 .. p_anchor.count
        loop
            l_query := l_query || p_anchor(i) || ',';
        end loop;
        -- Now add in the C{x+1}... CN columns to be pivoted:
        -- the format is "max(decode(rn,1,C{X+1},null)) cx+1_1"
        for i in 1 .. l_max_cols
        loop
            for j in 1 .. p_pivot.count
            loop
                l_query := l_query ||
                    'max(decode(rn,'||i||','||
                               p_pivot(j)||',null)) ' ||
                                p_pivot(j) || '_' || i || ',';
            end loop;
        end loop;
        -- Now just add in the original query
        l_query := rtrim(l_query,',')||' from ( '||p_query||') group by ';
        -- and then the group by columns...
        for i in 1 .. p_anchor.count
        loop
            l_query := l_query || p_anchor(i) || ',';
        end loop;
        l_query := rtrim(l_query,',');
        -- and return it
        execute immediate 'alter session set cursor_sharing=force';
        open p_cursor for l_query;
        execute immediate 'alter session set cursor_sharing=exact';
    end;
    end;
    /I can see from the error message that it is ignoring the x declaration, I assume it is because it does not recognise the type refcursor from the procedure.
    How do I get it to recognise this?
    Thank you in advance

    Thank you for your help
    This is the version of Oracle I am running, so this may have something to do with that.
    Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.8.0 - Production
    I found this on Ask Tom (http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:3027089372477)
    Hello, Tom.
    I have one bind variable in a dynamic SQL expression.
    When I open cursor for this sql, it gets me to ora-01008.
    Please consider:
    Connected to:
    Oracle8i Enterprise Edition Release 8.1.7.4.1 - Production
    JServer Release 8.1.7.4.1 - Production
    SQL> declare
      2    type cur is ref cursor;
      3    res cur;
      4  begin
      5    open res for
      6    'select * from (select * from dual where :p = 1) connect by 1 = 1'
      7    using 1;
      8  end;
      9  /
    declare
    ERROR at line 1:
    ORA-01008: not all variables bound
    ORA-06512: at line 5
    SQL> declare
      2    type cur is ref cursor;
      3    res cur;
      4  begin
      5    open res for
      6    'select * from (select * from dual where :p = 1) connect by 1 = 1'
      7    using 1, 2;
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    And if I run the same thing on 10g -- all goes conversely. The first part runs ok, and the second
    part reports "ORA-01006: bind variable does not exist" (as it should be, I think). Remember, there
    is ONE bind variable in sql, not two. Is it a bug in 8i?
    What should we do to avoid this error running the same plsql program code on different Oracle
    versions?
    P.S. Thank you for your invaluable work on this site.
    Followup   June 9, 2005 - 6pm US/Eastern:
    what is the purpose of this query really?
    but it would appear to be a bug in 8i (since it should need but one).  You will have to work that
    via support. I changed the type to tarray to see if the reserved word was causing a problem.
    variable v_refcursor refcursor;
    set autoprint on;
    begin 
         crosstab.pivot (p_max_cols => 4,
                 p_query => 
                   'SELECT job, COUNT (*) cnt, deptno, ' || 
                   '       ROW_NUMBER () OVER ( ' || 
                   '          PARTITION BY job ' || 
                   '          ORDER BY deptno) rn ' || 
                   'FROM   emp ' ||
                   'GROUP BY job, deptno',
                   p_anchor => crosstab.tarray ('JOB'),
                   p_pivot => crosstab.tarray ('DEPTNO', 'CNT'),
                   p_cursor => :v_refcursor);
    end;
    /Was going to use this package as a stored procedure in forms but I not sure it's going to work now.

  • Ref cursor and dynamic sql

    Hi..
    I'm using a ref cursor query to fetch data for a report and works just fine. However i need to use dynamic sql in the query because the columns used in the where condition and for some calculations may change dynamically according to user input from the form that launches the report..
    Ideally the query should look like this:
    select
    a,b,c
    from table
    where :x = something
    and :y = something
    and (abs(:x/:y........)
    The user should be able to switch between :x and :y
    Is there a way to embed dynamic sql in a ref cursor query in Reports 6i?
    Reports 6i
    Forms 6i
    Windows 2000 PRO

    Hello Nicola,
    You can parameterize your ref cursor by putting the query's select statement in a procedure/function (defined in your report, or in the database), and populating it based on arguments accepted by the procedure.
    For example, the following procedure accepts a strongly typed ref cursor and populates it with emp table data based on the value of the 'mydept' input parameter:
    Procedure emp_refcursor(emp_data IN OUT emp_rc, mydept number) as
    Begin
    -- Open emp_data for select all columns from emp where deptno = mydept;
    Open emp_data for select * from emp where deptno = mydept;
    End;
    This procedure/function can then be called from the ref cursor query program unit defined in your report's data model, to return the filled ref cursor to Reports.
    Thanks,
    The Oracle Reports Team.

Maybe you are looking for

  • Export to PDF from Infoview does not show correct data - CRS 2008

    I have a problem where users attempt to export a report from the Infoview interface to a PDF.  The report shows correctly in Infoview while in Crystal Reports format, but when the use exports the data, the data changes and shows different values.  To

  • In address book, if I try to show first name before the last name, why do only a few names change?

    Using address book on 10.7.2, when I go to "preferences" to change the display order between showing the "first name" before or after the last name, only about 25% of names will change.  The rest all stay in the same order.   Any ideas? 

  • Canon Gl2 Video Camera Not Recognized with Firewire 800 Connection

    I have a late 2010 mac with 2.93 Ghz Intel Core i7 Processor with 12GB DDR3 running 10.8.2 OSX.  I have a Canon GL2 video camcorder with a MiniDV tape I am trying to download to my computer.  I am using a new 4pin to 9pin Rocketfish Firewire 800 cabl

  • Help password protecting a desktop application

    Hey guys I'm creating an application that I need to password protect. I've already created a JFrame with components and action listeners where a user can enter a password (twice to make sure they match) and a username. When my application begins the

  • Site not loading properly on Ipad

    If you look at these two sites on your ipad http://www.algonquindream.ca/ http://www.algonquindream.ca/home.html The second site loads correctly, the first site is getting cut off so you have to scroll to the right to see it all from when it loads. F