| Lesson 5 | Using wildcards |
| Objective | Restrict many users at once by applying wildcards to SQL*Plus product profiles, using modern Oracle pattern-matching and security best practices. |
LIKE operator to search for patterns in text:
% (percent) matches zero or more characters._ (underscore) matches exactly one character.Examples in a typical query context:
-- Any last name starting with 'Smi'
SELECT *
FROM employees
WHERE last_name LIKE 'Smi%';
-- Exactly five characters, starting with 'Smi' and ending with 'h'
SELECT *
FROM employees
WHERE last_name LIKE 'Smi_h';
These same wildcard rules apply when you store patterns in a control table such as
PRODUCT_PROFILE (or its view PRODUCT_USER_PROFILE).
Instead of matching rows in a data table, the pattern is matched against usernames
and roles at SQL*Plus runtime, which is what this lesson focuses on.
When using wildcards, remember two modern best practices:
% in a LIKE predicate can prevent index usage
and cause full scans; use it intentionally and test performance.
Product profiles allow you to disable specific SQL*Plus commands or limit role
usage for users whose USERID or role matches a pattern. You can:
The examples in this lesson assume a table called
PRODUCT_PROFILE with columns such as
PRODUCT, USERID, ATTRIBUTE, and
CHAR_VALUE. SQL*Plus reads this information automatically when a user
logs in.
Suppose your naming convention uses BIDx (BID plus one character) for a
group of batch or integration users, and you want to prevent all of them from
issuing the INSERT command in SQL*Plus. You can do that with a single
row:
INSERT INTO PRODUCT_PROFILE (product, userid, attribute, char_value)
VALUES ('SQL*Plus', 'BID_', 'INSERT', 'DISABLED');
The underscore wildcard _ matches any single character, so this pattern
covers BID1, BID2, BIDA, and so on. Each of
those users will see INSERT disabled when they connect via SQL*Plus.
If you want to disable INSERT for every user whose name starts with
the letter B, you can make the pattern more general:
INSERT INTO PRODUCT_PROFILE (product, userid, attribute, char_value)
VALUES ('SQL*Plus', 'B%', 'INSERT', 'DISABLED');
Here, 'B%' matches BOB, BRIAN, BRUCE,
and any other username beginning with B. This is an efficient way to
enforce a business rule for a naming convention such as “all B* accounts are trainees
who must not insert data directly.”
INSERT INTO PRODUCT_PROFILE
(product, userid, attribute, char_value)
VALUES ('SQL*Plus', 'B%', 'INSERT', 'DISABLED');
This statement disables the INSERT command for every SQL*Plus user whose username begins with 'B'.
INSERT command when they connect through SQL*Plus.
Sometimes you need to prevent every SQL*Plus user from executing a specific command. For example, you might want to disable the HOST command so that users cannot spawn operating system shells from within SQL*Plus. You can accomplish this with a single wildcard pattern:
INSERT INTO PRODUCT_PROFILE (product, userid, attribute, char_value)
VALUES ('SQL*Plus', '%', 'HOST', 'DISABLED');
The '%' pattern in the USERID column matches all users, so this entry removes the HOST command from the SQL*Plus environment for every account that logs in.
INSERT, you prevent all users from accessing the
HOST command in SQL*Plus.
HOST command no longer
appears as an available command in SQL*Plus.
HOST command remains unavailable to all users who connect through SQL*Plus.
Product profiles also allow you to influence role behavior at login.
For example, the following statement prevents user BRIAN from having any roles enabled initially:
INSERT INTO PRODUCT_PROFILE (product, userid, attribute, char_value)
VALUES ('SQL*Plus', 'BRIAN', 'ROLES', '%');
In this case, the pattern is stored in CHAR_VALUE, and SQL*Plus treats
'%' as meaning “all roles.” Combined with the ROLES
attribute, this entry controls how roles are enabled when BRIAN starts a session.
In modern environments you would still design your security around database roles
and privileges, but product profiles can provide an additional layer of control for
SQL*Plus usage.
INSERT into PRODUCT_PROFILE can restrict a SQL
command such as INSERT for many users at once by using patterns like
'BID_' or 'B%'.
'%' in the USERID column disables a command
such as HOST for all SQL*Plus users.
ROLES attribute allow you to control which roles
are enabled for specific users when they connect.
In the next lesson, you will learn how to remove a restriction imposed by a product profile and restore a command or role for selected users.