I am not sure if MySql has a function similar to USER_ENV('CLIENT_INFO') in Oracle.
CLIENT_INFO is just a text stored in a session data by a client (whatever client - could be JDBC, OCI, sqlplus, toad etc.).
But you can simulate this by MySql session variables,
your 'client' (whatever it is) just must do:
set @client_info = 'some text'
and you can retrieve this text from a @client_info session variable.
If you do that in this way, then just replace USER_ENV('CLIENT_INFO') with @client_info in your code.
SUBSTRB ( text ,1,1 ) - retrieves the first letter from the text
DECODE( expr, val1, ret1, ret2 ) compares 'expr' with val1,
and when expr1=val1, returns 'ret1'. If they are not equal, then returns 'ret2'.
So
DECODE (
SUBSTRB ( USERENV ( 'CLIENT_INFO') ,1,1 ) , ' ' , NULL,
SUBSTRB ( USERENV ( 'CLIENT_INFO') ,1,10 )
)
checks if the first caracter of 'client_info' is a space,
and if yes -> returns NULL, otherwise returns first 10 characters from the 'client_info' string.
TO_NUMBER( str ) just converts a string to a number (or throws an exception if 'str' is not a number).
Edited 5 time(s). Last edit at 02/27/2012 02:55PM by irek kordirko.