Insert with update......

Hi,
I've this table:
desc TAB1
DESCRIPTION VARCHAR2(20);
QUANTITY NUMBER;
DESCRIPTION........QUANTITY
APPLE............. 10
COFFEE............ 7
I'd like to insert into TAB1 a new record, but if the value of description exist, It update quantity without
insert a new record.
Is it possible do it with just one statement sql without any control structure??
thanks
Raf

You can use the merge statement to get what you want:
SQL> merge into tab1
2 using (select 'APPLE' description,5 quantity from dual) tab2
3 on (tab1.description=tab2.description)
4 when matched then update set tab1.quantity=tab2.quantity
5 when not matched then insert(description,quantity) values(tab2.description,tab2.quantity);
1 rij is samengevoegd.
SQL> select * from tab1;
>>>
DESCRIPTION QUANTITY
APPLE 5
COFFEE 7
SQL> merge into tab1
2 using (select 'BEER' description,24 quantity from dual) tab2
3 on (tab1.description=tab2.description)
4 when matched then update set tab1.quantity=tab2.quantity
5 when not matched then insert(description,quantity) values(tab2.description,tab2.quantity);
1 rij is samengevoegd.
SQL> select * from tab1;
>>>
DESCRIPTION QUANTITY
APPLE 5
COFFEE 7
BEER 24
SQL>

