Oracle to MS SQL porting - dynamic sql - cursors

I have a stored procedure written for oracle which needs to be ported to MS SQL. Used SSMA to do that but the dynamic sql statements are not getting ported and are the same. Below is a dynamic sql from the SP after making changes with SSMA.
SET @dsql_statement =
'declare '
+
' p table_name%rowtype;'
+
' c table_name%rowtype;'
+
' TYPE DAT IS REF CURSOR;'
+
' type dtt is table of table_name1%rowtype index by binary_integer;'
+
' d dtt;'
+
' aRC DAT;'
+
' sq varchar2(1000);'
+
' i NUMBER:=0;'
+
' attributeLabel nvarchar2(255);'
+
' attributename nvarchar2(255);'
+
' attributetype nvarchar2(255);'
+
' fkvalue nvarchar2(255);'
+
' defaultfield nvarchar2(80);'
+
' tablename nvarchar2(80);'
+
' primarykeyfield nvarchar2(80);'
+
' begin '
+
' sq:=''SELECT * FROM mdbadmin.table_name WHERE lower(COLUMN1) IN'
+
' (''''update'''',''''insert'''') AND COLUMN2 >= '
+
ISNULL(CAST(@COLUMN2 AS nvarchar(max)), '')
+
+
' ORDER BY COLUMN3,COLUMN2 ASC'';'
+
' open aRC for sq;'
+
' fetch aRC into c;'
+
' loop '
+
' fetch aRC into p;'
+
' exit when aRC%NOTFOUND;'

