Lesson 5 | Adding comments |
Objective | Add Comments to a PL/SQL block. |
--
) anywhere on a line and can extend to the end of line.
-- This is an example of a comment
/*
and end with /
. Comments can span multiple lines and multiline comments in PL/SQL can be used to comment out whole sections of code.
/* This is an example of a comment that spans more than one line. */
/************************************************/ /* Name: pet_activity.sql */ /* Description: Sample Select Pet_Care_Log table*/ /* Arguments: (None) */ /* Return Value: (None) */ /* History: */ /************************************************/ DECLARE v_logdate DATE; v_product NUMBER(10); BEGIN SELECT LOG_DATETIME, PRODUCT_ID INTO v_logdate, v_product FROM PET_CARE_LOG WHERE PRODUCT_ID = 22; END;
DBMS_OUTPUT.PUT_LINE.
PETSTORE
in the User Name box. Type GREATPETS
in the Password box. Type MYDB
in the Host String box. Click the OK button.SET SERVEROUTPUT ON
End your SET command by clicking ENTER key. This tells SQL*Plus to execute the command. DECLARE
statement. Type DECLARE
at the SQL > prompt. End your command by clicking Enter. This tells SQL*Plus to move to the next line.NUMBER
and call it v_num
. Type v_num NUMBER;
at the 2 prompt. End your command by clicking Enter. This tells SQL*Plus to move to the next line.BEGIN
at the 3 prompt. End your command by clicking Enter. This tells SQL*Plus to move to the next line. v_num
. Type v_num := 42;
at the 4 prompt. End your command by clicking ENTER. This tells SQL*Plus to move to the next line./* Start nested block */
at the 5 prompt. End your command by clicking ENTER. This tells SQL*Plus to move to the next line.DECLARE
at the 6 prompt. End your command by clicking ENTER. This tells SQL*Plus to move to the next line. v_char
as a VARCHAR2(10)
variable that you will use at a later stage to convert the number to a string. Type v_char VARCHAR2(10);
at the 7 prompt. End your command by clicking ENTER. This tells SQL*Plus to move to the next line. BEGIN
at the 8 prompt. End your command by clicking ENTER. This tells SQL*Plus to move to the next line. v_num
) to a character string using the TO_CHAR
function and assign it to v_char
. Type v_char := TO_CHAR(v_num)
; at the 9 prompt. End your command by clicking ENTER.
This tells SQL*Plus to move to the next line. DBMS_OUTPUT.PUT_LINE
package procedure. Type DBMS_OUTPUT.PUT_LINE (v_char);
at the 10 prompt. End your command by clicking ENTER. This tells SQL*Plus to move to the next line.END;
at the 11 prompt. End your command by clicking ENTER. This tells SQL*Plus to move to the next line.END;
at the 12 prompt. End your command by clicking ENTER. This tells SQL*Plus to move to the next line./
at the 13 prompt for SQL*Plus to compile your PL/SQL block. End your command by clicking ENTER.