Decode函数的语法

2023-11-10

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                            SYSTEM
SYSTEM                         SYSTEM
OUTLN                          SYSTEM
CSMIG                          SYSTEM
SCOTT                          SYSTEM
EYGLE                          USERS
DBSNMP                         SYSTEM
WMSYS                          SYSTEM                         20-OCT-04
8 rows selected.

SQL> select username,decode(lock_date,null,'unlocked','locked') status from t;
USERNAME                       STATUS
------------------------------ --------
SYS                            unlocked
SYSTEM                         unlocked
OUTLN                          unlocked
CSMIG                          unlocked
SCOTT                          unlocked
EYGLE                          unlocked
DBSNMP                         unlocked
WMSYS                          locked
8 rows selected.
SQL> select username,decode(lock_date,null,'unlocked') status from t;
USERNAME                       STATUS
------------------------------ --------
SYS                            unlocked
SYSTEM                         unlocked
OUTLN                          unlocked
CSMIG                          unlocked
SCOTT                          unlocked
EYGLE                          unlocked
DBSNMP                         unlocked
WMSYS
8 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:

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.)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Decode函数的语法 的相关文章

  • 显示包含特定表的所有数据库名称

    我的 SQL Server 中有很多数据库 我必须只搜索包含特定表名的数据库名称Heartbitmaster 我有很多数据库 例如Gotgold DVD等 我只想从包含此表的查询中查找数据库名称Heartbitmaster 我搜索我尝试查询
  • PostgreSQL 如何创建数据库或模式的副本?

    有没有一种简单的方法可以在 PostgreSQL 8 1 中创建数据库或模式的副本 我正在测试一些软件 它对数据库中的特定模式进行大量更新 我想复制它 以便我可以与原始版本进行一些比较 如果它位于同一服务器上 则只需使用带有 TEMPLAT
  • ServiceStack自定义用户身份验证

    有谁有一个关于如何按照本建议使用 int RefId 的实际示例question https stackoverflow com questions 11117469 how can i extend servicestack authen
  • 将 Access 数据库转换为 SQL Microsoft DTS - 数据类型“130”不在映射文件中

    我正在尝试将大型 Access mdb 数据库导出到 SQL Server 数据库 但遇到了 Microsoft DTS 无法识别 Access 数据库中特定类型字段的数据类型的问题 我查看了相关的访问表 它们被设置为长度为 1 的 文本
  • 连接多个用户的 R 闪亮会话

    最小可重现示例 library shiny ui lt fluidPage actionButton button1 Run 1 actionButton button2 Run 2 server lt function session i
  • Facebook-API 中的会话密钥和访问令牌

    有人可以向我解释一下什么是会话密钥和访问令牌吗 怎样才能抓住那两个人呢 为什么以及何时需要使用它们 什么时候是 一次性 什么时候不是 另外 他们之间有什么区别 请用Java 来做 我是一位刚接触 facebook API 的 Java 开发
  • Grails + Spring Security:无法登录

    我刚刚开始学习Grails和Spring 我已经按照官方教程创建了一个登录系统 但我无法登录 用户名或密码不匹配 我知道 90 的情况下这是由于双重编码或多个数据源 这也导致双重编码 造成的 但我也没有这样做 class BootStrap
  • 在 Rails 3 中选择性地关闭 Devise 的 Flash 通知

    Devise 身份验证框架在各处都使用 Flash 通知 这使得与应用程序集成变得很容易 但有时会导致用户体验不佳 我想知道有什么简单的方法可以有选择地关闭 Rails 3 应用程序中的一些 Devise flash 通知 特别是 我想摆脱
  • 具有多个主键的 SQLAlchemy 不会自动设置任何

    我有一个简单的表 class test Base tablename test id Column Integer primary key True title Column String def init self title self
  • AADSTS50011:请求中指定的回复 URL 与为应用程序配置的回复 URL 不匹配:'*****-*****-*****-*****-**** ******'

    我正在尝试使用 Django Microsoft 身份验证后端 允许 o365 登录我的 Django 项目 https django microsoft auth readthedocs io en latest https django
  • 如何根据条件删除结果以计算平均值

    我有下面的架构 对其的快速解释是 鲍勃评分为 5 5 詹姆斯评分 1 5 梅西百货评分高达 5 5 逻辑 如果我是 A 请查找我屏蔽的所有人 查阅所有电影评论 任何留下电影评论且 personA 已屏蔽的人 请将其从计算中删除 计算电影的平
  • SQL 按计数排序

    如果我有一个表和这样的数据 ID Name Group 1 Apple A 2 Boy A 3 Cat B 4 Dog C 5 Elep C 6 Fish C 我希望根据 Group 的总和从小到大进行排序 例如 A 2条记录 B 1条记录
  • 浏览器关闭时 Omniauth 会话过期

    在我的 Rails 3 应用程序中 我使用 Omniauth 进行用户身份验证部分 fb twitter 实际上我遵循这个 https github com RailsApps rails3 mongoid omniauth https g
  • 游戏中心邀请处理程序,它属于哪里?

    我已经搜索了该网站并发现了这个 GameCenter 邀请处理程序 https stackoverflow com questions 4639284 gamecenter invitation handler He says 正如文档中所
  • 通过 SQLAlchemy 获取随机行

    如何使用 SQLAlchemy 从表中选择一个或多个随机行 这在很大程度上是一个特定于数据库的问题 我知道 PostgreSQL SQLite MySQL 和 Oracle 具有通过随机函数排序的能力 因此您可以在 SQLAlchemy 中
  • 如何使用 next auth 通过自定义 Spring API 库和端点进行身份验证

    我是 Next js 的新手 正在将我的前端从 React 迁移到 Next v4 我已经使用 Spring 开发了一个后端 它连接到 Azure 上托管的 MySQL 数据库 该 API 在 Postman 和 React 前端上经过全面
  • Android:打开和关闭SQLite数据库

    我正在开发Android应用程序 我经常在其中访问本地数据库 该数据库可以从不同的主题访问 因此我遇到了数据库的协调问题 我使用以下open and close method public void open mDb mDbHelper g
  • 自托管 WCF REST 服务和基本身份验证

    我创建了一个自托管的 WCF REST 服务 带有 WCF REST Starter Kit Preview 2 中的一些额外内容 这一切工作正常 我现在正在尝试向服务添加基本身份验证 但我在 WCF 堆栈中遇到了一些相当大的障碍 这阻止了
  • java库维护数据库结构

    我的应用程序一直在开发 所以偶尔 当版本升级时 需要创建 更改 删除一些表 修改一些数据等 通常需要执行一些sql代码 是否有一个 Java 库可用于使我的数据库结构保持最新 通过分析类似 db structure version 信息并执
  • 如何使用 Google 帐户对我们网站中的用户进行身份验证

    如何在我们的网站中使用 Google 帐户对用户进行身份验证 我希望用户重定向到谷歌登录页面 然后将他重定向到我的网站 我想要这个 PHP 实现 你要OAuth http code google com apis accounts docs