Some thing like
dsql_statement :=  'begin '
|| ' for I in (SELECT * FROM mdbadmin.table_name WHERE lower(COLUMN1) IN '
|| ' (''update'',''insert'') AND COLUMN2 >= '
|| 'NVL(to_char('||'@COLUMN2'||'), '''') '
|| ' ORDER BY COLUMN3,COLUMN2 ASC ) '
|| 'loop '
|| 'end loop; '
|| 'end; '
you can use for loop instead

Similar Messages

  • BI Publisher PL/SQL and Dynamic SQL

    Hi. Can I use a Dynamic SQL in BI Publisher Data Model (11g) ?
    Thanks Bye
    Riccardo

    Well, i'll try not to be too mean when i say this....but you have 5 posts, all with "what is X".
    The forum, google, OTN documentation, etc are all wonderful places for you to do some searching.

  • Creating static sql from dynamic sql

    HI ,
    I have a dynamic sql and  I have to convert it into a static sql .
    this query is somehow having a special case which states that if the values of one parameter @bounce_type is D then it appends some more conditions(column conditions) on this query .
    I want to know a way to convert this kind of SQL to a static sql .
    I want a static code for the code where the condition is as mentioned below
    for the where clause where @bounce_type='D'
    if @bounce_type is not null and @bounce_type = 'D'
    begin
    print @bounce_type
    set @WhereClause = @WhereClause + ' and per.event_type_id=4 and per.aspen_action_detail_id not in
    (select
    aspen_action_detail_id
    from
    program.email_response pers with (readuncommitted)
    inner join action.action ac with(nolock,readuncommitted) on
    pers.action_id = ac.action_id
    where
    pers.dealer_id in( ' + cast(@dealer_did as varchar(10)) + ' ) and
    pers.aspen_action_dt between ''' + convert(varchar(10),@from_date,101)+''' ' + 'and ''' + convert(varchar(10),@to_date,101) + ''' and
    pers.program_type_id in (4,5) and
    pers.event_type_id=1 and
    pers.is_enabled=1) and aa.program_group<>''Unknown'''
    I was able to convert almost all of the code but the code mentioned above.

    Perhaps this one
    if @bounce_type is not null and @bounce_type = 'D' 
    begin
    print @bounce_type
    SELECT * FROM tbl WHERE ... and per.event_type_id=4 and per.aspen_action_detail_id not in
    (select
    aspen_action_detail_id
    from 
    program.email_response pers with (readuncommitted)
    inner join action.action ac with(nolock,readuncommitted) on
    pers.action_id = ac.action_id  
    where 
    pers.dealer_id in(  cast(@dealer_did as varchar(10)))  and 
    pers.aspen_action_dt between  convert(varchar(10),@from_date,101) and 
    convert(varchar(10),@to_date,101)  and 
    pers.program_type_id in (4,5)
    and
    pers.event_type_id=1
    and
    pers.is_enabled=1) and aa.program_group<>'Unknown' 
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Oracle Reports 6i and the Dynamic SQL

    I use Oracle 8.1.7 and Oracle Reports 6i Builder;
    My problem is that I am trying to obtain dataset for the report via stored procedure (using ref cursor). As far as I understand I must specify strongly typed refcursor in my package (specify record type based of which the ref cursor will be created, not just ref cursor without any return specification). But when it comes to my stored procedure implementation, here I would like to use dynamically created SELECT statement and since it will be parsed and executed at runtime I forced to use only untyped ref cursor to return data from the stored procedure.
    TYPE my_refcur IS REF CURSOR;
    cv_tmp my_refcur;
    v_SQL VARCHAR2(2000);
    BEGIN
    -- here I set v_SQL ....
    OPEN cv_tmp
    FOR v_SQL;
    RETURN cv_tmp;
    END;
    But this way I somehow need to convert untyped ref cursor to strongly typed one. This is a problem I would like you to help me with.
    Thanks in advise.
    By the way, I am not familiar with Oracle Reports 9. Does it still require to return only strongly typed ref cursor from stored procedures?

    Hello Alexey,
    The reason Reports requires strongly typed ref cursors to be returned to it is that, with weak ref cursors the list of columns returned by the cursor cannot be determined at report design time. For a weak ref cursor, the data will be populated based on a query specified only at runtime. As a result, you will not be able to add any layout to your report, since the query group will be empty.
    Please take a look at the reply in the post below on the same topic, for a method to retrieve data from a stored procedure returning a weakly typed ref cursor:
    Re: Reports On Ref Cursor
    Thanks,
    Srivas.
    The Oracle Reports Team.

  • Column alias for spatial column within cursor loop using dynamic SQL

    The following PL/SQL is trying to generate an error report for records or objects which are 3 dimensional or above. I have no issue execute one statement in SQLPLUS but I need to use the column alias for the spatial column. But, it is a different story using PL/SQL and dynamic SQL Any help will be great because I've been working on this for than 8 hours but with no luck! Thanks.
    Here is the error I'm getting,
    stmt := 'select p.column_name.get_gtype(), id from '|| table_name p ' where p.column_name.get_gtype() > 2 ';
    ERROR at line 15:
    ORA-06550: line 15, column 79:
    PLS-00103: Encountered the symbol "P" when expecting one of the following:
    . ( * @ % & = - + ; < / > at in is mod remainder not rem
    <an exponent (**)> <> or != or ~= >= <= <> and or like LIKE2_
    LIKE4_ LIKEC_ between || member SUBMULTISET_
    The symbol "* was inserted before "P" to continue.
    and my PL/SQL is,
    set serveroutput on size 100000 feedback off
    declare
    rs integer;
    rs1 integer;
    cur integer;
    rp integer;
    trs integer;
    n integer;
    un varchar2(30);
    stmt varchar2(200);
    begin
    dbms_output.put_line(rpad('Table Name',40)||' Dimension');
    dbms_output.put_line(rpad('-',53,'-'));
    cur:= dbms_sql.open_cursor;
    for t in (select column_name,table_name from user_sdo_geom_metadata where regexp_like(table_name, '[^[A-B]_[AB]$'))
    loop
    stmt := 'select p.column_name.get_gtype(), id from '|| table_name p ' where p.column_name.get_gtype() > 2 ';
    dbms_sql.parse(cur, stmt, dbms_sql.native);
    dbms_sql.define_column(cur, 1, rs);
    dbms_sql.define_column(cur, 2, rs1);
    rp:= dbms_sql.execute(cur);
    n:=dbms_sql.fetch_rows(cur);
    dbms_sql.column_value(cur, 1, rs);
    dbms_sql.column_value(cur, 2, rs1);
    dbms_output.put_line(rpad(t.table_name,38,'.')||rpad(rs,15)||rpad(rs1,15));
    end loop;
    dbms_sql.close_cursor(cur);
    dbms_output.put_line(rpad('-',53,'-'));
    end;
    set serveroutput off feedback on feedback 6

    The following PL/SQL is trying to generate an error report for records or objects which are 3 dimensional or above. I have no issue execute one statement in SQLPLUS but I need to use the column alias for the spatial column. But, it is a different story using PL/SQL and dynamic SQL Any help will be great because I've been working on this for than 8 hours but with no luck! Thanks.
    Here is the error I'm getting,
    stmt := 'select p.column_name.get_gtype(), id from '|| table_name p ' where p.column_name.get_gtype() > 2 ';
    ERROR at line 15:
    ORA-06550: line 15, column 79:
    PLS-00103: Encountered the symbol "P" when expecting one of the following:
    . ( * @ % & = - + ; < / > at in is mod remainder not rem
    <an exponent (**)> <> or != or ~= >= <= <> and or like LIKE2_
    LIKE4_ LIKEC_ between || member SUBMULTISET_
    The symbol "* was inserted before "P" to continue.
    and my PL/SQL is,
    set serveroutput on size 100000 feedback off
    declare
    rs integer;
    rs1 integer;
    cur integer;
    rp integer;
    trs integer;
    n integer;
    un varchar2(30);
    stmt varchar2(200);
    begin
    dbms_output.put_line(rpad('Table Name',40)||' Dimension');
    dbms_output.put_line(rpad('-',53,'-'));
    cur:= dbms_sql.open_cursor;
    for t in (select column_name,table_name from user_sdo_geom_metadata where regexp_like(table_name, '[^[A-B]_[AB]$'))
    loop
    stmt := 'select p.column_name.get_gtype(), id from '|| table_name p ' where p.column_name.get_gtype() > 2 ';
    dbms_sql.parse(cur, stmt, dbms_sql.native);
    dbms_sql.define_column(cur, 1, rs);
    dbms_sql.define_column(cur, 2, rs1);
    rp:= dbms_sql.execute(cur);
    n:=dbms_sql.fetch_rows(cur);
    dbms_sql.column_value(cur, 1, rs);
    dbms_sql.column_value(cur, 2, rs1);
    dbms_output.put_line(rpad(t.table_name,38,'.')||rpad(rs,15)||rpad(rs1,15));
    end loop;
    dbms_sql.close_cursor(cur);
    dbms_output.put_line(rpad('-',53,'-'));
    end;
    set serveroutput off feedback on feedback 6

  • How to reduce Parse time in dynamic SQL

    I'm using for a part of my code dynamic SQL with DBMS_SQL Package, this dynamic SQL code is located in a loop with say 1000 repeatations, if we trace the code we see that this sql statement is parsed 1000 times and this causes
    a serios performance issue. If i convert this part of code into static PLSQL code , the statement is parsed only one time as expected. i would like
    to know how i can resolve this problem in the dynamic SQL code.
    Why in case of static SQL, despite it is inside the loop, it is parsed
    only one time by ORACLE and in case of dynamic SQL as many as the upper limit of counter.
    Why the ORACLE has different behaviour to parse them? Is there any way or trick
    to force ORACLE to parse it only one time like static SQL?

    despite the open cursor is also inside the loop but oracle parse it only one time.That is because PL/SQL is caching your cursor and resuing it. With DBMS_SQL you are opening a new cursor area in the loop for each iteration (DBMS_SQL.OPEN_CURSOR).
    what you need to do is open/parse once and bind the value each time through the loop:
    DECLARE
        expr      VARCHAR2(1000);
        check_cur PLS_INTEGER;
        nDummy    PLS_INTEGER;
        nFetched  PLS_INTEGER;
    BEGIN
        -- Open Cursor
        check_cur := dbms_sql.open_cursor;
        expr      := 'select 1 from dual where ' || ':bindvar1 ' || '=' ||
                     ' ''bindvar1'' ';
        -- Parse Cursor
        dbms_sql.parse(check_cur,
                       expr,
                       1);
        FOR counter IN 1 .. 1000
        LOOP
            -- Define Column
            DBMS_SQL.define_column(check_cur,
                                   1,
                                   1);
            -- Do Binding
            dbms_sql.bind_variable(check_cur,
                                   ':bindvar1',
                                   'bindname1');
            -- Execute Cursor
            nDummy := DBMS_SQL.EXECUTE(check_cur);
            -- Fetch Rows
            nFetched := DBMS_SQL.fetch_rows(check_cur);
        END LOOP;
        -- Close Cursor
        dbms_sql.close_cursor(check_cur);
    END;
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.21       0.23          0          0          0           0
    Execute   1000      0.11       0.10          0          0          0           0
    Fetch     1000      0.03       0.01          0          0          0           0
    total     2001      0.35       0.35          0          0          0           0

  • Performance between SQL Statement and Dynamic SQL

    Select emp_id
    into id_val
    from emp
    where emp_id = 100
    EXECUTE IMMEDIATE
    'Select '|| t_emp_id ||
    'from emp '
    'where emp_id = 100'
    into id_valWill there be more impact in performance while using Dynamic SQL?

    CP wrote:
    Will there be more impact in performance while using Dynamic SQL?All SQLs are parsed and executed as SQL cursors.
    The 2 SQLs (dynamic and static) results in the exact same SQL cursor. So both methods will use an identical cursor. There are therefore no performance differences ito of how fast that SQL cursor will be.
    If an identical SQL cursor is not found (a soft parse), the SQL engine needs to compile the SQL source code supplied, into a SQL cursor (a hard parse).
    Hard parsing burns a lot of CPU cycles. Soft parsing burns less CPU cycles and is therefore better. However, no parsing at all is the best.
    To explain: if the code creates a cursor (e.g. INSERT INTO tab VALUES( :1, :2, :3 ) for inserting data), it can do it as follows:
    while More Data Found loop
      parse INSERT cursor
      bind variables to INSERT cursor
      execute INSERT cursor
      close INSERT cursor
    end loopIf that INSERT cursor does not yet exists, it will be hard parsed and a cursor created. Each subsequent loop iteration will result in a soft parse.
    However, the code will be far more optimal as follows:
    parse INSERT cursor
    while More Data Found loop
      bind variables to INSERT cursor
      execute INSERT cursor
    end loop
    close INSERT cursorWith this approach the cursor is parsed (hard or soft), once only. The cursor handle is then used again and again. And when the application is done inserting data, the cursor handle is released.
    With dynamic SQL in PL/SQL, you cannot really follow the optimal approach - unless you use DBMS_SQL (a complex cursor interface). With static SQL, the PL/SQL's optimiser can kick in and it can optimise its access to the cursors your code create and minimise parsing all together.
    This is however not the only consideration when using dynamic SQL. Dynamic SQL makes coding a lot more complex. The SQL code can now only be checked at execution time and not at development time. There is the issue of creating shareable SQL cursors using bind variables. There is the risk of SQL injection. Etc.
    So dynamic SQL is seldom a good idea. And IMO, the vast majority of people that post problems here relating to dynamic SQL, are using dynamic SQL unnecessary. For no justified and logical reasons. Creating unstable code, insecure code and non-performing code.

  • Question on Dynamic SQL Execution

    Hi,
    Our company is currently using Oracle 7 but will move to Oracle 8i soon. I am trying to execute a dynamic SQL statement in a function and it always error-out during execution. The SQL statement is NOT doing any update to a table. Its doing a select only. The function is being called during an execution of another dynamic SQL statement in a procedure. Here are examples of the code listing for the procedure and function:
    CREATE OR REPLACE PROCEDURE TEST_PROC
    lookup_cursor      integer;
    ignore          integer;
    VARvalue          number;
    begin
    lookup_cursor := DBMS_SQL.open_cursor;
    DBMS_SQL.PARSE( lookup_cursor,
              'SELECT ' || TEST_FUNCTION || ' FROM DUAL,
              DBMS_SQL.NATIVE);
    DBMS_SQL.DEFINE_COLUMN( lookup_cursor, 1, VARvalue);
    ignore := DBMS_SQL.EXECUTE(lookup_cursor);
    loop
         IF DBMS_SQL.FETCH_ROWS(lookup_cursor) > 0 THEN
         DBMS_SQL.COLUMN_VALUE(lookup_cursor, 1, VARvalue);
         ELSE
         EXIT;
         END IF;
    END LOOP;
    DBMS_SQL.CLOSE_CURSOR(lookup_cursor);
    end TEST_PROC;
    CREATE OR REPLACE PROCEDURE TEST_FUNCTION
    lookup_cursor      integer;
    ignore          integer;
    VARvalue          number;
    VARsql_string     VARCHAR2(200);
    begin
    lookup_cursor := DBMS_SQL.open_cursor;
    VARsql_string := SOME GENERATED SQL STATEMENT;
    DBMS_SQL.PARSE( lookup_cursor,
              VARsql_string,
              DBMS_SQL.NATIVE);
    DBMS_SQL.DEFINE_COLUMN( lookup_cursor, 1, VARvalue);
    ignore := DBMS_SQL.EXECUTE(lookup_cursor);
    loop
         IF DBMS_SQL.FETCH_ROWS(lookup_cursor) > 0 THEN
         DBMS_SQL.COLUMN_VALUE(lookup_cursor, 1, VARvalue);
         ELSE
         EXIT;
         END IF;
    END LOOP;
    RETURN VARvalue;
    end TEST_FUNCTION;
    The error I received during execution of TEST_PROC is:
    ORA-06571: Function TEST_FUNCTION does not guarantee not to update database
    ORA-06512: at "SYS.DBMS_SYS_SQL", line 239
    ORA-06512: at "SYS.DBMS_SQL", line 32
    It may seem like the example procedure doesnt need to use a dynamic SQL execution to call TEST_FUNCTION but the actual code that I extracted from does.
    Does Oracle 7 always treat the dynamic SQL command set as some kind of update statement? Is that a bug? I understand that the EXECUTE IMMEDIATE command in Oracle 8i will replace the old command set found in the above examples. Will using the new EXECUTE IMMEDIATE command in Oracle 8i solve this problem?
    Thank you for any help,
    Tony

    In Oracle 7, for a function to be called from a select statement it has to follow the 'purity rule' that it does not modify any database table or package variable.
    Probably you will have to use the compiler directive PRAGMA RESTRICT_REFERENCES (WNDS,WNPS) on your TEST_FUNCTION so that it can be called within a SQL statement.
    This restriction is removed in Oracle 8i onwards.
    Hope this solves your problem.
    Regards

  • JDBC, Using Dynamic SQL

    How to implement dynamic SQL (like dynamic SQL Method 4 in Pro*C), which
    lets program accept or build dynamic SQL statements that contain an unknown
    number of select-list items or placeholders?

    You don't need the Oracle specific stuff. You can use ResultSetMetadata to analyze what your SQL statement returned. (I assume that's what you mean with "number of select-list items"). Basically:Statement stmt = connection.createStatement();
    boolean hasResult = stmt.execute(sql);
    if (hasResult)
      ResultSet rs = stmt.getResultSet();
      ResultSetMetadata meta = rs.     getMetaData();
      for (int c=0; c < meta.getColumnCount(); c++)
         System.out.println("Column: " + meta.getColumnName(c + 1); // column number starts at 1!
    }You will not be able to check whether your statement contains parameters/placeholders (to be used with PreparedStatements) because the Oracle driver does not implement the necessary methods.

  • Delcare Cursor using Dynamic SQL using PL/SQL in Oracle 7.3.4

    In Oracle 7.3.4, can I declare a cursor at run time using Dynamic SQL. From the sample code in this website, it seems that Oracle 8 support this function. Please help. Thanks a lot.
    If I can do this on Oracle 7.3.4, could you give me some sample codes? Thanks.
    Regards,
    Raymond

    Hi,
    Try using the the following code where you can dynamically build the Valid Select stmt. and call that where ever you want.
    declare
    Type Cur_ref Is Ref Cursor;
    C_ref Cur_ref;
    V_Str Varchar2(100);
    V_Name Varchar2(100);
    Begin
    V_Str := 'Select Ename from Scott.emp Where empno = 7369';
    Open C_Ref for V_Str;
    Fetch C_ref Into V_Name;
    close C_Ref;
    dbms_output.put_line(V_Name);
    End;
    regards
    gaurav
    null

  • Dynamic sql and cursors

    We are running an oracle sql procedure that uses a LOT of dynamic sql. We are using a 3rd party package (SQR) as a sort of shell to run the sql procedure. The 3rd party package passes to us an oracle error. This error says, in effect, that there are no inactive database cursors available and that the sql program is too large to process. We conclude from this that we must increase one or more of the cursor parameters in init.ora (v$parameters). Is this the correct assumption? If not, does anyone know what we can do? We'd prefer not to break up the sql procedure into smaller pieces.

    increase the parameter for open cursors.
    check, wether all cursors in your programs are closed in time, or if you are using ref cursors from front-ends (e.g. Java JDBC) that this front-ends close these ref cursors , too.
    If you want to decrease the size of procedures get rid of comments, superfluos spaces, tabs, etc.
    keep a commented version outside vor documentation purposes.
    Hope thsi helps

  • 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.

  • Perfomance review Cursor and dynamic SQL

    Hi every one ,
    I searcher over internet and oracle forums for what is the best for my case.
    I tried to rebuild indexes . I had two methods , Both working fine but I am looking for what is better from performance point of view
    1- using Cursor like in the below link .
    http://www.think-forward.com/sql/rebuildunusable.htm
    2- Using Dynamic SQL , which generated script file then run it.
    spool rebuildall.sql
    select ' alter index '|| owner||'.'||index_name ||' rebuild online; '
    from dba_indexes where status='UNUSABLE';
    spool off;
    @rebuildall.sql
    Thanks in advance . Your help is appreciated.

    Hi ,
    Thanks for your input . We had some customer which they have a lot of row chaining and migration , I need to increase PCTFREE
    with move command . As result of this command indexes becomes unusable as you know . So there are monthly tables become chained with wrong definitions in PCTFREE and INTRSAN.
    I used the above script as help my time and solve problem faster ,It is only when I need it ,So it is not scheduled or something like that .
    I'm looking for anything will help and simplify the work .

  • 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.

  • Open cursor for dynamic sql

    Hi
    I am using oracle 8.1.7 on solaris.
    I have created
    SQL> CREATE OR REPLACE PACKAGE TEST_PKG AS
    2 TYPE row_cursor IS REF CURSOR RETURN TEMP_TAB%ROWTYPE;
    3 PROCEDURE Return_Columns_proc (c_return IN OUT row_cursor);
    4 END TEST_PKG;
    5 /
    Package created.
    now i am trying to create the procedure Return_Columns_proc by
    CREATE OR REPLACE PACKAGE BODY TEST_PKG AS
    PROCEDURE Return_Columns_proc (c_return IN OUT row_cursor) AS
    QUERY_STR VARCHAR2(850);
    x number ;
    BEGIN
    x:=1;
    QUERY_STR :='SELECT * FROM temp_tab where order_line_id = '||x;
    OPEN c_return FOR QUERY_STR;
    END Return_Columns_proc;
    END TEST_PKG;
    I am getting following error.
    SQL> show error
    Errors for PACKAGE BODY TEST_PKG:
    LINE/COL ERROR
    8/4 PL/SQL: Statement ignored
    8/9 PLS-00455: cursor 'C_RETURN' cannot be used in dynamic SQL OPEN
    statement
    any help for this error.

    The error says it all. You have defined a strong ref cursor and it cannot be used with dynamic sql. However, that does not mean you cannot use the query directly in the OPEN clause
    OPEN c_Return FOR SELECT * FROM temp_tab where order_line_id = X ;

Maybe you are looking for

  • How do i link to a specific tab using the spry tabbed widget

    Hello i'm working on a microsite using the spry tabbed widget. I'm having trouble figuring out how to link to a specific tab using a an external link. here is the site. http://www.efaxcorporate.co.uk for example: if i wanted to give a user a url link

  • SID error in XI sysytem

    hai friends iam trying to create 2 SID's in one single system . 1 for devlopment 2nd for production . is it posible to create 2 sid's for one single system if it is posible pls tell me how to do this one . OR any other way to maintain this devlopment

  • Another schema reference in a stored procedure

    Hello - I need to call a stored procedure from another stored procedure in a different schema. Can this be done? For example: I am logged on as USER1 and I try to call these stored procedures from within a stored procedure: DO_STUFF (works - within o

  • Hypertext for Reader in Android

    I was surprised to find that Reader for Android does not support hypertext links - specifically mailto: like the windows version does.  I keep a directory for a group that includes links for email addresses making sending emails from the directory ve

  • Changing color of lines that identify selected objects

    Some of my artboards use the color yellow to highlight selected objects. Can I change that?