Is it possible to export the results of a query (a select statement with multiple joins) to an Excel spreadsheet without having to manually export the data, so the script runs the query and also executes the transfer to Excel?
You can use this code in SQL*Plus and Oracle SQL Developer.
Create a .sql file. (Create a text file and change the extension to .sql)
Put the following code in the file:
set heading off
spool excel_1.xls
select
first_name||chr(9)||last_name
from
employees;
spool off
Since I have made use of employees table from HR schema, connect hr schema.
Execute the script file
#<filename>.sql
you can use any number of columns but each should be separated as shown in above example.
Related
I am trying to export multiple tables to individual .csv files (approximately 70 tables need to be exported) in oracle SQL Developer. As of right now, I am running through this process
Run Query
SELECT * FROM TABLE;
From the result window, click "Export Query Results", choosing the encoding and delimiter and saving it as a .csv
This is a lengthy process, and takes around a minute per table (lots of information!), I can't help but think there has to be an easier, more efficient way of doing this. I just can't find any information.
Tools - Database Export
Pick your file format (csv) and directory.
I have Excel shown in the picture, but there's a dozen formats to choose from, including delimited and CSV. If you want European CSV (;), pick delimited and change the delimiter to ;
Then pick your 70 tables.
I think the best solution for mass table export is not to use the embedded SQL Developper export tool, but use the SPOOL SQL option.
you can check here how to generate SPOOL files:
How do I spool to a CSV formatted file using SQLPLUS?
I have two SQL queries and i am trying to output the results to multiple sheets in one excel
file. Is it achievable?
First query: select sum(sal) from table1 group_by dept;
Second query: select * from table2 limit 5;
I am trying to copy the output to same excel but multiple sheets. First query output should go to sheet1 and second query output should go to sheet2 in same excel file.
If you are looking for out of the box functionality, no.
It is however possible using ETL tools. I've done it in the pass using SSIS but I'm sure other tools could handle it.
Or you could export to multiple csv files using the \copy command and then use a 3rd party (kutools) to merge them in one excel file.
Using a SQL tool like SQL Developer / Toad for Oracle
Is it possible to write a SQL query that will do the following
SELECT * FROM TABLE
WHERE COLUMN1 IN CSV_FILE
The CSV file is just one column of data with no delimiters.
How can I achieve this?
Constraints
I cannot create a temp table to insert CSV file (no create permissions)
The data I am using of this column is the only index in that table so I cannot use other columns to query or else it will be really slow.
Thanks
Creating external table is the best way. If you dont have permission then the other way is to move the file to the path of any oracle directory(Oracle object - Directory). And with help of utl_file read the file, loop through it and do your operation inside a PL/SQL block which is too tedious.
See the eaxmples for using utl_file - http://psoug.org/reference/utl_file.html
But its better if you try and get create access.
Toad for Oracle data import (uses sqlldr internally)
Create a temp table and load the data using this utility and select the values
External tables
Create external table, load the data through the same and select the values.
Using SQL developer you can create a table in your schema and load this table with data from a csv file.
Notes:
You will need to create a void column per each column to import from excel
Excel export csv with ";" delimiter
If SQL developer(4.1.5) doesn't preview the fields in separated columns try moving forward/backwards with Next/back buttons
and a very graphical guide in the following page:
http://www.thatjeffsmith.com/archive/2012/04/how-to-import-from-excel-to-oracle-with-sql-developer/
I am using oracle 11g with plsql developer. My requirement is that the data retrieval should be automatic. That means when query a data in oracle table , the data should be convert into .csv file and then it should send that to some specific folder.
Example:
Assume that student_sub1 table have all students subject1 data.when i write a query like
select * from student_sub1 where student=1, the student1 data should convert into .csv file and then the .csv file should go to student1 folder.
Hence I am requesting you to suggest me how write a sql code to convert the data into .csv file and to create a folder to send that file using oracle.
Your inputs helps me alot.
see if this post helps. That solution works when you are running the query from sql developer.
EDIT: Btw, if you want this to be in a script. Then I think you can run it using spool command to output the results to a file. Something like this.
set echo off
set feedback off
Spool student1.csv;
Select id||','||name||','||grade from student1;
Spool off;
I wish to use an external Text/CSV file to read data and run an SQL Query. Is this possible without using the External_Table concept? I do not have write permissions in the DB, hence cannot create a temp table in the DB.
Basically, I have a list of employee numbers (around 100) in a text file, using which I wish to run the following query each time:
SELECT emp_record FROM emp_data WHERE emp_no = "#file-containing-number"
I have to run a series of tasks on these and they are in no particular order or sequence, but have been provided in that text file as a list.
I am using the TOAD client and have only read-only permissions on the DB I connect to.
When I do this sort of thing I will open the file in notepad, add a comma to the end of each line and use the following SQL query:
select emp_record FROM emp_data WHERE emp_no IN (
... Paste contents of file here.
)
No - based on the limitations you mention in your question.
Are you saying you cannot even insert these records into a table in the database? Who is imposing these restrictions? You have a job to do. Other support staff should help in providing a means to accomplish the job.