I have a select query producing a big output and I want to execute it in sqldeveloper, and get all the results into a file.
Sql-developer does not allow a result bigger than 5000 lines, and I have 100 000 lines to fetch...
I know i could use SQL+, but let's assume I want to do this in sqldeveloper.
Instead of using Run Script (F5), use Run Statement (Ctrl+Enter). Run Statement fetches 50 records at a time and displays them as you scroll through the results...but you can save the entire output to a file by right-clicking over the results and selecting Export Data -> csv/html/etc.
I'm a newbie SQLDeveloper user, so if there is a better way please let me know.
This question is really old, but posting this so it might help someone with a similar issue.
You can store your query in a query.sql file and and run it as a script. Here is a sample query.sql:
spool "C:\path\query_result.txt";
select * from my_table;
spool off;
In oracle sql developer you can just run this script like this and you should be able to get the result in your query_result.txt file.
#"C:\Path\to\script.sql"
Yes you can increase the size of the Worksheet by change the setting Tool-->Preferences - >Database -> Worksheet -> Max rows to print in a script(depends on you).
Mike G answer will work if you only want the output of a single statement.
However, if you want the output of a whole sql script with several statements, SQL*Plus reports, and some other output formats, you can use the spool command the same way as it is used in SQL*Plus.
Related
This is a 2 part question but Ill get to my first conundrum.
I have some code I'm just trying to test where I want Python to run a stored procedure with the required variables and it runs and even shows the new row. However, if I go into the DB and run a SELECT statement to show me the data, its not there. Its as if the DB blocked it or something strange.
This code WORKS if I run a select statement instead of this stored procedure. The stored procedure works and even when I run this code, Python will run the stored procedure and spit back the new row (complete with the new row number that's auto-generated due to the IDENTITY I have on the column)
import pyodbc
conn = pyodbc.connect('Driver={SQL Server};'
'Server=REPORT\INSTANCE;'
'UID=UserID;'
'PWD=Password;'
'Database=ReportDB;'
'Trusted_Connection=no;')
cursor = conn.cursor()
cursor.execute('EXEC [Schema].[Comments] \'2019-04-18 00:00:00.000\',\'Team\',\'1900-01-01 13:12:16.000\',\'testing this string\',\'username\'')
for row in cursor:
print(row)
Kind of lost here. Python will run the stored procedure (which I have set to run a select at the end of, to prove the data was committed) and Python shows that but I don't see it in the actual DB. That line is gone.
You can see here, the 470 is the ID Column (Identity, no null) and that's what it should be.
Notice that the most recent entry is still 469
Same Instance
Same DB
EDIT
I just noticed something in the Python. Each time I run the Python code, it runs the code and the stored procedure does the select at the end but each time I run it, the CommentsID increases by 1 (as it should) but its NOT remembering the previous ones inserted by Python. The only ones the SELECT statement pulls back in is the one I committed via SQL itself.
Notice here that the CommentsID (the first number in each line that starts with a 4) goes from 469 to 471. Yet I just had that image above that shows 470 - where did 470 go?!
Second part:
I'm having a hard time putting variables into that EXEC section of the code. I think I need to wrap it in single quotes which means I need to put \ in front of the quotes I need to stay for the SQL code. But when I do that and then try to run it, I cant get it to pull in the variables.
Here is what the SQL needs to be:
EXEC [schema].[Comments] 'Username'
In Python, I know I need it to be in single quotes but because the SQL code has quotes, you typically just put \ in front like this:
'EXEC [schema].[Comments] \'Username\''
That works. However, I then want username to pull from a variable, not be a string.
On SQL queries zeppelin 0.8.1 provide table output and several visualizations of data out of the box:
And it is very useful most of the time.
But sometimes I want just select text for presentation.
Said for query SELECT version();. There table output is annoying:
What very interesting, there already implemented text output, for example for EXPLAIN:
Off course ideally for EXPLAIN query you may also expect more visualize for nods, cost and so on, but it is absolutely another question.
So, main question: How I can switch output to text form for some of my SQL queries except explain but in similar form?
Additionally, If I run some maintenance commands like VACUUM and ANALYZE I can see output in many IDE, but in zeppelin it is empty!
/*'EXPLAIN '*/ select version();
An ugly workaround can be used while JDBCInterpreter contains EXPLAIN_PREDICATE
private static final String EXPLAIN_PREDICATE = "EXPLAIN ";
String results = getResults(resultSet,
!containsIgnoreCase(sqlToExecute, EXPLAIN_PREDICATE), isComplete);
In future it's will be nice to manage output type via paragraph properties.
VACUUM and ANALYZE send messages which should be caught via Statement#getWarnings
I use UPDATE a SET GR_P = REPLACE(GR_P,'','') FROM mytable a to replace things.
But replace function is not working for below charter:
In Query analyzer it works but when I used SSIS Execute SQL task or OLEDB Source then it is giving me error:
No Connection manager is specified.
In Toad against Oracle (since that's one of your tags), I issued this (pressing ALT-12 to get the female symbol) and got 191 as a result. note selecting it back using CHR(191) shows an upside-down question mark though.
select ascii('♀') from dual;
Given that, this worked but it's Oracle syntax, your mileage may vary.
UPDATE mytable SET GR_P = REPLACE(GR_P, CHR(191));
Note if it does not work, that symbol could be for another control character. You may need to use a regular expression to eliminate all characters not in a-zA-Z0-9, etc. I suspect you'll need to update your tags to get a more accurate answer.
Maybe this info will help anyway. Please post back what you find out.
All..
I am currently using some systems that has an Informix DB on some older IBM AIX OS based systems. I have found myself needing to use the command line "dbaccess" feature to make some quick queries. Informix has this really annoying habit of return output in this format:
employee -1
record_desc Update
field_id 2
value
opr_activity_date 20150831
opr_activity_time 1
employee -1
record_desc Update
field_id 2
value
opr_activity_date 20150831
opr_activity_time 1
employee -1
record_desc Update
field_id 2
value
opr_activity_date 20150831
opr_activity_time 1
MySQL, MSSQL, etc.. all output something more readable in table format..
city state zipcode
Sunnyvale CA 94086
San Francisco CA 94117
Palo Alto CA 94303
Redwood City CA 94026
Los Altos CA 94022
Mountain View CA 94063
Palo Alto CA 94304
Redwood City CA 94063
I noticed that Informix will/can output in a column/table format, but I have not figured out any rhyme or reason as to how it decides the flat versus the table format.
Any idea how I can force Informix to always display in column/table output via the command line?
Obviously, this is not an issue when I am near my computer and can use my GUI tool to query the DB...
Unfortunately, there's no way to control this behaviour in DB-Access.
If the width of the selected columns (plus a little white space) exceeds the width of the terminal, DB-Access switches to that block format, because it doesn't support sideways scrolling. That's the rhyme and reason.
You can try messing around with your terminal settings so that DB-Access is aware on start-up that the terminal width is wider than 80 characters, but I've always found there's more luck than science to that, and you'll still trigger the behaviour on some queries and not others.
When I need to do what you're describing - ad hoc, simple queries for troubleshooting etc - I tend to work within VIM rather than DB-Access, and use a macro to run the query and format the output. (This is using DBI::Shell behind the scenes.) I've also got a program that accepts either a table name or SQL statement and outputs tab-delimited, CSV or an old-school ASCII character formatted table of the results. This is also perl based. I could publish either of these if there's interest in them.
I think Jonathan Leffler's SQLCMD program can also be used in place of DB-Access to generate arbitrarily wide output.
Ok..
While I found the answers RET provided to be correct and pretty much sums up what I have been able to find on the net, I also found some work-arounds that enable the ability to get what you want, but in a kludgy way! Thanks Informix! :(
Open two terminal windows to your DB system, and launch the dbaccess and authenticate and connect to your database.
Next perform the following:
unload to /home/(user)/out ...the query...
Example:
unload to /home/jewettg/out select * from books_checked_in;
It will output the query results to the file and return the row-count of the return result.
On the second terminal, and here is the cool thing, run the following command:
column -t -s '|' /home/(user)/out
This will grab the content of the "out" file, and convert the pipe-delimited content to space-delimit content and output it to the screen.
Like I said, kludgy, but it works!
You can do this by setting the DBACCESS_COLUMNS environment variable. It is supported from version 12.10.xC9.
Example:
export DBACCESS_COLUMNS=1000
I'm using Pervasive 10 with PCC (Pervasive Control Center) and I need to export a lot of results (over 100 000) to a TXT file.I know it's possible "Execute in Text" but this feature does not work for me because after exporting about 20 000 records the program stops. I have also changed the settings in PCC (Windows->Preferences->Text Output-> Maximun number of rows to display = 500,000).
Anyone know a way to export my query result to a txt file?
You should be able to use the Export Data function. Right click on the table name in the PCC and select Export Data. From there, you can either execute the standard "select * from " or make a more complex query to pull only the data you need. You can set the delimiter to Comma, Tab, or Colon.
Nice answer mirtheil, was wondering about this my self as well.
To add something to the answer.
It does not matter which table you right click and choose "Export Data" on, Because your query will override the default table query.