Save queries in VFP - visual-foxpro

How to save queries on disk.I use the TO clause(example:SELECT * FROM vendors TO w.qpr).Everything works,but when I run the query with DO i receive the following error:
http://s52.radikal.ru/i138/1201/2f/15765ffe2346.png
And what should I change in order to obtain the query like in query designer,I mean that the query should appear in browse window,but using the command mode.
Thank you in advance.

The TO clause is for storing the results of the query, not the query itself. (And, TO is a VFP extension; INTO is preferred.)
If you want to save the query, open up a PRG file (MODIFY COMMAND) and write the query there, then save it.
If you simply omit the TO or INTO clause, the query results will appear in a BROWSE window. Alternatively, use INTO CURSOR and give a cursor name, then issue BROWSE to browse the cursor.
Tamar

As in the other answer, use MODIFY command to make a .prg for your select code.
The INTO clause is for the result.
SELECT * FROM zip INTO CURSOR c_zip
Or
SELECT * FROM zip INTO TABLE c:\temp\test
If you want a XLS or CSV or something, select into a cursor then use
EXPORT TO c:\temp\zip.csv XL5
To save a query file
Do File, New, and select QUERY radio button.

Related

how to find the query used for creation of Temporary table in Oracle sql developer

I have created a temporary table in oracle sql developer but I forgot to save it and now I want to reuse the query but I don't remember the code used then. Is there a process to get query used creation of temp table?
You can use dbms_metadata.get_ddl()
select dbms_metadata.get_ddl('TABLE', 'YOUR_TABLE_NAME_HERE')
from dual;
The result is a CLOB with the complete DDL. You might need to adjust the display in SQL Developer to make the content of that value fully visible (I don't use SQL Developer, so I don't know if that is necessary and if so, what you would need to do)
Edit:
It seems SQL Developer can't display the result of this query properly unless you use the "Run Script" option. And with that you need to use a SET LONG 60000 (or some other big number) before you run it, to see the complete source code:

How to copy data from one database/table to another database/table in oracle using toad

I am trying to copy a table data from dev box db to uat db which are 2 different data bases . I am trying in toad.All the connection details are correct but its not working and throwing the following error.
[Error] Execution (12: 1): ORA-00900: invalid SQL statement
This is what i am trying
copy from abc/cde#//abc.abc.com:1521/devbox to abc/cde#//abc.abc.com/uatbox
INSERT TOOL_SERVICE_MAPPING (*)
USING (SELECT * FROM TOOL_SERVICE_MAPPING)
If your table doesn't have a huge number of rows you can use Toad's Export function: it creates an insert statement for each row. You can then run these statements in destination DB to re-create your table's data.
Here are the steps:
A. Create a copy of the table in destination DB
in source DB in a schema browser window click on the table you want to copy, select "script" tab in the right part of the window: you will find the script to re-create your table; copy this script
paste the script in a new SQL editor window in destination DB and run it. This should create the new table
B. Copy data in new table
in a schema browser window right click on table name in source DB
select "Export Data" from context menu
write "where" statement of your export query (leave it blank if you want to copy the entire table)
select destination: clipboard
click "ok" (now insert statements are stored in your clipboard)
paste insert statements in a new SQL editor window in destination DB
run statements as script (shortcut F5)
copy is a SQL*Plus command, not a SQL statement. I would be surprised if Toad had implemented that particular SQL*Plus command (it does implement many of the simpler commands). If you want to use the copy command, you would need to use SQL*Plus, not Toad.
If you want to use Toad, you would need to use a SQL statement to copy the data. You could create a database link in the destination database that points to the source database and then
INSERT INTO tool_service_mapping
SELECT *
FROM tool_service_mapping#<<db link to source database>>
The easyest and most error-free way I have experienced so far is: Database->Compare->Schemas
It's not too complicated as it looks (lots of checkboxes), but you tick boxes for objects you need to be created in an empty database, and at the end of comparison you end up with SQL script including all objects (triggers, views, sequences, packges) that you selected (checkboxes).
I clearly see all tables, triggers, data, etc in generated sql script and even can tick these I don't wish to create (if any)... Before executing script, TOAD asks you to confirm against which database you are running the script - saved me few times... As ackward as it looks, it works perfectly.
I have arround 200 tables I don't know if this is suitable for huge databases.

