SQLcl: set color in sqlprompt (ANSI/VT100 Control sequences)
-
17-02-2021 - |
Domanda
This is my login.sql
SET sqlprompt "_user'@'_connect_identifier > "
SET sqlformat ansiconsole
SET serveroutput on
SET lines 3000
How to set the sqlprompt
to color red for Prod (and green color for testing)?
Soluzione
From above link I created a Java Script in sqlcli bin directory(on windows 10)
C:\sqlcl-19.2.1.246.1707\sqlcl\bin>type PromptColor.js
//file name PromptColor.js save in sqlcli bin dir
//login sqlcli and run script PromptColor.js
var dbUser = util.executeReturnOneCol('select user from sys.dual');
if ( dbUser == 'HR' )
{
sqlcl.setStmt('set sqlprompt "@|red _USER|@@@|red _CONNECT_IDENTIFIER|@@|red >|@"');
}
else if ( dbUser == 'SOE')
{
sqlcl.setStmt('set sqlprompt "@|green _USER|@@@|green _CONNECT_IDENTIFIER|@@|green >|@"');
}
else
{
sqlcl.setStmt('set sqlprompt "@|blue _USER|@@@|blue _CONNECT_IDENTIFIER|@@|blue >|@"');
}
sqlcl.run();
login with default prompt
C:\sqlcl-19.2.1.246.1707\sqlcl\bin>sql soe/soe@localhost:1521/orclpdb.localdomain -- pdb database
SQLcl: Release 19.2.1 Production on Tue Nov 12 12:17:13 2019
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SQL>script PromptColor.js
Next is to figure how to call javascript from login.sql
Edit:- create a sql file with single line script PromptColor.js
place in SQLPATH directory and add that sqlfile name in login.sql it automatically changes color based on user logged in
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a dba.stackexchange