I have sql script "example.sql":
SPOOL &1
Select '<.TR>'||'<.TD align="left">'||column_name||'<./TD>'||'<.TR>' from table1;
spool off
which dumps it contents to cshell script "getdata.csh" this is how i get data from sql script to csh script
sqlplus $ORA_UID/$ORA_PSWD #${SQL}example.sql ${DATA}${ext}
My problem is when I run my job to do this it dumbs all data extracted from sql query in log file too.. How can I avoid dumbing data into log files. What do I have to do in this code to do so? thank you
Look here for information about your issue: sqlplus spool
Essentially, you will need to add these two settings:
set echo off
set termout off
Related
i want to save the result of a query using spool command.
But i got the query and its output in the result file (result.txt)
spool "result.txt"
select * from table;
spool off
how can i remove the query from the file result.txt?
You need to add the following set command:
set termout off
If you store the complete script in a script file (for instance getData.sql) and then run it from SQL Plus with the following command you will have the results wanted.
#getData.sql
Note that typing these commands directly in SQL Plus will cause the select statement to be in the file, even with the set parameter.
I have a sql script in
dir:\some\path\script.sql
This script is executed via SqlDeveloper and spools some data into
dir:\some\path\data\tablename.csv
Now, I have to store the script in a .sql file because if I execute it from SqlDeveloper directly, spool writes the query itself to the file which I do not want.
But I also do not want to hard-code paths because everyone in my team has their GIT repo whereever they want, so the scenario I'd like to achieve is that my sql script uses relative paths from it's location to write the csv files.
Currently the script.sql looks something like this:
SET COLSEP ";"
spool dir:\some\path\data\table1.csv
select /*csv*/ * from table1;
spool off;
and I want to look it something like this
SET COLSEP ";"
spool current_dir\data\table1.csv
select /*csv*/ * from table1;
spool off;
So that when using the script, the path has to be typed only once, when calling the script.
More of a workaround than a solution to the problem, but for now I just created a scriptRunner.sql file in the same directory as the script.sql which simply runs the script (#script.sql).
When opening this file, it seems like SqlDevelopers working directory is set to the directory where both .sql files are in and this property is extended to the called script, therefore I can simply use
spool data\table1.csv
I have to generate a csv file by creating a sql query(oracle) and then mail it to the user. Up to this part I have completed and is working fine.
But if there is any data returned in the spooled file, then only the mail need to be sent.
I am having little trouble because my mail query is in sql part, so for checking the file do I need to displace its order
i.e. sqlplus -s user/pass <
mail logic(calling a procedure)
spool off;
exit
EOF
and how do I need to check the file size/count with which unix command s
or do I need to write this part in another sqlplus -s block and check with count of records
Can someone please suggest with the command or syntax for this as I am totally confused.Thanks in advance
You can create a unix script and call the sqlplus script within and before u send the email you can check if the file size is NOT zero.
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 have oracle table that holds more than 30 million records, I need to pull all that data into file and store it.. Can anyone suggest me what will be easiest way to do that and what kind of file do I have to use to store all that data. If there is a way I can put data into multiple files that will work too.. You can tell me manual or programatical method. Thank you
Ask Tom has an answer http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::p11_question_id:88212348059
Also, you could do it in SQL*Plus by doing a select with spool on (from a shell script)
sqlplus /nolog <<EOF
conn /as sysdba
set pagesize 0 heading off feedback off verify off echo off trimspool on
spool test.log
select 'dsmc inc "'||file_name||'">>hot_WISDOM_$BCKNAME.log' from dba_data_files
where rownum<5;
spool off;
exit
EOF
More info on the spool stuff at http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:25323432223677
That page is where I found that snippet above.
You will want to replace the connection details with your username / pw.
Starting with Oracle 10g you can create a new table with ORGANIZATION EXTERNAL and INSERT records from the original table into it. See this example from the Oracle 10gR2 documentation.
One of the easiest formats to store data in is comma seperated value (.csv). You can define your delimiter to be any character (comma is a default) as long as you know the delimiter when you are parsing it. (For instance, the ~ character would be a good decision). Usually this format can easily be opened in a spreadsheet program like Excel. It can also be easily parsed to be re-inserted into a database of your choosing.
To export from oracle, you can do something like:
spool backup.csv;
select column1||','||column2||','|| ... from table;
spool off;
After exporting, here is a resource for working with csv files in perl:
http://perlmeme.org/tutorials/parsing_csv.html
Apache commons has a great library for java:
http://commons.apache.org/sandbox/csv/apidocs/org/apache/commons/csv/CSVParser.html