简体   繁体   中英

Recover unsaved SQL query Scripts in Oracle SQL Developer

I know how to do this in SQL Server thanks to this clever bit of code

Use <database>
SELECT execquery.last_execution_time AS [Date Time], execsql.text AS [Script] 
FROM sys.dm_exec_query_stats AS execquery
CROSS APPLY sys.dm_exec_sql_text(execquery.sql_handle) AS execsql
ORDER BY execquery.last_execution_time DESC

SOURCE: Recover unsaved SQL query scripts

Is there a way to do this in Oracle SQL Developer?

If you have the privileges then:

SELECT * FROM v$sql

If not then press F8 to bring up a list of previously ran queries.

This has saved my butt several times.

It is realy a problem when you lose unsaved code. For about a month I have been working on a big procedure, and forgot to save the code in SVN. If you read this and remember have such unsaved code, commit it immediately! :) Because everything could happen with your test db. Ok. you're lucky if you were using Oracle SQL Developer, because this program has a great feature - it saves your code in its sql history inspite of eating a big party of your RAM. Open your file explorer and locate this folder:

C:\\Users%USERNAME%\\AppData\\Roaming\\SQL Developer\\SqlHistory

You'll find a lot of xml files, and if you're twice lucky, you'll find your lost code. Its wonderful. :) . If you're using another program, try to find feature like this and maybe it helps you. My condolences if this post doesn't help you, in any case, try to find something good among the next: 1) write your code again, and it will be better than before as you did it once 2) commit your code, so you'll not face such problem in the future

You can try too, so you can get the unsaved SQL.

View > SQL History , for example, look this picture: 在此处输入图片说明

This is using SQLDeveloper's history, like in Matt's answer, but if you want to search through the history files for specific query fragments you remember, they are located as .xml files in /home/username/.sqldeveloper/SqlHistory . From there, enter:

find -type f -mtime -1 -print0 | xargs -0 grep -l <text>

(where -mtime -1 means no sooner than one day ago).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM