国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Database Mysql Tutorial Oracle DECODE

Oracle DECODE

Jun 07, 2016 pm 03:50 PM
decode oracle function

Oracle DECODE函數(shù)功能很強(qiáng),下面就為您詳細(xì)介紹Oracle DECODE函數(shù)的用法,希望可以讓您對Oracle DECODE函數(shù)有更多的了解。 Oracle DECODE函數(shù) Oracle DECODE函數(shù)是Oracle公司獨(dú)家提供的功能,它是一個(gè)功能很強(qiáng)的函數(shù)。它雖然不是SQL的標(biāo)準(zhǔn),但對于性能非常

Oracle DECODE函數(shù)功能很強(qiáng),下面就為您詳細(xì)介紹Oracle DECODE函數(shù)的用法,希望可以讓您對Oracle DECODE函數(shù)有更多的了解。

Oracle DECODE函數(shù)

Oracle DECODE函數(shù)是Oracle公司獨(dú)家提供的功能,它是一個(gè)功能很強(qiáng)的函數(shù)。它雖然不是SQL的標(biāo)準(zhǔn),但對于性能非常有用。到目前,其他的數(shù)據(jù)庫供應(yīng)商還不能提供類似DECODE的功能,甚至有的數(shù)據(jù)庫的供應(yīng)商批評Oracle的SQL不標(biāo)準(zhǔn)。實(shí)際上,這種批評有些片面或不夠水平。就象有些馬車制造商抱怨亨利。福特的“馬車”不標(biāo)準(zhǔn)一樣。

1 DECODE 中的if-then-else邏輯
在邏輯編程中,經(jīng)常用到If – Then –Else 進(jìn)行邏輯判斷。在DECODE的語法中,實(shí)際上就是這樣的邏輯處理過程。它的語法如下:
DECODE(value, if1, then1, if2,then2, if3,then3, . . . else )
Value 代表某個(gè)表的任何類型的任意列或一個(gè)通過計(jì)算所得的任何結(jié)果。當(dāng)每個(gè)value值被測試,如果value的值為if1,Decode 函數(shù)的結(jié)果是then1;如果value等于if2,Decode函數(shù)結(jié)果是then2;等等。事實(shí)上,可以給出多個(gè)if/then 配對。如果value結(jié)果不等于給出的任何配對時(shí),Decode 結(jié)果就返回else 。
需要注意的是,這里的if、then及else 都可以是函數(shù)或計(jì)算表達(dá)式。
含義解釋:
DECODE(條件,值1,翻譯值1,值2,翻譯值2,...值n,翻譯值n,缺省值)

該函數(shù)的含義如下:
IF 條件=值1 THEN
RETURN(翻譯值1)
ELSIF 條件=值2 THEN
RETURN(翻譯值2)
......
ELSIF 條件=值n THEN
RETURN(翻譯值n)

ELSE
RETURN(缺省值)
END IF

2 DECODE 的簡單例子
Oracle系統(tǒng)中就有許多數(shù)據(jù)字典是使用decode 思想設(shè)計(jì)的,比如記錄會話信息的V$SESSION數(shù)據(jù)字典視圖就是這樣。我們從《Oracle8i/9i Reference》資料中了解到,當(dāng)用戶登錄成功后在V$SESSION中就有該用戶的相應(yīng)記錄,但用戶所進(jìn)行的命令操作在該視圖中只記錄命令的代碼 (0—沒有任何操作,2—Insert…),而不是具體的命令關(guān)鍵字。因此,我們需要了解當(dāng)前各個(gè)用戶的名字及他們所進(jìn)行的操作時(shí),要用下面命令才能得到 詳細(xì)的結(jié)果:
select sid,serial#,username,
DECODE(command,
0,’None’,
2,’Insert’,
3,’Select’,
6,’Update’,
7,’Delete’,
8,’Drop’,
‘Other’) cmmand
from v$session where username is not null;
3 DECODE實(shí)現(xiàn)表的轉(zhuǎn)置
數(shù)據(jù)庫中的表是由列和行構(gòu)成的一個(gè)二維表。一般列在任何數(shù)據(jù)庫中都是有限的數(shù)量,而行的變化較大,如果表很大,行的數(shù)量可能大上千萬行。同一列的不同行可能有不同的值,而且不是預(yù)先定義的。
例:住房公積金報(bào)表置換實(shí)例:
1.各個(gè)單位在本地經(jīng)辦行進(jìn)行開戶,開戶就是將單位的基本信息和職工信息的進(jìn)行登記;
2.每月各個(gè)單位的會計(jì)到經(jīng)辦行交繳本單位的所有職工的住房公積金,系統(tǒng)記錄有每個(gè)職工的交繳明細(xì)并在每條記錄上記錄有經(jīng)辦行的代碼;
3.每月、季、半年及年終都要求將經(jīng)辦行 變?yōu)椤傲小苯o出個(gè)月的明細(xì)報(bào)表:
經(jīng)辦行:城西區(qū) 城東區(qū)
月份:
2001.01 xxxx1.xx xxxxx2.xx
2001.02 xxxx3.xx xxxxx4.xx
。 。 。 。 。 。
原來的數(shù)據(jù)順序是:
城西區(qū)2001.01 xxxxx1.xx
城東區(qū)2001.01 xxxxx2.xx
城西區(qū)2001.02 xxxxx3.xx
城東區(qū)2001.02 xxxxx4.xx
住房公積金系統(tǒng)記錄職工的每月交繳名細(xì)的pay_lst表結(jié)構(gòu)是:
bank_code varchar2(6)NOT NULL, -- 經(jīng)辦行代碼
acc_no varchar2(15) not null, -- 單位代碼(單位帳號)
emp_acc_no varchar2(20) not null, -- 職工帳號
tran_date date not null, -- 交繳日期
tran_val Number(7,2) not null, -- 交繳額
sys_date date default sysdate, --系統(tǒng)日期
oper_id varchar2(10) --操作員代碼
這樣的表結(jié)構(gòu),一般按照將經(jīng)辦行作為行(row)進(jìn)行統(tǒng)計(jì)是很容易的,但是如果希望將經(jīng)辦行變?yōu)榱?column)這樣的格式來輸出就有困難。如果用DECODE函數(shù)來處理則變得很簡單:
我們創(chuàng)建一個(gè)視圖來對目前的pay_lst表進(jìn)行查詢。將經(jīng)辦行代碼變?yōu)橐恍┚唧w的經(jīng)辦行名稱即可:
CREATE OR REPLACE VIEW bank_date_lst AS
Select to_char(tran_date,’yyyy.mm’),
SUM( DECODE ( bank_code,’001’, tran_val,0 )) 城西區(qū),
SUM( DECODE ( bank_code,’002’, tran_val,0 )) 城南區(qū),
SUM( DECODE ( bank_code,’003’, tran_val,0 )) 城東區(qū)
FROM pay_lst
GROUP BY to_char(tran_date,’yyyy.mm’);
建立視圖后,可直接對該視圖進(jìn)行查詢就可按照列顯示出結(jié)果。
?

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to uninstall MySQL and clean residual files How to uninstall MySQL and clean residual files Apr 29, 2025 pm 04:03 PM

