Run immediately!

Hello

Oracle version: 10.2

How to run more than 4000 characters in EXECUTE IMMEDIATE?


Can anyone please suggest me to go forward.

Rgds,
San.

Level to 11g that supports the CLOB to EXECUTE IMMEDIATELY, or use the DBMS_SQL package to run a query of clob...

for example

SQL> ed
Wrote file afiedt.buf

  1  declare
  2    v_large_sql  CLOB;
  3    v_num        NUMBER := 0;
  4    v_upperbound NUMBER;
  5    v_sql        DBMS_SQL.VARCHAR2S;
  6    v_cur        INTEGER;
  7    v_ret        NUMBER;
  8  begin
  9    -- Build a very large SQL statement in the CLOB
 10    LOOP
 11      IF v_num = 0 THEN
 12        v_large_sql := 'CREATE VIEW vw_tmp AS SELECT ''The number of this row is : '||to_char(v_num,'fm0999999')||''' as col1 FROM DUAL';
 13      ELSE
 14        v_large_sql := v_large_sql || ' UNION ALL SELECT ''The number of this row is : '||to_char(v_num,'fm0999999')||''' as col1 FROM DUAL';
 15      END IF;
 16      v_num := v_num + 1;
 17      EXIT WHEN DBMS_LOB.GETLENGTH(v_large_sql) > 40000 OR v_num > 800;
 18    END LOOP;
 19    DBMS_OUTPUT.PUT_LINE('Length:'||DBMS_LOB.GETLENGTH(v_large_sql));
 20    DBMS_OUTPUT.PUT_LINE('Num:'||v_num);
 21    --
 22    -- Now split that large SQL statement into chunks of 256 characters and put in VARCHAR2S array
 23    v_upperbound := CEIL(DBMS_LOB.GETLENGTH(v_large_sql)/256);
 24    FOR i IN 1..v_upperbound
 25    LOOP
 26      v_sql(i) := DBMS_LOB.SUBSTR(v_large_sql
 27                                 ,256 -- amount
 28                                 ,((i-1)*256)+1 -- offset
 29                                 );
 30    END LOOP;
 31    --
 32    -- Now parse and execute the SQL statement
 33    v_cur := DBMS_SQL.OPEN_CURSOR;
 34    DBMS_SQL.PARSE(v_cur, v_sql, 1, v_upperbound, FALSE, DBMS_SQL.NATIVE);
 35    v_ret := DBMS_SQL.EXECUTE(v_cur);
 36    DBMS_OUTPUT.PUT_LINE('View Created');
 37* end;
SQL> /
Length:40015
Num:548
View Created

PL/SQL procedure successfully completed.

SQL> select count(*) from vw_tmp;

  COUNT(*)
----------
       548

SQL> select * from vw_tmp where rownum <= 10;

COL1
-----------------------------------
The number of this row is : 0000000
The number of this row is : 0000001
The number of this row is : 0000002
The number of this row is : 0000003
The number of this row is : 0000004
The number of this row is : 0000005
The number of this row is : 0000006
The number of this row is : 0000007
The number of this row is : 0000008
The number of this row is : 0000009

10 rows selected.

SQL>

Tags: Database

