SECLABEL_BY_NAME scalar function

The SECLABEL_BY_NAME function returns the specified security label. The security label returned has a data type of DB2SECURITYLABEL. Use this function to insert a named security label.

Read syntax diagramSkip visual syntax diagramSECLABEL_BY_NAME(security-policy-name ,security-label-name)

The schema is SYSIBM.

security-policy-name
A string that specifies a security policy that exists at the current server (SQLSTATE 42704). The string must be a character or graphic string constant or host variable.
security-label-name
An expression that returns the name of a security label that exists at the current server for the security policy named by security-policy-name (SQLSTATE 4274I). The expression must return a value that is a built-in CHAR, VARCHAR, GRAPHIC, or VARGRAPHIC data type.

Examples

In the following examples, Tina is trying to insert a row in table REGIONS which is protected by the security policy named CONTRIBUTIONS. Tina wants the row to be protected by the security label named EMPLOYEESECLABEL.

  • Example 1: This statement fails because CONTRIBUTIONS.EMPLOYEESECLABEL is an unknown identifier:
       INSERT INTO REGIONS
       VALUES (CONTRIBUTIONS.EMPLOYEESECLABEL, 1, 'Southwest')   -- incorrect 
  • Example 2: This statement fails because the first value is a string, it does not have a data type of DB2SECURITYLABEL:
       INSERT INTO REGIONS
       VALUES ('CONTRIBUTIONS.EMPLOYEESECLABEL', 1, 'Southwest') -- incorrect
  • Example 2: This statement succeeds because the SECLABEL_BY_NAME function returns a security label that has a data type of DB2SECURITYLABEL:
       INSERT INTO REGIONS
       VALUES (SECLABEL_BY_NAME('CONTRIBUTIONS', 'EMPLOYEESECLABEL'),
         1, 'Southwest')                                         -- correct