Get Current Schema and Database Name
Topic Introduction: In this Tutorial, we will discuss some DBA and system-related work. such as finding Schema Name, User Session, Instance Name, User Details, User IP, User PC Name, etc.
Using SQL
SELECT NAME
FROM v$database;
SELECT SYS_CONTEXT ('USERENV','CURRENT_SCHEMA')
FROM DUAL;
Using PL/SQL Block
DECLARE
CURSOR CUR_DBNAME
IS
SELECT NAME
FROM v$database;
v_DBNAME VARCHAR2 (4000);
BEGIN
OPEN CUR_DBNAME;
FETCH CUR_DBNAME
INTO v_DBNAME ;
CLOSE CUR_DBNAME;
htp.p('Schema Name: '||SYS_CONTEXT ('USERENV',
'CURRENT_SCHEMA'
));
htp.p('My Database Name: '|| v_DBNAME );
END;
Result :
Schema Name: HR
My DB Name: ORCL
No comments