首页 > 代码库 > Using Notepad++ to Execute Oracle SQL

Using Notepad++ to Execute Oracle SQL

原文链接:http://www.toadworld.com/products/toad-for-oracle/b/weblog/archive/2013/08/21/using-notepad-to-execute-oracle-sql.aspx

Notepad++是一个很实用的文本编辑工具,用它来执行Oracle SQL也很有意思,虽然不太实用,或许在某些场合会有用吧。

在此复制原文只作记录,原文见如上链接。

原文如下:

Toad for Oracle is the single most robust and powerful IDE (Integrated Development Environment) and DBA tool for all your Oracle database needs. It’s a veritable nuclear powered, Swiss army knife capable of grand accomplishments. However there may well be times where you need a smaller, focused and thus simpler tool for modest tasks – such as opening and running a straightforward SQL script, where you might make minor changes such as setting a different script variable value at the top. Yet you still expect important features such as syntax highlighting for readability. For those specific, lesser needs I often use the popular freeware editor Notepad++. However it requires some manual tweaking in order to have Notepad++ execute SQL via Oracle’s SQL*Plus. In this blog I’ll show you how.

Note: The astute reader might ask “Why not just use Toad’s free QSR utility (i.e. Quest Script Runner -- it ships with every copy of Toad for Oracle) which looks and operates the same way as the Toad Editor, but it only includes a subset of the Editor‘s features?” – shown below in Figure 1.   The answer is simple – people like choices and many people know and prefer Notepad++ as their standard Windows Notepad replacement and editor of choice for most simple needs.

Figure 1: Quest Script Runner Example

So let’s see how to enable Notepad++ to work much like QSR – where Notepad++ is the basic editor and spawns SQL*Plus to run the editor contents. It may not be as well integrated or flexible as QSR, but once again it’s what many people know and prefer for basic editing. Figure 2 shows the same script execution results as Figure 1.

Figure 2: Notepad++ Example

Here are the steps:

  1. Launch Notepad++
  2. Main menu -> Plugins -> Plugin Manager -> Show Plugin Manager
  3. Available Tab, Find and check NppExec plugin (see Figure 3 below)
  4. Press Install button to download & install plugin – restarts Notepad++
  5. Open a SQL script
  6. Press F6 key (NppExec’s default execute keyboard mapping)
  7. Enter the following macro script into the Execute pop-up (see Figure 4 below)   set ORA_USER=bert set ORA_PASS=bert1234 set ORA_SID= ORCL npp_save cmd /c copy /y "$(CURRENT_DIRECTORY)\$(FILE_NAME)" "$(SYS.TEMP)\$(FILE_NAME)" >nul 2>&1 cmd /c echo. >> "$(SYS.TEMP)\$(FILE_NAME)" cmd /c echo exit >> "$(SYS.TEMP)\$(FILE_NAME)" sqlplus -l $(ORA_USER)/$(ORA_PASS)@$(ORA_SID) @"$(SYS.TEMP)\$(FILE_NAME)"  
  8. Change the first three variables for your database, username and password
  9. Press the OK button

Figure 3: Notepad++ Plugin Manager – Enable NppExec

Figure 4: Save your SQL*Plus execute macro

 

 

Using Notepad++ to Execute Oracle SQL