Dynamic insert statement

Hi all
I had problem in insert statement.
I know the column of the table, tablename and the value to be insert.
My code:
Data: column(20) type c.   -
>refer to the tablecolumn
Data: tablename(20) type c.  -
>refer to table name
Data: value(20) type c.          -
>value to be insert to the column in the table
column = 'Admino'.
tablename = 'Student'.
value = '123456'.
<b>insert <column> into <tablename> values <value>.</b>
i know there something wrong with my insert statement. How to do it in abap insert code where i can put in all the parameter in the insert statement.
Anycode or sample to show. Many thank.

From f1 help....
EXTRACT
Basic form
EXTRACT fg.
Effect
Writes all fields of the field group fg (FIELD-GROUPS) as an entry in asequential dataset. If you have defined a field group HEADER,its fields precede each entry as a sort key. Afterwards, you canuse SORT and LOOP ... ENDLOOP to sort or process the datasetrespectively. No further EXTRACT statements are possible afterthis.
Notes
General:
As soon as you have extracted a dataset using EXTRACT, you canno longer extend the field group using INSERT. In particular, you cannot change the HEADERfield group at all after the first EXTRACT (regardless of thefield group to which it applied).
Large extract datasets are not stored in main memory. Instead, theyare kept in an external auxiliary file. You can set the directory inwhich this file is created using the SAP profile parameterDIR_EXTRACT. The default directory is the SAP data directory(SAP profile parameter DIR_DATA).
Notes
Runtime errors:
EXTRACT_AFTER_SORT/LOOP: EXTRACT after SORT, orLOOP. EXTRACT_BUFFER_NO_ROLL: Unable to create the required main
EXTRACT_FIELD_TOO_LARGE: Occupied length of a field is toolarge.
EXTRACT_HEADER_NOT_UNIQUE: Field group HEADER wasmodified after an EXTRACT statement.
EXTRACT_OPEN_EXTRACTFILE_OPEN:
Error opening the external extract dataset file.
EXTRACT_RESOURCEHANDLER_FAILED: Error deleting the externalextract dataset file.
EXTRACT_TOO_LARGE: Total length of the entry for extraction(including HEADER fields) is too large.
Additional help
Filling anExtract with Data
Extracts
Since internal tables have fixed line structures, they are not suited to handle data sets with varying structures. Instead, you can use extract datasets for this purpose.
An extract is a sequential dataset in the memory area of the program. You can only address the entries in the dataset within a special loop. The index or key access permitted with internal tables is not allowed. You may only create one extract in any ABAP program. The size of an extract dataset is, in principle, unlimited. Extracts larger than 500KB are stored in operating system files. The practical size of an extract is up to 2GB, as long as there is enough space in the filesystem.
An extract dataset consists of a sequence of records of a pre-defined structure. However, the structure need not be identical for all records. In one extract dataset, you can store records of different length and structure one after the other. You need not create an individual dataset for each different structure you want to store. This fact reduces the maintenance effort considerably.
In contrast to internal tables, the system partly compresses extract datasets when storing them. This reduces the storage space required. In addition, you need not specify the structure of an extract dataset at the beginning of the program, but you can determine it dynamically during the flow of the program.
You can use control level processing with extracts just as you can with internal tables. The internal administration for extract datasets is optimized so that it is quicker to use an extract for control level processing than an internal table.
Procedure for creating an extract:
Define the record types that you want to use in your extract by declaring them as field groups. The structure is defined by including fields in each field group.
Defining an Extract
Fill the extract line by line by extracting the required data.
Filling an Extract with Data
Once you have filled the extract, you can sort it and process it in a loop. At this stage, you can no longer change the contents of the extract.
Processing Extracts
INSERT Statement
The INSERT statement is used to insert values into a single database table.
<insert statement> ::= INSERT INTO <table name> <insert column list> <insert source>.
<insert source> ::= VALUES '(' <value> ( ',' <value> )* ')'
| <query specification>.
<value> ::= <value expression>
| <dynamic parameter specification>
| NULL.
<insert column list> ::= '(' <column name> ( ',' <column name> )* ')'.
In Open SQL the <insert column list> is not optional.
You cannot specify string literals as values for CLOB columns. Hex literals are not supported in Open SQL.
Examples
INSERT INTO employees (employee_id, employee_name)
VALUES (4711, 'John Smith')
Inserting Values. A new row is inserted into the table employees with the values 4711 and 'John Smith' for the columns employee_id and employee_name respectively.
INSERT INTO well_paid_employees (employee_id, salary)
SELECT employee_id, salary
FROM employees
WHERE salary > ?
Inserting the Result of a Query. The employee_idand the salaryof all employees from table employeeswith a salary exceeding a certain value are inserted into the table well_paid_employees.
Please reward points if helpful.

