Insert result of sql into table

Hi all, how do I insert result of sql into table marco_ttmp ?
I tried this, but it doesn't work, it returns "ORA-00928: missing SELECT keyword"
insert into marco_ttmp (var_id,arcdate,contragentid,lpnd,lusd,lkk)
with
rrk as (
select '01112010' as mydate FROM dual d
union all
select '01122010' as mydate FROM dual d
rru as (
select '33' contragentid from dual d
union all 
select '56' contragentid from dual d
b as (
select '01112010' as arcdate, '33' as contragentid, 'tt' as t from dual
union all
select '01122010' as arcdate, '56' as contragentid, 'un' as t from dual
union all
select '01122010' as arcdate, '33' as contragentid, 'kp' as t from dual
union all
select '01112010' as arcdate, '56' as contragentid, 'ur' as t from dual
d as (
select '01112010' as arcdate, '33' as contragentid, 'dr' as y from dual
union all
select '01122010' as arcdate, '56' as contragentid, 'rh' as y from dual
union all
select '01122010' as arcdate, '33' as contragentid, 'tr' as y from dual
union all
select '01112010' as arcdate, '56' as contragentid, 'wn' as y from dual
v as ( select '555' as kkt from dual ),
kkt as ( select count(*)+5 kkt from v )
--insert into marco_ttmp (var_id,arcdate,contragentid,lpnd,lusd,lkk)
select substr(rrk.mydate,4,2) || '.' || rru.contragentid var_id,
rrk.mydate as arcdate,
rru.contragentid as contragentid,
count(b.arcdate) lpnd,count(d.arcdate) lusd,
kkt.kkt lkk
from kkt cross join rrk cross join rru
left outer join b on b.arcdate = rrk.mydate and b.contragentid = rru.contragentid
left outer join d on d.arcdate = rrk.mydate and d.contragentid = rru.contragentid
group by rrk.mydate, rru.contragentid, kkt.kkt

Moved "insert into" to the beginning of statement, everything works.
insert into marco_ttmp (var_id,arcdate,contragentid,lpnd,lusd,lkk)
with
rrk as (
select '01112010' as mydate FROM dual d
union all
select '01122010' as mydate FROM dual d
rru as (
select '33' contragentid from dual d
union all 
select '56' contragentid from dual d
b as (
select '01112010' as arcdate, '33' as contragentid, 'tt' as t from dual
union all
select '01122010' as arcdate, '56' as contragentid, 'un' as t from dual
union all
select '01122010' as arcdate, '33' as contragentid, 'kp' as t from dual
union all
select '01112010' as arcdate, '56' as contragentid, 'ur' as t from dual
d as (
select '01112010' as arcdate, '33' as contragentid, 'dr' as y from dual
union all
select '01122010' as arcdate, '56' as contragentid, 'rh' as y from dual
union all
select '01122010' as arcdate, '33' as contragentid, 'tr' as y from dual
union all
select '01112010' as arcdate, '56' as contragentid, 'wn' as y from dual
v as ( select '555' as kkt from dual ),
kkt as ( select count(*)+5 kkt from v )
select substr(rrk.mydate,4,2) || '.' || rru.contragentid var_id,
rrk.mydate as arcdate,
rru.contragentid as contragentid,
count(b.arcdate) lpnd,count(d.arcdate) lusd,
kkt.kkt lkk
from kkt cross join rrk cross join rru
left outer join b on b.arcdate = rrk.mydate and b.contragentid = rru.contragentid
left outer join d on d.arcdate = rrk.mydate and d.contragentid = rru.contragentid
group by rrk.mydate, rru.contragentid, kkt.kkt

Similar Messages

  • Insert data file name into table from sql loader

    Hi All,
    I have a requirement to insert the data file name dynamically into table using sql loader.
    Example:
    sqlldr userid=username/passwword@host_string control=test_ctl.ctl data=test_data.dat
    test_ctl.ctl
    LOAD DATA
    FILED TERMINATED BY ','
    INTO TABLE test
    (empid number,
    ename varchar2(20),
    file_name varchar2(20) ---------- This should be the data file name which can be dynamic (coming from parameter)
    test_data.dat
    1,test
    2,hello
    3,world
    4,end
    Please help..
    Thanks in advance.
    Regards
    Anuj

    you'll probably have to write your control file on the fly, using a .bat or .sh file
    rem ===== file : test.bat ========
    rem
    rem ============== in pseudo speak =============
    rem
    rem
    echo LOAD DATA > test.ctl
    echo FILED TERMINATED BY ',' >> test.ctl
    echo INTO TABLE test >> test.ctl
    echo (empid number, >> test.ctl
    echo ename varchar2(20), >> test.ctl
    echo file_name constant %1% >> test.ctl
    echo ) >> test.ctl
    rem
    rem
    rem
    sqlldr userid=username/passwword@host_string control=test.ctl data=test_data.dat
    rem =============== end of file test.bat =======================
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/ldr_field_list.htm#i1008664

  • Error when insert data in Sql Server table(DateTime data type)

    Hello all,
    I have created a database link in oracle 11g to SQL Server 2008 using Sqlserver gateway for oracle,Oracle run on Linux and SQL Server run on Windows platform.
    I have queried a table and it fetches rows from the target table.
    I am using this syntax for insert a row in Sql Server table.
    Insert into Prod@sqlserver (NUMITEMCODE, NUMPREOPENSTOCK, NUMQNTY, NUMNEWOPENSTOCK, DATPRODDATE , TXTCOMPANYCODE, "bolstatus", NUMRESQNTY )
    Values (1118 , 1390.0 , 100.0 ,1490 , '2012-06-23 12:37:58.000','SFP' ,0 , 0 );
    but it give me error on DATPRODDATE,The data type of DATPRODDATE column in Sql Server is DATETIME.
    My Question is how can i pass the date values in INSERT statement for Sql Server DateTime data type.
    Regards

    Just as with Oracle, you have to specify the date using the to_date() function or use the native date format for the target database (if you can figure out what that is). This is good practice anyway and a good habit to get into.

  • How to insert date with timestamp into table values

    hi,
    I have a table
    create table abc1(dob date);
    insert into abc1 values (to_date(sysdate,'RRRR/MM/DD HH24:MI:SS'))
    but when i see in data base it shows as normal date without time stamp.
    Is it possible to insert into back end with timestamp.
    Thanks..

    First, SYSDATE is a DATE already, no need to convert it to a DATE using the TO_DATE() function.
    The date ALWAYS has a time component, whether or not it is displayed is up to your NLS settings. for example:
    SQL> CREATE TABLE ABC1(DOB DATE);
    Table created.
    SQL> ALTER SESSION SET NLS_DATE_FORMAT='MM/DD/YYYY';
    Session altered.
    SQL> INSERT INTO ABC1 VALUES(SYSDATE);
    1 row created.
    SQL> SELECT * FROM ABC1;
    DOB
    02/04/2010
    SQL> ALTER SESSION SET NLS_DATE_FORMAT='MM/DD/YYYY HH24:MI:SS';
    Session altered.
    SQL> SELECT * FROM ABC1;
    DOB
    02/04/2010 12:54:57
    SQL> DROP TABLE ABC1;
    Table dropped.

  • Error occured while inserting XML file data into table.

    Hello,
    I m trying to load xml data into table by following code.but getting below error
    Error at line 1
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00222: error received from SAX callback function
    ORA-06512: at "SYS.DBMS_XMLSTORE", line 78
    ORA-06512: at line 21
    DECLARE
      xmldoc   clob;
      insCtx   DBMS_XMLStore.ctxType;
      dname    varchar2(20) := 'MDIR';
      rows  number;
    BEGIN
        xmldoc := dbms_xslprocessor.read2clob(dname, 'try_xm3.xml');
        insCtx := DBMS_XMLStore.newContext('try1');
    dbms_output.put_line('1');
        DBMS_XMLStore.setRowTag(insCtx, 'cajas');
    rows := DBMS_XMLStore.insertXML(insCtx, xmlDoc);
    commit;
      dbms_output.put_line('INSERT DONE '||TO_CHAR(rows));
      DBMS_XMLStore.closeContext(insCtx);
    END;
    <?xml version="1.0" encoding="utf-8"?>
    <cajas xmlns="PBcion.Caja" fec="2011-03-02T14:20:14" codDeleg="093">
      <caj codPrev="80001223" fechaInicio="2011-03-02" fec="2011-09-02" couta="01" idPerio="1" caj="32"></caj>
    </cajas>can you please look into this?
    I m using oracle 10g

    SQL> create table try1
      2  (
      3  codPrev number,
      4  fechaInicio varchar2(25),
      5  fec varchar2(25),
      6  couta number,
      7  idPerio number,
      8  caj number
      9  );
    Table created
    SQL>
    SQL> insert into try1 (codprev, fechainicio, fec, couta, idperio, caj)
      2  select x.codprev, x.fechainicio, x.fec, x.couta, x.idperio, x.caj
      3  from xmltable(
      4         xmlnamespaces(default 'PBcion.Caja')
      5       , '/cajas/caj'
      6         passing xmltype(bfilename('TEST_DIR','try_xm3.xml'), nls_charset_id('AL32UTF8'))
      7         columns codPrev     number       path '@codPrev'
      8               , fechaInicio varchar2(25) path '@fechaInicio'
      9               , fec         varchar2(25) path '@fec'
    10               , couta       number       path '@couta'
    11               , idPerio     number       path '@idPerio'
    12               , caj         number       path '@caj'
    13       ) x
    14  ;
    1 row inserted
    SQL> select * from try1;
       CODPREV FECHAINICIO               FEC                            COUTA    IDPERIO        CAJ
      80001223 2011-03-02                2011-09-02                         1          1         32
    Since the two date attributes are coming in the W3C's xs:date format, you can directly define the corresponding columns as DATE and use a DATE projection in XMLTable :
    SQL> alter table try1 modify (fechainicio date);
    Table altered
    SQL> alter table try1 modify (fec date);
    Table altered
    SQL>
    SQL> insert into try1 (codprev, fechainicio, fec, couta, idperio, caj)
      2  select x.codprev, x.fechainicio, x.fec, x.couta, x.idperio, x.caj
      3  from xmltable(
      4         xmlnamespaces(default 'PBcion.Caja')
      5       , '/cajas/caj'
      6         passing xmltype(bfilename('TEST_DIR','try_xm3.xml'), nls_charset_id('AL32UTF8'))
      7         columns codPrev     number       path '@codPrev'
      8               , fechaInicio date         path '@fechaInicio'
      9               , fec         date         path '@fec'
    10               , couta       number       path '@couta'
    11               , idPerio     number       path '@idPerio'
    12               , caj         number       path '@caj'
    13       ) x
    14  ;
    1 row inserted
    SQL> select * from try1;
       CODPREV FECHAINICIO FEC              COUTA    IDPERIO        CAJ
      80001223 02/03/2011  02/09/2011           1          1         32

  • Insert form view data into table view

    Hi Experts,
      I have
                 --> a form view with three input fields and a button(ADD)
                 --> a table view with three columns.
    Both views in same page.
    My requirement is when a user enters the three inputs and click button (ADD) all the inputs entered should be inserted in the below table view.
    User can be able to enter multiple lines by clicking ADD again and again with different inputs.
    How to insert rows from a form view event (ADD) into table view?
    Thanks&Regards,
    karthik

    Hi
    Which 'System Action' are you using in the 'Add' button? You need to use 'Insert Row' Action. When you select this below the action you will get one box 'Apply To' there you select the table. Then save & deploy the model, you will get what you want.
    Caution - THis data will not get stored in the table permenently, once you close this model you will loose all the data.
    Regards
    Sandeep

  • Insert result of query into a table with unique constraint

    Hi,
    I have a query result that I would like to store in a table. The target table has a unique constraint. In MySQL you can do
    insert IGNORE into myResultTable <...select statement...>
    The IGNORE clause means if inserting a row would violate a unique or primary key constraint, do not insert the row, but continue inserting the rest of the query. Leaving the IGNORE clause out would cause the insert to fail and an error to return.
    I would like to do this in oracle... that is insert the results of a query that are not already in the target table. What is the best way to do this? One way is use a procedural language and loop through the first query, checking to see if each row is a duplicate before inserting it. I would think this would be slow if there are lots of records. Other options...
    insert into myTargetTable
    select value from mySourceTable where ... and not exists (select 'x' from myTargetTable where value = mySourceTable.value)
    insert into myTargetTable
    select mySourceTable.value
    from myTargetTable RIGHT JOIN mySourceTable
    ON myTargetTable.value = mySourceTable.value
    where ...
    and myTargetTable.value IS NULL
    any other suggestions?
    Thanks,
    Simon

    Try doing a MINUS instead of not exists., ie Source MINUS Target.
    Disabling the constraint will not help you since this will allow the duplicate rows to be inserted into the table. I don't think you want this.
    --kalpana                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to get current month from filename and bulk insert from text file into table?

    I set up some dynamic SQL to help my bulk copy data from a text file to a table.  This works fine for files that come in every day; I get the previous day’s data, based on the file name that’s placed
    in the folder.  That’s why I’m using the ‘-1’.  The dates will look like this: '20140131', so I'm using type 112.
    declare @fullpath1 varchar(1000)
    select @fullpath1 = '''\\system.local\ms\london\FTP\' + convert(varchar, getdate()-1, 112) + '_INDEXPRICES_EOM.SPC'''
    declare @cmd1 nvarchar(1000)
    print (@cmd1)
    select @cmd1 = 'bulk insert [dbo].[SB_Monthly] from ' + @fullpath1 + ' with (FIELDTERMINATOR = ''\t'', FIRSTROW = 5, LASTROW = 675, ROWTERMINATOR=''0x0a'')'
    print(@cmd1)
    exec (@cmd1)
    I think the syntax will be somewhat similar to this:
    YEAR(date_column)=YEAR(getdate()) AND MONTH(date_column)=MONTH(getdate())
    I’m not totally sure how to incorporate that into my current syntax.
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    I tried a couple versions of this.
    Declare @StartDate Date, @EndDate Date
    Select @StartDate = convert(varchar, getdate()-28, 112), @EndDate = convert(varchar, getdate()-1, 112)
    BEGIN
    declare @fullpath1 varchar(1000)
    select @fullpath1 = '''\\ms\london\FTP\' + ''' between ''' + Convert(Varchar(10), @StartDate, 101) + ''' and ''' + Convert(Varchar(10), @EndDate, 101) + '''_SP.SPC'''
    declare @cmd1 nvarchar(1000)
    print (@cmd1)
    select @cmd1 = 'bulk insert [dbo].[SPBMI_Monthly] from ' + @fullpath1 + ' with (FIELDTERMINATOR = ''\t'', FIRSTROW = 5, LASTROW = 675, ROWTERMINATOR=''0x0a'')'
    print(@cmd1)
    exec (@cmd1)
    END
    Here’s the string:
    bulk insert [dbo].[SPBMI_Monthly] from '\\ms\london\FTP\' between '02/03/2014' and '03/02/2014'_SP.SPC' with (FIELDTERMINATOR = '\t', FIRSTROW = 5, LASTROW = 675, ROWTERMINATOR='0x0a')
    The error message I keep getting is:
    Msg 156, Level 15, State 1, Line 1
    Incorrect syntax near the keyword 'between'.
    Msg 319, Level 15, State 1, Line 1
    Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
    I feel like I’m already pushing this thing to the limit. 
    Maybe this last part isn’t possible.
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

  • Inserting the column values into table from view through procedure!!!

    below is my example code
    Create or replace procedure test_proc
    is
    cursor test_cur is
    select a.col1 , b.col2, c.col3, d.col4, e.col5
    from tableA a, tableB b, tableC c, tableD d, tableE e;
    test_cur_rec test_cur%rowtype;
    Begin
    insert into test_stg ( col1, col2, col3, col4, col5, col6, col7)
    Values ( test_cur_rec. col1,
    test_cur_rec .col2,
    test_cur_rec .col3,
    test_cur_rec .col4,
    test_cur_rec .col5
    -- col6, col7 );
    create view test2 (
    select f.col6, g.col7 from tableF f,tableG g);
    I m trying to insert values into the table test_stg but for col6 and col7 i need to get the data from the view test2.
    In simple word, all i need to do is get the 2 columns data from view and insert into a table through procedure. The above code is the example which looks very much like my actual code.
    How do i accomplish this task ??

    well there is joining condition for a, b,c ,d, e tables, i have not mentioned here. The where condition has nothing to do with the other two columns of the view.
    There is no relation ship between the these tables the view. The col 6 and 7 i m inserting from view is sysdate timestamp and the job_id number.
    so its pretty straight forward insertion into the table from view columns. These two columns has just one row with id number and timestamp. so i need to insert these data into the the table when i run a procedure.
    Thank you so much!!!

  • Inserting comma seperated values into table

    Hi,
    There is a variable like this,
    var= 'C0001,C0002,C0003';
    I want c0001 c0002 and c0003 to get inserted into some temp table as seperate rows, how do I do that.
    Thnx again ur your response.

    Hi,
    There is a variable like this,
    var= 'C0001,C0002,C0003';
    I want c0001 c0002 and c0003 to get inserted into some temp table as seperate rows, how do I do that.
    Thnx again ur your response.

  • Inserting XML encoded ampersands into tables with OracleXMLSave / XMLLoader

    Hi,
    I've an XMLLoader application based on Steve Muench's design.
    My client has given me XML documents with XML encoded ampersands.
    The XMLloader (OracleXMLSave) is treating the ampersand as a substitution token and is adding chunks of unexpected text when it inserts the strings containing ampersands.
    How do I turn off the substition within the JDBC?
    Thanks,
    Steve.

    If your XML Document looks like:
    <ROWSET>
    <ROW>
    <FIELD1>val-1</FIELD1>
    <FIELD12>val-12</FIELD12>
    </ROW>
    </ROWSET>
    it will insert into just those two
    fields, the rest will be null for
    the purposes of the insert.

  • Inserting values from sql into a JTable

    Good day all,
    Please I need someone's assistance as regard inserting data retrieved from JavaDB into a JTable I created in NetBeanns6.5.
    I have to click on a ViewData Button in order to display data in the JTable below.
    Please I need a simple example to demostrate it.
    Also, how can I resize the column of my JTable so that I can see fully what is retrieved from the database, cos I have one that retrieves but the column is not wide enuogh to accommodate the data.(I did this outside NetBeans)
    Thanks
    Alam Ikenna Winner.

    First, learn to use PreparedStatements. Then we can talk further.

  • SQL server 2014 and VS 2013 - BuilInsert task - truncate a field data of a CSV file and insert it to SQL table.

    Hello everyone,
    To move data from roughly 50 CSV files in a loop to SQL tables (table per CSV file), I've used BulkInsert task in For each loop container.
    Please know, for all different columns of all CSV files, the filed length was specified as varchar(255).
    It worked well for the first 6 files but on 7th file, it has found the data in one of the columns of CSV file, which exceeds the limit of 255 characters. I would like to truncate the data and insert the remaining data for this column. In other words, I would
    like to insert first 255 characters into table for this field and let the package execute further.
    Also, if I would use SQLBulkCopy in Script task, will it be able to resolve this problem? I believe, I would face the similar problem over there too. Although, would like to get confirmation for the same from experts.
    Can you please advise how to get rid of this truncation error?
    Any help would be greatly appreciated.
    Thanks, <b>Ankit Shah</b> <hr> Inkey Solutions, India. <hr> Microsoft Certified Business Management Solutions Professionals <hr> http://ankit.inkeysolutions.com

    Hello! I suggest you add a derived column transformation between Source and Destination, use string functions to extract first 255 characters from the incoming field and send this output to destination field, that ways you can get rid of these sort of issues.
    Useful Links:
    http://sqlage.blogspot.in/2013/07/ssis-how-to-use-derived-column.html
    Good Luck!
    Please Mark This As Answer if it solved your issue.
    Please Vote This As Helpful if it helps to solve your issue

  • How to insert Thai or Chinese Word into table in IQ 16.0?

    Hi guys,
    I need your help. How I can insert chinese/ thai words into table?
    I have a text file with data (save in unicode)
    test你好| test
    When I load this file into a table,
    The result will become
    ÿþt e s t i n g 'O}Y | t e s t
    ÿþt e s t i n g 'O}Y - 14 characters
    t e s t - 10 characters
    How I can load the chinese word properly in the table?
    Thanks.

    Hi .
    You can use these method in sequence as follow:
    1)  CALL METHOD cl_gui_frontend_services=>file_open_dialog
         this method let the user choose a file form his computer ad return the file path (ex.: C:/..../file.txt)
    2) CALL METHOD cl_gui_frontend_services=>gui_upload
         this method upload the file and return the file content.
    After you got the content of the file you can store it inot a custom table .
    There are similira merhod for the inverse problem (file download).
    Regards,
    Fabri

  • Inserting blob image into table

    ora.gif, image001.jpeg are the image names .these are stored in the location D:\oracle\Bfiles
    create directory BFILE_FILES as ‘D:\oracle\Bfiles';
    i want to insert the 2 images into table using blob
    how to create the table and how to insert and how to test that image is inserted or not

    Tom Kyte has it all Here

Maybe you are looking for

  • Network browsing with Samba, Linux and Windows

    I'm having trouble with OSX 10.4.8 and a SMB network. My server is running Linux Debian, and exporting shares via Samba. I have a couple of XP boxes on the network, and they can see all the shares in the workgroup, and can mount them. However, from t

  • Hide/Show a graph based on button click .

    I have to show a graph based on the values selected in the shuttle . The graph should be drawn only when a button( "Show graph") is clicked . My question is 1) If the set the button's action to submit, it resets and empties the selected values in the

  • Sending PM objects (work orders,notifications) to external address

    Hello, I have a question about sending PM object to external address type of recepient. When I select 'send object with note' and pick external address, I only get attached .txt file to be sent (with order number), not the actual order..Whereas the c

  • IPhoto -  Aperture migration

    I have an iPhoto Library of some 20000 photos. When Migrating to Aperture, it seems that the recommendation is to use multiple libraries. I have already loaded the entire iPhoto library and given the differences in the look at feel between the two ap

  • CS javascript books

    I'm learning scripting. I don't suppose there are many books on the subject of javascriping for photoshop? I've avoided the Official JavaScript Reference as that's available as a PDF. I finally tracked down a copy of Photoshop CS2 Speed Clinic, but i