首页 > 数据库 > Oracle > pl/sql中的注释
一、注释分为单行注释和多行注释两种。
1.单行注释使用“--”。
DECLARE
howmany NUMBER;
num_tables NUMBER;
BEGIN
-- Begin processing
SELECT COUNT(*) INTO howmany
FROM USER_OBJECTS
WHERE OBJECT_TYPE = 'TABLE'; -- Check number of tables
num_tables := howmany; -- Compute another value
END;
2.多行注释以“/*”开始,“*/”结尾。
DECLARE
some_condition BOOLEAN;
pi NUMBER := 3.1415926;
radius NUMBER := 15;
area NUMBER;
BEGIN
/* Perform some simple tests and assignments */
IF 2 + 2 = 4 THEN
some_condition := TRUE;
/* We expect this THEN to always be performed */
END IF;
/* This line computes the area of a circle using pi,
which is the ratio between the circumference and diameter.
After the area is computed, the result is displayed. */
area := pi * radius**2;
DBMS_OUTPUT.PUT_LINE('The area is: ' || TO_CHAR(area));
END;
二、使用注释需要注意点
1.多行注释不能进行嵌套,如下面是错误的:
/*
IF 2 + 2 = 4 THEN
some_condition := TRUE;
/* We expect this THEN to always be performed */
END IF;
*/
2.多行注释里面可以嵌套单行注释:
/*
IF 2 + 2 = 4 THEN
some_condition := TRUE;
-- We expect this THEN to always be performed
END IF;
*/
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31557103/viewspace-2216639/ ,如需转载,请注明出处,否则将追究法律责任。