How to use ftp file path for SQL loader? - sql-loader

I could not use ftp file path in SQL loader. Help to solve this problem.
LOAD DATA INFILE 'ftp file path'
TRUNCATE INTO TABLE temp
FIELDS TERMINATED BY ',' TRAILING NULLCOLS "(col1,col2)";

The string following the INFILE parameter needs to be the name of a file containing the data. See the documentation here: http://docs.oracle.com/cd/B28359_01/server.111/b28319/ldr_control_file.htm#i1008015
If you are trying to make it a dynamic path to a file, you need to specify it on the command line when you call sql-Loader. In that case see the DATA parameter here: http://docs.oracle.com/cd/B28359_01/server.111/b28319/ldr_params.htm#i1004682

Related

Trouble loading data from txt file into MySQL with LOAD DATA INFILE

I am having a hard time loading my data to MySQL from a text file. I have been attempting to choose the correct delimiters but my file contains column names with each value.
The data is structured like this
{"id":"15","name":"greg","age":"32"}
{"id":"16","name":"jim","age":"42"}
the sql statement I am working on looks something like this currently
LOAD DATA LOCAL INFILE '/xxx.txt' INTO TABLE t1 FIELDS
TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\r\n'(id, name, age);
results are being stored like this
{"id":"16", "name","greg"}
I need to do away with the column name and store the value.
any tips?
Writing a script as suggested by #Shadow will be easier to wrap around but you can check the section on json on this page how to import json-text-xml and csv data into mysql
or
Import JSON to MySQL made easy with the MySQL Shell if you are using MySQL Shell 8.0.13 (GA)

global variable in MySQL

I dont think it is possible but there is no harm to ask.
I have this sql file :
LOAD DATA INFILE 'myfile.csv'
INTO TABLE TCONTACTN4DS
FIELDS TERMINATED BY ";"
LINES TERMINATED BY "\r\n"
if there is no path in the INFILE option, it goest to the data/name_of_the_DB folder to get the file.
I could put any path in the infile but let's assume that I dont know the path that will be used and I dont want those scripts to be changed.
Can I declare (dont know where exactly) a global variable that could be changed to describe the path ? How would I use it if it is possible ?
The mysql documentation on load data infile is very explicit about this, so no, you cannot do this:
The server uses the following rules to locate the file:
If the file name is an absolute path name, the server uses it as given.
If the file name is a relative path name with one or more leading components, the server searches for the file relative to the server's
data directory.
If a file name with no leading components is given, the server looks for the file in the database directory of the default database.
Since load data cannot be used in stored routines either, you cannot even have a workaround for this limitation.

Putting a file content into an sql query?

Hey I have a large database where customers request data that is specific to them. They usually send me the requests in a text or csv file. I was wondering if there is a way to get sql to read that file and take the content and put them into a sql query. This way I don't have to open up that file and copy and paste everything into a sql query.
Steve already answered it.
Let me add few words only.
you can not use the csv, text,excel or anyother format directly in
query for DML/DDL.. you can use file directly only for export/import.
No. MySQL is not designed to do this.
You need an intermediate script that can interpret the files and generate the queries you require.
Yes there is a way to do it: you can import the csv file to your database and then join it with any query you want.
You can load the csv file with an SQL query such as:
LOAD DATA INFILE "/tmp/test.csv"
INTO TABLE test
COLUMNS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES;
You can use other ways to import the data, see: How to import CSV file to MySQL table.
I tried this SQL solution in Ubuntu 14.04 with MySQL 5.6. For this to work you will have to put the test.csv file in the /tmp directory and do a chmod 755 test.csv for it to work. Otherwise MySQL is gives "Permission denied" errors. More about this issue on: LOAD DATA INFILE Error Code : 13

How to transfer csv data to mysql using asp classic

I have a csv file and I need to transfer all its data to MySQL with a click of a button using ASP Classic. I have searched a lot but I couldn't find an answer.
I would upload the file first using something like Pure ASP File Upload (there are alternatives) and then using this solution to read the file and then process the contents How to read CSV files line by line in VBScript
What pee2pee said is the best method, as you will need a script in ASP-Classic that can handle the file upload. MySQL has a default directory it uses to exchange files that you will need to use unless you end up modifying --secure_file_priv and clear it like secure-file-priv = "". If you do this you can put the file anywhere and upload it, otherwise you have to check that variable with SHOW VARIABLES LIKE "secure_file_priv"; and see if it is cleared or locate and only use the directory stored in that variable.
Now this is the opposite of what you need, but I will give you this first. This is how you can get it to export data out of your database back into a CSV again. But keep in mind what I said about about the directory where you export or import files, as it won't work if you don't use the one it allows or unlock it to allow any, but keep in mind that later option is less secure, so you might set it back before deploying to a work environment unless you really trust your users.
SELECT * FROM table
INTO OUTFILE '/bin/export/yourdata.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
And the invert of that would be:
LOAD DATA INFILE 'yourdata.csv'
INTO TABLE t1
(column1, column2, column3, ...)
FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '"'
LINES TERMINATED BY '\n';`
Once you get the directory setup and perhaps file privileges granted if needed, then get the an ASP upload script such as the one mentioned above, and use something like the code I provided to get it going once you have the ability to upload the file via the magic of an ASP Classic HTML button click.

can LOAD DATA INFILE use a giving path instead of the default mysql data path?

I am trying to use LOAD DATA INFILE to upload xls/CSVfile content into mysql database.
the file in which I want to upload is located on a different path that the databases. I don't want to put the xls/CSV file in my same path as my data so I put them into a different path. but it seems that MySQL ignore the path I am providing It always searching for a file located in the data bases directory.
here is my code
LOAD DATA INFILE 'D:\uploads\new_campaign_request.xls'
INTO TABLE new_db.new_campaign
FIELDS TERMINATED BY ',';
How can I get MySQL to search for the file
LOAD DATA INFILE 'D:\\uploads\\new_campaign_request.xls'
INTO TABLE new_db.new_campaign(column_name)
FIELDS TERMINATED BY ',';
User double back slash for load file path and define column name in which data should be loaded