To safely and thoroughly uninstall MySQL and clean all residual files, follow the following steps: 1. Stop MySQL service; 2. Uninstall MySQL packages; 3. Clean configuration files and data directories; 4. Verify that the uninstallation is thorough.

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

What steps are required to configure CentOS in HDFS What steps are required to configure CentOS in HDFS Apr 14, 2025 pm 06:42 PM

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

MongoDB vs. Oracle: Understanding Key Differences MongoDB vs. Oracle: Understanding Key Differences Apr 16, 2025 am 12:01 AM

MongoDB is suitable for handling large-scale unstructured data, and Oracle is suitable for enterprise-level applications that require transaction consistency. 1.MongoDB provides flexibility and high performance, suitable for processing user behavior data. 2. Oracle is known for its stability and powerful functions and is suitable for financial systems. 3.MongoDB uses document models, and Oracle uses relational models. 4.MongoDB is suitable for social media applications, while Oracle is suitable for enterprise-level applications.

MongoDB vs. Oracle: Choosing the Right Database for Your Needs MongoDB vs. Oracle: Choosing the Right Database for Your Needs Apr 22, 2025 am 12:10 AM

MongoDB is suitable for unstructured data and high scalability requirements, while Oracle is suitable for scenarios that require strict data consistency. 1.MongoDB flexibly stores data in different structures, suitable for social media and the Internet of Things. 2. Oracle structured data model ensures data integrity and is suitable for financial transactions. 3.MongoDB scales horizontally through shards, and Oracle scales vertically through RAC. 4.MongoDB has low maintenance costs, while Oracle has high maintenance costs but is fully supported.

How to configure the database connection of weblogic on centos How to configure the database connection of weblogic on centos Apr 14, 2025 pm 02:06 PM

Configuring WebLogic database connection on a CentOS system requires the following steps: JDK installation and environment configuration: Make sure that the server has installed a JDK that is compatible with the WebLogic version (for example, WebLogic14.1.1 usually requires JDK8). Correctly set JAVA_HOME, CLASSPATH and PATH environment variables. WebLogic installation and decompression: Download the WebLogic installation package for CentOS system from the official Oracle website and unzip it to the specified directory. WebLogic user and directory creation: Create a dedicated WebLogic user account and set a security password

Centos options after stopping maintenance Centos options after stopping maintenance Apr 14, 2025 pm 08:51 PM

CentOS has been discontinued, alternatives include: 1. Rocky Linux (best compatibility); 2. AlmaLinux (compatible with CentOS); 3. Ubuntu Server (configuration required); 4. Red Hat Enterprise Linux (commercial version, paid license); 5. Oracle Linux (compatible with CentOS and RHEL). When migrating, considerations are: compatibility, availability, support, cost, and community support.

Can vscode run kotlin Can vscode run kotlin Apr 15, 2025 pm 06:57 PM

Running Kotlin in VS Code requires the following environment configuration: Java Development Kit (JDK) and Kotlin compiler Kotlin-related plugins (such as Kotlin Language and Kotlin Extension for VS Code) create Kotlin files and run code for testing to ensure successful environment configuration

See all articles