Plsql 简明教程
PL/SQL - Environment Setup
在本章中,我们将讨论 PL/SQL 的环境设置。PL/SQL 不是一个独立的编程语言;它是 Oracle 编程环境中的一个工具。 SQL Plus* 是一个交互式工具,它允许你在命令提示符处键入 SQL 和 PL/SQL 语句。然后将这些命令发送到数据库进行处理。一旦这些语句 được xử lý,结果将被发送回并在屏幕上显示。
In this chapter, we will discuss the Environment Setup of PL/SQL. PL/SQL is not a standalone programming language; it is a tool within the Oracle programming environment. SQL Plus* is an interactive tool that allows you to type SQL and PL/SQL statements at the command prompt. These commands are then sent to the database for processing. Once the statements are processed, the results are sent back and displayed on screen.
要运行 PL/SQL 程序,你应该在你的机器上安装了 Oracle RDBMS Server。这将负责执行 SQL 命令。Oracle RDBMS 的最新版本是 11g。你可以从以下链接下载 Oracle 11g 的试用版 -
To run PL/SQL programs, you should have the Oracle RDBMS Server installed in your machine. This will take care of the execution of the SQL commands. The most recent version of Oracle RDBMS is 11g. You can download a trial version of Oracle 11g from the following link −
你将不得不根据你的操作系统下载 32 位或 64 位版本的安装程序。通常有两个文件。我们下载了 64 位版本。你还可以对你的操作系统使用类似的步骤,无论它是 Linux 还是 Solaris。
You will have to download either the 32-bit or the 64-bit version of the installation as per your operating system. Usually there are two files. We have downloaded the 64-bit version. You will also use similar steps on your operating system, does not matter if it is Linux or Solaris.
-
win64_11gR2_database_1of2.zip
-
win64_11gR2_database_2of2.zip
在下载以上两个文件后,你需要将它们解压到一个目录 database 中,并在该目录下你会找到以下子目录 -
After downloading the above two files, you will need to unzip them in a single directory database and under that you will find the following sub-directories −
Step 1
现在让我们使用安装文件启动 Oracle Database Installer。以下是第一个屏幕。你可以提供你的电子邮件 ID,并选中复选框,如以下屏幕截图所示。单击 Next 按钮。
Let us now launch the Oracle Database Installer using the setup file. Following is the first screen. You can provide your email ID and check the checkbox as shown in the following screenshot. Click the Next button.
Step 2
系统将把你定向到以下屏幕;取消选中复选框,然后单击 Continue 按钮继续。
You will be directed to the following screen; uncheck the checkbox and click the Continue button to proceed.
Step 3
使用单选按钮仅选择第一个选项 Create and Configure Database ,然后单击 Next 按钮继续。
Just select the first option Create and Configure Database using the radio button and click the Next button to proceed.
Step 4
我们假设你正在安装 Oracle 以用于基本的学习目的,并且你正在你的 PC 或笔记本电脑上安装它。因此,选择 Desktop Class 选项,然后单击 Next 按钮继续。
We assume you are installing Oracle for the basic purpose of learning and that you are installing it on your PC or Laptop. Thus, select the Desktop Class option and click the Next button to proceed.
Step 5
提供一个安装 Oracle 服务器的位置。只需修改 Oracle Base ,其他位置将自动设置。你還需要提供一个密码;此密码将由系统 DBA 使用。一旦你提供了所需的信息,单击 Next 按钮继续。
Provide a location, where you will install the Oracle Server. Just modify the Oracle Base and the other locations will set automatically. You will also have to provide a password; this will be used by the system DBA. Once you provide the required information, click the Next button to proceed.
Step 7
单击 Finish 按钮继续;这将启动实际的服务器安装。
Click the Finish button to proceed; this will start the actual server installation.
Step 8
这将会花些片刻时间,直到 Oracle 开始执行必需的配置。
This will take a few moments, until Oracle starts performing the required configuration.
Step 9
在此,Oracle 安装将复制必需的配置文件。这应该需要片刻时间−
Here, Oracle installation will copy the required configuration files. This should take a moment −
Step 10
复制数据库文件后,您将看到以下对话框。只需单击 OK 按钮并退出。
Once the database files are copied, you will have the following dialogue box. Just click the OK button and come out.
Final Step
现在是验证您的安装的时候了。在命令提示符处,如果您使用的是 Windows,请使用以下命令:−
It is now time to verify your installation. At the command prompt, use the following command if you are using Windows −
sqlplus "/ as sysdba"
您应该拥有用于编写 PL/SQL 命令和脚本的 SQL 提示符 −
You should have the SQL prompt where you will write your PL/SQL commands and scripts −
Text Editor
从命令提示符运行大型程序可能会导致无意中丢失部分工作。始终建议使用命令文件。要使用命令文件−
Running large programs from the command prompt may land you in inadvertently losing some of the work. It is always recommended to use the command files. To use the command files −
-
Type your code in a text editor, like Notepad, Notepad+, or EditPlus, etc.
-
Save the file with the .sql extension in the home directory.
-
Launch the SQL*Plus command prompt from the directory where you created your PL/SQL file.
-
Type @file_name at the SQL*Plus command prompt to execute your program.
如果您不使用文件执行 PL/SQL 脚本,则只需复制 PL/SQL 代码并右键单击显示 SQL 提示符的黑色窗口;使用 paste 选项将完整代码粘贴到命令提示符中。最后,如果尚未执行代码,只需按 Enter 即可执行代码。
If you are not using a file to execute the PL/SQL scripts, then simply copy your PL/SQL code and right-click on the black window that displays the SQL prompt; use the paste option to paste the complete code at the command prompt. Finally, just press Enter to execute the code, if it is not already executed.