Re: get the computer name (without the domain name)?

From: Aaron Leonard <aachleon_at_gmail.com>
Date: Thu, 20 May 2010 10:36:34 -0500
Message-ID: <AANLkTikqcLVJ_K8TsNzFAuEWIyVTphP_YIupZYp-wurv_at_mail.gmail.com>



In 10g and above, you can use the regexp_substr function to split on the backslash. You might want to use nvl to include those machines w/o a domain.

Example:

> select machine, nvl(regexp_substr(machine,'[^\]+',1,2),machine) from
v$session;

MACHINE
NVL(REGEXP_SUBSTR(MACHINE,'[^\]+',1,2),MACHINE)




OVRPROD\OPS-FLDWEBPRD03
OPS-FLDWEBPRD03
OVRPROD\OPS-FLDWEBPRD01
OPS-FLDWEBPRD01
OVRPROD\OPS-FLDWEBPRD02
OPS-FLDWEBPRD02
OVRPROD\OPS-FLDWEBPRD04
OPS-FLDWEBPRD04
OVRPROD\OPS-FLDWEBPRD02
OPS-FLDWEBPRD02
cscdbslxa023.ovrprod.com
cscdbslxa023.ovrprod.com
OVRPROD\OPS-FLDWEBPRD01
OPS-FLDWEBPRD01 On Thu, May 20, 2010 at 10:03 AM, Roger Xu <wellmetus_at_gmail.com> wrote:

> Hi expert,
>
> How can I only get the computer name (without the domain name)?
>
> SQL> select machine from v$session where sid=41;
> MACHINE
> --------------------
> Domain1\BB011499
> SQL>
>
>
> In UNIX, I would do this but I need it to be done inside SQL
>
> # echo 'Domain1\BB011499' | awk -F\\ '{print $NF}'
> BB011499
>
> Thanks,
>
> Roger Xu

--
http://www.freelists.org/webpage/oracle-l
Received on Thu May 20 2010 - 10:36:34 CDT

Original text of this message