BULK load into Oracle not working with script - oracle

I trie to load a csv file into my oracle database. i use the script below for insert. But it dosen't work. The word 'DATA' in the first line is underlined and comment as "bad syntax" --- Why?
LOAD DATA INFILE 'c:\\SCHWEIZER_DATA_TABLE.csv'
INTO TABLE PEP
CHARACTER SET UTF8
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;

You're trying to use SQL*Loader control file syntax. LOAD is not a SQL command, and you can't use that control file as a statement in SQL Developer.
You can use SQL*Loader if you have the full client or server installed on your PC - the instant client does not include it. If you can put the file on the server you could use an external table.
But SQL Developer has its own data import wizard which you can use to load the data from your file.
Use this wizard to import data into a table. For example, if you right-click the Tables node or a table name in the Connections navigator and select Import Data, you can specify the .source file (such as a spreadsheet or a delimited file) from which to import data. You create a table and import data into it, or import data into an existing table.

Related

SQL LOADER Control File without fields

I'm working on a task to load Database table from a flat file. My database table has 60 columns.
Now, In SQL LOADER control file, Is it mandatory to mention all the 60 fields ?
Is there a way to tell SQL LOADER that all 60 columns should be treated as required without mentioning the fields in the Control File ?
Oracle 12c (and higher versions) offer express mode.
In a few words (quoting the document):
The SQLLoader TABLE parameter triggers express mode. The value of the TABLE parameter is the name of the table that SQLLoader will load. If TABLE is the only parameter specified, then SQL* loader will do the following:
Looks for a data file in the current directory with the same name as the table being loaded that has an extension of ".dat". The upper/lower case used in the name of the data file is the same as the case for the table name specified in the TABLE parameter
Assumes the order of the fields in the data file matches the order of the columns in the table
Assumes the fields are terminated by commas, but there is no enclosure character
(...) order of the fields in the data file matches the order of the columns in the table. The following SQL*Loader command will load the table from the data file.
sqlldr userid=scott table=emp
Notice that no control file is used. After executing the SQL*Loader command, a SELECT from the table will return (...)
I guess that's what you're after.

SQL Loader in Oracle

As I am inserting data from a CSV file to a oracle table using SQL Loader and it is working fine .
LOAD DATA
INFILE DataOut.txt
BADFILE dataFile.bad
APPEND INTO TABLE ASP_Net_C_SHARP_Articles
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
(ID,Name,Category)
above settings are being used to do that but I do not want to specify any of the column name ex. (ID,Name,Category) .
Is this possible or not if yes can anybody tell me how..
In SQL*Loader you need to specify the column names. If you still persist in ignoring the column names in the control file, then I would suggest you to use SQL to "discover" the name of the columns and dynamically generate the control file and wrap it via shell script to make it more automated.
Meanwhile, you can consider External Tables which uses the SQL*Loader engine, so you will still have to perform some dynamic creation here for your input file as suggested above. But you can create a script to scan the input file and dynamically generate the CREATE TABLE..ORGANIZATION EXTERNAL command for you. Then the data becomes available as if it were a table in your database.
You can also partially skip the columns if that would help you, by using FILLER. BOUNDFILLER (available with Oracle 9i and above) can be used if the skipped column's value will be required later again.

How to import excel data into Toad 9.5 table

How to import Excel data into Toad 9.5 Table
I have Toad for Oracle 9.5 and MS Excel 2007. I want to import Excel data into Oracle table using Toad.
Please let me know the steps, how to do that. Thanks
try the following methods
METHOD 1: Click Tools → Import → Import Wizard. This window can be used to import data from various kinds of source files into a table.
METHOD 2: SQL*Loader You can use TOAD's interface to a program from Oracle called sqlloader. Save the Excel file as a comma-delimited (.csv) or tab-delimited (.txt) file. If your data has commas within a text field, save your file as tab-delimited.
Open DBA→Sql Loader Wizard
Choose "build a new control file". Next.
Click "Add". Choose your comma-delimited or tab-delimited file. Next.
Click "Add". Choose your table.
If you are loading a comma-delimited file, type a comma in the "all fields delimited by" combo box. If you are loading a tab-delimited file, select "TAB" from the "all fields delimited by" combo box. Next.
Choose a "load method" noting the following:
TRUNCATE will erase whatever is in the table before loading.
INSERT will insert data if table is empty but will return an error if table has any data in it.
APPEND will insert data without deleting any existing data. You might get duplicates this way but it's a good method if you're trying to get that last line that somehow got munged for some reason or another.
If your file has column headers in its first row, type a 1 in the skip box. Next.
Type a control file name in the control file name box. Next.
Choose either "execute now" to load the data now or "just build the control file" to build the .ctl file. Once you have the ctl file theoretically you don't even need TOAD, as you could just use sqlloader on any machine that has sqlloader and can connect to the database. But why would you want to. :) I choose execute now.
Note: If you are working with Oracle 8.0 or earlier on a Windows 2000 or later OS, uncheck "Watch Progress"
Note: once you have a ctl file you can:
Choose DBA→Sql Loader Wizard
Choose "Use control file". Next.
Select your control file. Next.
Choose "execute now". Finish.
Menu Database then Import and Import Table data.
You have to select the table where are you going to import and then, the more easy way, import from Clipboard (so before proceed to import just ctrl+c your cells in excel).
Usually I copy also the header row, it helps me in checking if columns are matched well.

Oracle: importing records from tab delimited text file to database using pl-sql

I have never worked with Oracle. This is the first time and the job is quite tricky. I have a text file with records delimited with tab. These records are to be imported into a database using pl-sql. I have searched online but the solutions suggests using SQL Loader utility. But the requirement is to do that using sql statements. No command line utility. Preferable the SP or UDF will take file path and database name as input parameters and it will import the records when executed. Is this possible? Can someone provide me sample sql statements or any link that explain this process step by step? Also note that there can be blank records in file. Thanks in advance.
External Tables seems like the best approach.
http://docs.oracle.com/cd/B19306_01/server.102/b14215/et_concepts.htm
UTL_FILE is possible but you would have to write the code to parse the tab delimited text etc.
http://www.allroundautomations.nl/download/NewFeatures7.pdf
check on that file, easy to upload a csv file to a table

Magento: How to load large tables into custom db table?

I have a sql installer file for my custom Magento module. It attempts to insert many thousands of rows into a custom database table but it runs out of memory and the module doesn't install.
Everything works fine if I put the table in manually with normal mysql and there is no 'memory balloon' doing it that way.
I would like my module to work as a module, without having to do anything manually on the command line. Is there any way I can break down my installer file or call some external routine to get the data in?
You could distribute a CSV file containing the data with your module and use MySQL's LOAD DATA command to load the data into the table you create in your upgrade script.
Maybe something like:
$db = Mage::getSingleton('core/resource')->getConnection('core_write');
$filename = Mage::getBaseDir('code').'/local/Your/Module/sql/your_module_setup/foo.csv';
$sql = "LOAD DATA LOCAL INFILE '".$filename."' INTO TABLE foo FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' lines terminated by '\r\n'";
$db->query($sql);
You can, of course, run further queries if you need to process the data somehow.
You can split up creating table and inserts in different upgrade scripts.

Resources