Новая Школа - онлайн-школа подготовки к ЕГЭ
Задача Задача №3620078
А
Аноним
17 июня 2026 23:04 · публичный вопрос
А
Аноним

(select concat((select granted_role from user_role_privs where granted_role = 'DBA') from DUAL))

Ответ нейросети
17 июня 2026 23:04

That snippet looks like an attempt to fetch the DBA role via a scalar subquery and odd use of CONCAT. As written, it’s not valid Oracle SQL for a couple of reasons:

  • CONCAT in Oracle takes exactly two arguments; your expression supplies only one.
  • The outer FROM DUAL belongs to the outer query, not inside the subquery argument.
  • The inner scalar subquery (select granted_role from user_role_privs where granted_role = 'DBA') may return multiple rows or none, which can cause errors.

If you just want to know whether the current user has the DBA role (and avoid errors if there are multiple rows), you can use one of these safer options:

  1. Check existence (clear boolean result)
  • Oracle: SELECT CASE WHEN EXISTS (SELECT 1 FROM user_role_privs WHERE granted_role = 'DBA') THEN 'DBA granted' ELSE 'DBA not granted' END AS dba_status FROM dual;
  1. Return the actual role value (safe single-row return)
  • Oracle (limits to one row with ROWNUM): SELECT NVL((SELECT granted_role FROM user_role_privs WHERE granted_role = 'DBA' AND ROWNUM = 1), 'NO_ROLE') AS granted_role FROM dual;
  1. Simple concatenation of the result (using ||)
  • Oracle: SELECT 'Role: ' || NVL((SELECT granted_role FROM user_role_privs WHERE granted_role = 'DBA' AND ROWNUM = 1), 'NONE') AS result FROM dual;

If you want to keep the idea of concatenation, use the two-argument CONCAT or the || operator, and ensure the inner subquery returns at most one row (often enforced with ROWNUM or an appropriate WHERE clause).