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

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

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

What you posted is Oracle SQL, but as written it isn’t valid.

What it does (or tries to do)

  • The inner subquery: (select granted_role from user_role_privs where granted_role = 'DBA') looks for the DBA role granted to the current user.
  • The outer part: select concat(... ) from DUAL attempts to call CONCAT but only provides one argument. Oracle’s CONCAT function requires two arguments, so this will raise an error (ORA-00922: missing or invalid option).

How to fix or write it correctly (exam-friendly variants)

  • Simple presence check (returns 'DBA' if the role exists, otherwise NULL) select (select granted_role from user_role_privs where granted_role = 'DBA') from dual;

  • Use COALESCE/NVL to have a non-NULL result select NVL((select granted_role from user_role_privs where granted_role = 'DBA'), 'NO_ROLE') from dual;

  • If you want to concatenate with another string (use the || operator or a properly 2-argument CONCAT) select (select granted_role from user_role_privs where granted_role = 'DBA') || '_suffix' from dual;

    Note: If the inner subquery might be NULL, you’ll get NULL for the whole expression with both CONCAT and || unless you wrap the inner query with NVL/COALESCE.

  • Alternative logical check (clear intent) select case when exists (select 1 from user_role_privs where granted_role = 'DBA') then 'DBA' else 'NOT_GRANTED' end as status from dual;

Key points

  • CONCAT in Oracle takes two arguments; your version has only one.
  • The inner scalar subquery returns 'DBA' or NULL depending on whether the role is granted.
  • Use NVL/COALESCE or the || operator for safe concatenation.

If you share what the intended output should be (e.g., just a flag, the role name, or a concatenated string), I can give a one-line correct query tailored to that.