Backup SQL + output to a text file
I have to use SQL + on one of my databases. No way around it. So I'll write my queries, execute them, check the output, tweak them and run again if necessary. So I could start withSELECT
ename,
job
FROM
emp;
Once I know that it's working properly, I wrap it in a procedure so I can get the data in a text file:SET TRIM ON
SET PAGESIZE 2000
SET SERVEROUTPUT ON SIZE unlimited
EXEC DBMS_OUTPUT.ENABLE(null)
--
SPOOL c:\mySQL\out.txt
--
BEGIN
--
DECLARE
--
CURSOR c_cur IS
--
SELECT
ename,
job
FROM
emp;
--
BEGIN
--
DBMS_OUTPUT.PUT_LINE(
'NAME|JOB|'
);
FOR r_cur IN c_cur LOOP
DBMS_OUTPUT.PUT_LINE(
r_cur.ename||'|'||
r_cur.job
);
END LOOP;
END;
END;
/
Then I import into Excel as data delimited on the pipe.works fine until I have decide that I really need a column more. So I made changes on the SQL code, and two more changes in the part of the output (one for the title and one for the LOOP)
I was wondering if someone had written a cool procedure I could run across ALL SQL, and he would automatically know my names to column write the titles and then to loop through data automatically.
I'm not tied to the use of the exact procedure I described above. The key is, I'm looking for a general procedure that I can run any script through, and it will load the output for me, without further changes.
Hello
Why do you not consider creation and HTML file which can be read easily with Excel.
that is to say:
SET SERVEROUTPUT ON SIZE UNLIMITED
SET LIN 500
SET DEFINE OFF
SET UNDERLINE OFF
SET TAB OFF
SET FEEDBACK OFF
SET VERIFY OFF
SET TERMOUT OFF
SET PAGES 9999
SET MARKUP HTML ON TABLE "cellspacing=0 border=1" ENTMAP OFF
spool myexcel.xls
/* Replace the query below as you like */
SELECT * FROM EMP;
spool off
EXIT
The format is HTML, but once you load in Excel, you can easily save the format you like.
Kind regards.
Al
Tags: Database
Similar Questions
-
Save the waveform output to a text file when VI runs continuously?
How can I save waveform output to a text file when I start my VI permanently?
I do power profiling and you want to save voltage drop measures continuely.
Oh... I see. I wasn't aware of this.
This is my first time using LabVIEW, so I used one of the example files. There, I just added "Write file to measure" with total input current... and because I used using buttom "continuous run", I added the Activate button to control when I write of the measurement files.
However, ideally, I want to run x seconds or x minutes and then stop without turn off the device that is connected to the battery Simulator of NOR. At present, its reset whenever I hit the 'run' button, which makes me put in place the special test device I want to measure again.
-
Can not get the result of the command output to a text file...
Hello
I tried to get a list of my virtual machines (using PowerCLI) with CBT (block change tracking) enabled, and while the following command returns the results, I can't have it at the output to a text file. Any help you can offer would be appreciated.
foreach ($vm in get - vm) {write-host $vm; get-advancedsetting - entity $vm | select-string - pattern 'ctkEnabled' | sort; write-host | out-file c:\somepath\file.txt}
I get the correct result on screen, but the text file is empty.
Please notify.
Thank you
Hello, wmilligan2013-
You can get the information to an output file by removing the Write-Host calls. How to do:
Get-VM | Get-AdvancedSetting -Name *ctkEnabled* | Sort-Object Entity,Name | Select Entity,Name,Value,Type | Export-Csv -NoTypeInformation -UseCulture c:\temp\advSettingInfo.csv
Which will be, for any virtual computer that has a * ctkEnabled * advanced configuration, parameter information advanced output for such virtual machine to the CSV file in the appropriate location. It relies on the ability to Get-AdvancedSetting to accept the VM objects as the value to - entity from the pipeline (so the foreach statement is not necessary) and used the - param Name of this cmdlet, avoiding any disorder Select-String. I used Export-Csv to the output method so that you can easily consume these data later if you need to act on these data or even manipulate it.
How does do for you?
-
Nobody knows how to output to a text file.
I have a timestamp and when a key is pressed at the last level I want to output a Boolean variable in a text file, preferably to the desktop
It is a simple .swf that I created.
OK, I've managed to do:
var file:FileReference = new FileReference(); Create a filereference object
var flag: Boolean = false; Create the variable
function taketheticket(event:MouseEvent):void
{
trace ("change is" + flag); prints the value of change
leader. Save (flag, "result.text"); saves the value of the indicator in a text file named result.text
gotoAndStop (8); go to the section 8 and stop
}
When the above method is exectuted it allows you to select a particular destination.
-
Hello
I have two master & detailed for example, EMP, Dept table.
I need my output in the text file with delimiter ~ in the format below.
Rgds10~accounting~newyork 7782~CLARK~MANAGER~7839~6/9/1981~2450.00~10 7839~KING~PRESIDENT~11/17/1981~5000.00~10 7934~MILLER~CLERK~7782~1/23/1982~1300.00~10
VKHello
This should work to get the right file name, but you can add your own code.
clear buffer clear screen clear columns column fname new_value my_spoolfilename input prompt Enter a valid department id.. accept dept number prompt 'Department ID. :' select 'IND'||upper(d.department_name)||to_char(sysdate,'yyyymmddhh24miss')||'.txt' fname from departments d where d.department_id = &dept; spool c:\temp\&my_spoolfilename spool off
If I run it as a script, I get:
Voer waarde voor dept in: 30 oud 3: where d.department_id = &dept nieuw 3: where d.department_id = 30 FNAME --------------------------------------------------- INDPURCHASING20090517125510.txt Verstreken: 00:00:00.39 HR%xe>
And my c:\temp\ dir contains a file named INDPURCHASING20090517125510.txt:
-
How to load SQL scripts from a text file.
Hi, I tried several times to load a script file/SQL text with 10 different tables and the data, but 10g Express doesen't allows me to do that, can someone direct me or tell me what I do or what I need to adopt a special method to achieve this. I'm sure there must be something where you can download SQL scripts from a text file (in the SQL command editor!). Thank youHello
Yes, as Aust replied, you must use SQL Workshop/SQL Script, instead the command SQL Editor.
Sqlplus can also do so, I think, as well as SQL Developer, now it is 1.5.
sqlplus: (the window command line, black of sql)
SQL > @path /--(l'extension devrait être.sql) filename.sql.
Peter
-
How to write the result of a SQL query to a text file?
I'm using Oracle 11 g and SQL Plus.
I have a large table called side.
Whenever I do
SQL > select * rating.
The output goes well beyond what can show the screen sqlplus. So, I want to store the result of this query in a text file.
How is that possible? Help, please. Thank you.SQL > SPOOL results.txt
SQL > select * rating.
SQL > SPOOL OFF -
coil only the SQL result to a text file
Hello
Here's my script for getmetadata.sql. The sql script retrieves the metadata of objects for a schema specific to start from a specific date.
Set serveroutput off
the feeding off value
fixed lines 200
set of 2000 pages
set verify off
Set term on
object_name format a30 column
coil result_ddl.lst
Select dbms_metadata.get_ddl (object_type, object_name). ';' from dba_objects where owner_name = '& schema_name' and to_date (to_char (created, 'DDMMYYYY'), 'DDMMYYYY') > = to_date ('& DDMMYYYY ', ' DDMMYYYY');
In the hold with the result file I get the below lines too.
"
Enter the value of schema_name:CUSTOM
Enter the date value: 08032011
"
I wish that this text does not do print and only the metadata script is created.
Please guide.A - K wrote:
HelloHere's my script for getmetadata.sql. The sql script retrieves the metadata of objects for a schema specific to start from a specific date.
Set serveroutput off
the feeding off value
fixed lines 200
set of 2000 pages
set verify off
Set term on
object_name format a30 column
coil result_ddl.lst
Select dbms_metadata.get_ddl (object_type, object_name). ';' from dba_objects where owner_name = '& schema_name' and to_date (to_char (created, 'DDMMYYYY'), 'DDMMYYYY') > = to_date ('& DDMMYYYY ', ' DDMMYYYY');In the hold with the result file I get the below lines too.
"
Enter the value of schema_name:CUSTOM
Enter the date value: 08032011
"Is it really what you see? "Do not enter value for DDMMYYYY '?
Be sure to view the results you get in fact from the code you post.I wish that this text does not do print and only the metadata script is created.
Probably the best way is to explicitly set substritution variables before you start curling, like this:
set serveroutput off set feed off set lines 200 set pages 2000 set verify off set term on column object_name format a30 ACCEPT schema_name PROMPT "Please enter the schema name (case-sensitive, e.g. CUSTOM): " ACCEPT ddmmyyyy PROMPT "Please enter the minimum created date (DDMMYYY, e.g. 28022011): " spool result_ddl.lst select dbms_metadata.get_ddl(object_type,object_name) || ';' from dba_objects where owner_name ='&schema_name' and created >= to_date ('&DDMMYYYY', 'DDMMYYYY') ; ...
Beware of round-trip conversions, such as
to_date(to_char ...
They are almost never necessary in Oracle. If you have a reason why you can't use just created, then it is almost certainly to get the same results without changing the types of data more efficiently (and less confusing).
-
backup sql output as separate command values
Hello
version 10.2.0.3
I am trying to wrap an output select sql in the form of values separated by commas. Could you help me on this please?
I'm getting
1234, testdata (spaces), atr
Expected result:
1234, testdata, atr
Thank you
Published by: APV on October 7, 2009 09:30If you don't mind each column space padded then you can use:
set colsep ,
But if (as I think is the case with your query) you want to get rid of the padding, then you're going to concatenate columns together in a single string:
select col1 || ',' || col2 || ',' || col3 from
Additional note: If one of your columns contains commas in the data, you'll probably like too much quoting them and double quotes in the data.
Published by: Andy Triggs on October 7th, 2009 10:42
I have a lot that downloads the files, and I want to redirect the output to a text file. The lot is set up similar to the following:
Set ftp = c:\ftp.txt
hdir = Set / mydir
Define ldir = c:\temp
echo open monsite.org > ftp %
echo user > ftp %
echo pw > ftp %
echo get myfile.txt > ftp %
echo mget my*.dat > ftp %
to echo bye > ftp %
-I - s FTP: ftp % > "c:\temp\ftp.log."This lot works perfectly if I redirect the output of the ftp command, but, when I redirect the output, I get a logfile with 3 lines as follows:
no connection
mget my*.dat
Good byeI tried the commands different redirect, with undesired results
> & (which causes only the batch to close by anything in the logs)Why is - what this redirect would break the batch and the ftp script in particular?
This is now fixed; was a simple mistake really, but thanks for all the help anyway.
Diff data loading while doing through SQL and while doing through text file
I have an ASO cube data charges every day morning. Loading the data is automated by MaxL and this MaxL files uses a SQL (against teradata) as the source of data and a State of charge for loading data. 1 week incorrect data return has begun to show upward and nothing has been changed. It's strange when I run the SQL in a teradata assistant and copy the results to a text file and load the data via EAS from the text data source file and the same rule that data file appears on the right. Any ideas on why this is happening. So basically when I use a SQL data source and a particular rule file data seems to be missing, where as during the use of the results of the same SQL copied into a text file and load data into the text file and the same rule file it seems to work. I'm on 11.1.1.4 and in this case only a private citizen of the cube.
Thank you
Ted.Hi Ted, thanks.
Well, you reset the database before each load that takes the properties 'Overwrite' or 'Add' of the equation which is good. And it looks like nothing of going with several buffers (no parallel loading SQL, right?). That really just leaves box "Aggregate use Last" - did you happen to check this? By default applied your MaxL charge would be "Aggregation Sum" (which is the equivalent of not check "Use Last Aggregate").
A_defaut, I would suggest that you add a WHERE clause of your SQL query to zoom right down to one of your 'problem' values (you have not really described what you see error data) and a) load just this intersection and b) see the result of the query in the data prep Editor.
How do I redirect the CELLCLI output to text file
Hello
I want to redicrect the cellcli command output to a text file.
For example, how do I redirect the output of this command to a text on/tmp file
Thank youCellCLI> list metrichistory where objectType = 'CELL' -
and name = 'CL_TEMP'
cellcli offers similar to sqlplus coil features:
CellCLI> help spool Usage: SPO[OL] [
[ CRE[ATE] | REP[LACE] | APP[END]] | OFF ] Purpose: SPOOL : Direct the results to the file . SPOOL OFF: Turn off the spooling. SPOOL: Check the current spooling status. Arguments: : The filename where the results will be output. Options: [APPEND]: If the filename already exists, the following output will be appended to the file. Without this option, the existing file contents will be replaced. [CREATE]: If the filename already exists, an error is reported. [REPLACE]: If the filename already exists, the contents will be replaced. This is the default, when no option is provided. Examples: spool myfile spool myfile append spool off spool But if you try to add a script, it would be easier to simply execute the command line:
# cellcli -e "list metrichistory where objectType = 'CELL' and name = 'CL_TEMP'" > /tmp/CL_TEMP.txt
Also look at the dcli that allows you to run commands cellcli on one or more cells of a compute node.
Good luck.
alignment of the text file column data
Hi all
I want to format the output file as shown in need. Suggestions appreciated. I tried with lpad, rpad in the query. Also tried with justify right in the column after A5 format... (A5 size frame right)
It is part of an important application.
Please suggest.
SQL file
--------
set verify off
Set feedback off
NewPage 0 value
set pagesize 63
set linesize 280
TOPIC ON THE VALUEcoil c:\test.txt.
column heading "CTY" A5 format Change_typestermout off Set
Select CT of
tab;output in the text file
CTY
-----
NPower required:
CTY
-----
N(* See space above)
Oracle 10g
running sqlplusThank you
HA!
Hello
G2500 wrote:
Hi all
I want to format the output file as shown in need. Suggestions appreciated. I tried with lpad, rpad in the query. Also tried with justify right in the column after A5 format... (A5 size frame right)
It is part of an important application.
Please suggest.
SQL file
--------
set verify off
Set feedback off
NewPage 0 value
set pagesize 63
set linesize 280
TOPIC ON THE VALUEcoil c:\test.txt.
column heading "CTY" A5 format Change_typestermout off Set
Select CT of
tab;output in the text file
CTY
-----
NPower required:
CTY
-----
N(* See space above)
Oracle 10g
running sqlplusThank you
HA!
This sounds like a job for LPAD. What exactly have you tried? It is difficult to say what hurts you without knowing what you were doing.
I don't have a copy of your table, so I'll use the scott.dept table to illustrate:
SELECT LPAD (dname, 20) department_name
OF scott.dept
;
Output:
DEPARTMENT_NAME
--------------------
ACCOUNTING
SEARCH
SALES
OPERATIONS
You want to justify the right title, like this
DEPARTMENT_NAME
--------------------
ACCOUNTING
SEARCH
SALES
OPERATIONS
?
If so, make this SQL * more order
Department_name RIGHT-JUSTIFIED COLUMN
before running the query. COLUMN... JUSTIFICATION applies only to the topic, not the data.
Compare 2 text files data and output match
Hi all
I need some advice.
First of all, in BinaryCode.txt data are thus:
Replace BinaryCode0 1 0 0 0 0 0 0 0 0
Replace 1 0 0 0 0 0 0 0 1 BinaryCode0
Replace 1 1 1 0 1 1 1 1 1 BinaryCode1
Replace BinaryCode1 1 0 0 0 0 0 0 0 0the first line of the text file is the header. So I need to check if the names in the second column (BinaryCode0 or BinaryCode1) appear in the Timed_Sets.txt file.
Timed_Sets.txt data as such:
BinaryCode0, 6, 40...
BinaryCode0, 7: 40...
BCName1, 0, 20...BCName1, 1, 20...
For example, as BinaryCode0 is a match that I pulled out the line whole Timed_Set.txt in another table.
I worked on a program, but I do not get the expected results.
Text files and VI are attached.
I appreciate your kind assistance in this matter.
Thank you
Concerning
Kart
If I understand what the output should be so what you essentially have to do is walk through the column for each unique value and BinaryCode.txt, pull the corresponding lines of Timed_Sets.txt. There are a variety of ways to do this, depending on the amount of data you have and whether or not you can use any kind of prior knowledge as to the actual content of the file (for example names of key search). It's a joint way. Modify if needed.
Use the lines of a text file as input to an SQL command
Hello
I have a text file containing the lines...
123
1234
I would like to use as input for a SQL command running in a script. ie
Update flag set < table > = 'Y' where job = < the text file lines >;
Any help much appreciated.
See you soon
External table will do.
For reference...
CREATE TABLE Hold'em (SEQ_NUM NUMBER (10));
insertion in hold select SEQ_NUM in task where proc like '% PROC;
update set hold_flag = task ' ' where in SEQ_NUM (select hold SEQ_NUM);
Maybe you are looking for
-
Can not see my files [SOLVED]
When I run Thunderbird, my normal display appears for about a second. This has all of my folders - Inbox, trash, and local ones I created. Watch then suddenly one of my local files. He doesn't have a button to restore the display. I tried to start in
-
The confocal issue custom with PCI-based 1409 acquisition
We use a PCI-1409 to acquire a video from a custom confocal system flow and high definition image. We use the junction box BNC to send in luminance, hsync and vsync in the PhotoMultiplierTube and our custom control box. Because of the way we scan usi
-
I have a brand new Thinkcentre Edge 72. I can't boot from the CD. I disabled the secure boot. I changed the boot in all 3 possible options sequence first use the cd. He's not even trying. If I hold F12 during the boot, I get a temp. but boot device s
-
Windows media player11 does not play files mp4 video
videos made with a cell phone based on windows.
-
Problem when creating a report with a date of schduled
When I tried to create a report with a schedule (any option except now) I get the error 'Date of the first report occur must be after or equal to the current date", unless I have use a date of 01-10-2012 or later in the first report occurs on the fie