CURRENT_SCHEMA

CURRENT_SCHEMA is a SQL function that returns the name of the current schema. In SQL, a schema is a collection of database objects that include tables, views, indexes, and procedures. The CURRENT_SCHEMA function is handy for determining the schema that is currently being utilized in a session. The return type of this function is a string representing the current schema's name.

CURRENT_SCHEMA()

Example

CREATE SCHEMA tech;
SET search_path TO tech;
SELECT CURRENT_SCHEMA;

Output

current_schema
------------------
tech
(1 row)

Explanation

In the example, a new schema named ‘tech’ is created. After that, the search path is set to ‘tech’, effectively making it the current schema. The CURRENT_SCHEMA function is then used to return the name of the current schema, which is ‘tech’.

CURRENT_SCHEMA

Example

SELECT CURRENT_SCHEMA FROM dual;

Output

'HR'

Explanation

The above SQL code retrieves the current schema in an Oracle database. The output ‘HR’ indicates that the current schema in use is ‘HR’.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.