Insert the dynamic creation of statements

Hello

My version of db is: 11g Enterprise edition 11.2.0.3.0

I am trying to create queries dynamically insert using the code below:

declare

v_cl varchar2 (4000);

v_tn1 varchar2 (30): = 'T1 ';

v_tn2 varchar2 (30): = 'T2 ';

v_vl varchar2 (4000);

v_id number 4: = 900;

v_il varchar2 (4000);

v_count number (3): = 1;

cursor c1 is select column_name from all_tab_columns where table_name = v_tn1 order of column_id.

cursor c2 is select column_name user_tab_columns where table_name = v_tn2;

Start

I'm looping c1

v_cl: = v_cl | «, » || i.column_name;

end loop;

v_cl: = ltrim (v_cl, ',');

v_il: = ' insert into ' |. ' v_tn1 | ' ('| v_cl |') values (';)

for j in loop c2

v_vl: = v_vl | Chr (10) | v_id | «, » || v_count | «, » || j.column_name |') ' ;

v_count: = v_count + 1;

v_il: = v_il | v_vl;

end loop;

dbms_output.put_line (v_il);

end;

The problem is with this v_il statement: = v_il | v_vl

The desired output is to get

insert into tn1 values (...)

insert into tn1 values (...)

.

.

But I'm getting

insert into values tn1 (insert values (...) tn1)

How to change the code above to get the desired result.

Also, I'm getting ORA-06502: PL/SQL: digital or value error: character string buffer too small when I run dbms_out.put_line

Please advice.

I did a minor change, and it seems to work now.

What I did:

Declared all the variable as a CLOB

And modified

v_vl: = v_vl | Chr (10) | v_il | v_id | «, » || v_count | «, »...

v_count: = v_count + 1;

end loop;

dbms_output.put_line (v_vl);

The above change worked. Thank you.

Tags: Database

Similar Questions

  • Hi friends this is the code for the dynamic creation of user in plsql, but these statements are not run if pls help for this error

    DECLARE

    n NUMBER.

    BEGIN

    n: = 1;

    WHILE (n < = 10)

    LOOP

    CREATE a user EM | IDENTIFIED BY KLU n;

    SESSION CREATION GRANT, GRANT ANY PRIVILEGE TO EM. n;

    COMMIT;

    n: = n + 1;

    END LOOP;

    END;

    Hello

    Here is the dynamic creation of user query and giving grants to the user,.

    DECLARE

    n NUMBER.

    cr_user VARCHAR2 (300);

    gr_user VARCHAR2 (300);

    BEGIN

    n: = 1;

    While (n<=>

    LOOP

    cr_user: = 'CREATE user EM | n | "IDENTIFIED BY KLU";

    gr_user: = "GRANT CREATE SESSION, GRANT ANY PRIVILEGE to EM '. n | '';

    EXECUTE IMMEDIATE cr_user;

    EXECUTE IMMEDIATE gr_user;

    n: = n + 1;

    END LOOP;

    END;

    Edited: Removed when OTHER exceptions to Code.

    See you soon!

  • JavaScript to insert the dynamic buffer

    In the PDF form, Java script for a dynamic insertion stamp 'Received' or 'Approved' as well as of the author by default, date etc...

    I created a PDF form button, when the button is clicked, the "Receipt" dynamic annotation stamp stamp to insert in the particular position. Please, let me know the java script for this action.

    Make sure that you select a comment from stamp applied (using the mouse) before you run this code.

  • Insert the select statement result in CLOB

    Hi, I would like to insert the result of a statement select into a CLOB with a trigger.

    Whevner a number is registered my research to trigger how often the number is used in several objects and now my problem I also would like to know the record ID where the number is used.

    SELECT 'ITEXT '.
    OF 'CHECK_INR '.
    WHERE 'USE' > 1

    This select records of results 2 How can I insert the result into a CLOB with my trigger?

    Thanks in advance

    Steven,

    It's really a question better suited for another forum because it is not really associated with ApEx. Also, something tells me that you really want to do an UPDATE not an insert. However, here's a quick example...

    DECLARE
    
       l_orders VARCHAR2(4000);
    
    BEGIN
    
       FOR x IN (
          SELECT *
          FROM my_orders_table
       )
       LOOP
          l_orders := l_orders || ', ' || x.order_data_column;
       END LOOP;
    
       l_orders := l_trim(l_orders, ', ');
    
       UPDATE some_table
       SET some_column = l_orders
       WHERE id = some_id;
    
    END;
    

    That's the key. Use VARCHAR2 unless you need CLOB.

    Kind regards
    Dan

    http://danielmcghan.us
    http://sourceforge.NET/projects/tapigen

  • Time of design and of the dynamically created controls

    I have a project written in VC6 as a project of the MFC dialog box. In a particular area, I dynamically create several (the exact number depends on user input) CNiGraphs. There is also a two CNiButtons that were created at design time using the resource editor. The problem I have is that when this dialog box is open, a message appears saying it is an eval version and the control will go off after 5 minutes. After 5 minutes of waiting, the CNiButtons 2 go inactive (black tower), but the continuous CNiGraphs of work. I have a valid license of MStudio 8.1.6, version but it seems that these 2 buttons do not recognize the license. There are also other buttons from the moment of conception of the project, but these have no problem at all. When you create the dynamic creation of the CNiGraphs, give them a valid license string, and I was wondering if there is a problem with the time created and dynamically controls created in the same dialog box to design. Anyone know?

    I don't remember, but I can have created these 2 CNiButtons when I was with only an eval license. (All others were undoubtedly create when I got a full license) Could have an impact on them? I have a vague memory of reading somewhere that DTC create controls to check the license when they are created in the designer and store that info in them license. If this is the case does anyone know an easy way to update the license stored in control? I rather not just delete it and Add again because I would avoid having to redo the tab order (unless someone knows how to easily insert something in the middle of the order of tab instead of having to click through all the controls in the correct order)?

    In addition, I don't know if this would affect anything, but the project was originally built with ComponentWorks 1.0, we were forced to move to MStudio when we met a few bugs in CW, so all controls were originally CW controls which have been converted into control of CNi. I doubt that this is so like everywhere else, we changed during controls is not a problem, but I'm ready to try the suggestions.

    Hi JC,.

    I hope you had a good weekend!  I'm glad to hear that you're back running.  Add the extra button was, in fact, causing update the licensing information for the other buttons, as you can imagine.  After further research, I found that the license information are stored only the form of the control, and if this control doesn't change in any way (or in your case, adding a new project), he sees no reason when compiling to recreate a link to the license.  However, after the change of control and a new, it updates the link between the license information, which solved this problem in your case.

    I hope this helps, JC.  Have a great day!

  • Is it possible to use the dynamic link twice? (from creation to AE)

    I made my edit in Premiere Pro (SC6). During my work I had to use the dynamic effects as a stabilizer of the chain link. Now, I'm finished with the work on the creation and would like to redo the calibration color effects. But now, when I import the entire Premiere Pro project in AE, all videos I have already related before, don't work/game more in AE. I also tried to use dynamic linking again rather than the import option. But it's the same problem.

    Is there a workflow to publish excerpts from the first sequence in after effects by dynamic links, and then when I got there also change the whole first sequence in After Effects?

    Maybe I should do in a sense the next time? What would you suggest to do in this case?

    Thank you

    Philippe

    You cannot create cyclic connections. The clips using DL already should be rendered correctly before being able to use the DL on the entire sequence.

    Mylenium

  • Cannot perform the insert/update on the form of tables, due to the dynamic action

    Hi all

    I created a dynamic action that calculates multiple cells in a table.

    This feature works well, when I change the value of the associated cell then the computed value is changed by the dynamic action.

    But I am not able to insert or update the line in a table when the dynamic action is enabled. When I put the condition 'Never', then the line is inserted or updated without any problems.

    All guess where is the problem?

    Apex version: 4.1.1.00.23

    Jiri

    Nina wrote:

    I don't know why the 123,40 value (or other) is set to the next item in line (f09, fsc, etc.)
    >

    What is hidden and generated Apex elements are always included in the last cell (td) of the line. Thus, it has nothing to do with the next item, only the last cell.
    If you see the last cell of the 888 Page you will see probably the same type = "hidden" entries here also.

    Your problem is not related to the HTML fragment to the last cell in the row showing all those extra items, it's somewhere else.

    Oh, here comes the jQuery selector:

    var clickedRow = $(this.triggeringElement).closest('tr');
    
    $(clickedRow).children('td[headers="SAL"]').find("input").val(myCalculatedTotal);
    

    SAL, COMM, w/e. here you will find the TD with headers = "COMM" and all the input fields and the value of all the entries in total calculated. Your selection is not precise enough in this case.
    So, target the specific entry.
    With the code example:

    
    
    
    
    
    
    
    
    

    change the switch on

    $(clickedRow).children('td[headers="SAL"]').find('input[name="f08"]').val(myCalculatedTotal);
    
  • Insert the statement Question

    I'm trying to insert a set of values in a table where one of the values necessary for inclusion is identical to the auto-generated primary key. I am not currently insertion of the value for the primary key because it is generated automatically. Given that I'm not insert the value of the primary key, is anyway to set another value inserted on the same primary key value?

    For example:

    insert into ent_config.device (created_dt, created_tz, created_by_seq, modified_dt, modified_tz, modified_by_seq, enterprise_seq, clinicals_organization_seq, facility_id, dept_id, hostname, tty_id, process_num, device_name, device_status, device_type, loc_type, netbios_id, db_name) values (sysdate, 'IS', '106303', sysdate, 'IS', '106303', '5001', '5035', '9', '19', 'phslnx020', 'P12320', ' 2099', 'PC', 'ON_LINE' "cv220") (, 'NUR', * '2736' *, 'ALL');

    The primary key for this table is called device_seq which is generated automatically and must be unique which as you can see from the above insert statement is inserted, and the netbios_id must be set to the same value when inserting.

    No idea how I could go to do this?

    Hello

    Welcome to the forum!

    When you say that device_seq is 'auto generated', do you mean that there is a trigger that provides this value? (I assume you are using a sequence, but it probably does not matter in this issue). See if you can change the trigger. If netbios_id is always the same as device_seq when you INSERT (but can be changed by updates later), then it is very easy. Otherwise, you may need to designate some specail value (as - 9E9) which replaces the trigger with the same value that it used to device_seq.

    Change the trigger is the only good way I can think of that. If you can't touch the existing trigger, you might be able to add a new trigger, but it would be more complicated and less effective.

  • How to insert the value of the variable using select statement - function Oracle

    Hello

    I have a function that inserts the record based on a condition


    INSERT IN the case
    (
    Case_ID,
    Case_Status,
    Closure_Code,
    Closure_Date
    )(
    SELECT newCaseID,
    caseStatus,
    Closure_Code,
    Closure_Date,
    CASE
    WHERE Case_ID = caseID
    );

    Now, I want the new value casestatus instead of value caseStatus select statement. I have a m_caseStatus variable and I want to use the value of this variable in the select statement above.
    How can I use this.


    Thank you
    INSERT INTO Case
    (
    Case_ID,
    Case_Status,
    Closure_Code,
    Closure_Date
    )(
    SELECT newCaseID,
    m_caseStatus,  <-- here place your variable
    Closure_Code,
    Closure_Date,
    FROM Case
    WHERE Case_ID = caseID
    );
    

    Nicolas.

  • Insert the statement so that a line taking more than 6 minutes.

    When I tried to insert just one line in a table... it's take more than 6 minutes. No idea why its causing so much time for just insertion of a line.

    Please advice...


    Kind regards
    Yasser.

    YasserRACDBA wrote:
    Charles,

    Yes you are right. Optimizer is set to rule that it is the version of Oracle 8i.

    Problem has been solved... rinse us just sharing pool and insert the statement was finished within 1 second.

    Still confused that how its related to the hot flushes of shared pool... May be due to bad hit ratio.

    Flushing the shared pool causes the instructions shared/updates cached so far in the shared pool to get hard analysis/optimized again. Explanation so the most obvious would be that for some reason, the implementation plan have been changed to the statement you're talking about, although the plan should be quite deterministic, because you're on 8i (no bind variable peeking questions) and using the optimizer basic RULE.

    Kind regards
    Randolf

    Oracle related blog stuff:
    http://Oracle-Randolf.blogspot.com/

    SQLTools ++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676 /.
    http://sourceforge.NET/projects/SQLT-pp/

  • SQL statement error INSERT The conflicted with the FOREIGN KEY constraint

    I recently installed a reporting for vmware vsphere software, but I get a SQL error. I opened a request for assistance with vmware, but so far they have not come up with a solution. The error is caused by: com.microsoft.sqlserver.jdbc.SQLServerException: instruction INSERT The conflicted with the FOREIGN KEY constraint 'FK_CB_VSM_NETWORK_VC_ID '. The conflict occurred in database 'VCChargebackVCC02', table "dbo." " CB_VSM_SERVER', column 'VC_ID '. I don't know a lot about SQL, so I'm lost in the extent of troubleshooting is concerned. If anyone has any ideas I'd love to hear them.

    SQL questions are better posed on Technet.  They are better equipped to manage the

    http://social.technet.Microsoft.com/forums/en-us/categories/

  • Get the message insert the disc of State at startup in windows 7

    Original title: How can I remove the status.msi windows 7

    Whenever I boot, I get the following message: Please insert the 'Status' disk and click OK. The source of use is 1. I use the Task Manager to cancel but it becomes boring. Any help to remove it would be appreciated.

    Try this link:http://www.geekpolice.net/t21995-help-it-keeps-saying-insert-the-status-disk-and-click-ok

    Helped?

  • Insert the statement do not using the MultiSelect values correctly

    I have a set of boxes MultiSelect displayed with in a cfloop. I named the MultiSelect boxes "MultiSelect #ID # with #ID #

    the value of KP for each record retrieved. I do this to make sure that each MultiSelect box has a unique name so that when I

    Insert data by using a query of < cfloop > names of are not in conflict. Here's the HTML for the selectbox.

    < select name = "" MultiSelect #ID # ' several size = "3" > (query #ID 'getNonRoleItemDetails) "
    < cfloop query = "getMultiitems" >
    < option value = "#AddInfoID #" > #Name # < / option > (these two values are taken from the "getMultiItems" query
    < / cfloop >

    Here's the query insert I use on the action page that uses this data.



    < cfloopquery getNonRoleItemDetails >

    < cfquery = name "Datasource =' #application.dbname # of the Insert_Multi_Records" >

    INSERT INTO tblItemDetailUpdates (ItemID, ItemDetailsListID, ItemDetailValue, ActionItemID)

    VALUES (#getNonRoleItemDetails.ItemID #, #getNonRoleItemDetails.ID #, ' #form ["MultiSelect" & ID] #', #ArrayOfIds [Counter] #)

    < / cfquery >
    < / cfloop >



    The problem I have here is that the query works correctly, but it is the insertion of the ID MultiSelect values selected (104, 105,

    (106), rather than the real names of these values (IOC, AP, AR... etc).


    I looked at the source code and each MultiSelect box is named correctly and uniquely. Insert inserts the correct ID

    values, but not the names.

    Sigh too bad I am a fool. Well at least I thought about it.

  • Starting problems. - RunDLL32.exe, procedure entry point_except_handler4_common could not be located in the dynamic link librarymsvcrt.dll

    I get the message RunDLL32.exe, procedure entry point_except_handler4_common could not be located in the dynamic link librarymsvcrt.dll. What should I do?

    I had starting problems, boot loop, I think it seems to have been resolved by using the last known good configuration, but I get this popup dialog box. I've not closed for fear that it will start XP looping again.

    Hi EddieBryan,

    1. did you of recent changes on the computer?

    2. do you have security software installed on the computer?

    3. when exactly you receive the error message?

    Method 1
    Check if the problem persists in safe mode and after return with the result.
    A description of the options to start in Windows XP Mode
    http://support.Microsoft.com/kb/315222

    Method 2
    If the problem does not persist in safe mode, then it is possible that some third-party programs installed on the computer is causing the problem.
    I suggest that you configure the computer in a clean boot state and check if it helps.
    To help resolve the error and other messages, you can start Windows XP by using a minimal set of drivers and startup programs. This type of boot is known as a "clean boot". A clean boot helps eliminate software conflicts.
    See section to learn more about how to clean boot.
    How to configure Windows XP to start in a "clean boot" State
    http://support.Microsoft.com/kb/310353

    Reset the computer to start as usual
    When you are finished troubleshooting, follow these steps to reset the computer to start as usual:
    1. click on Start , then click run.
    2. type msconfig , then click OK.
    The System Configuration Utility dialog box appears.
    3. click on the general tab, click Normal Startup - load all services and device drivers and then click OK.
    4. When prompted, click on restart to restart the computer.

    Method 3

    If the previous step fails then I suggest that scan you SFC on the computer that will search the corrupted system files and try to correct them.

    The analysis may take some time, so be patient. Windows allows to fix corrupt or missing files it finds. If the information of the installation CD is required to fix the problem, you may be asked to insert your Windows XP installation CD.

    Description of Windows XP and Windows Server 2003 System File Checker (Sfc.exe)

    http://support.Microsoft.com/kb/310747

    You are prompted to insert a Windows XP SP2 CD when you try to run the tool on a Windows XP SP2 computer system File Checker

    http://support.Microsoft.com/kb/900910

  • The dynamic function of question regarding

    Hello

    Please find the attachment for the required scripts.

    Please help me how to run a package function dynamically in anonymous block. I tried to use EXECUTE IMMEDIATE but did not work.

    My requirement is I have a lot of emp_demo in which it contains 3 functions and I've created a lookup table which are inserted the names of functions. then I tried to read a function name after another using the loop and execution, but it shows PLS-00382: expression is of type incorrect error.

    Please suggest.

    Kind regards

    Phani.

    Hey Brad,

    Try this

    set serveroutput on
    declare
      plsql_block varchar2(200);
      c1 sys_refcursor;
      v_empno number;
      v_ename varchar2(20);
      v_job varchar2(20);
    begin
      for r in(select name as function_name from lt_emp_demo)
      loop
        plsql_block := replace('begin :rc := emp_demo.@FUNCTION; end;', '@FUNCTION', r.function_name);
        dbms_output.put_line(plsql_block);
        --
        EXECUTE IMMEDIATE plsql_block USING OUT c1;
        --
        fetch c1 into v_empno,v_ename,v_job;
        dbms_output.put_line(v_empno || ', ' || v_ename || ', ' || v_job);
      end loop;
    end;
    /
    
    anonymous block completed
    begin :rc := emp_demo.rpt_emp1; end;
    7369, SMITH, CLERK
    begin :rc := emp_demo.rpt_emp2; end;
    7654, MARTIN, SALESMAN
    begin :rc := emp_demo.rpt_emp3; end;
    7844, TURNER, SALESMAN
    

    See http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/dynamic.htm#LNPLS011

    "Dynamic SQL is a programming methodology to build and run SQL statements at run time. This is useful when the time writing programs versatile and flexible as ad hoc query systems, when you write programs that must run the database (DDL) instructions definition language, or when you don't know at compile time the full type of statement, the number or data SQL of its input and output variables. »

Maybe you are looking for