---
description: In this Oracle PL/SQL exercise, we will create a sample Hello World program. We will use dbms_output.put_line() to print Hello World.
title: PL/SQL Hello World Program (Example)
image: https://www.guru99.com/images/pl-sql-hello-world-program.png
---

[Skip to content](#main)

**⚡ Smart Summary**

PL/SQL First Program demonstrates how to connect to an Oracle database through SQL\*Plus and run a Hello World example. This resource explains the SQL\*Plus tool, connection details, anonymous blocks, variable declaration, and how comments work in PL/SQL.

- 🛠️ **SQL\*Plus Tool:** SQL\*Plus is the interactive and batch query tool installed with Oracle for executing PL/SQL commands.
- 🔌 **Database Connection:** Connecting requires a username, password, and host string with the port number and database SID.
- 👋 **Hello World Block:** An anonymous block uses BEGIN, dbms\_output.put\_line, and END followed by a slash to print output.
- 📦 **Using Variables:** The DECLARE section defines a VARCHAR2 variable that is assigned a value and printed at run time.
- 💬 **Comments:** PL/SQL supports single-line comments with double hyphens and multi-line comments wrapped in slash-star markers.

Read More

![PL/SQL First Program: Hello World](https://www.guru99.com/images/pl-sql-hello-world-program.png)

In this tutorial, we will introduce SQL\*Plus and learn how to connect it to the database.

After connection, we are also going to see how to write our first program, “Hello World”, in PL/SQL.

## What is SQL\*Plus?

SQL\*Plus is an interactive and batch query tool that is installed with every Oracle installation. It can be found at Start > Programs > Oracle-OraHomeName > Application Development > SQL Plus. Alternatively, you can also download it from the Oracle Technology Network (OTN).

It has a command-line user interface, a Windows GUI, and a web-based user interface.

It allows the user to connect to the database and execute PL/SQL commands.

## Connecting to Database

In this section, we are going to learn how to connect to SQL\*Plus in the Windows GUI. When we open SQL\*Plus, it will prompt for the connection details as shown below.

### Connection Details

- Username: \<user name of the database>
- Password: \<password for that user>
- Host String: \<host details along with the port number and SID of the database>

[![Connecting to Database]()](https://www.guru99.com/images/PL-SQL/110215_0652_PLSQLFirstP1.png)

- After the successful connection, the [SQL](https://www.guru99.com/sql.html) Plus will appear as shown below.

[![Connecting to Database]()](https://www.guru99.com/images/PL-SQL/110215_0652_PLSQLFirstP2.png)

- We need to execute “set serveroutput on” if we need to see the output of the code.
- Now we are ready to work with the SQL\*Plus tool.

## How to write a simple program using PL/SQL

In this section, we are going to write a simple program for printing “Hello World” using an “ [Anonymous block](https://www.guru99.com/blocks-pl-sql.html)“.

[![Write a simple program using PL/SQL]()](https://www.guru99.com/images/PL-SQL/110215_0652_PLSQLFirstP3.png)

```
BEGIN
dbms_output.put_line ('Hello World..');
END;
/
```

**Output:**

```
Hello World...
```

**Code Explanation:**

- **Code line 2**: Prints the message “Hello World…”.
- The below screenshot explains how to enter the code in SQL\*Plus.

**Note:** A block should always be followed by ‘/’, which sends the information to the compiler about the end of the block. Until the compiler encounters ‘/’, it will not consider the block complete, and it will not execute it.

[![Write a simple program using PL/SQL]()](https://www.guru99.com/images/PL-SQL/110215_0652_PLSQLFirstP4.png)

## Declaring and usage of variables in the program

Here we are going to print “Hello World” using variables.

[![Declaring and usage of Variables]()](https://www.guru99.com/images/PL-SQL/110215_0652_PLSQLFirstP5.png)

```
DECLARE
text VARCHAR2(25);
BEGIN
text := 'Hello World';
dbms_output.put_line (text);
END;
/
```

**Output:**

```
Hello World
```

**Code Explanation:**

- **Code line 2**: Declaring a variable “text” of a VARCHAR2 type with size 25.
- **Code line 4**: Assigning the value “Hello World” to the variable “text”.
- **Code line 5**: Printing the value of the variable “text”.

**Don't Miss:**

- [What is PL/SQL? Full Form & Architecture Explained](https://www.guru99.com/introduction-pl-sql.html)
- [PL/SQL Block: Structure, Syntax & Anonymous Example](https://www.guru99.com/blocks-pl-sql.html)
- [Oracle PL/SQL Object Types: CREATE TYPE with Examples](https://www.guru99.com/object-types-pl-sql.html)
- [While Loop in Oracle PL/SQL with Example](https://www.guru99.com/oracle-plsql-while-loop.html)

## Comments in PL/SQL

Commenting code simply instructs the compiler to ignore that particular code from executing.

Comments can be used in the program to increase the readability of the program. In PL/SQL, code can be commented in two ways:

- Using ‘–‘ at the beginning of the line to comment that particular line.
- Using ‘/\*……\*/’ we can comment multiple lines. The symbol ‘/\*’ marks the start of the comment and the symbol ‘\*/’ marks the end of the comment. The code between these two symbols will be treated as comments by the compiler.

**Example**: In this example, we are going to print ‘Hello World’ and we are also going to see how the commented lines behave in the code.

[![Comments in PL/SQL]()](https://www.guru99.com/images/PL-SQL/110215_0652_PLSQLFirstP6.png)

```
BEGIN
--single line comment
dbms_output.put_line ('Hello World');
/*Multi line commenting begins
Multi line commenting ends */
END;
/
```

**Output:**

```
Hello World
```

**Code Explanation:**

- **Code line 2**: Single-line comment, and the compiler ignored this line from execution.
- **Code line 3**: Printing the value “Hello World”.
- **Code line 4**: Multiline commenting starts with ‘/\*’.
- **Code line 5**: Multiline commenting ends with ‘\*/’.

## FAQs

🤖 Can AI write PL/SQL Hello World programs for beginners?

Yes. AI assistants can generate and explain PL/SQL blocks instantly. Beginners should still run each example in SQL\*Plus and understand every line to build a solid foundation in the language.

🧠 Does AI help debug PL/SQL code?

Yes. AI tools can spot common errors such as a missing slash, semicolon, or unbalanced quotes, and suggest fixes. This speeds up learning, but you should verify each fix by running the code.

🖨️ What does “set serveroutput on” do in PL/SQL?

It enables SQL\*Plus to display output from dbms\_output.put\_line. Without running this command first, your printed messages stay hidden and the program appears to produce no visible result.

📦 What is an anonymous block in PL/SQL?

An anonymous block is an unnamed PL/SQL program with an optional DECLARE section and a mandatory BEGIN-END section. It runs once and is not stored in the database, making it ideal for quick tests.

#### Summarize this post with:

ChatGPT Perplexity Grok Google AI

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.**

##### Sign up for the newsletter

Subscribe for Free

You have successfully subscribed.  
Please check your inbox.

![AI-Newsletter]() Chosen by over **350,000+** professionals

[Scroll to top](#wrapper)

×

Search for:

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/pl-sql-hello-world-program.png","url":"https://www.guru99.com/images/pl-sql-hello-world-program.png","width":"700","height":"250","caption":"PL/SQL Hello World Program","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/pl-sql-first-program-helloworld.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/pl-sql","name":"PL-SQL"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/pl-sql-first-program-helloworld.html","name":"PL/SQL Hello World Program (Example)"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/pl-sql-first-program-helloworld.html#webpage","url":"https://www.guru99.com/pl-sql-first-program-helloworld.html","name":"PL/SQL Hello World Program (Example)","dateModified":"2026-10-07T18:07:45+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/pl-sql-hello-world-program.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/pl-sql-first-program-helloworld.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/editorial","name":"Editorial Team","url":"https://www.guru99.com/author/editorial","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/favicon-new-logo.png","url":"https://www.guru99.com/images/favicon-new-logo.png","caption":"Editorial Team","inLanguage":"en-US"},"sameAs":["https://www.guru99.com/editorial-team"],"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"PL-SQL","headline":"PL/SQL Hello World Program (Example)","description":"In this Oracle PL/SQL exercise, we will create a sample Hello World program. We will use dbms_output.put_line() to print Hello World.","keywords":"pl-sql","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/editorial","name":"Editorial Team"},"dateModified":"2026-10-07T18:07:45+05:30","image":{"@id":"https://www.guru99.com/images/pl-sql-hello-world-program.png"},"copyrightYear":"2026","name":"PL/SQL Hello World Program (Example)","subjectOf":[{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"Can AI write PL/SQL Hello World programs for beginners?","acceptedAnswer":{"@type":"Answer","text":"Yes. AI assistants can generate and explain PL/SQL blocks instantly. Beginners should still run each example in SQL*Plus and understand every line to build a solid foundation in the language."}},{"@type":"Question","name":"Does AI help debug PL/SQL code?","acceptedAnswer":{"@type":"Answer","text":"Yes. AI tools can spot common errors such as a missing slash, semicolon, or unbalanced quotes, and suggest fixes. This speeds up learning, but you should verify each fix by running the code."}},{"@type":"Question","name":"What does \"set serveroutput on\" do in PL/SQL?","acceptedAnswer":{"@type":"Answer","text":"It enables SQL*Plus to display output from dbms_output.put_line. Without running this command first, your printed messages stay hidden and the program appears to produce no visible result."}},{"@type":"Question","name":"What is an anonymous block in PL/SQL?","acceptedAnswer":{"@type":"Answer","text":"An anonymous block is an unnamed PL/SQL program with an optional DECLARE section and a mandatory BEGIN-END section. It runs once and is not stored in the database, making it ideal for quick tests."}}]}],"@id":"https://www.guru99.com/pl-sql-first-program-helloworld.html#schema-1126333","isPartOf":{"@id":"https://www.guru99.com/pl-sql-first-program-helloworld.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/pl-sql-first-program-helloworld.html#webpage"}}]}
```