Similar Messages

  • Help needed in forming dynamic insert statement

    HI,
    I am trying to construct a insert statement as given below.
    Please help me as to how to form this and where am i going wrong?
    i want the columns names to be auto populated when a table name is given.
    output should be like:
    ==============
    insert into tablename
    col1,col2,col3..coln)
    values
    (col1, col2, col3..coln);
    declare
    v_sql varchar2(5000);
    cnt number :=0;
    col_count number;
    name varchar2(5000); 
    TYPE string_assarrtype IS TABLE OF VARCHAR2 ( 25 ) INDEX BY VARCHAR2 ( 20 );
    arr string_assarrtype;
    BEGIN
       select count(column_name) into col_count from user_tab_columns
      where
      table_name = 'PS_D_RE_BCSREGIONMAPPING';
       v_sql:='insert into tablename (' ;
         for i  in 1..arr(col_count)
          loop
           v_sql:='v_sql' ||' '||arr(i);
          DBMS_OUTPUT.PUT_lINE(v_sql);
         END LOOP;
    END;

    Below is the actual code which i am trying to write:
    Since the below trigger logic is same for around 25/30 tables i wanted to construct a generic procedure which will take input parameter as tablename and auit_table and form the insert statement which will populate the column names which are different for different tables.
    Please guide...
    CREATE OR REPLACE PROCEDURE make_trigger(  tablename  in  VARCHAR2,
                                             auditable  in   VARCHAR2                                                                                  
    AS
    v_sql varchar(10000);
    begin
    v_sql := 'DROP TRIGGER  TRD_D_AUDIT_D'||tablename;
    dbms_output.put_line (v_sql );
    v_sql:='CREATE OR REPLACE TRIGGER TRG_D_AUDIT_D_'||tablename||' '||
    'BEFORE INSERT OR UPDATE OR DELETE ON 'tablename||' '||' REFERENCING OLD AS OLD NEW AS NEW
    FOR EACH ROW';
    dbms_output.put_line (v_sql );
    v_sql:= 'DISABLE
    DECLARE
    v_Operator        psoprdefn.oprid%type;
    v_Sysdate        Date;
    v_Actn            varchar2(1);
    V_AUDIT_RECNAME    PSRECDEFN.RECNAME%type;
    BEGIN';
    dbms_output.put_line (v_sql );
    v_sql:= 'If (Inserting) Then
       v_Actn    :='||'''||'A'||'''||';'||
       'Insert into '||auditable||'
                        ('||
                       AUDIT_RECNAME,
                    AUDIT_ACTN,
                    AUDIT_OPRID,
                    AUDIT_STAMP,
                    D_USER_GROUP,
                    D_GROUP_DESC,
                    D_BCS_ID,
                    D_UBR_ID,
                    D_FILTER_ID,
                    D_NAME_ACCESS_TYPE,
                    D_GLOBAL_EMP_LIST
                        Values
                    V_AUDIT_RECNAME,
                    v_Actn,
                    v_Operator,
                    v_Sysdate,
                    :NEW.D_USER_GROUP,
                    :NEW.D_GROUP_DESC,
                    :NEW.D_BCS_ID,
                    :NEW.D_UBR_ID,
                    :NEW.D_FILTER_ID,
                    :NEW.D_NAME_ACCESS_TYPE,
                    :NEW.D_GLOBAL_EMP_LIST
    end if;
    end;Edited by: user11942774 on Oct 5, 2012 11:46 AM
    Edited by: user11942774 on Oct 5, 2012 8:09 PM
    Edited by: user11942774 on Oct 5, 2012 8:10 PM

  • Looking for some help with building insert statements...

    Hi, I am using some sql to build some insert statements for me to update a set of tables in our qa environments. The scripts that I have created were working great until someone added a column to some of the tables in the qa env which in turn makes my scripts break because I was simply building the statment to do someting like this...
    insert into dest_table (select * from source_table@dblink);
    But now when the coumns in the tables do not match it breaks...
    This is the dynamic create script I use, can anyone help or suggest a better way to be able to build update statements update to qa tables when the columns are mismatched?
    spool insert.sql
    select
    'insert into ' || table_name || ' (select * from ' || table_name || '@prod );' || chr(10) || ' commit;'
    from user_tables
    where table_name in
    (select * from refresh_tablesl)
    any help is greatly appreciated,
    Thanks.

    See my reply to your duplicate post
    looking for help building dynamic insert statements...

  • Generate insert statement using columns from all_tab_cols view

    i am trying to generate a dynamic insert statement using the columns for a table from the all_tab_cols view. if i do a select, i get the output as rows. How do i convert the row out to columns so that i get something like this : INSERT INTO TABLE_NAME (COL1, COL2, COL3,COL4.....) .
    Any help will be appreciated!

    SQL> select * from my_test;
    no rows selected
    SQL> desc my_Test;
    Name                                      Null?    Type
    COL1                                               NUMBER
    COL2                                               NUMBER
    COL3                                               NUMBER
    SQL> declare
      2  cursor c1 is select column_name from all_tab_cols where table_name = 'MY_TEST';
      3  v_sql VARCHAR2(10000) := NULL;
      4  v_cnt NUMBER := 0;
      5  BEGIN
      6  FOR I in C1 LOOP
      7  v_cnt := v_cnt + 1;
      8  v_sql := 'INSERT INTO my_test('||I.column_name||') values('||v_cnt||')';
      9  EXECUTE IMMEDIATE v_sql;
    10  END LOOP;
    11  COMMIT;
    12  end;
    13  /
    PL/SQL procedure successfully completed.
    SQL> select * from my_Test;
          COL1       COL2       COL3
             1
                        2
                                   3
    SQL>

  • Dynamic IF statement in PL/SQL on-insert trigger in Forms 6.0

    I would like to build a dynamic IF statement for the on-insert trigger in a form... Users are restricted to which "projects" they are allowed to enter into the database. These restrictions are based on a security table. The same restrictions are used to build the dynamic where clause that limits which previously inserted records the users can see when they are in the form. Since the restrictions are identical, I want to use the same logic that I use to build a where clause to build a dynamic If statement instead... If the statement is true, the user can insert the record. If its false, they can't.
    I'm trying to this as follows:
    declare
    big_if varchar2(10000) :=' ';
    begin
    if :global.admin='YES'
    then
    insert_record;
    else
    declare
    cursor cur1 is
    select paren1, field, comparison_operator, value, paren2, and_or
    from rcdb.user_project_assign2
    where user_id = user;
    c1_rec cur1%ROWTYPE;
    begin
    for c1_rec in cur1 loop
    big_if:= big_if &#0124; &#0124; c1_rec.paren1 &#0124; &#0124; ':tbl_main_data.' &#0124; &#0124;c1_rec.field &#0124; &#0124;c1_rec.comparison_operator &#0124; &#0124; '''' &#0124; &#0124; c1_rec.value &#0124; &#0124; '''' &#0124; &#0124; c1_rec.paren2 &#0124; &#0124; ' '&#0124; &#0124; c1_rec.and_or &#0124; &#0124; ' ';
    end loop;
    end;
    if big_if
    then
    insert_record;
    else message('You are not allowed to insert this record');
    end if;
    end if;
    end;
    The problem is in the line
    IF big_if
    big_if is the variable that holds the text to my if statement (hense dynamic If statement) but I can't get the code to allow me to use that variable.
    Can anyone do this?
    null

    That code was great, but forms isn't allowing me to use the dbms_sql so I have to make a procedure out of forms and call it from the form. Both my form code and the procedure are compiling, but I"m still getting an error when the result is coming back to the form...
    the code in the form is:
    declare
    big_if varchar2(10000) :=' ';
    result varchar2(5) :=' ';
    check_state varchar2(2):=:tbl_main_data.state_abr;
    check_region varchar2(3):=:tbl_main_data.region_abr;
    check_program varchar2(25):=:tbl_main_data.program;
    begin
    if :global.admin='YES'
    then
    insert_record;
    else
    declare
    cursor cur1 is
    select paren1, field, comparison_operator, value, paren2, and_or
    from rcdb.user_project_assign2
    where user_id = user;
    c1_rec cur1%ROWTYPE;
    begin
    for c1_rec in cur1 loop
    big_if:= big_if &#0124; &#0124; c1_rec.paren1;
    if c1_rec.field = 'state_abr' then
    big_if:=big_if &#0124; &#0124; 'check_state' &#0124; &#0124;c1_rec.comparison_operator &#0124; &#0124; '''' &#0124; &#0124; c1_rec.value &#0124; &#0124; '''' &#0124; &#0124; c1_rec.paren2 &#0124; &#0124; ' '&#0124; &#0124; c1_rec.and_or &#0124; &#0124; ' ';
    elsif c1_rec.field = 'region_abr' then
    big_if:=big_if &#0124; &#0124; 'check_region' &#0124; &#0124;c1_rec.comparison_operator &#0124; &#0124; '''' &#0124; &#0124; c1_rec.value &#0124; &#0124; '''' &#0124; &#0124; c1_rec.paren2 &#0124; &#0124; ' '&#0124; &#0124; c1_rec.and_or &#0124; &#0124; ' ';
    elsif c1_rec.field = 'program' then
    big_if:=big_if &#0124; &#0124; 'check_program' &#0124; &#0124;c1_rec.comparison_operator &#0124; &#0124; '''' &#0124; &#0124; c1_rec.value &#0124; &#0124; '''' &#0124; &#0124; c1_rec.paren2 &#0124; &#0124; ' '&#0124; &#0124; c1_rec.and_or &#0124; &#0124; ' ';
    end if;
    end loop;
    end;
    message(big_if); pause;
    message(check_state); pause;
    message(check_region); pause;
    message(check_program); pause;
    rcdb.check_if(big_if,result,check_state,check_region,check_program);
    message('resulte = &#0124; &#0124;result&#0124; &#0124;');
    if result = 'TRUE' then insert_record;
    else
    message ('you cant enter');
    end if;
    end if;
    end;
    AND THE CODE IN THE PROCEDURE IS....
    create or replace procedure check_if (
    big_if in varchar2,
    result out varchar2,
    check_state in varchar2,
    check_region in varchar2,
    check_program in varchar2
    IS
    v_indx binary_integer := 0;
    v_sql_syntax varchar2(32767);
    root_cursor number;
    ignore integer;
    your_if_statement VARCHAR2(32767);
    v_check VARCHAR2(5);
    BEGIN
    your_if_statement := ' if '&#0124; &#0124;big_if&#0124; &#0124;' then :v_check := ''TRUE''; end if;';
    v_sql_syntax := 'begin '&#0124; &#0124;your_if_statement&#0124; &#0124;' end;';
    root_cursor := dbms_sql.open_cursor;
    v_sql_syntax := replace(replace(REPLACE(v_sql_syntax,chr(10),' '),chr(13),' '),chr(9),' ');
    dbms_sql.parse(root_cursor,v_sql_syntax,dbms_sql.v7);
    dbms_sql.bind_variable( root_cursor, ':v_check',v_check,5);
    ignore := dbms_sql.execute(root_cursor);
    dbms_sql.variable_value(root_cursor, ':v_check', v_check);
    if v_check = 'TRUE' then result:='TRUE';
    else
    result:='FALSE';
    end if;
    dbms_sql.close_cursor(root_cursor);
    END check_if;
    DO YOU KNOW WHATS WRONG?

  • Preparing Dynamic SQL statement for inserting in Pro*C

    Hi Friends,
    From quite some time i am struggling writing Dynamic SQL statement for dynamic insert and update in Pro*C.
    Can somebody go through my code and suggest me the rigth way of doing.
    Right now it throws an error saying " Error while updating ORA-00904: invalid column name "
    Please help me.
    Girish.
    int main()
    EXEC SQL BEGIN DECLARE SECTION;
    char *uid ="scott/tiger";
    static char sqlstmt[129];
    struct /* DEPT record */
    int dept_num;
    char dept_name[15];
    char location[14];
    } dept_rec;
    EXEC SQL END DECLARE SECTION;
    EXEC SQL WHENEVER SQLERROR DO sql_error();
    EXEC SQL CONNECT :uid;
    dept_rec.dept_num = 50;
    strcpy(dept_rec.dept_name,"ADMIN");
    strcpy(dept_rec.location,"IN");
    strcpy(sqlstmt,"UPDATE dept set DNAME = dept_rec.dept_name where DEPTNO = dept_rec.dept_num");
    EXEC SQL EXECUTE IMMEDIATE:sqlstmt;
    EXEC SQL COMMIT;
    exit(0);
    void sql_error()
    printf("\nError while updating %s",sqlca.sqlerrm.sqlerrmc);
    EXEC SQL ROLLBACK;
    }

    A bit rusty here but this is how I see it.
    Think of it this way ..
    all Oracle is going to see is:
    UPDATE dept set DNAME = dept_rec.dept_name where DEPTNO = dept_rec.dept_num
    Its NOT going to know what dept_rec.dept_name is or dept_rec.dept_num is ..
    it doesnt go back and fill in those values.
    You need something like
    strcpy(sqlstmt,"UPDATE dept set DNAME = \"");
    strcat(sqlstmt,dept_rec.dept_name);
    strcat(sqlstmt,"\" where DEPTNO = ");
    strcat(sqlstmt,dept_rec.dept_num);
    printf(sqlsmt); # Just to be sure the update statement look right during testing.

  • Dynamic INSERT from associative array

    Ok, this would be an one-liner in python or perl, but as a newbie in PL/SQL, it feels like swimming in molasses. So before going on and reinvent the wheel, is there any builtin or sample code that generates dynamically an insert statement from a hashtable ? That is, given a table:
    hashtable = {
    'name' : 'Michael',
    'age' : 23,
    'income' : 67213.34
    and a table_name ('Employee'), generate the query
    INSERT INTO Employee (name,age,income) VALUES ('Michael', 23, 67213.34);
    Thanks,
    George

    user603743 wrote:
    @sb92075
    Well, we have been in product development for past dozen years. In my humble opinion, we know a thing are two about product design. But thanks for your inputs though.
    Obviously you are not doing so well with this "design"... Just sayin'... :) :)
    You seems to be expert in the application/product design. Have you ever heard of "user data mashup" concept in data warehousing? Just curious.
    "user mashup" would indicate that the user actually controls how this is done. You, as a "product" will be making some [potentially very bad] assumptions about the end-user data that cannot be accounted for in a "canned" product. You can influence how it is done, but, in the end, does it meet the exact business needs of the end-user.
    you could possibly use some PL/SQL packages to
    1) get all of the tables
    2) get all of the columns.
    3) do the mashup.
    Now a question. Let's say table1 and table3 have (col1 + col2) that are the same and column3 is different. What do you put in column3?? or is this another row.
    Edited by: user603743 on May 29, 2013 4:52 PM

  • Dynamic insertion of MIME object into a web dynpro component

    Hi,
    I want to dynamically insert a MIME object of type JPEG or type GIF into my web dynpro component at runtime.
    I was unable to find the database table which contains the list of MIME objects for a particular web dynpro component.
    Can you please help me out with this?
    Thanks in advance,
    Adithya
    Moderator message: wrong forum, please have a look in the "Web Dynpro ABAP" forum.
    Edited by: Thomas Zloch on May 23, 2011 9:55 AM

    Hi Muzammil Bichoo ,
                                   when you copy the wda component, it will be copied and will be in active state, once all the components are activated means, windows, views, everything will be available.
    now create application for your component, if you have more than one window(interface view) select the one which you need for the application.
    Regards
    Sarath

  • Dynamic insert for Special Characters

    Hello,
    I'm running into a problem inserting data with Special Characters. I have a report (designed oracle reports), that takes data and inserts the data into table. I use the SRW.do_sql built in package in a before report trigger to process the data. However the problem that I'm running into is how to dynamically account for the special characters in a description field that I have. There is no way for me to predict where or how many can appear in a field. For example, I may have a field that contains data like:
    O'REILLY AND ASSOCIATES INC.
    OR
    FULLER & D'ALBERT, INC.
    OR
    JOANNE'S BED & BACK SHOP
    The only special characters that seem to be used and are causing me problems are the " ' " and " & ".
    Does anyone know how I can dynamically account for these special characters in my insert statement?
    Thanks,
    Martin

    Hello,
    I'm using SRW.DO_SQL procedure in oracle reports because that is one you can run text via reports. The report actually exports the results to a text file and insert the results into a table. Anyway, the SRW.DO_SQL isn't my problem but rather the special characters. I have researched the problem some more and I have found a solution. You can use the "replace" feature to do an insert/update of special characters. You also need to find the character number for each special character. I believe "&" is chr(38), "%" is chr(37), "#" is chr(35), "@" is chr(64), "'" is char(39). So the code would be:
    insert into tableA (column1) values(
    replace(replace(replace(replace(replace(v_entity_name,chr(39),chr(39)),chr(38),chr(38)),chr(35),chr(35)),chr(37),chr(37)),chr(64),chr(64));
    Martin

  • Nds Insert statement little problem

    DB version XE 10g
    Hello
    I have little problem with my insert statement.
    In my code, are many examples, but plz focus on V2 and V3 part.
    As you can see V2 and V3 are not working
    I get following errors
    V2
    Error report:
    ORA-00984: column not allowed here
    ORA-06512: AT line 28
    00984. 00000 - "column not allowed here"
    V3
    Error report:
    ORA-00917: missing comma
    ORA-06512: AT line 33
    00917. 00000 - "missing comma"
    I really have no idea, why i'm getting these errors...
    DROP TABLE FILMYARNOLD;
    CREATE TABLE FILMYARNOLD
        FIL_ID VARCHAR2 (329),
        FIL_NAME VARCHAR2 (592),
        FIL_YEAR VARCHAR2 (294),
        FIL_ACTOR VARCHAR2 (392),
        FIL_TEXTT VARCHAR2 (2596)
    SET SERVEROUTPUT ON
    DECLARE
      TYPE FIL_TABLE IS TABLE OF VARCHAR2 (256);
      vfilmiczki FIL_TABLE := fil_table();
      statement VARCHAR2 (2048);
    BEGIN
    vfilmiczki.EXTEND;
    vfilmiczki(1) := '77804';
    vfilmiczki.EXTEND;
    vfilmiczki(2) := 'Predator';
    vfilmiczki.EXTEND;
    vfilmiczki(3) := '1984';
    vfilmiczki.EXTEND;
    vfilmiczki(4) := 'Arnold';
    vfilmiczki.EXTEND;
    vfilmiczki(5) := 'get to the choppa';
    /*statement := 'INSERT INTO FILMYARNOLD (FIL_ID, FIL_NAME, FIL_YEAR, FIL_ACTOR, FIL_TEXTT) VALUES ( ';
    statement := statement|| '''chlip'',''lol'',''lol'',''chlip''';--
    statement := statement||',''hmm'')';*/
    -------V1------------working-----------------
    --statement := 'INSERT INTO FILMYARNOLD (FIL_ID) VALUES ( ';
    --statement := statement||vfilmiczki(1)||' )';
    --EXECUTE IMMEDIATE statement;
    --------V2-------------------- not working -----------------------------------------
    --statement := 'INSERT INTO FILMYARNOLD (FIL_ID, FIL_NAME) VALUES ( ';
    --statement := statement||vfilmiczki(1)||','||vfilmiczki(2)||' )';
    --EXECUTE IMMEDIATE statement;
    ----V3------------ not working ------------
    statement := 'INSERT INTO FILMYARNOLD (FIL_ID, FIL_NAME, FIL_YEAR, FIL_ACTOR, FIL_TEXTT) VALUES ( ';
    statement := statement||vfilmiczki(1)||','||vfilmiczki(2)||','||vfilmiczki(3)||','||vfilmiczki(4)||','||vfilmiczki(5)||' )';
    EXECUTE IMMEDIATE statement;
    /* statement := 'INSERT INTO FILMYARNOLD VALUES (:jeden, :dwa, :trzy, :cztery, :piec)';
    EXECUTE IMMEDIATE statement
      USING vfilmiczki(1)
      ,     vfilmiczki(2)
      ,     vfilmiczki(3)
      ,     vfilmiczki(4)
      ,     vfilmiczki(5); */
      statement := 'INSERT INTO FILMYARNOLD VALUES ('; --(:jeden, :dwa, :trzy, :cztery, :piec)';
        FOR i IN 1..vfilmiczki.COUNT
        LOOP
            IF i = vfilmiczki.LAST THEN
                statement := statement||vfilmiczki(i)||' )';
            ELSE
            statement := statement||vfilmiczki(i)||', ';
          END IF;
            --DBMS_OUTPUT.PUT_LINE (vfilmiczki(i));
        END LOOP;
        EXECUTE IMMEDIATE statement;
        --INSERT INTO FILMYARNOLD
        --VALUES (vfilmiczki(vfilmiczki.FIRST),vfilmiczki(2),vfilmiczki(3),
                --vfilmiczki(4), vfilmiczki(5));
        --DBMS_OUTPUT.PUT_LINE ('*****************');
        --DBMS_OUTPUT.PUT_LINE (vfilmiczki((vfilmiczki.LAST)));
    END;
    /Im waiting for your replys
    greetings

    Hi,
    change V2 to:
    STATEMENT := 'INSERT INTO FILMYARNOLD (FIL_ID, FIL_NAME) VALUES ( ';
    STATEMENT := STATEMENT||VFILMICZKI(1)||','''||VFILMICZKI(2)||''' )';
    EXECUTE IMMEDIATE statement;and V3 to:
    ----V3------------ not working ------------
    STATEMENT := 'INSERT INTO FILMYARNOLD (FIL_ID, FIL_NAME, FIL_YEAR, FIL_ACTOR, FIL_TEXTT) VALUES ( ';
    STATEMENT := STATEMENT||VFILMICZKI(1)||','''||VFILMICZKI(2)||''','||VFILMICZKI(3)
                 ||','''||VFILMICZKI(4)||''','''||VFILMICZKI(5)||''' )';
    EXECUTE IMMEDIATE statement;EXECUTE IMMEDIATE statement;One general remark: INSERT can be used directly in PL/SQL, you don't need to bother with dynamic SQL,
    and the direct SQL will be probably more efficient than dynamic SQL.
    Try this:
    SET SERVEROUTPUT ON
    DECLARE
      TYPE FIL_TABLE IS TABLE OF VARCHAR2 (256);
      vfilmiczki FIL_TABLE := fil_table();
      statement VARCHAR2 (2048);
    BEGIN
    vfilmiczki.EXTEND;
    vfilmiczki(1) := '77804';
    vfilmiczki.EXTEND;
    vfilmiczki(2) := 'Predator';
    vfilmiczki.EXTEND;
    vfilmiczki(3) := '1984';
    vfilmiczki.EXTEND;
    vfilmiczki(4) := 'Arnold';
    vfilmiczki.EXTEND;
    vfilmiczki(5) := 'get to the choppa';
    -------V1------------working-----------------
    INSERT INTO  FILMYARNOLD (FIL_ID) VALUES ( VFILMICZKI(1) );
    --------V2-------------------- not working -----------------------------------------
    INSERT INTO FILMYARNOLD (FIL_ID, FIL_NAME) VALUES ( VFILMICZKI(1),VFILMICZKI(2));
    ----V3------------ not working ------------
    INSERT INTO FILMYARNOLD (FIL_ID, FIL_NAME, FIL_YEAR, FIL_ACTOR, FIL_TEXTT)
    VALUES ( VFILMICZKI(1), VFILMICZKI(2), VFILMICZKI(3), VFILMICZKI(4), VFILMICZKI(5));
    END;
    /

  • Quotes in insert statement

    Hi all,
    I have a Insert statement as follows.
    insert into mytable(description)
    values('Spoon 'n Fork');
    In order to have the single quote before the n, I can frame the sentence as follows,
    insert into mytable(description)
    values('Spoon ''n Fork');
    But if the same comes in a sql script there many rows will have single quote as 'n.
    How can I fix this?
    any ideas
    thanks
    asp

    Hi,
    sorry..i actually misunderstood the requirement... its like follows..
    I have a flat file coming generated from system with column values:
    Description1     Description2     Description3     Description4     Description5
    prasanth     baby'sdayout     prime minister     dad's book     my work          
    world's clock     president     computer     printer's     laptop
    alphabets     party's          spoon 'n foke     icecream's     etcThe above flat file is dynamic which
    will have some times 100 rows sometimes 1000 rows.
    I should write a insert build procure that should work such a way that
    it should check all columns values in each to find ' (single quote) and if present then it should build insert statement accordingly.. i.e incude '' so that single quote will be inserted.
    Here the tricky thing is that in 1st row '(single quote) present in 2nd column (baby'sdayout) and 3rd column 4th(dad'sbook) so my prgoram should build insert statement like
    insert into mytable(description1,description2,description3,description4,description5)
    values('prasanth','baby''sdayout','prime minister','dad''sbook','my work');
    So here tricky is i really dont know which column value has ' (quote) with in it and i should find out build insert accordingly..
    if you see second row above then '(quote) came in Description1 and Description 4 so, insert statement should only place that '' in those column alone..
    any ideas how to achieve this
    thanks
    asp
    Edited by: Onenessboy on Aug 1, 2011 8:03 AM

  • Reduce time consumption of a bulk insert statement

    Hi All,
    I am trying to insert some large amount of data records into a Global Temporary Table (GTT) using a query like below. Below SQL statement is generated as a string and executed as a dynamic sql statement.
    INSERT INTO
    my_table ( col1, col2, col3, col4)
    SELECT c1, c2, c3, c4
    FROM tab1 t1,
    tab2 t2,
    tab3 t3
    WHERE <<dynamically generated where clause>>
    UNION ALL
    SELECT c1, c2, c3, c4
    FROM tab4 t4,
    tab5 t5,
    tab6 t6
    WHERE <<dynamically generated where clause>>
    UNION ALL
    SELECT c1, c2, c3, c4
    FROM tab4 t4,
    tab5 t5,
    tab6 t6
    WHERE <<dynamically generated where clause>>
    UNION ALL
    SELECT c1, c2, c3, c4
    FROM tab4 t4,
    tab5 t5,
    tab6 t6
    WHERE <<dynamically generated where clause>>
    The problem is, it takes some considerable amount of time(25-30 seconds) to write the resulted data set into GTT(my_table ). I have checked the SELECT statement above (without the INSERT), and it gives the result set in few seconds. Therefore i assume it's the INSERT that takes more time. (SELECT statement returns around 75000+ records). The GTT consists of 8 columns and 6 out of those are marked as a primary key.
    Are there any other mechanisms that I can use to efficiently insert large amount of data in to the table? Really appreciate all of your comments and suggestions.
    Best Regards,
    Nipuna

    Hi,
    I'm not sure about your query speed :) Don't have it against me, but sometimes users just run SELECT statement and waits unitl first rows are returned (e.g. using TOAD which fetches 500 first rows as default) and they are convinced that this is response time for whole set. You have to navigate to last record to see real response time. But probably this is not the casse here. When you insert a large set of data consider to move such statement from forms to database (you avoid data roundtrip between forms and DB). If your insert still takes to much time then try to trace session you run your statement and(if possible) try to monitor your database resource ussge. If you're not able to use dbms_trace then you can just lokk at the system v$Session views. Following two views can be helpful to investigate most time consuming waits and can help understand the reason of slowness.
    select * from v$session_wait
    select * from v$session_wait_history

  • Getting result of dynamic select statement into variable

    I have a function that builds a dynamic sql statement. I then want to take the result of that statement and insert it into a variable. I have tried this
    execute immediate strSQL USING OUT intCounter;but that is giving me an error on that line of code. The SQL is a select count(*) and works fine. It is just how to get it into the variable that is tripping me up.
    Thanks,
    Eva

    Sure. Version 11g. The complete procedure reads as follows:
    CREATE OR REPLACE FUNCTION VALIDATIONQUESTIONRESULT
        p_ShortName VARCHAR2,
        p_SiteID    VARCHAR2
    RETURN NUMBER IS
        strSQL VARCHAR2(5000);
        strTableName VARCHAR2(200);
        strPatIDFieldName VARCHAR2(200);
        intCounter NUMBER;
    BEGIN
        select VALIDATIONSQL into strSQL from vwvalidationquestions where upper(shortname) = upper(p_ShortName);
        select
                case UPPER(DBTABLENAME)
                    when 'CPTICODES' then 'CPTIPATID'
                    when 'CPTIICODES' then 'CPTIIPATID'
                    when 'DEMOGRAPHICS' then 'PATID'
                    when 'FAMILYHISTORY' then 'FHPATID'
                    when 'GCODES' then 'GCODEPATID'
                    when 'HOSPITALIZATION' then 'HPATID'
                    when 'MEDICALHISTORY' then 'MHPATID'
                    when 'MEDICATIONS' then 'MPATID'
                    when 'PROCEDURES' then 'PPATID'
                    when 'VISITS' then 'VPATID' end into strPatIDFieldName
        from DATASPECIFICATIONS where UPPER(SHORTNAME) = UPPER(p_ShortName);
        strSQL := strSQL||' and '||strPatIDFieldName||' in (select PATID from DEMOGRAPHICS where PARTICID = '||p_SiteID||');';
        execute immediate strSQL into intCounter;
        return intCounter;
    END VALIDATIONQUESTIONRESULT; strSQL when checked builds perfectly. I get 100% what I expect from it. An example of what I am getting from strSQL is:
    select count(*) from Procedures where TO_CHAR(ProcdDt, 'MM') = TO_CHAR(ADD_MONTHS(SYSDATE, -1), 'MM') and TO_CHAR(ProcdDt, 'YYYY') = TO_CHAR(ADD_MONTHS(SYSDATE, -12), 'YYYY') and PPATID in (select PATID from DEMOGRAPHICS where PARTICID = 12);I am getting the number I would expect from this. I just need to put that number into intCounter. I tried altering strSQL so it looked like this:
    select count(*) into intCounter from Procedures where TO_CHAR(ProcdDt, 'MM') = TO_CHAR(ADD_MONTHS(SYSDATE, -1), 'MM') and TO_CHAR(ProcdDt, 'YYYY') = TO_CHAR(ADD_MONTHS(SYSDATE, -12), 'YYYY') and PPATID in (select PATID from DEMOGRAPHICS where PARTICID = 12);but that gave me an error on the execute immediate line as well.
    Sorry, I thought it would be simple so that was why I only put that bit of info. I guess it is more complicated than it at first appeared!
    Eva

  • No insert Statements for EKKO EKPO in ST05 sql trace for transaction me21n

    No insert Statements for EKKO EKPO in ST05 sql trace for transaction me21n.
    IN ST05 I set a filter for ME21N and executed transaction to create a Purchase Order and then checked
    ST05 but there is  NO insert for EKKO or EKPO??
    How Do I find in which columns of EKKO and EKPO data is inserted in ST05?
    Edited by: DeepakNandikanti on Apr 28, 2010 8:27 AM

    Hi,
    I tried in my system and I can see INSERT statement on EKKO and EKPO tables. What exactly you are looking for? Some one else might have switched on the trace at the same time. Can you try again and see.
    ST05=>Switch on trace
    ME21N=>Create PO.
    ST05=>Switch off and display trace.
    In trace list search for EKKO and EKPO.
    Column names are not shown in the trace list. It is the SQL trace and column list is generated dynamically like :A0, :A1....
    @ Suhas,
    That might be because the tables are updated via BAPIs ... Do you think SAP uses direct update statements on the DB tables ??
    I didn't get above statement. Is there any other way of updation that happens when using BAPI? I believe that, even in case of BAPI there will be update task FMs called during database update. Please correct if i got it wrong.
    Thanks,
    Vinod.

  • How to prepare an INSERT statement from the resultset

    Hi Friends ,
    I have to generate CREATE and INSERT statements for the Table already present in the database .
    I can prepare CREATE statement by getting the MetaData from the database . Is it possible to create INSERT statement for the data already present in the database table if so how.
    Thanks ,
    Rajesh Reddy

    You should be able to do something like SELECT * FROM foo WHERE 1 = 2. No rows will be returned. Call ResultSet#getMetaData() to get the meta data for the column names and types. You should then be able to dynamically create your own INSERT statement.
    - Saish

Maybe you are looking for