Newbie : bulk insert help

In our application we have few read only tables. I want to generate a script too populate the tables after creating in a separate database. What is the best way to do it. I am very new to oracle.
Any links, tutorials etc will help.
I can execute one insert statement at a time, but there must be far more efficient way to do the same that I don't know.
Any help will be much appreciated.
Thanks,
girirx

If you need to move a lot of data from one database to another, you can consider ...
i) Inserting, using a database link (see SQL Reference for examples on creating it)
ii) using the SQL*Plus COPY command (documented in the SQL*Plus user's guide, but subject to some restrictions and now deprecated)
iii) Writing out the data to a flatfile, then transfering the file (if the other database is on a different machine), then using SQL*Loader/External tables to load it.
iv) Transportable tablespaces.
v) Export/Import utilities
Maybe some other options also. The first (db links) are the simplest to implemnent, as you can combine them with synonyms to make remote tables appear to be local, and from there on it's all simple SQL.

Similar Messages

  • Bulk insert of text file Help PLEASE!

    Hello,
    I am trying to insert the following data into a sql server table.
    11470012 31020141100AMFI2              TENTATIVE APPOINTMENT SET FOR 03/17/2014 AT 10:00 AM
    11470012 31720141000AMFI7              INTERVIEW COMPLETED.
    I am using the following code.
    Bulk Insert dbo.Totalnt
    From 'c:\totalnt.txt'
    with (rowterminator = '\n');
    I get the following error.
    Msg 4866, Level 16, State 7, Line 4
    The bulk load failed. The column is too long in the data file for row 1, column 1. Verify that the field terminator and row terminator are specified correctly.
    Msg 7399, Level 16, State 1, Line 4
    The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
    Msg 7330, Level 16, State 2, Line 4
    Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".
    Please help,
    M. Wilson
    M. Wilson

    Here is the create table statement.  I appreciate your assistance.  I have never imported a file into sql server.
    USE
    [2013ProductionData]
    GO
    /****** Object:  Table [dbo].[Totalnt]    Script Date: 03/31/2014 21:24:17 ******/
    SET
    ANSI_NULLS
    ON
    GO
    SET
    QUOTED_IDENTIFIER
    ON
    GO
    CREATE
    TABLE [dbo].[Totalnt](
    [Cluster] [nvarchar]
    (2)
    NOT
    NULL,
    [Project] [nvarchar]
    (3)
    NOT
    NULL,
    [Case] [nvarchar]
    (2)
    NOT
    NULL,
    [RecType] [nvarchar]
    (1)
    NULL,
    [ContactDateM] [nvarchar]
    (2)
    NULL,
    [ContactDateD] [nvarchar]
    (2)
    NULL,
     [ContactDateY] [nvarchar]
    (4)
    NULL,
    [ContactTimeH] [nvarchar]
    (2)
    NULL,
    [ContactTimeM] [nvarchar]
    (2)
    NULL,
    [ContactTimeAMPM] [nvarchar]
    (2)
    NULL,
    [Who] [nvarchar]
    (2)
    NULL,
    [Result] [nvarchar]
    (1)
    NULL,
    [ApptDateM] [nvarchar]
    (2)
    NULL,
    [ApptDateD] [nvarchar]
    (2)
    NULL,
    [ApptDateY] [nvarchar]
    (4)
    NULL,
    [ApptTimeH] [nvarchar]
    (2)
    NULL,
    [ApptTimeM] [nvarchar]
    (2)
    NULL,
    [ApptTimeAMPM] [nvarchar]
    (2)
    NULL,
    [Comments1] [nvarchar]
    (50)
    NULL,
    [Comments2] [nvarchar]
    (50)
    NULL,
    [Comments3] [nvarchar]
    (50)
    NULL,
    [Comments4] [nvarchar]
    (50)
    NULL
    ON [PRIMARY]
    GO
    M. Wilson

  • Help with BULK Insert

    Hello SQL Buddies,
    I am trying to run a BULK insert.
    Here is my code:
    Code start:
    use Lagerliste
    drop table Import
    use Lagerliste
    create table Import
    TOTALQTY float null,
    PARTNO nvarchar (255) null,
    [DESC] nvarchar (255) null,
    CO nvarchar (255) null,
    BIN nvarchar (255) null,
    PRICE float null,
    DISCOUNT nvarchar (255) null,
    LASTPURC nvarchar (255) null,
    AGECODE nvarchar (255) null,
    MANFPART nvarchar (255) null
    use Lagerliste
    bulk
    insert Import
    from 'D:\FTP\RG\Stockfile.csv'
    with
    formatfile = 'D:\FormatFile\test.xml',
    Errorfile = 'D:\FormatFile\error.txt'
    Code stop..
    My format file code is here:
    Code start:
    <?xml version="1.0"?>
      <BCPFORMAT xmlns = "http://schemas.microsoft.com/sqlserver/2004/bulkload/format"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <RECORD>
          <FIELD ID="1"    xsi:type="CharTerm"        TERMINATOR= ',"'    />
          <FIELD ID="2"    xsi:type="CharTerm"    MAX_LENGTH="255"    TERMINATOR= '","' />
          <FIELD ID="3"    xsi:type="CharTerm"    MAX_LENGTH="255"    TERMINATOR= '","'    />
          <FIELD ID="4"    xsi:type="CharTerm"    MAX_LENGTH="255"    TERMINATOR= '","'    />
          <FIELD ID="5"    xsi:type="CharTerm"    MAX_LENGTH="255"    TERMINATOR= '",'    />
          <FIELD ID="6"    xsi:type="CharTerm"      TERMINATOR= ',"'    />
          <FIELD ID="7"    xsi:type="CharTerm"    MAX_LENGTH="255"    TERMINATOR= '","'    />
          <FIELD ID="8"    xsi:type="CharTerm"    MAX_LENGTH="255"    TERMINATOR= '","'    />
          <FIELD ID="9"    xsi:type="CharTerm"    MAX_LENGTH="255"    TERMINATOR= '","'    />
          <FIELD ID="10"    xsi:type="CharTerm"    MAX_LENGTH="255"    TERMINATOR= '"'        />
        </RECORD>
        <ROW>
          <COLUMN SOURCE="1" NAME="TOTALQTY"    xsi:type="SQLFLT8"/>
          <COLUMN SOURCE="2" NAME="PARTNO"    xsi:type="SQLNVARCHAR"/>
          <COLUMN SOURCE="3" NAME="DESC"        xsi:type="SQLNVARCHAR"/>
          <COLUMN SOURCE="4" NAME="CO"        xsi:type="SQLNVARCHAR"/>
          <COLUMN SOURCE="5" NAME="BIN"        xsi:type="SQLNVARCHAR"/>
          <COLUMN SOURCE="6" NAME="PRICE"        xsi:type="SQLFLT8"/>
          <COLUMN SOURCE="7" NAME="DISCOUNT"    xsi:type="SQLNVARCHAR"/>
          <COLUMN SOURCE="8" NAME="LASTPURC"    xsi:type="SQLNVARCHAR"/>
          <COLUMN SOURCE="9" NAME="AGECODE"    xsi:type="SQLNVARCHAR"/>
          <COLUMN SOURCE="10" NAME="MANFPART"    xsi:type="SQLNVARCHAR"/>
        </ROW>
      </BCPFORMAT>
    Code stop..
    If i run the code it says:
    Msg 4832, Level 16, State 1, Line 20
    Bulk load: An unexpected end of file was encountered in the data file.
    Msg 7399, Level 16, State 1, Line 20
    The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
    Msg 7330, Level 16, State 2, Line 20
    Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".
    And the error file says:
    Row 473629 File Offset 42503226 ErrorFile Offset 0 - HRESULT 0x80004005
    If i then in my bulk insert adds: "Lastrow = '473629' it works all fine. So it will mean that it gets an error at the last line where there is no more data? But this sql query should run every day, so i have to do so it dont gets the error.
    Can someone help me?
    Looking forward to an answer, i hope someone have a solution.
    Regards Christian.

    Try the below format file,
    <?xml version="1.0"?>
    <BCPFORMAT xmlns = "http://schemas.microsoft.com/sqlserver/2004/bulkload/format"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <RECORD>
    <FIELD ID="1" xsi:type="CharTerm" TERMINATOR= ',"' />
    <FIELD ID="2" xsi:type="CharTerm" MAX_LENGTH="255" TERMINATOR= '","' />
    <FIELD ID="3" xsi:type="CharTerm" MAX_LENGTH="255" TERMINATOR= '","' />
    <FIELD ID="4" xsi:type="CharTerm" MAX_LENGTH="255" TERMINATOR= '","' />
    <FIELD ID="5" xsi:type="CharTerm" MAX_LENGTH="255" TERMINATOR= '",' />
    <FIELD ID="6" xsi:type="CharTerm" TERMINATOR= ',"' />
    <FIELD ID="7" xsi:type="CharTerm" MAX_LENGTH="255" TERMINATOR= '","' />
    <FIELD ID="8" xsi:type="CharTerm" MAX_LENGTH="255" TERMINATOR= '","' />
    <FIELD ID="9" xsi:type="CharTerm" MAX_LENGTH="255" TERMINATOR= '","' />
    <FIELD ID="10" xsi:type="CharTerm" MAX_LENGTH="255" TERMINATOR= '"\r\n' />
    </RECORD>
    <ROW>
    <COLUMN SOURCE="1" NAME="TOTALQTY" xsi:type="SQLFLT8"/>
    <COLUMN SOURCE="2" NAME="PARTNO" xsi:type="SQLNVARCHAR"/>
    <COLUMN SOURCE="3" NAME="DESC" xsi:type="SQLNVARCHAR"/>
    <COLUMN SOURCE="4" NAME="CO" xsi:type="SQLNVARCHAR"/>
    <COLUMN SOURCE="5" NAME="BIN" xsi:type="SQLNVARCHAR"/>
    <COLUMN SOURCE="6" NAME="PRICE" xsi:type="SQLFLT8"/>
    <COLUMN SOURCE="7" NAME="DISCOUNT" xsi:type="SQLNVARCHAR"/>
    <COLUMN SOURCE="8" NAME="LASTPURC" xsi:type="SQLNVARCHAR"/>
    <COLUMN SOURCE="9" NAME="AGECODE" xsi:type="SQLNVARCHAR"/>
    <COLUMN SOURCE="10" NAME="MANFPART" xsi:type="SQLNVARCHAR"/>
    </ROW>
    </BCPFORMAT>
    Refer
    http://stackoverflow.com/questions/8530353/sql-bulk-insert-xml-format-file-with-double-quotes-in-terminator
    http://technet.microsoft.com/en-us/library/ms191234(v=sql.105).aspx
    Regards, RSingh

  • I need help on bulk inserts....

    Hello,
    I need help on bulk inserts. I have heard about it but don't know how to do it and how to specify the number of records to be inserted at a time.
    Can anyone please help me out?
    For example: I would like to insert in my TEST_TABLE a group of data at tha same time...
    INSERT INTO TEST_TABLE VALUES ( (1, 'xxx', 'www'), (2, 'yyy', 'hhh'), (3, 'aaa', 'kkk') )
    I using Oracle 10g .
    Tks!!
    Message was edited by:
    user532944
    Message was edited by:
    user532944

    But I want to insert a group of data at the same time, with one sql instruction...
    I don´t know if exists this SQL command...I just know that I can insert
    string sqlStmt = "INSERT INTO TESTE VALUES (:x, :x, :x)";
    stmt = con->createStatement (sqlStmt);
    But and this instruction ?? In MYSql I can do it!!
    string sqlStmt = "INSERT INTO TESTE VALUES ((:x, :x, :x), (:x, :x, :x));
    Message was edited by:
    user532944

  • SQL2K, XML Bulk Insert woes. Please Help

    I have Win2k3 server with latest sp's. I have mssql 2k
    enterprise with SP4. I have installed sqlxml3.0 sp 3. I've tried
    the examples in the documentation but cannot get this to work. I
    really need to be able to do a bulk insert using the xml file below
    through a coldfusion query. I saw an example online how to do it
    with CF and followed the example to the letter and get this error:
    Could not bulk insert. Unknown version of format file
    'D:\Websites\globalFunctions]getEventPerformersMapping.xml'.
    My XML file ("getEventPerformers.txt") looks like this:
    <ROOT>
    <EventPerformer>
    <EventID>448410</EventID>
    <PerformerID>3160</PerformerID>
    <PerformerName>Lion King</PerformerName>
    </EventPerformer>
    <EventPerformer>
    <EventID>448412</EventID>
    <PerformerID>3160</PerformerID>
    <PerformerName>Lion King</PerformerName>
    </EventPerformer>
    </ROOT>
    The format file I'm using (that I got from the online
    example) is:
    <?xml version="1.0" ?>
    <Schema xmlns="urn:schemas-microsoft-com:xml-data"
    xmlns:dt="urn:schemas-microsoft-com:xml:datatypes"
    xmlns:sql="urn:schemas-microsoft-com:xml-sql" >
    <ElementType name="EventID" dt:type="i8" />
    <ElementType name="PerformerID" dt:type="int" />
    <ElementType name="PerformerName" dt:type="string" />
    <ElementType name="ROOT" sql:is-constant="1">
    <element type="EventPerformer" />
    </ElementType>
    <ElementType name="EventPerformer"
    sql:relation="tbl_EventPerformers">
    <element type="EventID" sql:field="EventID" />
    <element type="PerformerID" sql:field="PerformerID" />
    <element type="PerformerName" sql:field="PerformerName"
    />
    </ElementType>
    </Schema>
    My db table structure is this:
    EventID - bigint - Primary Key
    PerformerID - int
    PerformerName varchar(100)
    In the msdn docs there is an example that uses VB script
    create a SQLXMLBulkLoad.SQLXMLBulkload.3.0 object, but I couldn't
    get that to work either.
    Someone please help!

    I've got the same problem:
    We're porting from Orion to Tomcat and the following erro occurs at the following line:
         response.sendRedirect("asistente/frmresultat.jsp?ant=false");

  • Bulk Insert, Domain Based Attributes

    Hi
    I have a product model similar to the ProductSamplemodel that ships with MDS. i.e. Product Category, Product Sub Category entities. Both of these entities have been created to automatically generate a code - as a code does not exist in the business only a description.
    The product entity has both the category and sub category attributes as domain-based attributes which results in storing the code physically and also displaying the description.
    From a bulk insert scenario where the business has a number of new products that they want to add (due to a new range) I was suggesting that they use the Excel AddIn. This would allow them to cut and paste the data into the product entity. However as the category
    and sub category are domain-based Attributes they will need to know the ID – they will only know the name.
    From a MDS functionality point of view is it possible to get it to look up the code from the name?
    My current understanding on how to achieve this would mean I would need to have both code and name attributes on the Product entity for Category and Sub. The name attributes would be free text and the code attribute would be populated from a business rule.
    Downside to this approach is that you lose out on the nice dropdown pick list and the user does not know what a valid entry is as they can no longer select one.
    How is this usually implemented or handled in MDS?
    Cheers
    Kevin

    Hi Kevin,
    Another approach (if the one above does NOT suit you).
    Once again, as Reza suggested and  I agree with him totally, this is a job for SSIS.
    For what it's worth...
    Whilst I understand what you are trying to do, may I suggest another approach. What concerns me is users adding data willy-nilly and that YOU have no control as to what is going on. Secondly, what is more disconcerting is the thought of losing relational
    integrity, especially if you are using derived hierarchies within MDS. 
    I would handle this in a different manner, using SSIS and a filesystem watcher.
    Let the users submit their spreadsheets (with their updates) to a common directory on the server. Implement a .NET FileSystemWatcher (this takes 10 minutes for a Newbie). This file system watcher will launch a DOS batch file on the arrival of a spreadsheet
    within the given directory. The DOS batch file  fires a DTS exec to start an SSIS package. This package together with SQL Server procedures will ensure that the correct codes are obtained and the attribute data is correctly inserted into the correct Entities(with
    the correct relationships).
    While this sounds vague, I do it all the time. I am more than prepared to help you get going, should wish any assistance. I KNOW that this is not the answer that you are looking for HOWEVER it is perhaps the most effective.
    sincerest regards
    Steve Simon SQL Server MVP
    [email protected]

  • How can I debug a Bulk Insert error?

    I'm loading a bunch of files into SQL server.  All work fine, but one keeps erroring out on me.  All files should be exactly the same in structure, but they have different dates, and other different financial metrics, but the structure and field
    names should be exactly the same.  Nevertheless, one keeps konking out, and throwing this error.
    Msg 4832, Level 16, State 1, Line 1
    Bulk load: An unexpected end of file was encountered in the data file.
    Msg 7399, Level 16, State 1, Line 1
    The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
    Msg 7330, Level 16, State 2, Line 1
    Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".
    The ROWTERMINATOR should be CRLF, and when you look at it in Notepad++ that's what it looks like, but it must be something else, because I keep getting errors here.  I tried the good old:  ROWTERMINATOR='0x0a'
    That works on all files, but one, so there's something funky going on here, and I need to see what SQL Server is really doing.
    Is there some way to print out a log, or look at a log somewhere?
    Thanks!!
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    The first thing to try is to see if BCP likes the file. BCP and BULK INSERT adhere to the same spec, but they are different implementations, but there are subtle differences.
    There is an ERRORFILE option, but it more helps when there is bad data.
    You can also use the BATCHSIZE option to see how many records in the file it swallows, before things go bad. FIRSTROW and LASTROW can also help.
    All in all, it can be quite tedious find that single row where things are different - and where BULK INSERT loses sync entirely. Keep in mind that it reads fields on by one, and it there is one field terminator to few on a line, it will consume the line
    feed at the end of the line as data.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • 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.

  • [Forum FAQ] How to use multiple field terminators in BULK INSERT or BCP command line

    Introduction
    Some people want to know if we can have multiple field terminators in BULK INSERT or BCP commands, and how to implement multiple field terminators in BULK INSERT or BCP commands.
    Solution
    For character data fields, optional terminating characters allow you to mark the end of each field in a data file with a field terminator, as well as the end of each row with a row terminator. If a terminator character occurs within the data, it is interpreted
    as a terminator, not as data, and the data after that character is interpreted and belongs to the next field or record. I have done a test, if you use BULK INSERT or BCP commands and set the multiple field terminators, you can refer to the following command.
    In Windows command line,
    bcp <Databasename.schema.tablename> out “<path>” –c –t –r –T
    For example, you can export data from the Department table with bcp command and use the comma and colon (,:) as one field terminator.
    bcp AdventureWorks.HumanResources.Department out C:\myDepartment.txt -c -t ,: -r \n –T
    The txt file as follows:
    However, if you want to bcp by using multiple field terminators the same as the following command, which will still use the last terminator defined by default.
    bcp AdventureWorks.HumanResources.Department in C:\myDepartment.txt -c -t , -r \n -t: –T
    The txt file as follows:
    When multiple field terminators means multiple fields, you use the below comma separated format,
    column1,,column2,,,column3
    In this occasion, you only separate 3 fields (column1, column2 and column3). In fact, after testing, there will be 6 fields here. That is the significance of a field terminator (comma in this case).
    Meanwhile, using BULK INSERT to import the data of the data file into the SQL table, if you specify terminator for BULK import, you can only set multiple characters as one terminator in the BULK INSERT statement.
    USE <testdatabase>;
    GO
    BULK INSERT <your table> FROM ‘<Path>’
     WITH (
    DATAFILETYPE = ' char/native/ widechar /widenative',
     FIELDTERMINATOR = ' field_terminator',
    For example, using BULK INSERT to import the data of C:\myDepartment.txt data file into the DepartmentTest table, the field terminator (,:) must be declared in the statement.
    In SQL Server Management Studio Query Editor:
    BULK INSERT AdventureWorks.HumanResources.DepartmentTest FROM ‘C:\myDepartment.txt’
     WITH (
    DATAFILETYPE = ‘char',
    FIELDTERMINATOR = ‘,:’,
    The new table contains like as follows:  
    We could not declare multiple field terminators (, and :) in the Query statement,  as the following format, a duplicate error will occur.
    In SQL Server Management Studio Query Editor:
    BULK INSERT AdventureWorks.HumanResources.DepartmentTest FROM ‘C:\myDepartment.txt’
     WITH (
    DATAFILETYPE = ‘char',
    FIELDTERMINATOR = ‘,’,
    FIELDTERMINATOR = ‘:’
    However, if you want to use a data file with fewer or more fields, we can implement via setting extra field length to 0 for fewer fields or omitting or skipping more fields during the bulk copy procedure.  
    More Information
    For more information about filed terminators, you can review the following article.
    http://technet.microsoft.com/en-us/library/aa196735(v=sql.80).aspx
    http://social.technet.microsoft.com/Forums/en-US/d2fa4b1e-3bd4-4379-bc30-389202a99ae2/multiple-field-terminators-in-bulk-insert-or-bcp?forum=sqlgetsta
    http://technet.microsoft.com/en-us/library/ms191485.aspx
    http://technet.microsoft.com/en-us/library/aa173858(v=sql.80).aspx
    http://technet.microsoft.com/en-us/library/aa173842(v=sql.80).aspx
    Applies to
    SQL Server 2012
    SQL Server 2008R2
    SQL Server 2005
    SQL Server 2000
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

    Thanks,
    Is this a supported scenario, or does it use unsupported features?
    For example, can we call exec [ReportServer].dbo.AddEvent @EventType='TimedSubscription', @EventData='b64ce7ec-d598-45cd-bbc2-ea202e0c129d'
    in a supported way?
    Thanks! Josh

  • BULK INSERT from a text (.csv) file - read only specific columns.

    I am using Microsoft SQL 2005, I need to do a BULK INSERT from a .csv I just downloaded from paypal.  I can't edit some of the columns that are given in the report.  I am trying to load specific columns from the file.
    bulk insert Orders
    FROM 'C:\Users\*******\Desktop\DownloadURL123.csv'
       WITH
                  FIELDTERMINATOR = ',',
                    FIRSTROW = 2,
                    ROWTERMINATOR = '\n'
    So where would I state what column names (from row #1 on the .csv file) would be used into what specific column in the table.
    I saw this on one of the sites which seemed to guide me towards the answer, but I failed.. here you go, it might help you:
    FORMATFILE [ = 'format_file_path' ]
    Specifies the full path of a format file. A format file describes the data file that contains stored responses created using the bcp utility on the same table or view. The format file should be used in cases in which:
    The data file contains greater or fewer columns than the table or view.
    The columns are in a different order.
    The column delimiters vary.
    There are other changes in the data format. Format files are usually created by using the bcp utility and modified with a text editor as needed. For more information, see bcp Utility.

    Date, Time, Time Zone, Name, Type, Status, Currency, Gross, Fee, Net, From Email Address, To Email Address, Transaction ID, Item Title, Item ID, Buyer ID, Item URL, Closing Date, Reference Txn ID, Receipt ID,
    "04/22/07", "12:00:21", "PDT", "Test", "Payment Received", "Cleared", "USD", "321", "2.32", "3213', "[email protected]", "[email protected]", "", "testing", "392302", "jdal32", "http://ddd.com", "04/22/03", "", "",
    "04/22/07", "12:00:21", "PDT", "Test", "Payment Received", "Cleared", "USD", "321", "2.32", "3213', "[email protected]", "[email protected]", "", "testing", "392932930302", "jejsl32", "http://ddd.com", "04/22/03", "", "",
    Do you need more than 2 rows? I did not include all the columns from the actual csv file but most of it, I am planning on taking to the first table these specfic columns: date, to email address, transaction ID, item title, item ID, buyer ID, item URL.
    The other table, I don't have any values from here because I did not list them, but if you do this for me I could probably figure the other table out.
    Thank you very much.

  • BULK INSERT into View w/ Instead Of Trigger - DML ERROR LOGGING Issue

    Oracle 10.2.0.4
    I cannot figure out why I cannot get bulk insert errors to aggregate and allow the insert to continue when bulk inserting into a view with an Instead of Trigger. Whether I use LOG ERRORS clause or I use SQL%BULK_EXCEPTIONS, the insert works until it hits the first exception and then exits.
    Here's what I'm doing:
    1. I'm bulk inserting into a view with an Instead of Trigger on it that performs the actual updating on the underlying table. This table is a child table with a foreign key constraint to a reference table containing the primary key. In the Instead of Trigger, it attempts to insert a record into the child table and I get the following exception: +5:37:55 ORA-02291: integrity constraint (FK_TEST_TABLE) violated - parent key not found+, which is expected, but the error should be logged in the table and the rest of the inserts should complete. Instead the bulk insert exits.
    2. If I change this to bulk insert into the underlying table directly, it works, all errors get put into the error logging table and the insert completes all non-exception records.
    Here's the "test" procedure I created to test my scenario:
    View: V_TEST_TABLE
    Underlying Table: TEST_TABLE
    PROCEDURE BulkTest
    IS
    TYPE remDataType IS TABLE of v_TEST_TABLE%ROWTYPE INDEX BY BINARY_INTEGER;
    varRemData remDataType;
    begin
    select /*+ DRIVING_SITE(r)*/ *
    BULK COLLECT INTO varRemData
    from TEST_TABLE@REMOTE_LINK
    where effectiveday < to_date('06/16/2012 04','mm/dd/yyyy hh24')
    and terminationday > to_date('06/14/2012 04','mm/dd/yyyy hh24');
    BEGIN
    FORALL idx IN varRemData.FIRST .. varRemData.LAST
    INSERT INTO v_TEST_TABLE VALUES varRemData(idx) LOG ERRORS INTO dbcompare.ERR$_TEST_TABLE ('INSERT') REJECT LIMIT UNLIMITED;
    EXCEPTION WHEN others THEN
    DBMS_OUTPUT.put_line('ErrorCode: '||SQLCODE);
    END;
    COMMIT;
    end;
    I've reviewed Oracle's documentation on both DML logging tools and neither has any restrictions (at least that I can see) that would prevent this from working correctly.
    Any help would be appreciated....
    Thanks,
    Steve

    Thanks, obviously this is my first post, I'm desperate to figure out why this won't work....
    This code I sent is only a test proc to try and troubleshoot the issue, the others with the debug statement is only to capture the insert failing and not aggregating the errors, that won't be in the real proc.....
    Thanks,
    Steve

  • How to use BULK INSERT for a data from a cursor?

    Oracle 10G enterprise edition.
    I tried to Bulk insert datas returning from a cursor, its returning error.
    PLS-00302: component 'LAST' must be declared
    I need some help to use the Bulk INSERT here.Can any one help me to specify what error i have made?
    CREATE OR REPLACE PROCEDURE HOT_ADMIN.get_search_keyword_stats_prc
    IS
    CURSOR c_get_scenarios
    IS
    SELECT a.*,ROWNUM rnum
    FROM (
    SELECT TRUNC(r.search_date) sdate,
    r.search_hits hits,
    r.search_type stype,
    r.search_qualification qual,
    r.search_location loc,
    r.search_town stown,
    r.search_postcode pcode,
    r.search_college college,
    r.search_colname colname,
    r.search_text text,
    r.affiliate_id affiliate,
    r.search_study_mode smode,
    r.location_hint hint,
    r.search_posttown ptown,
    COUNT(1) cnt
    FROM w_search_headers r
    WHERE search_text IS NOT NULL
    AND NVL(search_type,' ') <> 'C'
    AND TRUNC(search_date)= TO_DATE(TO_CHAR(SYSDATE-1,'DD-MON-RRRR'))
    GROUP BY TRUNC(r.search_date),
    r.search_hits,
    r.search_type,
    r.search_qualification,
    r.search_location,
    r.search_town,
    r.search_postcode,
    r.search_college,
    r.search_colname,
    r.search_text,
    r.affiliate_id,
    r.search_study_mode,
    r.location_hint,
    r.search_posttown
    ORDER BY cnt desc
    ) a
    WHERE ROWNUM <=1000;
    lc_get_data c_get_scenarios%ROWTYPE;
    BEGIN
    OPEN c_get_scenarios;
    FETCH c_get_scenarios into lc_get_data;
    CLOSE c_get_scenarios;
    FORALL i IN 1..lc_get_data.last
    INSERT INTO W_SEARCH_SCENARIO_STATS VALUES ( i.sdate,
    i.hits,
    i.stype,
    i.qual,
    i.loc,
    i.stown,
    i.pcode,
    i.college,
    i.colname,
    i.text,
    i.affiliate,
    i.smode,
    i.hint,
    i.ptown,
    i.cnt
    COMMIT;
    END;

    This isn't what you asked, but I've generally found it helpful to list the columns in an INSERT statement before the values. It is of course optional, but useful for reference when looking at the statement later

  • Bulk Insert using Script Task in SSIS

    Hi guys,
    Please I have about 300Million rows of data I want to load from a remote SQL server into another SQL server. The problem is that the data takes forever to load and I have a time line.
    I was wondering if there is a way in can do bulk insert for this or maybe if I can get a code that I can use to load the data faster.
    Please I really need your help as my job depends on this.
    me

    CREATE TABLE [dbo].[post_tran](
    [post_tran_id] [bigint] NOT NULL,
    [post_tran_cust_id] [bigint] NOT NULL,
    [settle_entity_id] [dbo].[POST_ID] NULL,
    [batch_nr] [int] NULL,
    [prev_post_tran_id] [bigint] NULL,
    [next_post_tran_id] [bigint] NULL DEFAULT ((0)),
    [sink_node_name] [dbo].[POST_NAME] NULL,
    [tran_postilion_originated] [dbo].[POST_BOOL] NOT NULL,
    [tran_completed] [dbo].[POST_BOOL] NOT NULL,
    [message_type] [char](4) NOT NULL,
    [tran_type] [char](2) NULL,
    [tran_nr] [bigint] NOT NULL,
    [system_trace_audit_nr] [char](6) NULL,
    [rsp_code_req] [char](2) NULL,
    [rsp_code_rsp] [char](2) NULL,
    [abort_rsp_code] [char](2) NULL,
    [auth_id_rsp] [varchar](10) NULL,
    [auth_type] [numeric](1, 0) NULL,
    [auth_reason] [numeric](1, 0) NULL,
    [retention_data] [varchar](999) NULL,
    [acquiring_inst_id_code] [varchar](11) NULL,
    [message_reason_code] [char](4) NULL,
    [sponsor_bank] [char](8) NULL,
    [retrieval_reference_nr] [char](12) NULL,
    [datetime_tran_gmt] [datetime] NULL,
    [datetime_tran_local] [datetime] NOT NULL,
    [datetime_req] [datetime] NOT NULL,
    [datetime_rsp] [datetime] NULL,
    [realtime_business_date] [datetime] NOT NULL,
    [recon_business_date] [datetime] NOT NULL,
    [from_account_type] [char](2) NULL,
    [to_account_type] [char](2) NULL,
    [from_account_id] [varchar](28) NULL,
    [to_account_id] [varchar](28) NULL,
    [tran_amount_req] [dbo].[POST_MONEY] NULL,
    [tran_amount_rsp] [dbo].[POST_MONEY] NULL,
    [settle_amount_impact] [dbo].[POST_MONEY] NULL,
    [tran_cash_req] [dbo].[POST_MONEY] NULL,
    [tran_cash_rsp] [dbo].[POST_MONEY] NULL,
    [tran_currency_code] [dbo].[POST_CURRENCY] NULL,
    [tran_tran_fee_req] [dbo].[POST_MONEY] NULL,
    [tran_tran_fee_rsp] [dbo].[POST_MONEY] NULL,
    [tran_tran_fee_currency_code] [dbo].[POST_CURRENCY] NULL,
    [tran_proc_fee_req] [dbo].[POST_MONEY] NULL,
    [tran_proc_fee_rsp] [dbo].[POST_MONEY] NULL,
    [tran_proc_fee_currency_code] [dbo].[POST_CURRENCY] NULL,
    [settle_amount_req] [dbo].[POST_MONEY] NULL,
    [settle_amount_rsp] [dbo].[POST_MONEY] NULL,
    [settle_cash_req] [dbo].[POST_MONEY] NULL,
    [settle_cash_rsp] [dbo].[POST_MONEY] NULL,
    [settle_tran_fee_req] [dbo].[POST_MONEY] NULL,
    [settle_tran_fee_rsp] [dbo].[POST_MONEY] NULL,
    [settle_proc_fee_req] [dbo].[POST_MONEY] NULL,
    [settle_proc_fee_rsp] [dbo].[POST_MONEY] NULL,
    [settle_currency_code] [dbo].[POST_CURRENCY] NULL,
    [icc_data_req] [text] NULL,
    [icc_data_rsp] [text] NULL,
    [pos_entry_mode] [char](3) NULL,
    [pos_condition_code] [char](2) NULL,
    [additional_rsp_data] [varchar](25) NULL,
    [structured_data_req] [text] NULL,
    [structured_data_rsp] [text] NULL,
    [tran_reversed] [char](1) NULL DEFAULT ((0)),
    [prev_tran_approved] [dbo].[POST_BOOL] NULL,
    [issuer_network_id] [varchar](11) NULL,
    [acquirer_network_id] [varchar](11) NULL,
    [extended_tran_type] [char](4) NULL,
    [ucaf_data] [varchar](33) NULL,
    [from_account_type_qualifier] [char](1) NULL,
    [to_account_type_qualifier] [char](1) NULL,
    [bank_details] [varchar](31) NULL,
    [payee] [char](25) NULL,
    [card_verification_result] [char](1) NULL,
    [online_system_id] [int] NULL,
    [participant_id] [int] NULL,
    [opp_participant_id] [int] NULL,
    [receiving_inst_id_code] [varchar](11) NULL,
    [routing_type] [int] NULL,
    [pt_pos_operating_environment] [char](1) NULL,
    [pt_pos_card_input_mode] [char](1) NULL,
    [pt_pos_cardholder_auth_method] [char](1) NULL,
    [pt_pos_pin_capture_ability] [char](1) NULL,
    [pt_pos_terminal_operator] [char](1) NULL,
    [source_node_key] [varchar](32) NULL,
    [proc_online_system_id] [int] NULL,
    [from_account_id_cs] [int] NULL,
    [to_account_id_cs] [int] NULL,
    [pos_geographic_data] [char](5) NULL,
    [payer_account_id] [char](5) NULL,
    [cvv_available_at_auth] [varchar](30) NULL,
    [cvv2_available_at_auth] [varchar](30) NULL
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    GO
    me

  • Bulk insert security

    I have an SSIS package on server A which calls a stored procedure on server B.  The stored procedure runs the bulk insert command to load an XML file.  The service account which SQL Server Services is running under on server A is a sysadmin on
    Server B, and has permissions to the file.  When I run the package I am getting "Cannot bulk load because the file could not be opened.  Operating system error code 5(Access is denied).  
    If I create the server B database on server A, so that the SSIS package and the database where I call the bulk insert command from are both on server A, and run the SSIS package it runs successfully.
    When everything is on the same server it works, so whatever account it is using has the necessary permissions.  But that account must not have the necessary permissions on server B.  What other accounts would need permissions on server B?
    Thanks for the help.

    If you are logged in with a Windows account, BULK INSERT impersonates that user, and that user's Windows permissions apply. If you are logged in with an SQL login, the permissions of the service account applies.
    Keep in mind that, the login on server B is a new login. There could be a login mapping set up. Also, several levels of impersonation may not work out well.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Bulk Insert Issue with BCP

    I'm running SQL Server 2008 R2 and trying to test out bcp in one of our databases. For almost all the tables, the bcp and bulk insert work fine using similar commands below.  However on a few tables I am experiencing an issue when trying to Bulk Insert
    in.
    Here are the details:
    This is the bcp command to export out the data (via simple batch file):
     1.)
    SET OUTPUT=K:\BCP_FIN_Test
    SET ERRORLOG=C:\Temp\BCP_Error_Log
    SET TIMINGS=C:\Temp\BCP_Timings
    bcp "SELECT * FROM FS84RPT.dbo.PS_PO_LINE Inner Join FS84RPT.[dbo].[PS_RECV_LN_ACCTG] on PS_PO_LINE.BUSINESS_UNIT = PS_RECV_LN_ACCTG.BUSINESS_UNIT_PO and PS_PO_LINE.PO_ID= PS_RECV_LN_ACCTG.PO_ID and PS_PO_LINE.LINE_NBR= PS_RECV_LN_ACCTG.LINE_NBR WHERE
    PS_RECV_LN_ACCTG.FISCAL_YEAR = '2014' and PS_RECV_LN_ACCTG.ACCOUNTING_PERIOD BETWEEN '9' AND '11' " queryout %OUTPUT%\PS_PO_LINE.txt -e %ERRORLOG%\PS_PO_LINE.err -o %TIMINGS%\PS_PO_LINE.txt -T -N
     2.)
    BULK INSERT PS_PO_LINE FROM 'K:\BCP_FIN_Test\PS_PO_LINE.txt' WITH (DATAFILETYPE = 'widenative')
    Msg 4869, Level 16, State 1, Line 1
    The bulk load failed. Unexpected NULL value in data file row 2, column 22. The destination column (CNTRCT_RATE_MULT) is defined as NOT NULL.
    Msg 4866, Level 16, State 4, Line 1
    The bulk load failed. The column is too long in the data file for row 3, column 22. Verify that the field terminator and row terminator are specified correctly.
    Msg 7399, Level 16, State 1, Line 1
    The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
    Msg 7330, Level 16, State 2, Line 1
    Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".
    I've tried a few different things including trying to export as character and import as BULK INSERT PS_PO_LINE FROM 'K:\BCP_FIN_Test\PS_PO_LINE.txt' WITH (DATAFILETYPE = 'char')
    But no luck
    Appreciate help

    It seems that the target table does not match your expectations.
    Since I don't know exactly what you are doing, I will have to resort to guesses.
    I note that you export query goes:
      SELECT * FROM FS84RPT.dbo.PS_PO_LINE Inner Join
    And then you are importing into a table called PS_PO_LINE as well. But for your operation to make sense the import PS_PO_LINE must not only have the columns from the PS_PO_LINE, but also all columns from PS_RECV_LN_ACCTG. Maybe your SELECT should read
      SELECT PS_PO_LINE.* FROM FS84RPT.dbo.PS_PO_LINE Inner Join
    or use an EXISTS clause to add the filter of PS_RECV_LN_ACCTG table. (Assuming that it appears in the query for filtering only.)
    Erland Sommarskog, SQL Server MVP, [email protected]

Maybe you are looking for

  • Macbook air 2014 wine spill, back to life

    Hello I'm not sure if anyone would have any experience of this, but in July, after 8 weeks of owning my macbook air, it was in the firing line after I knocked a glass of wine over.  Only a very small amount went on the mac, however by the time I'd go

  • Get SlidingPanelsContent ID

    Hi, I need to know the next or the prewiex SlidingPanelsContent ID when click the link next or preview. If possible to a javascript function! Thanks a lot MY CODE: <a href="#" onClick="sp.showPreviousPanel(); return false;"> <div class="next-colli"><

  • HTMLLoader - Embed local .html in remote .html using iframe.sandboxRoot and iframe.documentRoot ?

    Hi! This already took me hours of research and testing but I might misunderstand this part of the Adobe AIR documentation: http://help.adobe.com/en_US/AIR/1.5/devappshtml/WS5b3ccc516d4fbf351e63e3d118666ade46-7f08. html#WS5b3ccc516d4fbf351e63e3d118666

  • YouTube playlist on Ipad 2

    Hi everyone, Does anyone know how to play a complete playlist on YouTube with the Ipad-2? Thanks for help .

  • Selector bug?

    Hello. I've written sample socket server on Java using java.nio.* and expirienced problem that seemed to be solved here: [http://bugs.sun.com/view_bug.do?bug_id=6403933]. Behaviour is like described in bug report: after some connections Selector does