ORA-1481 using DBMS_SQL.FETCH_ROWS

Hi all.
I have a package, called from forms 6, that in one of its functions uses DBMS_SQL package.
It has a bunch of DBMS_SQL.DEFINE_COLUMN ....
but fails with ora-1481 in this line (after all the DEFINE_COLUMN)
<quote>
traza := '07 ';
if (DBMS_SQL.FETCH_ROWS(v_cursor)= 0 ) then
traza := '71';
     exit;
end if;
traza := '08';
.... more code
<end quote>
The procedure shows, going to the WHEN OTHERS exception, the error 1481 with '07' as traza (trace). Not '71', not '08'.
Someone can help? Thank you all in advance.

It could be caused because in the previous DBS_SQL.DEFINE_COLUMN some of the variables used like
- "DBMS_SQL.DEFINE_COLUMN (v_cursor, 71, v_cdclave_sust ,1000 );" -> that (w_cdclave_sust) is a varchar2
- or "DBMS_SQL.DEFINE_COLUMN (v_cursor, 71, v_cdclave_sust_2 );" -> w_cdclave_sust_2 is a number)
are number?
Thanks

Similar Messages

  • Using DBMS_SQL getting ORA-29255

    Sort of new to DBMS_SQL - as I've been using NDS for almost everything to this point.
    However - I have a situation where I'm selecting data that requires a predicate of multiple values for a single column (i.e. column in (:v1)) where :v1 is a list of values. I was using bind_array to set the values for :v1. However - I get the error above.
    The SQL returns mutiple rows so - define array is being used to indicate what column should be returned to what array.
    I understand based on the error message that they can't be used together. So- my question is - when using a SQL statement that requires "columnA IN (multiple_values)" how are you supposed to bind those using DBMS_SQL?
    Any help is appreciated!!

    Thanks... Code is below...
    You can see where the vspccat is a predicate and - we're trying to get the multiple values 'bound' to the SQL. However - the sql also returns multiple rows (hence the 'define array' to get the return values).
    We're using DBMS_SQL over NDS simply because (as isn't illustrated in the example below - which I was using just to get the concept working in an example to use moving forward with the actual code I will need to write) I'm needing to use multiple varrying predicates depending on the situation and - this is a cleaner way to handle that - rather than tracking what's been dynamically written and - handling it with every possible scenario in many different executes (with the different 'using's' attached).
    Your help is appreciated!
    DECLARE
    col1    NUMBER(9,0);
    col2    VARCHAR2(15);
    col3    VARCHAR2(15);
    col4    VARCHAR2(60);
    col5    DATE;
    col6    DATE;
    col7    VARCHAR2(6);
    col8    NUMBER(9,0);
    col9    VARCHAR2(1);
    spc_cat_array   DBMS_SQL.VARCHAR2_TABLE;
    col1_array      DBMS_SQL.NUMBER_TABLE;
    col2_array      DBMS_SQL.VARCHAR2_TABLE;
    col3_array      DBMS_SQL.VARCHAR2_TABLE;
    col4_array      DBMS_SQL.VARCHAR2_TABLE;
    col5_array      DBMS_SQL.DATE_TABLE;
    col6_array      DBMS_SQL.DATE_TABLE;
    col7_array      DBMS_SQL.VARCHAR2_TABLE;
    col8_array      DBMS_SQL.NUMBER_TABLE;
    col9_array      DBMS_SQL.VARCHAR2_TABLE;
    p_spc_cat   VARCHAR2(15) := '03';
    p_status    VARCHAR2(6)  := 'APPROV';
    src_cur  INTEGER;
    dest_cur INTEGER;
    ignore   INTEGER;
    fdbk     INTEGER;
    l_sql   VARCHAR2(1000);
    dest_rec    VARCHAR2(500);
    BEGIN
        spc_cat_array(1) := '03';
        spc_cat_array(2) := '09';    
        spc_cat_array(3) := '35';
        l_sql := ' SELECT *' ||
                      ' FROM (SELECT maint_id, NULL AS ica_price_rule, spc_category, description,' ||
                                   ' effective_date, term_date, status,' ||
                                   ' seq_ica_spc_pr_whole AS sequence_id, update_type' ||
                              ' FROM ica_spc_pr_whole_hdr_wrk' ||
                                ' WHERE spc_category IN (:vspccat)' ||
                                ' AND status = :vstatus  ' ||
                                ' AND term_date IS NULL' ||
                             ' UNION ALL' ||
                            ' SELECT NULL AS maint_id, NULL AS ica_price_rule, spc_category,' ||
                                   ' description, effective_date, term_date, status,' ||
                                   ' seq_ica_spc_pr_whole AS sequence_id, NULL AS update_type' ||
                              ' FROM ica_spc_pr_whole_hdr live'  ||
                                ' WHERE spc_category IN (:vspccat)' ||
                                ' AND status = :vstatus  ' ||
                                ' AND term_date IS NULL' ||
                               ' AND NOT EXISTS (SELECT spc_category' ||
                                                 ' FROM ica_spc_pr_whole_hdr_wrk wrk' ||
                                                ' WHERE wrk.spc_category = live.spc_category)) a';
        -- open cursor on source table
      src_cur := dbms_sql.open_cursor;
      -- parse the SELECT statement
      dbms_sql.parse(src_cur, l_sql, dbms_sql.NATIVE);
      -- Bind Variables
    --  DBMS_SQL.BIND_VARIABLE (src_cur, ':vspccat', p_spc_cat);
      DBMS_SQL.BIND_ARRAY (src_cur, ':vspccat', spc_cat_array);
      DBMS_SQL.BIND_VARIABLE (src_cur, ':vstatus', p_status);
      -- define the column type
      dbms_sql.define_array(src_cur, 1, col1_array, 5, 1);
      dbms_sql.define_array(src_cur, 2, col2_array, 5, 1);
      dbms_sql.define_array(src_cur, 3, col3_array, 5, 1);
      dbms_sql.define_array(src_cur, 4, col4_array, 5, 1); 
      dbms_sql.define_array(src_cur, 5, col5_array, 5, 1);
      dbms_sql.define_array(src_cur, 6, col6_array, 5, 1);
      dbms_sql.define_array(src_cur, 7, col7_array, 5, 1);
      dbms_sql.define_array(src_cur, 8, col8_array, 5, 1);
      dbms_sql.define_array(src_cur, 9, col9_array, 5, 1);
      ignore := dbms_sql.execute(src_cur);
      if dbms_sql.fetch_rows(src_cur) > 0  then
              dbms_sql.column_value( src_cur, 1, col1_array);
              dbms_sql.column_value( src_cur, 2, col2_array);
              dbms_sql.column_value( src_cur, 3, col3_array);
              dbms_sql.column_value( src_cur, 4, col4_array);
              dbms_sql.column_value( src_cur, 5, col5_array);
              dbms_sql.column_value( src_cur, 6, col6_array);
              dbms_sql.column_value( src_cur, 7, col7_array);
              dbms_sql.column_value( src_cur, 8, col8_array);
              dbms_sql.column_value( src_cur, 9, col9_array);         
          end if;
        dbms_output.put_line(col3_array(1));
      dbms_sql.close_cursor(src_cur);
    end;

  • Error when using DBMS_SQL.parse

    Has anyone ever ran into this error "ORA-00932: inconsistent datatypes: expected NUMBER got DATE" when using DBMS_SQL.parse? I'm trying to pass in a sql statement that includes date columns but it keeps failing during the parse step. If I put a "to_char" around the dates it works fine.
    Any ideas?
    declare
        l_cursor   PLS_INTEGER;
        l_rows     PLS_INTEGER;
        l_col_cnt  PLS_INTEGER;
        l_desc_tab DBMS_SQL.desc_tab;
        l_buffer   CLOB;
        v_query    clob;
        l_file UTL_FILE.file_type;
        g_sep  VARCHAR2(5) := ',';
      BEGIN
        l_cursor := DBMS_SQL.open_cursor;
        v_query := 'SELECT CREATED FROM DBA_USERS';
        DBMS_SQL.parse(l_cursor, v_query, DBMS_SQL.native);
        DBMS_SQL.describe_columns(l_cursor, l_col_cnt, l_desc_tab);
        FOR i IN 1 .. l_col_cnt
        LOOP
          DBMS_SQL.define_column(l_cursor, i, l_buffer);
        END LOOP;
        l_rows := DBMS_SQL.execute(l_cursor);   
        -- Output the column names.
        FOR i IN 1 .. l_col_cnt
        LOOP
          IF i > 1 THEN
            UTL_FILE.put(l_file, g_sep);
          END IF;
          UTL_FILE.put(l_file, l_desc_tab(i).col_name);
        END LOOP;
        UTL_FILE.new_line(l_file);
        -- Output the data.
        LOOP
          EXIT WHEN DBMS_SQL.fetch_rows(l_cursor) = 0;
          FOR i IN 1 .. l_col_cnt
          LOOP
            IF i > 1 THEN
              UTL_FILE.put(l_file, g_sep);
            END IF;
            DBMS_SQL.COLUMN_VALUE(l_cursor, i, l_buffer);
            -- Check for column data type. If "character" data type enclose in quotes
            -- 1 = VARCHAR2 and NVARCHAR2, 96 = CHAR and NCHAR, 112 = CLOB
            IF l_desc_tab(i).col_type IN (1, 96, 112) THEN
              l_buffer := '"' || l_buffer || '"';
            END IF;
            UTL_FILE.put(l_file, l_buffer);
          END LOOP;
          UTL_FILE.new_line(l_file);
        END LOOP;
        UTL_FILE.fclose(l_file);
      EXCEPTION
        WHEN OTHERS THEN
          IF UTL_FILE.is_open(l_file) THEN
            UTL_FILE.fclose(l_file);
          END IF;
          IF DBMS_SQL.is_open(l_cursor) THEN
            DBMS_SQL.close_cursor(l_cursor);
          END IF;
          RAISE;
      END;Edited by: jpvybes on Jun 6, 2013 3:47 PM

    >
    Has anyone ever ran into this error "ORA-00932: inconsistent datatypes: expected NUMBER got DATE" when using DBMS_SQL.parse? I'm trying to pass in a sql statement that includes date columns but it keeps failing during the parse step. If I put a "to_char" around the dates it works fine.
    >
    No - it is NOT failing on the parse step. If you comment out various sections of the code you will find that your loop is causing the problem.
    Comment out this loop and there is NO exception.
        l_buffer   CLOB;
        FOR i IN 1 .. l_col_cnt
        LOOP
          DBMS_SQL.define_column(l_cursor, i, l_buffer);
        END LOOP;Do you now see the problem?
    You are using 'define_column' and passing 'l_buffer' which is a CLOB. But this is your query
        v_query := 'SELECT CREATED FROM DBA_USERS';And that 'CREATED' column in the query is a DATE.
    Why are you defining a column as a CLOB when the cursor column is a DATE?
    See the example3 in Chapter 100 DBMS_SQL in the Packages and Types doc. It shows an example that includes a DATE column.
    http://docs.oracle.com/cd/B19306_01/appdev.102/b14258/d_sql.htm#i996963

  • Create Table using DBMS_SQL package and size not exceeding 64K

    I have a size contraint that my SQL size should not exceed 64K.
    Now I would appriciate if some one could tell me how to create a table using
    Dynamic sql along with usage of DBMS_SQL package.
    Brief Scenario: Users at my site are not given permission to create table.
    I need to write a procedure which the users could use to create a table .ALso my SQL size should not exceed 64K. Once this Procedure is created using DBMS_SQL package ,user should pass the table name to create a table.
    Thanks/

    "If a user doesn't have permission to create a table then how do you expect they will be able to do this"
    Well, it depends on what you want to do. I could write a stored proc that creates a table in my schema and give some other user execute privilege on it. They would then be able to create a able in my schema without any explicitly granted create table privilege.
    Similarly, assuming I have CREATE ANY TABLE granted directly to me, I could write a stroe proc that would create a table in another users schema. As long as they have quota on their default tablespace, they do not need CREATE TABLE privileges.
    SQL> CREATE USER a IDENTIFIED BY a
      2  DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp;
    User created.
    SQL> GRANT CREATE SESSION TO a;
    Grant succeeded.
    SQL> CREATE TABLE a.t (id NUMBER, descr VARCHAR2(10));
    CREATE TABLE a.t (id NUMBER, descr VARCHAR2(10))
    ERROR at line 1:
    ORA-01950: no privileges on tablespace 'USERS'So, give them quota on the tablespace and try again
    SQL> ALTER USER a QUOTA UNLIMITED ON users;
    User altered.
    SQL> CREATE TABLE a.t (id NUMBER, descr VARCHAR2(10));
    Table created.Now lets see if it really belongs to a:
    SQL> connect a/a
    Connected.
    SQL> SELECT table_name FROM user_tables;
    TABLE_NAME
    T
    SQL> INSERT INTO t VALUES (1, 'One');
    1 row created.Yes, it definitely belongs to a. Just to show that ther is nothing up my sleeve:
    SQL> create table t1 (id NUMBER, descr VARCHAR2(10));
    create table t1 (id NUMBER, descr VARCHAR2(10))
    ERROR at line 1:
    ORA-01031: insufficient privilegesI can almost, but not quite, see a rationale for the second case if you want to enforce some sort of naming or location standards but the whole thing seems odd to me.
    Users cannot create tables, so lets give them a procedure to create tables?
    John

  • How to make dynamic query using DBMS_SQL variable column names

    First of all i will show a working example of what i intend to do with "EXECUTE IMMEDIATE":
    (EXECUTE IMMEDIATE has 32654 Bytes limit, which isn't enough for me so i'm exploring other methods such as DBMS_SQL)
    -------------------------------------------------CODE-----------------------------------
    create or replace PROCEDURE get_dinamic_query_content
    (query_sql IN VARCHAR2, --any valid sql query ('SELECT name, age FROM table') 
    list_fields IN VARCHAR2) --list of the columns name belonging to the query (  arr_list(1):='name';   arr_list(2):='age';
    -- FOR k IN 1..arr_list.count LOOP
    -- list_fields := list_fields || '||content.'||arr_list(k)||'||'||'''~cs~'''; )
    AS
    sql_stmt varchar (30000);
    BEGIN
                   sql_stmt :=
    'DECLARE
         counter NUMBER:=0;     
    auxcontent VARCHAR2(30000);     
         CURSOR content_cursor IS '|| query_sql ||';
         content content_cursor%rowtype;     
         Begin
              open content_cursor;
              loop
                   fetch content_cursor into content;
                   exit when content_cursor%notfound;
                   begin                              
                        auxcontent := auxcontent || '||list_fields||';                    
                   end;
                   counter:=counter+1;     
              end loop;
              close content_cursor;
              htp.prn(auxcontent);
         END;';
    EXECUTE IMMEDIATE sql_stmt;
    END;
    -------------------------------------------------CODE-----------------------------------
    I'm attepting to use DBMS_SQL to perform similar instructions.
    Is it possible?

    Hi Pedro
    You need to use DBMS_SQL here because you don't know how many columns your query is going to have before runtime. There are functions in DBMS_SQL to get information about the columns in your query - all this does is get the name.
    SQL&gt; CREATE OR REPLACE PROCEDURE get_query_cols(query_in IN VARCHAR2) AS
    2 cur PLS_INTEGER;
    3 numcols NUMBER;
    4 col_desc_table dbms_sql.desc_tab;
    5 BEGIN
    6 cur := dbms_sql.open_cursor;
    7 dbms_sql.parse(cur
    8 ,query_in
    9 ,dbms_sql.native);
    10 dbms_sql.describe_columns(cur
    11 ,numcols
    12 ,col_desc_table);
    13 FOR ix IN col_desc_table.FIRST .. col_desc_table.LAST LOOP
    14 dbms_output.put_line('Column ' || ix || ' is ' ||
    15 col_desc_table(ix).col_name);
    16 END LOOP;
    17 dbms_sql.close_cursor(cur);
    18 END;
    19 /
    Procedure created.
    SQL&gt; exec get_query_cols('SELECT * FROM DUAL');
    Column 1 is DUMMY
    PL/SQL procedure successfully completed.
    SQL&gt; exec get_query_cols('SELECT table_name, num_rows FROM user_tables');
    Column 1 is TABLE_NAME
    Column 2 is NUM_ROWS
    PL/SQL procedure successfully completed.
    SQL&gt; exec get_query_cols('SELECT column_name, data_type, low_value, high_value FROM user_tab_cols');
    Column 1 is COLUMN_NAME
    Column 2 is DATA_TYPE
    Column 3 is LOW_VALUE
    Column 4 is HIGH_VALUE
    PL/SQL procedure successfully completed.I've just written this as a procedure that prints out the column names using dbms_output - I guess you're going to do something different with the result - maybe returning a collection, which you'll then parse through in Apex and print the output on the screen - this is just to illustrate the use of dbms_sql.
    best regards
    Andrew
    UK

  • Problem using DBMS_SQL in a form

    hi,
    I am trying to write a procedure which get an input string containing a SQL statement (a SELECT), executes it, fetches the rows and writes them into a Excel sheet. I found this article http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_sql.htm describing how to use DBMS_SQL package. My goal is to parse my query and store result in an array (using DEFINE_ARRAY).
    I put theese two lines
    (declare c number;)
    c := dbms_sql.open_cursor;
    dbms_sql.parse(c,p_query,dbms_sql.native); (p_query is my input string containing SQL)
    But when I compile my program unit I get an error looking like that: "implementation restriction: DBMS_SQL.NATIVE: unable to access a remote package variable or cursor".
    Where is the error? should I set something to access the package, or is it not possible to use it inside a form?

    W1zard is correct. Switch to Exec_SQL. Oracle does not support Forms using DBMS_SQL.
    Now... please explain why you are not using a dynamic record group. It is SOOO much easier!
    And if you want to look at some code using both methods, Exec_SQL and dynamic record group, you can download my "Quick Access" dynamic utility form, here:   Oracle Forms Utilities

  • Dynamic SQL using DBMS_SQL Package

    Hi,
    How do i construct a
    "select * from :table_name(input parameter)"
    in a store proc in Oracle8 ?
    I know this is only possible using DBMS_SQL package in Oracle 8.
    I know that this is easily done using native Dyanamic SQL 8i onwards.
    Also I want to return the resultset obtained above through a REF cursor.
    Please Help !!!
    Will be greatly indebted to anyone who can supply the code or direct me to some helpful information on the net.
    Thanks in advance.
    Peeyush

    You are asking for two things here, use the tablename dynamically
    as bind variable to fetch the resultset and send the resultset to
    a stored procedure.
    I thought of doing both of them with REF Cursors, no Dynamic SQL here.
    Consider the following test,SQL> create or replace package ref_types as
      2       type r_cursor(pSal NUMBER) is ref cursor;
      3  end;
      4  /
    Package created.
    -- Please note that I did some quick and dirty coding to switch
    -- between the table names to show the results.
    SQL> create or replace procedure p_dynamic_table
      2  (pRefCur IN ref_types.r_cursor, pTable varchar2) as
      3     emp_rec my_emp%ROWTYPE;
      4     inv_rec test444%ROWTYPE;
      5  begin
      6    loop
      7       IF UPPER(pTable) = 'MY_EMP' Then
      8          fetch pRefcur into emp_rec;
      9       Elsif UPPER(pTable) = 'INV' THEN
    10          fetch pRefCur into inv_rec;
    11       Else
    12          exit;
    13       End if;
    14       exit when pRefcur%NOTFOUND;
    15       If UPPER(pTable) = 'MY_EMP' Then
    16          dbms_output.put_line(emp_rec.empno);
    17       Elsif UPPER(pTable) = 'INV' Then
    18          dbms_output.put_line(inv_rec.seq);
    19       Else
    20         Null;
    21       End if;
    22    end loop;
    23  end;
    24  /
    Procedure created.
    SQL> declare
      2     vRefCur         ref_types.r_cursor;
      3     vTableName      Varchar2(30);
      4  begin
      5    vTableName := 'my_emp';
      6    open vRefCur for 'select * from ' || vTableName;
      7    p_dynamic_table(vRefCur, vTableName);
      8    close vRefCur;
      9    vTableName := 'inv';
    10    open vRefCur for 'select * from ' || vTableName;
    11    p_dynamic_table(vRefCur, vTableName);
    12    close vRefCur;
    13  end;
    14  /
    7369
    7499
    7521
    7566
    7654
    7698
    7782
    7788
    7839
    7844
    7876
    7900
    7902
    7934
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    PL/SQL procedure successfully completed.Thx,
    Sri

  • Need to execute Long Insert (6000 characters)statement using dbms_sql.parse

    I built an insert statement which is more than 6000 (six thousand) characters stored into two varchar2 variables. I need to execute the statement using dbms_sql.parse.
    I tryed using dbms_sql.varchar2s variable and having no success.
    Any ideas or examples?
    Thanks
    JK

    6000 chars shouldn't be a problem.
    What do you mean with no success?Did you get any error?
    Any ideas or examples?See this thread
    Re: execute immediate with a string longer than 32767

  • DBMS_SQL.FETCH_ROWS

    Hi,
    I am seeing a strange thing. See the below code snippet.
    v_qry := 'select count(1) from emp where ename = ''SCOT''';
    DBMS_OUTPUT.PUT_LINE(V_QRY);
    DBMS_SQL.PARSE (cur, v_qry, DBMS_SQL.NATIVE);
    int_output := DBMS_SQL.EXECUTE (cur);
    int_exec := DBMS_SQL.FETCH_ROWS (cur);
    as no row with ename ='SCOT' exists, the int_exec should be 0. It shows 1.

    the int_exec should be 0. It shows 1.Check this:
    SQL> set serverout on
    SQL> DECLARE
       cur          INT := dbms_sql.open_cursor ();
       int_output   INT;
       int_exec     INT;
       val_out      INT;
       v_qry        VARCHAR2 (100);
    BEGIN
       v_qry := 'select count(1) from emp where ename = ''SCOT''';
       dbms_output.put_line (v_qry);
       dbms_sql.parse (cur, v_qry, dbms_sql.native);
       int_output := dbms_sql.execute (cur);
       dbms_sql.define_column (cur, 1, val_out);
       int_exec := dbms_sql.fetch_rows (cur);
       dbms_sql.column_value (cur, 1, val_out);
       dbms_output.put_line (int_exec);
       dbms_output.put_line (val_out);
       dbms_sql.close_cursor (cur);
    END;
    select count(1) from emp where ename = 'SCOT'
    1
    0
    PL/SQL procedure successfully completed.

  • Using differing numbers of inputs for a similar query using DBMS_SQL

    Hi,
    I'm trying to use DBMS_SQL for a query that's either going to include the following WHERE statement:
    "AND sched_requirement_id = pin_sr_id"
    or not base upon conditions passed to the procedure calling it
    v_sql_stmt :=
    'SELECT COUNT(1)
    INTO v_exists
    FROM SCHED_PSA_REQS
    WHERE sched_week_id = pin_sched_week_id
    AND sequence_number = pin_seq_no
    AND sched_original_req_id = pin_sor_id
    ----> AND sched_requirement_id = pin_sr_id<---------
    AND ROWNUM = 1';
    The only reason I can't use NDS for this is because of the pin_sr_id input doesn't exist inside the universe of the v_sql_stmt. If it was an inner join or something I could get away with it.
    I read that DBMS_SQL doesn't care how many input values it gets until the dbms_sql.EXECUTE statement, but in all the documentation I've read through I have yet to come across an example that deals with a varying number of input values. Does anyone out there have an example of DBMS_SQL that deals with a varying number of bind input values based upon a conditional statement or input values?
    Thanks!

    Mike,
    Thanks for your input but the EXECUTE IMMEDIATE I would be using contains the following input values:
    EXECUTE IMMEDIATE v_sql_stmt
    INTO v_psa_req_id USING pin_sched_week_id, pin_seq_no, pin_sor_id, pin_sr_id;
    I experimented with exactly what you suggested with scott/tiger:
    set serveroutput on
    DECLARE
    v_target_val NUMBER;
    v_str varchar2(4000);
    f_tbl varchar2(200);
    f_exp varchar2(200);
    dept_var NUMBER:= 20;
    BEGIN
    f_tbl := ', dept d';
    f_exp := 'and e.deptno = dept_var ';
    --f_exp := ' and e.deptno = d.deptno ';
    v_str := ' Select '
    ||' sal '
    ||' from emp e '
    ||f_tbl
    ||'
    where '
    ||' e.empno = :b_v_for_where_cond '
    ||f_exp;
    dbms_output.put_line(v_str);
    EXECUTE IMMEDIATE v_str
    INTO v_target_val USING 7369;
    dbms_output.put_line(v_target_val);
    EXCEPTION
    when no_data_found then
    dbms_output.put_line('No data exception raised');
    when others then
    dbms_output.put_line(SQLCODE||' '||SQLERRM);
    END;
    The code bombs miserably when I try to introduce a variable that's not fed in from the USING clause. From what I've learned of NDS all values must either be deliberately fed in like from the USING statement or must exist "inside the universe" of that SQL statement. Example if I use the line:
    f_exp := ' and e.deptno = d.deptno ';
    instead it works because d.deptno can be referenced from within that SQL statement from table dept.
    So in my case either pin_sr_id is part of the USING clause or it's not. This is the one thing that DBMS_SQL still has over NDS is the fact "It does not need to know the number and types of arguments it will receive and process." (1) Oracle Database 10g PL/SQL Programming pg. 609.
    They say you can use DESCRIBE_COLUMNS and DESCRIBE_COLUMNS2. However, I've yet to find an example of its use. If anybody has any web links to such it would be greatly appreciated.

  • Error while executing query longer thank 32K using dbms_sql

    Hi,
    I'm using oracle database version is 10.2.0.4.0
    I've a query of size 41K.
    I can't run it with execute immediate, so when I'm running it with dbms_sql I'm getting error -
    ORA-06502: PL/SQL: numeric or value error.
    But when I'm running it in my pl/sql developer it is running fine.
    Code snippet is below
    -- Created on 24/05/2010 by TSHARMA
    declare
    -- Local variables here
    cursor_name INTEGER;
    i integer;
    tc clob;
    begin
    -- Test statements here
    select col1 into tc from temp where a1 = 't1'; --getting the long query from a temp table
    tc := 'create table temp1 as ' || tc;
    cursor_name := dbms_sql.open_cursor;
    DBMS_SQL.PARSE(cursor_name, tc, DBMS_SQL.NATIVE);
    i := DBMS_SQL.EXECUTE(cursor_name);
    DBMS_SQL.CLOSE_CURSOR(cursor_name);
    end;
    -------------------------------

    Hi,
    DBMS_SQL.PARSE is overloaded to accept a VARCHAR2A as the statement parameter. This is a table of VARCHAR2(32767) which can be built up using your long query. I've written the following to handle long CLOB's. Just call the execute_sql procedure passing in the long sql:
    PROCEDURE execute_sql (p_sql IN CLOB) IS
       l_sql_table DBMS_SQL.VARCHAR2a;
       l_ds_cursor PLS_INTEGER;
       l_ret_val   PLS_INTEGER;
    BEGIN
       l_sql_table := populate_sql_table(p_sql => p_sql);
       l_ds_cursor := DBMS_SQL.OPEN_CURSOR;
       DBMS_SQL.PARSE(l_ds_cursor, l_sql_table, l_sql_table.FIRST, l_sql_table.LAST, FALSE, DBMS_SQL.NATIVE);
       l_ret_val := DBMS_SQL.EXECUTE(l_ds_cursor);
       DBMS_SQL.CLOSE_CURSOR(l_ds_cursor);
    END execute_sql;
    FUNCTION populate_sql_table (p_sql IN CLOB) RETURN DBMS_SQL.VARCHAR2a IS
       l_buffer_length CONSTANT PLS_INTEGER := 32767;
       l_lob_length PLS_INTEGER;
       l_offset PLS_INTEGER := 1;
       l_amount PLS_INTEGER := l_buffer_length;
       l_sql_table DBMS_SQL.VARCHAR2a;
    BEGIN
       l_sql_table.DELETE;
       l_lob_length := DBMS_LOB.GETLENGTH(p_sql);
       LOOP
          IF l_buffer_length > l_lob_length THEN
             l_amount := l_lob_length;
          END IF;
          l_sql_table(NVL(l_sql_table.LAST, 0) + 1) := DBMS_LOB.SUBSTR(p_sql, l_amount, l_offset);
          l_offset := l_offset + l_buffer_length;
          l_lob_length := l_lob_length - l_amount;
          IF l_lob_length <= 0 THEN
             EXIT;
          END IF;
       END LOOP;
       RETURN(l_sql_table);
    END populate_sql_table;Hope that helps

  • Using DBMS_SQL in a procedure

    Hi,
    I am using Oracle8i 8.1.5 on RedHat Linux 6.1. I have a stored procedure that executes some DDL statements using the DBMS_SQL package.
    When I go to execute the stored procedure, I get the following errors:
    ORA-01031: insufficient privileges
    ORA-06512: at "SYS.DBMS_SYS_SQL", line 487
    ORA-06512: at "SYS.DBMS_SQL", line 32
    The user I am running the procedure as (who also happens to own the procedure) has DBA privileges as well as EXECUTE ANY PROCEDURE privilege.
    Has anyone else seen this before, and what do I need to do to remedy it.
    Timothy Sim
    [email protected]
    null

    Who owns the stored procedure? In Oracle 7.X - 8.0, the person who owns the procedure is the person who executes it. In other words, Oracle assumes the identity of the owner of the procedure when it is executed. Therefor, it would not matter if you are a DBA, if the owner of the procedure is not a DBA. In Oracle 8.i, the default behavior is the same. However, you can change this behavior if you'd like (Make the executor the person who executes the DDL). I am not sure of the exact syntax, but I could get it for you if you need it.
    This may be your problem.
    -Jim Wartnick
    [email protected]

  • Dynamic DDL execution using DBMS_SQL

    Hello,
    I've done a set of PL/SQL blocks that helps me to automate some tasks of my schema for better productivity. It concerns the most of the time :
    - activate/deactivate foreign keys and constraints
    - delete and recreate a set of objects
    - etc
    My routines execute a query on the dictionary to construct other queries to manipulate my objects. It works fine for a couple of comands:
    -- DISABLE CONSTRAINTS
    DECLARE
    CURSOR curs
    IS
    SELECT 'ALTER TABLE "'
    || table_name
    || '" DISABLE CONSTRAINT "'
    || constraint_name
    || '"' text
    FROM SYS.user_constraints
    WHERE constraint_type = 'R' AND owner = r_owner;
    c_row curs%ROWTYPE;
    cursor_name INTEGER;
    BEGIN
    FOR c_row IN curs
    LOOP
    cursor_name := DBMS_SQL.open_cursor;
    DBMS_SQL.parse (cursor_name, c_row.text, DBMS_SQL.native);
    DBMS_SQL.close_cursor (cursor_name);
    END LOOP;
    END;
    -- TRUNCATE ALL TABLES
    DECLARE
    CURSOR curs
    IS
    SELECT 'TRUNCATE TABLE "' || table_name || '"' text
    FROM SYS.user_tables
    WHERE partitioned = 'NO';
    c_row curs%ROWTYPE;
    cursor_name INTEGER;
    BEGIN
    FOR c_row IN curs
    LOOP
    cursor_name := DBMS_SQL.open_cursor;
    DBMS_SQL.parse (cursor_name, c_row.text, DBMS_SQL.native);
    DBMS_SQL.close_cursor (cursor_name);
    END LOOP;
    END;
    It works fine, but it's not the case for this one:
    -- DROP ALL SCHEMA OBJECTS
    DECLARE
    CURSOR curs
    IS
    SELECT 'DROP '
    || object_type
    || ' "'
    || object_name
    || '"'
    || DECODE (object_type, 'TABLE', ' CASCADE CONSTRAINTS PURGE', '')
    || ';' text
    FROM user_objects
    WHERE object_type NOT IN ('INDEX','TRIGGER');
    c_row curs%ROWTYPE;
    cursor_name INTEGER;
    BEGIN
    FOR c_row IN curs
    LOOP
    cursor_name := DBMS_SQL.open_cursor;
    DBMS_OUTPUT.put_line (c_row.text);
    --DBMS_SQL.parse (cursor_name, c_row.text, DBMS_SQL.native);
    DBMS_SQL.close_cursor (cursor_name);
    END LOOP;
    END;
    The DBMS Output gives me successfuly de set of commands like:
    DROP TABLE "T1" CASCADE CONSTRAINTS PURGE;
    DROP SEQUENCE "SEQ1";
    and so on...
    When I uncomment the DBMS_SQL.parse for this one... I receive the following error:
    ORA-00911: invalid character
    ORA-06512: at "SYS.DBMS_SYS_SQL", line 906
    ORA-06512: at "SYS.DBMS_SQL", line 39
    ORA-06512: at line 21
    I can't figure it out.... any ideas ?
    Thanks in advance
    Bruno Lavoie

    What I prefere for such a task is to use SQL*PLUS scripts.
    Select and Spool all the commands (DROP, ALTER, whatever) to some sql file. THen run this file.
    The advantage is that you can much better see which commands are actually executed.

  • Occasional ora-6502 using forms 6i and 10g

    Hi all.
    We have been experiencing some weird and unexpected ora-6502 errors in some of our forms 6i modules running against 10g (rel 1 or 2).
    Forms modules are correctly functioning and for some reason, one day an ora-6502 error suddenly pops up.
    Now the weirdest thing is that after you put some messages on the trigger, so you can track down where the error is coming from, it disappears.
    I know that this may sound hard to believe, but it has happened several times. All we do is put some message built in, recompile all, and the error is gone (for a while).
    So my questions are:
    - Is this a known issue beween forms 6i and 10g Db?.
    - Is there a patch on Metalink ( we use Forms [32 bits] Versión 6.0.8.26.0 (Producción))
    - A workaround?
    and most important
    - Have anyone been exposed to a similar situation?
    Regards, Luis ...!

    Now the weirdest thing is that after you put some messages on the trigger, so you can track down where the error is coming from, it disappears.Sounds like the form has not been "clean compiled" against the server on which it is running. Try a "Compile All", which causes all previously compiled program units to be compiled fresh.
    Or even better, clean out all the compiled code from your fmb before compiling the fmb on the server where it runs.
    See this topic:   Re: Why does this happen - find ';', replace with ';'?

  • ORA-03113 using Database Link

    Asking help Urgently..
    We need to create a DB link from 7.3 to 10g. After initial problems, the DB link is finally established and we can query and do DML on the 10g DB from 7.3. using SQLPLUS.
    Now the problem: We want to create triggers on tables in 7.3 DB to insert the same rows in 10g DB using the DB Link. The moment we create the trigger the connection is dropped with the error: ORA-03113: end-of-file on communication channel. We tried to write the insert statement inside a procedure/function but still the same problem.
    Please help as we are desperate to find a solution for the said problem. The objective is to be able to insert a row in 10g (DB Linked) Database based on a trigger fired in 7.3 Database (Reference DB). Any help will be appreciated.
    Thanks and regards.
    Rajeev.

    I know that 7.x to 10g is not supported officially and should not be used in production environment.
    But in our case, we need it for a short duration (duration of Parallel run) and my query is that, if I am able to do inserts from the SQLPLUS using the said DB Link, then why this cannot be done thru a procedure or a trigger.
    if anyone has an explanation or workaround, it will be great.
    Rajeev.

Maybe you are looking for