Similar Messages

  • Insert or Update data in SAP with Business Objects?

    Hi all,
    I am new to Business Objects world with my little expertise in Crystal Reports and Xclesius.
    Could you please clarify me that is there any solution or technology or Product of Business Objects which not only make impressive dashboards and analyze the data but also can communicate with back end SAP R/3 to save or update data.
    We are actually analyzing our Client requirements in which there is a need of Dashboards as well as some custom configurations that needs to be saved somewhere in the SAP system in order to make decisions in future.
    Our back end system is SAP BW. One possibility is to use Adobe Flex as a base architecture with BSP and BW but we are more concerned with what BOBJ provides.
    Looking forward for your suggestions.
    Kind Regards
    Umer Farooq

    GR81 wrote:
    I would like to know how I can insert or update data in a Google Spreadsheet from an Oracle Database please?
    Thanks,you can't since Oracle knows nothing about spreadsheets; Google or otherwise.

  • INSERT or UPDATE with multiple rows

    Hi there!
    I want to ask what I should do in the following case: I have to handle mutliple rows of data to insert OR to update into the database.
    The first question is about how to decide whether I should take INSERT or UPDATE. I read here in the forum that I could take a SELECT-statement before, and, if it isn't null, I could update the resultset..if it is null I can make an INSERT-statement.
    But now I a have multiple rows to update or to insert which I want to handle as a transaction (with a batch), so I don't want to check each row the way I described above. Does anyone has a hint ?
    Thanks a lot in advance.

    This is not a problem with java but rather a problem
    with databases in general. The solution generally
    depends on the data that is being operated on.
    If there is a primary key involved, and most records
    were expected to NOT be in the database, then you
    could just insert them in blocks (transaction/batch).
    Each block would fail when a primary key duplicate.
    Then you can process each block as individual
    l statements. The ones that fail are done as
    inserts.
    The reverse of the above is used if you expect most
    records to be in the database. Do updates and the
    break out the blocks with failures to locate the
    inserts.
    Keep in mind that queries for keys probably will be
    faster, but that requires that your keys are ordered.
    If you keys are ordered then you can get a range from
    the initial data. Use that to query the database for
    keys between that range (only return the keys.)
    Using the returned keys you can decide whether each
    h record needs to be an update or insert (presort the
    data into each group and batch each group for more
    speed.)
    If the data is really mixed and the database supports
    it then you can write a stored proc (MySQL does not)
    which decides whether an insert/update is needed.
    Finally if you have large amounts of data, bulk
    operations especially inserts are better done with
    tools supplied by the database vendor. Instead of
    using JDBC to do the insert/updates you write the
    output to a file and pass the file to the tool. You
    might use JDBC (again with the ordered key query) to
    decide which operation to do. Although faster for
    large sets this is problematic due to the error
    handling that you have to add.
    Thanks for this, jschell. I look for your answers, because they're on the money and written well. I learn a lot from them. - MOD

  • Insert OR Update with Data Loader?

    Hello,
    can i Insert OR Update at same time with Data Loader?
    How can i do this?
    Thanks.

    The GUI loader wizard does allow for this including automatically adding values to the PICKLIST fields.
    However, if you mean the command line bulk loader, the answer is no. And to compound the problem, the command line version will actually create duplicates for some of the objects. It appears that the "External Unique Id" is not really "unique" (as in constrained via unique index) for some of the objects. So be very careful when you prototype something with the GUI loader and then reuse the map on the command line version.
    You will find that some objects can work well with the command line loader (some objects will not).
    Works well (just a few examples):
    Account (assuming your NAME,LOCATION fields are unique).
    Financial Product
    Financial Account
    Financial Transaction
    Will definitely create duplicates via command line bulk loader:
    Contact
    Asset
    Also be aware that you might hear that during a go-live that Oracle will remove the 30k record limit on bulks loads (temporarily). I have not had any luck with Oracle Support making that change (2 clients specifically in the last 12 months).

  • How to insert or update comparing values  with two or more table

    Hai All
    I have three or four table in my database.
    Table 1 Dailattend is the main table here i need to insert or update my data and the fieds are
    Emplcode number,attdate date, intime date,intrin date ,introut date, outtime date are the fields
    Table 2 acclempbarcode the fields are
    emplcode number ,barcode number ....etc
    so now my data is in text format and i have broke the date like this
    0011221100112200100320100815
    First 16 is barcode and next 8 is date and 4 is time and i have created a temp table and store the date and move to main table
    My problem is the main table dailattend has no barcode so when i am going to insert or update i need to check whether the barcode is match with the emplcode in the main table
    How can i write insert or update statement
    The data is like this
    00110022 is barcode,10-03-2010 is my date and 0815 is time so i need to insert into dailattend table so now i have emplcode in dailattend table so i need to compare the barcode belong the emplcode in the another table and i need to insert in the dailattend table
    Pls give me some solution with example
    Regards
    Srikkanth.M

    try somthing like this
    create table t1
    as
    select '0011221100112200' barcode,to_date('100320100815','ddmmyyyyhh24mi') dt
    from dual
      create table barcodetbl
      emplcode varchar2(2000)
      barcode varchar2(2000)
      datetime date
    merge into barcodetbl bc
    using( select  * from  t1) x
    on
    (bc.barcode = x.barcode)
    when matched
    then update
    set datetime = x.dt
    when not matched
    then
    insert (emplcode,barcode,datetime)
    values(1,x.barcode,x.dt)
    /didn't realize that barcode is not in the main table.
    something along the lines
    Table 1 Dailattend is the main table here i need to insert or update my data and the fieds are
    Emplcode number,attdate date, intime date,intrin date ,introut date, outtime date are the fields
    Table 2 acclempbarcode the fields are
    emplcode number ,barcode number ....etc
    merge into dailattend bc
    using( select  * from  t1, acclempbarcode ac where t1.barcode = ac.barcode) x
    on
    (bc.emplcode = x.emplcode)
    when matched
    then update
    set datetime = x.dt
    when not matched
    then
    insert (emplcode,datetime)
    values(1,x.dt)
    /Alvinder
    Edited by: alvinder on Mar 23, 2010 3:50 PM

  • SQL INSERT / SQL UPDATE don't work with form page, don't affect table

    The subject line says it all. No matter what I try, my updates on the form don't appear on the report page, which accesses the table. When I look at the table using SQL WORKSHOP, the changes aren't made there either. What am I missing? I have another report page and form page with a different table in the same application and updates in that table work fine. I coded them both the same. What should I be looking at?
    Steve "the n00b" in Raleigh NC

    Steve,
    How you have created the FORM page? Using FORM WIZARD? Or You have created blank page and after that you have manually created all the form items?
    If you have used WIZARD to create form page, then you can see a page process with Automatic Row Processing (DML) type. Here you need can set DML (Insert/Update/Delete) you wish to use on this form. APEX will take care of the rest.
    If there is no such process in your page, then you need to create one. You may have one process to do both (Insert and Update) and you can have two sepate processes. I prefer having two seperate page processes (after submit), one for Insert and one for Update.
    Now you can make the Insert process conditional so that it only execute when you click button - Create (Add or any similar button you have ) Also make the Update process conditional so that it only execute when you click button - Save (Update or any similar button you have )
    Just a quick note - From the above trigger, I can guess you are allowing users to enter Primary Key manually? In my opinion, Primary key should be always system generated using SEQUENCE. Users can only enter BUSINESS KEY (if any) and we should not use Business key as Primary Key.
    Good Luck :-)
    - Hari
    Edited by: Hari_639 on Oct 23, 2009 8:02 PM

  • Insert and update query to calculate the opening and closing balance

    create table purchase(productid number(5) ,dateofpurchase date,
    qty number(5));
    create table inventory(invid number(5),productid number(5),
    idate date,openingqty number(5),closingqty number(5));
    Records in inventory:
    1,1,'01-jan-2009', 10, 20
    2,1,'03-jan-2009', 20, 30
    3,1,'04-jan-2009', 40, 50
    when I enter the purchase invoice for 15 qty on 02-jan-2009
    after say '15-jan-09' , a new record should get inserted
    with opening balance = (closing balance before 02-jan-2009)
    and all the opening and closing balance for that product should
    get affected.
    If the invoice for 20 qty is entered for the existing date say
    '03-jan-2009' in inventory , then the closing balance
    for 03-jan-2009 should get updated and all the following records
    should get affected.
    I need the insert for the first one and update query for the
    second one.
    Vinodh

    <strike>You can do this in one statement by using the merge statement</strike>
    Hmm, maybe I spoke too soon.
    Edited by: Boneist on 25-Sep-2009 13:56
    Thinking about it, why do you want to design your system like this?
    Why not simply have your purchases table hold the required information and then either work out the inventory on the fly, or have a job that calls a procedure to add a row for the previous day?
    If you continue with this design, you're opening yourself up to a world of pain - what happens when the data doesn't match the purchases table? Also when is the inventory cut-off to reset the opening/closing balances? Monthly? Annually? Weekly? If it's set to one of those, what happens when the business request the inventory for a particular week?
    Edited by: Boneist on 25-Sep-2009 13:59

  • Can we use both INSERT and UPDATE at the same time in JDBC Receiver

    Hi All,
    I would like to know is it possible to use both INSERT and UPDATE at the same time in one interface because I have a requirement in which I have to perform both the task.
    user send the file which contains both new and old record and I need to save those in MS SQL database.
    If the record exist then use UPDATE otherwise use INSERT.
    I looked on sdn but didn't find any blog which perform both the things at the same time.
    Interface Requirement
    FILE -
    > PI -
    > JDBC(INSERT & UPDATE)
    I am thinking to use JDBC Lookup but not sure if it good to use for bulk record.
    Can somebody please suggest me something or send me the link of any blog or anything to solve this problem.
    Thanks,

    Hi ,
              If I have understood properly the scenario properly,you are not performing insert and update together. As you posted
    "If the record exist then use UPDATE otherwise use INSERT."
    Thus you are performing either an insert or an update which depends on outcome of a search if the records already exist in database or not. Obviously to search the tables you need " select * from ...  where ...." query. If your query returns some results you proceed with update since this means there are some old records already in database. If your query returns no rows  you proceed with "insert into tablename....." since there are no old records present in database.
      Now perhaps the best method to do the searching, taking a decision to insert or update, and finally insert or update operation is to be done by a stored procedure in MS SQL database.  A stored procedure is a subroutine available to applications accessing a relational database system. Here the application is PI server.   If you need further help on how to write and call stored procedure in MS SQL you can look into these links
    http://www.daniweb.com/web-development/databases/ms-sql/threads/146829
    http://www.sqlteam.com/article/stored-procedures-parameters-inserts-and-updates
    [ This part you can ignore, Since its not sure that you will face this situation
        Still you might face some problems while your scenario runs. Lets consider this scenario, after the stored procedure searches the database it found no rows. Thus you proceed with an insert operation. If your database table is being accessed by multiple applications (or users) other than yours then it is very well possible that after the search operation completed with a null result, an insert/update operation has been performed by some other application with the same primary key. Now when you are trying to insert another row with same primary key you get an error message like "duplicate entry not possible for same primary key value". Thus you need to be careful in this respect. MS SQL has a feature called "exclusive locks ". Look into these links for more details on the subject
    http://msdn.microsoft.com/en-us/library/aa213039(v=sql.80).aspx
    http://www.mssqlcity.com/Articles/Adm/SQL70Locks.htm
    http://www.faqs.org/docs/ppbook/r27479.htm
    http://msdn.microsoft.com/en-US/library/ms187373.aspx
    http://msdn.microsoft.com/en-US/library/ms173763.aspx
    http://msdn.microsoft.com/en-us/library/e7z8d5hf(v=vs.80).aspx
    http://mssqlserver.wordpress.com/2006/11/08/locks-in-sql/
    http://www.mollerus.net/tom/blog/2008/03/using_mssqls_nolock_for_faster_queries.html
        There must be other methods to avoid this problem. But the point is you need to be sure that all access to database for insert/update operations are isolated.
    regards
    Anupam

  • How can I use multiple row insert or update into DB in JSP?

    Hi all,
    pls help for my question.
    "How can I use multiple rows insert or update into DB in JSP?"
    I mean I will insert or update the multiple records like grid component. All the data I enter will go into the DB.
    With thanks,

    That isn't true. Different SQL databases have
    different capabilities and use different syntax, That's true - every database has its own quirks and extensions. No disagreement there. But they all follow ANSI SQL for CRUD operations. Since the OP said they wanted to do INSERTs and UPDATEs in batches, I assumed that ANSI SQL was sufficient.
    I'd argue that it's best to use ANSI SQL as much as possible, especially if you want your JDBC code to be portable between databases.
    and there are also a lot of different ways of talking to
    SQL databases that are possible in JSP, from using
    plain old java.sql.* in scriptlets to using the
    jstlsql taglib. I've done maintenance on both, and
    they are as different as night and day.Right, because you don't maintain JSP and Java classes the same way. No news there. Both java.sql and JSTL sql taglib are both based on SQL and JDBC. Same difference, except that one uses tags and the other doesn't. Both are Java JDBC code in the end.
    Well, sure. As long as you only want to update rows
    with the same value in column 2. I had the impression
    he wanted to update a whole table. If he only meant
    update all rows with the same value in a given column
    with the same value, that's trivial. All updates do
    that. But as far as I know there's know way to update
    more than one row where the values are different.I used this as an example to demonstrate that it's possible to UPDATE more than one row at a time. If I have 1,000 rows, and each one is a separate UPDATE statement that's unique from all the others, I guess I'd have to write 1,000 UPDATE statements. It's possible to have them all either succeed or fail as a single unit of work. I'm pointing out transaction, because they weren't coming up in the discussion.
    Unless you're using MySQL, for instance. I only have
    experience with MySQL and M$ SQL Server, so I don't
    know what PostgreSQL, Oracle, Sybase, DB2 and all the
    rest are capable of, but I know for sure that MySQL
    can insert multiple rows while SQL Server can't (or at
    least I've never seen the syntax for doing it if it
    does).Right, but this syntax seems to be specific to MySQL The moment you use it, you're locked into MySQL. There are other ways to accomplish the same thing with ANSI SQL.
    Don't assume that all SQL databases are the same.
    They're not, and it can really screw you up badly if
    you assume you can deploy a project you've developed
    with one database in an environment where you have to
    use a different one. Even different versions of the
    same database can have huge differences. I recommend
    you get a copy of the O'Reilly book, SQL in a
    Nutshell. It covers the most common DBMSes and does a
    good job of pointing out the differences.Yes, I understand that.
    It's funny that you're telling me not to assume that all SQL databases are the same. You're the one who's proposing that the OP use a MySQL-specific extension.
    I haven't looked at the MySQL docs to find out how the syntax you're suggesting works. What if one value set INSERT succeeds and the next one fails? Does MySQL roll back the successful INSERT? Is the unit of work under the JDBC driver's control with autoCommit?
    The OP is free to follow your suggestion. I'm pointing out that there are transactions for units of work and ANSI SQL ways to accomplish the same thing.

  • How to insert or update multiple values into a records of diff fields

    Hai All
    I have to insert or update or multiple values into a single records of diff fields from one to another table.
    Table1 has 3 fields
    Barcode bardate bartime
    0011 01-02-10 0815
    0022 01-02-10 0820
    0011 01-02-10 1130
    0022 01-02-10 1145
    0011 01-02-10 1230
    0022 01-02-10 1235
    0011 01-02-10 1645
    0022 01-02-10 1650
    these are the times that comes in at 0815 and goes break at 1130 and comes in at 1230 and goes home at 1645
    from these table i have to insert into another table called table2
    and the fields are barcode, date,timein intrin,introut,tiomout
    And the output want to like this
    barcode timein intrin introut timeout date
    0011 0815 1130 1230 1645 01-02-10
    0022 0820 1145 1235 1650 01-02-10
    If any give some good answer it will be help full..
    Thanks & Regards
    Srikkanth.M

    SQL> with table1 as (
      2  select '0011' Barcode,'01-02-10' bardate,'0815' bartime from dual union
      3  select '0022','01-02-10','0820' from dual union
      4  select '0011','01-02-10','1130' from dual union
      5  select '0022','01-02-10','1145' from dual union
      6  select '0011','01-02-10','1230' from dual union
      7  select '0022','01-02-10','1235' from dual union
      8  select '0011','01-02-10','1645' from dual union
      9  select '0022','01-02-10','1650' from dual
    10  )
    11  select barcode, bardate,
    12         max(decode(rn,1,bartime,null)) timein,
    13         max(decode(rn,2,bartime,null)) intrin,
    14         max(decode(rn,3,bartime,null)) introut,
    15         max(decode(rn,4,bartime,null)) timeout from (
    16                          select barcode, bardate, bartime,
    17                                 row_number() over (partition by barcode, bardate
    18                                                    order by bartime) rn
    19                            from table1)
    20  group by barcode, bardate;
    BARC BARDATE  TIME INTR INTR TIME
    0011 01-02-10 0815 1130 1230 1645
    0022 01-02-10 0820 1145 1235 1650Max
    http://oracleitalia.wordpress.com

  • Help me in creating a Trigger for Insert and Update Options

    Hi
    Please help me in creating a Trigger .
    My requirement is that after insert or update on a Table , i want to fire an event .
    I have started this way ,but doesn't know how to fully implement this .
    say i have a dept table
    CREATE TRIGGER DepartmentTrigger
    AFTER INSERT ON Dept
    BEGIN
    INSERT INTO mytable VALUES("123","Kiran");
    END DepartmentTrigger;
    Please tell me how can i put the Update option also .
    Thanks in advance .

    Please tell me how can i put the Update option also .Add "Or Update". ;-)
    Here are a few suggestions, but you definitely need to refer to the manual page that the previous poster suggested.
    CREATE OR REPLACE TRIGGER DepartmentTrigger
    AFTER INSERT Or Update ON Dept
    BEGIN
    INSERT INTO mytable VALUES(:new.Dept,'DEPT ADDED OR CHANGED');
    END DepartmentTrigger;
    The "Or Replace" means you can replace the trigger while you're developing without having to type in a drop statement every time. Just change and rerun your script, over and over until you get it right.
    Adding "Or Update" or "Or Delete" makes the trigger fire for those events too. Note, you may want seperate triggers in different scripts and with different names for each event. You have to decide if your design really does the same thing whether it's an insert or an update.
    :new.Dept is how you would refer to the changed vale of the Dept column (:old.Dept is the prior value). I changed the double quotes on the string in the VALUES clause to single quotes.
    Andy

  • SAP r/3 insert or update

    Hi,
    We have a scenario, in which we need to insert or update the data in the SAP r/3 based on the availability of the primary field in the SAP r/3.
    For ex, if i have the employee details in SAP r/3 where in for a particular existing employee the salary details might be updated based upon the salary hike or if he is a new employee the details have to be inserted.
    For this we have the primary field as the emp no.
    How to proceed with this scenario.
    Regards,
    Kishore

    Hi,
    U can do with the server proxy create an proxy. Inside the method write ur code in ABAP
    1) First check the employee no which u got from file with the employee no which is maintained in the abap table if it exits then update the information if it is not then insert the data in table.
    refer the server proxy scenario for ur reference.
    first:
    ABAP Proxy configuration:
    /people/vijaya.kumari2/blog/2006/01/26/how-do-you-activate-abap-proxies
    second:
    Server Proxy -
    /people/siva.maranani/blog/2005/04/03/abap-server-proxies
    File to Inbound Proxy:
    /people/prateek.shah/blog/2005/06/14/file-to-r3-via-abap-proxy
    Debugging Inbound Proxy:
    /people/stefan.grube/blog/2006/07/28/xi-debug-your-inbound-abap-proxy-implementation
    chirag

  • How to use group function in insert or update

    Hai All
    How can we use group function in insert or update statement
    I am generating an attendance so i have different set of timing for example
    0800,1200,1230, 1700 and i need to insert into these data into table with min value to intime and max value to
    outtime and othere to inertval time in or out
    Pls tell me with some example
    For example
    For INSERT
    insert into T2 (barcode,empcode,intime,attend_date)
                   values(r2.cardn,r2.enpno,MIN(r2.ptime),r2.pdate);
    For UPDATE
    update dail_att set outtime= MAX(r2.ptime) where empcode=r2.enpno and barcode=r2.cardn and
    attend_date=r2.pdate;
    Here instead of where i need to use having so pls tell how to use
    Thanks & Regards
    Srikkanth.M

    Hai Man
    R2 is not a table name its a record
    Let me explain clearly
    I have to generate daily attendance for lot of employees So i have two table t1 and t2
    T1 consist of three column empno,date,time
    T2 consist of empno,name,date,intime,outtime,intrin,introut
    So now i need to give the T1 Min value Of time to T2 Intime and T1 Max value of Time to T2 Outtime fields so there so many records while i am using
    max(time) it gives the max value of all so i seperated by group function so now i have an error in subquery ie it is an single row subquery so i need to use multiple row subquery how i can use multiple row subquery in update statement
    Thanks In Advance
    Srikkanth.M

  • Insert or update via ViewObjectImpl or ApplicationModuleImpl

    How can I insert or update a database from java code? I am attempting to do this in a subclass of ApplicationModuleImpl?
    The code below throws RowValException: JBO-27024: Failed to validate a row with key
    ConcUserLoginViewImpl culv =(ConcUserLoginViewImpl)findViewObject("ConcUserLoginView1");
    Row concUsageRow = culv.createRow();
    concUsageRow.setAttribute("UserPk",userPk);
    concUsageRow.setAttribute("LoginDate","sysdate");
    concUsageRow.setAttribute("ConcAccessCookieValue",ConcAccessCookieValue);
    culv.insertRow(concUsageRow);
    culv.getDBTransaction().commit();
    Please could someone supply some example code to do this.
    Presumably, this should be possible from a ViewObjectImpl class - is this correct?

    Hello,
    You can make use of the Execute method in WS 2.0 as an alternate, but if you are looking out for InsertOrUpdate Functionality u have to use WS 1.0.

  • After insert or update calculate column

    question about a table.
    I have a table called table1
    AFTER data is inserted or updated into the table1
    I want to run an update on the same table (table1) with a case statement
    update table1
    set column2 = case
    WHEN column1 = 'abc' THEN 'testl'
    WHEN column1 = 'def' THEN 'test2'
    ELSE 'test3'
    END;
    commit;
    END;
    i cant use a trigger because i get error since the insert would be on same table.
    What else can i use for this update ? I cant use a stored procedure that runs daily or something like that because the column2 in the table needs to be populated immediately after an insert or update
    thanks for any ideas

    SQL>  CREATE TABLE TABLE1
      2  (
      3    COLUMN1 VARCHAR2(10),
      4    COLUMN2 VARCHAR2(10)
      5  );
    Table created.
    SQL> CREATE OR REPLACE TRIGGER TRG_TABLE1
      2  BEFORE INSERT OR UPDATE OF COLUMN1 ON TABLE1
      3  FOR EACH ROW
      4  BEGIN
      5
      6  IF :NEW.COLUMN1 = 'abc' THEN
      7     :NEW.COLUMN2 := 'test1';
      8  ELSIF :NEW.COLUMN1 = 'def' THEN
      9     :NEW.COLUMN2 := 'test2';
    10  ELSE
    11     :NEW.COLUMN2 := 'test3';
    12  END IF;
    13
    14  END;
    15  /
    Trigger created.
    SQL> INSERT INTO TABLE1(COLUMN1) VALUES('abc');
    1 row created.
    SQL> SELECT * FROM TABLE1;
    COLUMN1    COLUMN2
    abc        test1
    SQL> UPDATE TABLE1 SET COLUMN1 = 'def';
    1 row updated.
    SQL> SELECT * FROM TABLE1;
    COLUMN1    COLUMN2
    def        test2
    SQL>
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for