Ubuntu环境下使用Oracle SQL*Plus如何打开编辑器编写PL/SQL?
Hey there! I totally get what you're asking—on Windows, the ED "name.sql" command in SQLPlus pops open Notepad to write your SQL/PLSQL, but Ubuntu doesn't do that out of the box. No worries though, we can fix this by configuring SQLPlus to use a text editor of your choice. Here's how to do it step by step:
Temporary Fix (Works for Current SQL*Plus Session Only)
When you're inside SQL*Plus, just run this command to set your editor temporarily. For example, if you prefer the easy-to-use nano (which comes pre-installed on most Ubuntu systems):
DEFINE _EDITOR = 'nano'
If you're a vim fan, swap out nano for vim. Want a graphical editor like gedit? Use 'gedit' instead. After running this, typing ED name.sql will launch your chosen editor to write or edit your PL/SQL code.
Permanent Fix (Applies to Every SQL*Plus Session)
To make this setting stick every time you open SQL*Plus, you have two options:
Option 1: User-Level Configuration (Only for Your Account)
SQL*Plus runs a login.sql script when it starts (if it exists in your home directory). Let's create or edit it:
- Open your terminal and run:
nano ~/login.sql - Add this single line to the file:
DEFINE _EDITOR = 'nano' - Save and exit (press
Ctrl+O, thenEnter, thenCtrl+Xin nano).
Next time you start SQL*Plus, the editor setting will be loaded automatically.
Option 2: System-Level Configuration (All Users on the Machine)
If you want every user on the Ubuntu system to use the same editor, edit the global SQL*Plus startup script:
- Run this command (you'll need sudo privileges):
sudo nano $ORACLE_HOME/sqlplus/admin/glogin.sql - Add the same
DEFINE _EDITOR = 'nano'line to the file. - Save and exit. Now all users will have this editor setup when they use SQL*Plus.
Quick Tips
- If you're using a graphical editor like
gedit, make sure you're running SQL*Plus from a desktop terminal (not a headless/remote terminal without a GUI). Otherwise, it won't launch properly. - After editing your code and closing the editor, SQL*Plus will automatically recognize the changes. You can run the script right away with
@name.sqlor go back to editing withED name.sqlagain.
内容的提问来源于stack exchange,提问作者sujoy

