rspec/rules/S4532/plsql/rule.adoc

73 lines
1.7 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
Labels are useful to match the begin and end of each PACKAGE, PROCEDURE or FUNCTION, especially when the code is badly indented or too much nested.
This rule raised an issue when the END statement of a PACKAGE, PROCEDURE or FUNCTION is having no label matching the name of the corresponding "begin" statement.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,sql]
2021-04-28 16:49:39 +02:00
----
CREATE OR REPLACE PACKAGE BODY cust_sal AS
PROCEDURE find_sal(c_id customers.id%TYPE) IS
c_sal customers.salary%TYPE;
BEGIN
SELECT salary INTO c_sal
FROM customers
WHERE id = c_id;
dbms_output.put_line('Salary: '|| c_sal);
END; -- Noncompliant; not a PROCEDURE
END; -- Noncompliant; not a PACKAGE
/
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,sql]
2021-04-28 16:49:39 +02:00
----
CREATE OR REPLACE PACKAGE BODY cust_sal AS
PROCEDURE find_sal(c_id customers.id%TYPE) IS
c_sal customers.salary%TYPE;
BEGIN
SELECT salary INTO c_sal
FROM customers
WHERE id = c_id;
dbms_output.put_line('Salary: '|| c_sal);
END find_sal; -- Compliant; it's matching the name of the PROCEDURE
END cust_sal; -- Compliant: it's matching the name of the PACKAGE
/
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Add the missing "xxx" label to this statement.
=== Highlighting
First: the END statement
Second: the identifier of the matching package, procedure, function name
'''
== Comments And Links
(visible only on this page)
=== on 26 Mar 2018, 21:28:38 Alexandre Gigleux wrote:
This rule can't be applied to T-SQL: \https://docs.microsoft.com/en-us/sql/t-sql/statements/create-function-transact-sql
endif::env-github,rspecator-view[]