随机推荐

  • 【C语言实现简单数据结构】单链表

    C语言实现简单数据结构 单链表 心有所向 日复一日 必有精进 文章目录 C语言实现简单数据结构 单链表 前言 链表 1 1链表的概念和结构 1 2链表的分类 1 3单链表的实现 1 3 1接口实现 1 3 2动态申请一个结点 1 3 3单链
  • 【Linux】文件目录操作指令(pwd、ls、cd、mkdir、rmdir、touch、cp、rm、mv、cat、echo、tail等)

    目录 1 指定运行级别 1 1 基本介绍 1 2 应用实例 2 帮助指令 2 1 man获得帮助信息 2 2 help指令 3 文件目录类 3 1 pwd指令 3 2 ls指令 3 3 cd指令 3 4 mkdir指令 3 5 rmdir指
  • sort自定义排序方式

    2022 05 14 sort 方式1 结构体内重载运算符 方式2 cmp参数 与优先队列类比 Java和python的处理方式 Java python sort sort a begin a end sort a a n n为数组长度 通
  • C/C++Unix网络编程-IPC简介

    IPC是进程间通信的简称 进程 线程与信息共享 Unix进程间的信息共享的方式 1 左边的两个进程共享存留于文件系统中某个文件上的某些信息 为访问这些信息 每个进程都得穿越内核 例如read write lseek等 当一个文件有待更新时
  • Hadoop MapReduce执行过程详解(带hadoop例子)

    为什么80 的码农都做不了架构师 gt gt gt 分析MapReduce执行过程 MapReduce运行的时候 会通过Mapper运行的任务读取HDFS中的数据文件 然后调用自己的方法 处理数据 最后输出 Reducer任务会接收Mapp
  • UE4_模型_Bound(边界)

    放置在关卡中的每个Actor都有一个bound bound由两部分组成 蓝色的长方体和黄色的球体 Bound是专门用来测试一个物体是否可见的 边界球用于通过简单的距离测试进行快速碰撞检测 而且 通常情况下 它的大小大于它包含的对象 另一方面
  • 逻辑左移、逻辑右移、算术左移、算术右移、循环左移、循环右移的学习

    逻辑左移时 最高位丢失 最低位补0 逻辑右移时 最高位补0 最低位丢失 算术左移时 依次左移一位 尾部补0 最高的符号位保持不变 算术右移时 依次右移一位 尾部丢失 符号位右移后 原位置上复制一个符号位 循环左移时 将最高位重新放置最低位
  • Vue promise的用法

    1 promise是什么 它可以说是异步编程的一种解决方法 就拿传统的ajax发请求来说 单个还好 如果是一个请求回来的数据还要被其他请求调用 不断地嵌套 可想而知 代码看起来是很乱的 promise主要是为了解决这种情景而出现的 2 简单
  • 山东科技大学oj题库1165 打印金字塔 之一

    include
  • vs查看宏展开

    宏在我们的代码中能经常给我们带来很大的便利 但是有些宏会造成意向不到的错误 能够查看宏展开就能够查看宏错误的根源 VS2008对编译是不保存预处理的文件信息的 而宏展开的信息就是在预编译阶段 如下图 工程属性 配置属性 c c 预处理器 生
  • 【数据分析】数据分析方法(七):AARRR 模型分析 & 漏斗分析

    数据分析方法 七 AARRR 模型分析 漏斗分析 1 AARRR 模型分析方法 如果把产品看作一个鱼塘 使用产品的用户看作鱼塘里的鱼 AARRR 模型的五个环节可以描述如下 获取用户 Acquisition 想办法给鱼塘里添加新的鱼 从而扩
  • vue注册自定义指令

    src 新建文件夹directive directive下新建modules文件夹 里面存放指令js文件 新建prevetMultiClick jk 防按钮多次重复点击的指令 export default inserted el bindi
  • python open3d点云可视化(本节会根据实际所用持续更新)

    本文为博主原创文章 未经博主允许不得转载 本文为专栏 python三维点云从基础到深度学习 系列文章 地址为 https blog csdn net suiyingy article details 124017716 为了便于加强对点云数
  • 基于cocos2d-x的2D空间中的OBB(Orient Bounding Box)碰撞检测算法

    引言 最近在与好友聊天的过程中 好友问我如何实现类似这样的游戏 它主要想知道 如何检测旋转过后的物体与其他物体之间的碰撞 我们知道 在没有旋转的情况下 对于这样的方块 比较规则的物体 我们完全可以使用AABB Axie Align Bond
  • Docker容器安装启动以及基本指令

    Docker使用步骤 一 ubuntu安装Docker 更新ubuntu的apt源索引 sudo apt get update 安装包允许apt通过HTTPS使用仓库 sudo apt get install apt transport h
  • 《零基础入门学习python》学习过程(四)

    学习时间 2017 09 19 第14课 元组 知识点汇总 元组和列表最本质的区别就是元组是封闭的列表 它一旦定义就不可修改 不可插入或删除任意一个元素等操作 创建和访问一个元组 gt gt gt tuple2 创建一个空元组 gt gt
  • vue里的$attrs

    attrs官网介绍 关于 attrs vue官网如是介绍 包含了父作用域中不作为 prop 被识别 且获取 的特性绑定 class 和 style 除外 当一个组件没有声明任何 prop时 这里会包含所有父作用域的绑定 class 和 st
  • CSS transform变换(一)

    1 transiate x y 设置盒子位移
  • Vue 中既可以输入也可以下拉选择(改进版)

    项目场景 项目场景 由于前些天 弄了一个下拉选择 也可以输入的 input输入框 但我感觉效果并不是很优美 所以今天对以前的代码 改进并进行优化 达到一个完美的效果 代码CV就可以用前提是你得将数据参数改为你的 问题描述 昨天的代码 参照网
  • Decode函数的语法

    Decode函数的语法结构如下 decode expression search 1 result 1 decode expression search 1 result 1 search 2 result 2 decode express