Similar Questions

  • How can I create VI with inputs that run immediately when the update?

    I'm using LabView for controlling stepper motors. I would create a VI with a front panel that has 4 arrows, 2 per engine. My goal is to be able to run the VI and then press a button to move the engine.

    I created separate VI for each funcition of engines - one vi to set current operations, to determine the current travel, another to move up by a certain amount and so on. Work of these vi and I can move and adjust engines, but only by running separate VI.

    How can I combine them into a single VI and make them run to the pressure of a button or the change of a property? An example would be to establish a new current holding company and place the operation current vi run immediately and send the order to the engine. Then continue to press the arrow keys without having to hit 'run' on an another vi.

    Thank you very much


  • What is the purpose of USE in "run immediately".

    Hi all

    I just want to understand what is the purpose of USING in "EXECUTE IMMEDIATE".

    Say for example, the procedure below, what is the difference? Both will end up in the same result.

    DECLARE

    FIXED_STAT VARCHAR2 (4000);

    VAL_STAT VARCHAR2 (4): = "ijkl";

    BEGIN

    EXECUTE IMMEDIATE ' INSERT INTO abcd (efgh) VALUES (: text_string)' USING "ijkl";

    FIXED_STAT: = "INSERT INTO abcd (efgh) VALUES ('|)" VAL_STAT |') ' ;

    IMMEDIATELY RUN FIXED_STAT;

    END;

    /

    Two major assets to HELP to run immediately, i.e. using parameters

    (1) SQL statement should not hard analysed by the database every time [performance gain].

    (2) more important, to avoid the "SQL injection" and ensure that the variable data will be properly includes as part of the statement

  • run immediately fails with the error

    The following code generates the error and I can not understand what the problem is:

    SET SERVEROUTPUT ON;

    declare

    Val number (21);

    s_sql varchar2 (2000);

    Start

    s_sql: = q '{select last_number in the Vale of all_sequences where sequence_owner = 'SST' and sequence_name = "ADDRESS_SEQ"}';

    Dbms_output.put_line ('sql 1 ' | s_sql);

    run immediately s_sql;

    end;


    Error report:

    ORA-00905: lack of keyword

    ORA-06512: at line 7

    00905 00000 - 'lack the key word'

    * Cause:

    * Action:

    select last_number SQL 1 in val all_sequences where sequence_owner = 'SST' and sequence_name = "ADDRESS_SEQ."

    The error is strange since

    Select last_number in the all_sequences where sequence_owner = 'SST' and sequence_name = "ADDRESS_SEQ."

    is a valid instruction

    Although I see no need for SQL dynamic in this case, in general, you must provide the vatiable to receive the value of the select statement outside the immediate execution.  More like:

    s_sql: = q '{select last_number in the all_sequences where sequence_owner = 'SST' and sequence_name = "ADDRESS_SEQ"}';

    execute immediate s_sql in val

    John

  • procedure call to run immediately

    Hi Please help me call the procedure to run immediately.

    I am trying to execute the procedure for several tables.

    the same procedure on the SQL prompt works very well as shown below.

    EXECUTE PROC1 ('BC_COALMINE');

    Start

    for rec in (select table_name

    from all_tables

    where table_name like '% BC_.

    )

    loop

    run immediately 'execute proc1 (rec.table_name);

    end loop;

    end;

    I get an error invalid SQL ORA-900.

    concerning

    EXECUTE is a SQL Plus command. In PL/SQL, you can simply call the procedure. And you need not EXECUTE IMMEDIATE. You can make a static call to the procedure. Like this.

    Start

    for rec in (select table_name

    from all_tables

    where table_name like '% BC_.

    )

    loop

    PROC1 (Rec.table_name);

    end loop;

    end;

  • Run immediately in Oracle 10 g

    Hi, I have a small doubt regarding run immediately.

    According to my knowledge that we use run immediately to the writing of DDL(create,truncate,...) instructions to be executed in the procedure or function.

    But I saw in my organization, some of the senior people (already left organization) used to write the inserts, updates, deletes in will also run immediate even there is not much involved dynamic logic.

    But as per my knowledge run immediately can be misused by most pirates with SQL injection, I suppose!

    Is there some reason they use run immediately instead of writing code directly? Or is there an advantage in writing like this. ???

    Delivery immediate to create tables and another using DDL is fundamentally undesirable and should be avoided at all costs.
    Using run immediately you seem to exhibit, avoid too. Seniors were apparently not aware of the purpose of PL/SQL and the inconvenience of immediate execution.
    If I could vote to remove execute immediate PL/SQL, I would immediately in favour, especially in the packages, procedures and functions, as they are saved, which means pre-built.

    -----------
    Sybrand Bakker
    Senior Oracle DBA

  • ONE ERROR: run immediately (p_sql) return to p_id;

    Has written a simple procedure:

    procedure p_test)
    P_ID number,
    p_sql in varchar2
    *)*
    is
    Start
    run immediately (p_sql) return to p_id;
    end;

    Now, test it:

    declare
    P_ID number;
    p_sql varchar2 (2000): = ' insert into test1 (pk, str) values (1, "aaa")';
    Start
    pkg_utility.sp_save_without_blob (p_id, p_sql);
    dbms_output.put_line ('p_id' | p_id);
    end;


    The problem:
    Without the 'back in p_id' statement, the sql code can be run successfully. But with the "p_id return', an error occurred:

    ORA-20999: unexpected error when insert into test1 (pk, str) values (1, 'aaa')
    ORA-01006: there is no bind variable


    What I've done wrong? and how do I solve the problem?


    Thank you for helping.

    You're not saying 'what' you try to return.

    See the examples in the doc of PL/SQL
    http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28370/Collections.htm#BABHDGIG
    >
    Example 5-52, using the RETURN IN the Clause with a Record

    DECLARE
    RECORD IS of TYPE EmpRec (last_name, employees.last_name%TYPE,
    salary employees.salary%TYPE);
    method EmpRec;
    emp_id NUMBER: = 100;
    BEGIN
    UPDATE employees SET salary = salary * 1.1
    WHERE employee_id = emp_id
    RETURN last_name, salary INTO method;
    DBMS_OUTPUT. PUT_LINE
    ("Just give a stimulus to ' | emp_info.last_name |)
    ', which now makes | emp_info.salary);
    ROLLBACK;
    END;
    /

  • Oracle 11G copy a table to help to run immediately

    I want to copy the contents of a table in another aid to run immediately.

    It keeps fails with the following error

    ORA-00903: invalid table name
    ORA-06512: at "TABLE_COPY", line 6
    ORA-06512: at line 8 level



    create or replace
    procedure TABLE_COPY)
    Table1 varchar2,
    Varchar2 TABLE2)
    is
    Start
    run immediately 'insert'. TABLE2. "(select * from ' |) TABLE1 |') ' ;
    end;

    Published by: user9213000 on January 24, 2013 07:38

    user9213000 wrote:
    I want to copy the contents of a table in another aid to run immediately.

    It keeps fails with the following error

    ORA-00903: invalid table name
    ORA-06512: at "TABLE_COPY", line 6
    ORA-06512: at line 8 level

    create or replace
    procedure TABLE_COPY)
    Table1 varchar2,
    Varchar2 TABLE2)
    is
    Start
    run immediately 'insert'. TABLE2. "(select * from ' |) TABLE1 |') ' ;
    end;

    Published by: user9213000 on January 24, 2013 07:38

    Standard when boards (ab) use of EXECUTE IMMEDIATE is to compose the SQL statement in a single VARCHAR2 variable
    Then print the variable before passing to EXECUTE IMMEDIATE.
    COPY the statement & PASTE in sqlplus to validate its correctness.

  • How to replace run immediately in 11g?

    Hi, package and I need not not to use run immediately. There are a few plsql dynamic generation and sql stored in global lists. Any other possibility to execute without run immediately? TNX for help.

    Edited by: 982676 2013-01-18 01:11

    Dynamic code is dynamic. It must be run dynamically. And THIS should be the concern and not what dynamic execution interface is used.

    Regarding the interfaces to execute dynamic PL/SQL code:
    -immediate execution
    -ref Cursor
    -DBMS_SQL

  • How to pass a sequence of 'help' to run immediately

    How can I place a sequence.nxlval as a parameter using, here is my code looks like

    sql_string is-> insert into some_tab (col1, col2,...) (select col1: passed_seq,...) where the... (I want to insert values in sequence for col2)


    and I call it like


    passed_seq: = "seq_". some_dynamic_num |'. nextval' (in my PB will be sequences with the string formed as seq_10.nextval)

    EXECUTE IMMEDIATE sql_string using passes_seq;

    If I do like this I get

    Error: - 1722:ORA - 01722: invalid number seq_10.nextval

    Published by: DIVI on 8 January 2013 07:40

    >
    So is there another way to solve my problem, where queries are already formed and stored in a table in the form of data in the column, and I need to run those from different sequences in different scenarios.
    >
    Yes - you change applications to use a placeholder for the sequence you need (e.g. [SEQ_GOES_HERE]) when you need to run it you create a PL/SQL block into a VARCHAR2 variable, then use run immediately on the variable.

    If your stored query would look like this

    sql_string is -> insert into some_tab (col1,col2, ....) (select col1,[SEQ_GOES_HERE],......) where .... 
    

    Load the good seq.nextval in a variable, and then replace "[SEQ_GOES_HERE]" in the query with this value.

  • Scheduled task (dba_job) running immediately after starting

    Hello


    Clone of post a scheduled task (dba_job) runs immediately after startup. This task must be performed only in Production - not in the test environment.


    I know that we can stop the task to run using exec dbms_job.broken (42, TRUE), but to do this, I have to start the database.

    The job runs as soon as I start the database. This creates problems.


    Could someone help to prevent the execution of this work.


    Thank you
    Prasad Arava

    JOB_QUEUE_PROCESSES = 0

  • using where clause with value to hardcode in run immediately

    Dear Experts, I use below in the stored procedure make exception.

    RUN IMMEDIATELY "REMOVE CC. TB WHERE COL ='HG ";

    When the collar is varchar2 (30) DC. TB

    Please guide how to use above the statement in the stored procedure


    Thank you

    DBA wrote:
    Dear Experts, I use below in the stored procedure make exception.

    RUN IMMEDIATELY "REMOVE CC. TB WHERE COL ='HG ";

    When the collar is varchar2 (30) DC. TB

    Please guide how to use above the statement in the stored procedure

    Thank you

    Why you use dynamic SQL? DELETE statement is a DML statement and its valid inside a PL/SQL block.

    So, you can remove the immediate execution and write your DELETE statement directly.

    begin
      delete from cc.tb where col = 'HG';
    end;
    
  • Run immediately - please help

    Hello

    I have a requirement where I have to choose the number of records in each table (which meets specific criteria) in a variable and print it.
    I wrote the following piece of code which results in an error.

    Code:
    declare
    row_cnt number;
    v_query varchar2 (200);
    Start
    for x in (select table_name
    from all_tables
    where owner = ' EDI$ ".
    table_name order)
    loop
    v_query: = ' select count (*) in: Y of ' | x.table_name;
    dbms_output.put_line (x.table_name);
    dbms_output.put_line (v_query);
    execute immediate v_query using row_cnt;
    end loop;
    end;
    /


    Output:
    EDI_UFE
    Select count (*) in: Y de EDI_UFE
    ERROR on line 13:
    ORA-06550: line 13, column 14:
    PLS-00103: encountered the symbol "SELECT" at the expected in the following way:
    (- + new case mod not null < an ID >)


    Let me know if the code has a any error.

    Thanks in advance.

    declare
    row_cnt number;
    v_query varchar2 (200);
    Start
    for x in (select table_name
    from all_tables
    where owner = ' EDI$ ".
    table_name order)
    loop
    v_query: = ' select count (*) from ' | x.table_name;
    dbms_output.put_line (x.table_name);
    dbms_output.put_line (v_query);
    run immediately v_query in row_cnt;
    end loop;
    end;
    /

    Edited by: lifexisxnotxsoxbeautiful Vithalani March 4, 2011 04:36

  • ORA-01031: insufficient privileges on run immediately 'create a table... '. »

    Hello. I created a stored procedure that starts an immediate execution "create table..." Responses to Oracle with the message ' ORA-01031: insufficient privileges.

    I solved the problem adding 'authid current_user is' in the procedure declaration.

    Unfortunately, if I try to plan his by DBMS_JOB, responses to oracle with the same error again.

    Why? And how can I avoid it?

    Thank you very much in advance

    Published by: user4501018 on 6-mag-2010 4.00

    user4501018 wrote:

    Unfortunately, if I try to plan his by DBMS_JOB, responses to oracle with the same error again.

    Add:

    run immediately "role play all THE ';"

    before immediate 'create table..."

    SY.

  • run immediately and the set of query results

    Hi gurus,

    I want to create a series of paintings on the fly using run immediately.
    the table_names are stored in another table work_table.


    run immediately (select 'create table' | table_name |) '(id int)' of
    * (select table_name in work_tables)); *


    This will raise error.

    ORA-06550: line 1, column 18:
    PLS-00103: encountered the symbol "SELECT" at the expected in the following way:

    (en) - + new case mod not null < an ID >
    < between double quote delimited identifiers of > < a variable binding >


    instead of using a cursor to run one by one is the lines an alternative solution?

    Thank you very much
    Charles

    May not know why you want to do it in a single statement, anyway:

    SQL> select * from work_tables;
    
    TABLE_NAME
    ------------------------------
    x1
    x2
    
    SQL> declare
      2  str varchar2(32000);
      3  begin
      4    for r in (select table_name from work_tables) loop
      5      str := str || 'execute immediate ''create table ' || r.table_name || '( id int )''; ' ;
      6    end loop;
      7
      8    execute immediate 'begin '||str||' end;';
      9
     10  end;
     11  /
    
    PL/SQL procedure successfully completed.
    
    SQL> desc x1
     Name                                                        Null?    Type
     ----------------------------------------------------------- -------- ------------------------------
     ID                                                                   NUMBER(38)
    
    SQL> desc x2
     Name                                                        Null?    Type
     ----------------------------------------------------------- -------- ------------------------------
     ID                                                                   NUMBER(38)
    

    Max
    http://oracleitalia.WordPress.com

    Published by: Massimo Ruocchio, February 18, 2010 15:03

  • run immediately - stop running on "no data found".

    run immediately v_sql
    in v_georaster
    using p_prin_id;

    On an exception "no data found", execution seems to stop. No error is thrown. If I wrap an exception/begin/end block around I can catch the error.

    11 GR 1 material patch7

    What is this problem fixed in 11 GR 2?

    itsme1234 wrote:
    Select wma_test.insert_coin (double);

    If you call your function in a SQL statement. In this case, it throws an error like "0 rows returned" is a valid state for a SQL statement.

    If you want no_data_found to throw an error when it is called from a SQL statement, you must trigger a different error - user-defined would be best.

Maybe you are looking for