UsingPLSQLWithOracleServer - Block statements Learning...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Block statements Learning objective After completing this topic, you should be able to write lexical units in their correct format in a PL/SQL block. 1. Identifiers A block is the most basic unit of code in the PL/SQL programming language. You use a series of blocks to build a module, such as a procedure or a function. A collection of modules makes up an application. Lexical units are the elements that make up each PL/SQL block. You use sequences of letters, numbers, special characters, symbols, spaces, tabs, and returns to create the various lexical units. Each lexical unit can be classified as an identifier a delimiter a literal a comment Identifiers are used to give names to variables. An identifier can be any of the following PL/SQL objects: a constant an exception a function a package a procedure For example, here you are naming a date variable, " begin date" , and assigning a value to the variable. The identifier is begin_date . DECLARE begin_date DATE:= '20-Mar-2001'; An identifier can be a maximum of 30 characters in length must start with a letter can contain $ (dollar sign), # (pound sign), and _ (underscore) characters cannot contain blank spaces, unless it is a quoted identifier Here's an example of a PL/SQL block using a number of identifiers to define variables. In the first declaration section, you have identified the output for Father's Name as a variable, father_name , which in this case is Patrick .
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The second variable identifies 20-Apr-1972 as the value of date_of_birth . SET SERVEROUTPUT ON DECLARE father_name VARCHAR2(20):='Patrick'; date_of_birth DATE:='20-Apr-1972'; BEGIN DECLARE child_name VARCHAR2(20):='Mike'; date_of_birth DATE:='12-Dec-2002'; BEGIN DBMS_OUTPUT.PUT_LINE('Father''s Name: '||father_name); DBMS_OUTPUT.PUT_LINE('Date of Birth: '||date_of_birth); DBMS_OUTPUT.PUT_LINE('Child''s Name: '||child_name); END; DBMS_OUTPUT.PUT_LINE('Date of Birth: '||date_of_birth); END; / You then use these identifiers to specify how the output will appear. And here is the output after using the identifiers. You can get around some of the restrictions of identifiers by placing the quote marks around the identifier, as shown here. Using quote marks enables you to make identifiers case sensitive include characters such as spaces use reserved words make identifiers case sensitiveinclude characters such as spacesuse reserved words DECLARE "Begin Date" DATE:= '20-Mar-2001'; Question You are writing PL/SQL to output the names of an employee. You want to name the First Name variable first name , and assign it the value Carol . Complete the missing code to use an identifier to retrieve this first name.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 49

UsingPLSQLWithOracleServer - Block statements Learning...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online