LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Write a script to extract information from db tables (https://www.linuxquestions.org/questions/linux-newbie-8/write-a-script-to-extract-information-from-db-tables-809958/)

LadyAnne 05-25-2010 04:50 AM

Write a script to extract information from db tables
 
Hi

I want to write a script that will extract information from a db table and store that information to a csv file.

Basically, I have imported data into a table, I want to save this data to a csv file for later processing.

How do I connect to the db and extraxt information from the table?

Thank you

longbow0 05-25-2010 05:00 AM

It depends:

1. Which scripts you prefer, Perl, Python or other?
2. What database you are working on, MySQL, SQLite or something else?

Export data from database table into csv is not necessary since many script languages provide database interfaces. For instance, the DBI for Perl.

grail 05-25-2010 05:01 AM

hmmm ... db ... Mysql, Oracle, DB2 ... and the list goes on

You will need to advise the database you are dealing with (I could assume mysql but long track if i am wrong) and you need to also tell us what you
would like to use, ie bash, perl, etc

vikas027 05-25-2010 05:02 AM

use this


For ORACLE
Code:

sqlplus username/password@database_name << END
....
Your SQL Commands
....
END

OR-OR

Code:

sqlplus username/password@database_name @ abc.sql
where abc.sql contains your SQL commands

For MySQL
Code:

mysql -u username -p password database -e "Your SQL Commands"


All times are GMT -5. The time now is 01:44 PM.