Oracle SQL Developer: how to get back the SQL statement that had been executed?

In SQL Developer, you can pin the query result. After running dozens of querys, it is hard to find certain one from history or SQL worksheet, but you probably know which query you are looking for by viewing the pinned query results. If you put your mouse at the tab of the pinned query result, the executed SQL to generate that result is shown as a tool tip, however, I don't know how to copy that SQL statement and exeture it again. Can anyone help?
If all you want to do is re-execute the query, from the pinned query result window you can click on the Refresh button.
If you want to copy+paste the statement in order to modify it before re-executing, in the pinned query result window there is an SQL button that will show you the sql command used and will let you copy it.
(I am using SQL Developer 3.1)

Quickest way to get results from multiple sql select statements?

Basically, I have an excel sheet with numerous select statements; wondering what's the quickest way to run all these and return the data to a file or query analyzer result window.
These are really simple select statements, they are basically
SELECT A, B, C FROM VIEW WHERE ID = '00001'
but there are about 200 hundred of these so I am wondering what's a fast way to run these
If you simply want to run them all in succession, and save the output, you can do something like this:
Copy them to a plain text file, call it my_queries.sql, then add a line at the top that says:
spool my_queries.lst
and then add a line to the end of the file:
spool off
Then you can connect via SQL*plus:
sqlplus username/password#your_connect_string
and then run the script with:
SQL> #my_queries.sql
You'll end up with all the results in the spool file, my_queries.lst.
Hope that helps.

How to export query result to csv in Oracle SQL Developer?

I'm using Oracle SQL Developer 3.0. Trying to figure out how to export a query result to a text file (preferably CSV). Right clicking on the query results window doesn't give me any export options.
Version I am using
Update 5th May 2012
Jeff Smith has blogged showing, what I believe is the superior method to get CSV output from SQL Developer. Jeff's method is shown as Method 1 below:
Method 1
Add the comment /*csv*/ to your SQL query and run the query as a script (using F5 or the 2nd execution button on the worksheet toolbar)
select /*csv*/ *
from emp;
That's it.
You can also use spool to automatically save it as a CSV file:
spool "/path/to/file.csv";
select /*csv*/ *
from emp;
spool off;
Just be sure to "Run as Script" or press F5.
Method 2
Run a query
Right click and select unload.
Update. In Sql Developer Version 3.0.04 unload has been changed to export
Thanks to Janis Peisenieks for pointing this out
Revised screen shot for SQL Developer Version 3.0.04
From the format drop down select CSV
And follow the rest of the on screen instructions.
Not exactly "exporting," but you can select the rows (or Ctrl-A to select all of them) in the grid you'd like to export, and then copy with Ctrl-C.
The default is tab-delimited. You can paste that into Excel or some other editor and manipulate the delimiters all you like.
Also, if you use Ctrl-Shift-C instead of Ctrl-C, you'll also copy the column headers.
FYI, you can substitute the /*csv*/
for other formats as well including /*xml*/ and /*html*/.
select /*xml*/ * from emp would return an xml document with the query results for example.
I came across this article while looking for an easy way to return xml from a query.
FYI to anyone who runs into problems, there is a bug in CSV timestamp export that I just spent a few hours working around. Some fields I needed to export were of type timestamp. It appears the CSV export option even in the current version (3.0.04 as of this posting) fails to put the grouping symbols around timestamps. Very frustrating since spaces in the timestamps broke my import. The best workaround I found was to write my query with a TO_CHAR() on all my timestamps, which yields the correct output, albeit with a little more work. I hope this saves someone some time or gets Oracle on the ball with their next release.
To take an export to your local system from sql developer.
Path : C:\Source_Table_Extract\des_loan_due_dtls_src_boaf.csv
SPOOL "Path where you want to save the file"
SELECT /*csv*/ * FROM TABLE_NAME;
CSV Export does not escape your data. Watch out for strings which end in \ because the resulting \" will look like an escaped " and not a \. Then you have the wrong number of " and your entire row is broken.

Resources