Decode函数的语法结构如下:
decode (expression, search_1, result_1)
decode (expression, search_1, result_1, search_2, result_2)
decode (expression, search_1, result_1, search_2, result_2, ...., search_n, result_n)
decode (expression, search_1, result_1, default)
decode (expression, search_1, result_1, search_2, result_2, default)
decode (expression, search_1, result_1, search_2, result_2, ...., search_n, result_n, default)
decode函数比较表达式和搜索字,如果匹配,返回结果;如果不匹配,返回default值;如果未定义default值,则返回空值。
以下是一个简单测试,用于说明Decode函数的用法:
SQL> create table t as select username,default_tablespace,lock_date from dba_users;Table created.SQL> select * from t;USERNAME DEFAULT_TABLESPACE LOCK_DATE------------------------------ ------------------------------ ---------SYS SYSTEMSYSTEM SYSTEMOUTLN SYSTEMCSMIG SYSTEMSCOTT SYSTEMEYGLE USERSDBSNMP SYSTEMWMSYS SYSTEM 20-OCT-048 rows selected.SQL> select username,decode(lock_date,null,'unlocked','locked') status from t;USERNAME STATUS------------------------------ --------SYS unlockedSYSTEM unlockedOUTLN unlockedCSMIG unlockedSCOTT unlockedEYGLE unlockedDBSNMP unlockedWMSYS locked8 rows selected.SQL> select username,decode(lock_date,null,'unlocked') status from t;USERNAME STATUS------------------------------ --------SYS unlockedSYSTEM unlockedOUTLN unlockedCSMIG unlockedSCOTT unlockedEYGLE unlockedDBSNMP unlockedWMSYS8 rows selected. ------------------------------------------------------------------------------------------------------------------------------------------------
userenv命令的语法:
USERENV returns information about the current session. This information can be useful for writing an application-specific audit trail table or for determining the language-specific characters currently used by your session. You cannot use USERENV in the condition of a CHECK constraint. Table 6-3 describes the values for the parameter argument.
All calls to USERENV return VARCHAR2 data except for calls with the SESSIONID, ENTRYID, and COMMITSCN parameters, which return NUMBER.
Table 6-3 Parameters of the USERENV Function
Parameter Return Value
CLIENT_INFO
CLIENT_INFO returns up to 64 bytes of user session information that can be stored by an application using the DBMS_APPLICATION_INFO package.
Caution: Some commercial applications may be using this context value. Check the applicable documentation for those applications to determine what restrictions they may impose on use of this context area.
See Also:
Oracle9i Database Concepts for more on application context
CREATE CONTEXT and SYS_CONTEXT
ENTRYID
ENTRYID returns available auditing entry identifier. You cannot use this attribute in distributed SQL statements. To use this keyword in USERENV, the initialization parameter AUDIT_TRAIL must be set to TRUE.
ISDBA
ISDBA returns 'TRUE' if the user has been authenticated as having DBA privileges either through the operating system or through a password file.
LANG
LANG returns the ISO abbreviation for the language name, a shorter form than the existing 'LANGUAGE' parameter.
LANGUAGE
LANGUAGE returns the language and territory currently used by your session along with the database character set in this form:
language_territory.characterset
SESSIONID
SESSIONID returns your auditing session identifier. You cannot use this attribute in distributed SQL statements.
TERMINAL
TERMINAL returns the operating system identifier for your current session's terminal. In distributed SQL statements, this attribute returns the identifier for your local session. In a distributed environment, this is supported only for remote SELECT statements, not for remote INSERT, UPDATE, or DELETE operations.
Examples
The following example returns the LANGUAGE parameter of the current session:
SELECT USERENV('LANGUAGE') "Language" FROM DUAL;
Language
-----------------------------------
AMERICAN_AMERICA.WE8DEC
----------------------------------------------------------------------------------------------------------------------------------------------------
sys_contex()函数作用:
Oracle9i(Version 9.2)SYS_CONTEXT函数的用法
这个函数在写一些触发器,函数的时候非常有用处。
用法:SELECT sys_context('USERENV', '<parameter>') FROM dual;
第二个参数的可选值:
AUTHENTICATION_DATA
Data being used to authenticate the login user. For X.503 certificate authenticated sessions, this field returns the context of the certificate in HEX2 format.
Note: You can change the return value of the AUTHENTICATION_DATA attribute using the length parameter of the syntax. Values of up to 4000 are accepted. This is the only attribute of USERENV for which Oracle implements such a change.
AUTHENTICATION_TYPE
How the user was authenticated:
DATABASE: username/password authentication
OS: operating system external user authentication
NETWORK: network protocol or ANO authentication
PROXY: OCI proxy connection authentication
BG_JOB_ID
Job ID of the current session if it was established by an Oracle background process. Null if the session was not established by a background process.
CLIENT_INFO
Returns up to 64 bytes of user session information that can be stored by an application using the DBMS_APPLICATION_INFO package.
CURRENT_SCHEMA
Name of the default schema being used in the current schema. This value can be changed during the session with an ALTER SESSION SET CURRENT_SCHEMA statement.
CURRENT_SCHEMAID
Identifier of the default schema being used in the current session.
CURRENT_USER
The name of the user whose privilege the current session is under.
CURRENT_USERID
User ID of the user whose privilege the current session is under.
DB_DOMAIN
Domain of the database as specified in the DB_DOMAIN initialization parameter.
DB_NAME
Name of the database as specified in the DB_NAME initialization parameter.
ENTRYID
The available auditing entry identifier. You cannot use this option in distributed SQL statements. To use this keyword in USERENV, the initialization parameter AUDIT_TRAIL must be set to true.
EXTERNAL_NAME
External name of the database user. For SSL authenticated sessions using v.503 certificates, this field returns the distinguished name (DN) stored in the user certificate.
FG_JOB_ID
Job ID of the current session if it was established by a client foreground process. Null if the session was not established by a foreground process.
HOST
Name of the host machine from which the client has connected.
INSTANCE
The instance identification number of the current instance.
IP_ADDRESS
IP address of the machine from which the client is connected.
ISDBA
TRUE if you are logged on as SYS.
LANG
The ISO abbreviation for the language name, a shorter form than the existing 'LANGUAGE' parameter.
LANGUAGE
The language and territory currently used by your session, along with the database character set, in the form:language_territory.characterset.
NETWORK_PROTOCOL
Network protocol being used for communication, as specified in the 'PROTOCOL=protocol' portion of the connect string.
NLS_CALENDAR
The current calendar of the current session.
NLS_CURRENCY
The currency of the current session.
NLS_DATE_FORMAT
The date format for the session.
NLS_DATE_LANGUAGE
The language used for expressing dates.
NLS_SORT BINARY
or the linguistic sort basis.
NLS_TERRITORY
The territory of the current session.
OS_USER
Operating system username of the client process that initiated the database session.
PROXY_USER
Name of the database user who opened the current session on behalf of SESSION_USER.
PROXY_USERID
Identifier of the database user who opened the current session on behalf of SESSION_USER.
SESSION_USER
Database user name by which the current user is authenticated. This value remains the same throughout the duration of the session.
SESSION_USERID
Identifier of the database user name by which the current user is authenticated.
SESSIONID
The auditing session identifier. You cannot use this option in distributed SQL statements.
TERMINAL
The operating system identifier for the client of the current session. In distributed SQL statements, this option returns the identifier for your local session. In a distributed environment, this is supported only for remote SELECT statements, not for remote INSERT, UPDATE, or DELETE operations.
(The return length of this parameter may vary by operating system.)
decode (expression, search_1, result_1)
decode (expression, search_1, result_1, search_2, result_2)
decode (expression, search_1, result_1, search_2, result_2, ...., search_n, result_n)
decode (expression, search_1, result_1, default)
decode (expression, search_1, result_1, search_2, result_2, default)
decode (expression, search_1, result_1, search_2, result_2, ...., search_n, result_n, default)
decode函数比较表达式和搜索字,如果匹配,返回结果;如果不匹配,返回default值;如果未定义default值,则返回空值。
以下是一个简单测试,用于说明Decode函数的用法:
SQL> create table t as select username,default_tablespace,lock_date from dba_users;Table created.SQL> select * from t;USERNAME DEFAULT_TABLESPACE LOCK_DATE------------------------------ ------------------------------ ---------SYS SYSTEMSYSTEM SYSTEMOUTLN SYSTEMCSMIG SYSTEMSCOTT SYSTEMEYGLE USERSDBSNMP SYSTEMWMSYS SYSTEM 20-OCT-048 rows selected.SQL> select username,decode(lock_date,null,'unlocked','locked') status from t;USERNAME STATUS------------------------------ --------SYS unlockedSYSTEM unlockedOUTLN unlockedCSMIG unlockedSCOTT unlockedEYGLE unlockedDBSNMP unlockedWMSYS locked8 rows selected.SQL> select username,decode(lock_date,null,'unlocked') status from t;USERNAME STATUS------------------------------ --------SYS unlockedSYSTEM unlockedOUTLN unlockedCSMIG unlockedSCOTT unlockedEYGLE unlockedDBSNMP unlockedWMSYS8 rows selected. ------------------------------------------------------------------------------------------------------------------------------------------------
userenv命令的语法:
USERENV returns information about the current session. This information can be useful for writing an application-specific audit trail table or for determining the language-specific characters currently used by your session. You cannot use USERENV in the condition of a CHECK constraint. Table 6-3 describes the values for the parameter argument.
All calls to USERENV return VARCHAR2 data except for calls with the SESSIONID, ENTRYID, and COMMITSCN parameters, which return NUMBER.
Table 6-3 Parameters of the USERENV Function
Parameter Return Value
CLIENT_INFO
CLIENT_INFO returns up to 64 bytes of user session information that can be stored by an application using the DBMS_APPLICATION_INFO package.
Caution: Some commercial applications may be using this context value. Check the applicable documentation for those applications to determine what restrictions they may impose on use of this context area.
See Also:
Oracle9i Database Concepts for more on application context
CREATE CONTEXT and SYS_CONTEXT
ENTRYID
ENTRYID returns available auditing entry identifier. You cannot use this attribute in distributed SQL statements. To use this keyword in USERENV, the initialization parameter AUDIT_TRAIL must be set to TRUE.
ISDBA
ISDBA returns 'TRUE' if the user has been authenticated as having DBA privileges either through the operating system or through a password file.
LANG
LANG returns the ISO abbreviation for the language name, a shorter form than the existing 'LANGUAGE' parameter.
LANGUAGE
LANGUAGE returns the language and territory currently used by your session along with the database character set in this form:
language_territory.characterset
SESSIONID
SESSIONID returns your auditing session identifier. You cannot use this attribute in distributed SQL statements.
TERMINAL
TERMINAL returns the operating system identifier for your current session's terminal. In distributed SQL statements, this attribute returns the identifier for your local session. In a distributed environment, this is supported only for remote SELECT statements, not for remote INSERT, UPDATE, or DELETE operations.
Examples
The following example returns the LANGUAGE parameter of the current session:
SELECT USERENV('LANGUAGE') "Language" FROM DUAL;
Language
-----------------------------------
AMERICAN_AMERICA.WE8DEC
----------------------------------------------------------------------------------------------------------------------------------------------------
sys_contex()函数作用:
Oracle9i(Version 9.2)SYS_CONTEXT函数的用法
这个函数在写一些触发器,函数的时候非常有用处。
用法:SELECT sys_context('USERENV', '<parameter>') FROM dual;
第二个参数的可选值:
AUTHENTICATION_DATA
Data being used to authenticate the login user. For X.503 certificate authenticated sessions, this field returns the context of the certificate in HEX2 format.
Note: You can change the return value of the AUTHENTICATION_DATA attribute using the length parameter of the syntax. Values of up to 4000 are accepted. This is the only attribute of USERENV for which Oracle implements such a change.
AUTHENTICATION_TYPE
How the user was authenticated:
DATABASE: username/password authentication
OS: operating system external user authentication
NETWORK: network protocol or ANO authentication
PROXY: OCI proxy connection authentication
BG_JOB_ID
Job ID of the current session if it was established by an Oracle background process. Null if the session was not established by a background process.
CLIENT_INFO
Returns up to 64 bytes of user session information that can be stored by an application using the DBMS_APPLICATION_INFO package.
CURRENT_SCHEMA
Name of the default schema being used in the current schema. This value can be changed during the session with an ALTER SESSION SET CURRENT_SCHEMA statement.
CURRENT_SCHEMAID
Identifier of the default schema being used in the current session.
CURRENT_USER
The name of the user whose privilege the current session is under.
CURRENT_USERID
User ID of the user whose privilege the current session is under.
DB_DOMAIN
Domain of the database as specified in the DB_DOMAIN initialization parameter.
DB_NAME
Name of the database as specified in the DB_NAME initialization parameter.
ENTRYID
The available auditing entry identifier. You cannot use this option in distributed SQL statements. To use this keyword in USERENV, the initialization parameter AUDIT_TRAIL must be set to true.
EXTERNAL_NAME
External name of the database user. For SSL authenticated sessions using v.503 certificates, this field returns the distinguished name (DN) stored in the user certificate.
FG_JOB_ID
Job ID of the current session if it was established by a client foreground process. Null if the session was not established by a foreground process.
HOST
Name of the host machine from which the client has connected.
INSTANCE
The instance identification number of the current instance.
IP_ADDRESS
IP address of the machine from which the client is connected.
ISDBA
TRUE if you are logged on as SYS.
LANG
The ISO abbreviation for the language name, a shorter form than the existing 'LANGUAGE' parameter.
LANGUAGE
The language and territory currently used by your session, along with the database character set, in the form:language_territory.characterset.
NETWORK_PROTOCOL
Network protocol being used for communication, as specified in the 'PROTOCOL=protocol' portion of the connect string.
NLS_CALENDAR
The current calendar of the current session.
NLS_CURRENCY
The currency of the current session.
NLS_DATE_FORMAT
The date format for the session.
NLS_DATE_LANGUAGE
The language used for expressing dates.
NLS_SORT BINARY
or the linguistic sort basis.
NLS_TERRITORY
The territory of the current session.
OS_USER
Operating system username of the client process that initiated the database session.
PROXY_USER
Name of the database user who opened the current session on behalf of SESSION_USER.
PROXY_USERID
Identifier of the database user who opened the current session on behalf of SESSION_USER.
SESSION_USER
Database user name by which the current user is authenticated. This value remains the same throughout the duration of the session.
SESSION_USERID
Identifier of the database user name by which the current user is authenticated.
SESSIONID
The auditing session identifier. You cannot use this option in distributed SQL statements.
TERMINAL
The operating system identifier for the client of the current session. In distributed SQL statements, this option returns the identifier for your local session. In a distributed environment, this is supported only for remote SELECT statements, not for remote INSERT, UPDATE, or DELETE operations.
(The return length of this parameter may vary by operating system.)
发表评论
-
Oracle特别函数---First_Value
2009-11-10 14:09 1855FIRST_VALUE 功能描述:返回组中数据窗口的第一个值。 ... -
oracle定时删除表空间的数据并释放表空间
2009-10-13 16:53 2614这两天我一个朋友问我 ... -
oracle定时任务(dbms_job)
2009-10-13 16:50 2300今天总结下oracle的任务队列管理器(job queue ) ... -
Oracle 中truncate与delete的区别
2009-10-13 16:27 1024Oracle 中truncate与delete的区别 收藏 ... -
数据库---存储过程总结
2009-10-13 16:20 946定义: ... -
oracle执行计划的理解
2009-10-13 16:12 736执行计划的理解 计信息 ------------------ ... -
oracle定时添加或删除分区表的分区
2009-10-13 16:11 2080这几天,根据业务的需求和性能的考虑,需要定时删除历史数据,表里 ... -
Oracle常用数据字典表
2009-09-16 09:00 1106查看当前用户的缺省表空间 SQL>select us ... -
关于SQL中的“\”的转义
2009-05-30 08:23 946select ename from myemp where e ... -
Oracle存储过程学习(2)
2009-05-11 08:05 1145存储过程创建语法: create or rep ... -
ora-12154 TNS:"无法处理服务名"的一个解决方法
2009-04-13 15:48 1449很怪异的一个问题,在网络环境下配置客户端,竟然怎么也连不上主机 ... -
触发器
2009-02-10 20:27 1017触发器 触发器是指被隐含执行的存储过程,当发生特定事件(例如修 ... -
Oracle 包
2009-02-06 20:08 1205包 包用于逻辑组合相关的PL/SQL类型、项、子程序,它由包 ... -
函数的纯度级别以及使用
2009-02-05 16:09 942函数的纯度级别以及使用 - 定义由函数读取或修改的数据种类。 ... -
管理存储过程和函数
2009-02-05 10:47 743管理存储过程和函数 1.列出当前用户的子程序 SQL>c ... -
Oracle 自定义函数
2009-02-04 14:49 3621函数 函数用于返回特定数据。执行时得找一个变量接收函数的返回值 ... -
Oracle存储过程
2009-02-04 11:05 1044Oracle存储过程 存储过程不仅可以简化客户端应用程序的开发 ... -
PL/SQL DEVELOPER 基本用法详解
2009-02-03 10:37 2369一.编辑表数据(浏览表 ... -
游标(二)
2009-02-02 16:14 824游标FOR循环 游标FOR循环是游标使用的最简单的方式,当使用 ... -
游标(一)
2009-02-01 15:28 812使用游标 当在pl/sql块中 ...
相关推荐
它的语法结构为 `decode(条件,值 1,返回值 1,值 2,返回值 2,...值 n,返回值 n,缺省值)`。decode 函数的含义是,如果条件等于值 1,则返回返回值 1,如果条件等于值 2,则返回返回值 2,以此类推,如果条件不等于任何...
### 关于decode函数的使用详解 #### 函数概述 `decode()`函数在SQL语言中是一种常用的条件函数,它可以根据指定的表达式返回不同的值。这种功能对于数据转换、分类统计等场景非常有用。 #### 主要作用 `decode()`...
Oracle DECODE函数功能很强,下面就为您详细介绍Oracle DECODE函数的用法,希望可以让您对Oracle DECODE函数有更多的了解。 Oracle DECODE函数 Oracle DECODE函数是Oracle公司独家提供的功能,它是一个功能很强的...
DECODE函数的基本语法如下: ``` DECODE(expression, search_1, result_1, search_2, result_2, ..., default) ``` 其中,`expression`是要检查的值,`search_n`是与`expression`进行比较的条件,而`result_n`是当...
DECODE 函数的语法是:DECODE(value, if1, then1, if2, then2, if3, then3, ..., else),表示如果 value 等于 if1 时,DECODE 函数的结果返回 then1,...,如果不等于任何一个 if 值,则返回 else。初看起来,DECODE...
Decode函数是Oracle数据库中用于实现条件逻辑的一个内置函数,它类似于编程语言中的switch-case语句或if-then-else语句。Decode函数可以对给定的表达式进行多个条件判断,并返回匹配条件的相应值。Decode函数广泛...
DECODE函数的基本语法如下: `DECODE(value, if1, then1, if2, then2, ..., else)` - `value`: 这是被比较的值,可以是表中的任何列或者计算结果。 - `if1, if2, ...`: 这些是测试条件,用来与`value`进行比较。 -...
DECODE函数的基本语法如下: ```sql DECODE(条件, 值1, 返回值1, 值2, 返回值2, ..., 值n, 返回值n, 缺省值) ``` 这个函数的工作原理是检查条件是否等于给定的一系列值。如果条件等于第一个值,则返回相应的第二个值...
#### 二、DECODE函数的基本语法 `DECODE`函数的基本语法如下: ```sql DECODE(input_value, value, result [, value, result] [, default_result]); ``` 其中: - `input_value`:需要被比较的输入值。 - `value`...
DECODE函数的基本语法如下: ```sql DECODE(column, value1, result1, value2, result2, ..., default_result) ``` 这里`column`是要检查的列,`value1`、`value2`等是你想要比较的值,`result1`、`result2`等是对应...
`DECODE`函数是Oracle数据库提供的一种条件判断函数,用于在表达式中执行简单的if-then逻辑。它的基本语法是: ```sql DECODE(expression, value1, result1, [value2, result2, ...], [default]) ``` - `...
在阅读博客文章《decode函数与case when 的妙用》时,作者可能分享了一些具体的示例和使用技巧,帮助我们更好地理解和掌握这两种方法。通过学习和实践,我们可以将这些知识应用于日常的数据库操作,优化数据处理流程...
Decode函数的语法结构如下: 代码如下:decode (expression, search_1, result_1)decode (expression, search_1, result_1, search_2, result_2)decode (expression, search_1, result_1, search_2, result_2, …., ...
### ORACLE DECODE函数在中国式报表统计查询中的组合条件实现 #### 一、引言 在Oracle数据库中,`DECODE`函数是一种非常实用的功能,主要用于条件判断并返回不同的值。它经常被用来进行简单的条件分支处理,尤其...
DECODE 函数的语法如下: DECODE(value, if1, then1, if2, then2, if3, then3, ... else) 其中,value 代表某个表的任何类型的任意列或一个通过计算所得的任何结果。当每个 value 值被测试,如果 value 的值为 if1...
DECODE()函数,它将输入数值与函数中的参数列表相比较,根据输入值返回一个对应值。区别于SQL的其它函数,DECODE函数还能识别和操作空值。本文详细介绍了DECODE函数的语法。