2.2. Running Your First PL/SQL Program

To partake in a grand tradition of beginning programmers, the first program to write in a new language will merely print out the message "hello, world". PL/SQL can display this archetypal greeting with only three lines of code:

   DBMS_OUTPUT.PUT_LINE('hello, world');

This is called an anonymous block—that is, a block with no name. Its only executable statement is a call to the procedure PUT_LINE, supplied in Oracle's built-in package named DBMS_OUTPUT. This built-in stored procedure can accept a string that can get printed to the screen when you run it. As you can see, when your program needs to call another stored procedure, you merely invoke its name and supply any needed values. We'll discuss packaged procedures extensively in upcoming chapters.

The program seems simple enough, but how would you go about running it? For this we'll turn to an Oracle tool called SQL*Plus.

2.2.1. Starting SQL*Plus

Once you have access to an Oracle server, you almost certainly have access to a program called SQL*Plus, which is a very common command-line tool used by almost every Oracle programmer. Once it's installed properly, you can usually launch SQL*Plus from the command prompt (see the sidebar) using the sqlplus command.

OS> sqlplus

(Here, I've substituted OS> for the operating system command prompt. On MS Windows it might say C:\>, and on Unix, $.)

Sidebar 1. "Command Prompt"? What's That?

If you're a programming neophyte, it's possible ...

Get Learning Oracle PL/SQL now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.