Decode usage in oracle and row-to-column conversion in oracle

Source: Internet
Author: User
Decode is actually if-else, such as decode (ybc, null, 0, ybc). This means that if the ybc column is null, the function returns 0; otherwise, the function returns ybc. Another example is decode (variable, condition, condition). This means: if-elsif. if it is decode (variable, condition, condition, 3 ), this is if-elsif-else

Decode is actually if-else, such as decode (ybc, null, 0, ybc). This means that if the ybc column = null, the function returns 0; otherwise, the function returns ybc. Another example is decode (variable, condition, condition). This means: if-elsif. if it is decode (variable, condition, condition, 3 ), this is if-elsif-else

Decode is actually if-else, such as decode (ybc, null, 0, ybc). This means that if the ybc column is = null, the function returns 0, otherwise, the value of ybc is returned.

Another example is decode (variable, condition 1, value 1, condition 2, value 2). This means: if-elsif. if it is decode (variable, condition 1, value 1, condition 2, value 2, value 3), which is if-elsif-else.

A specific reference for oracle row-to-column: http://www.2cto.com/database/201108/100792.html


The following is the code:

insert into tj_kszgjf(id,bjdm,xxdm,xqdm,dsdm,ybc,xxtj,xqtj,dstj,tj_kszgjf.zstg,tj_kszgjf.sum, shijian,flag)select seq_kszgjftj.nextval,bj.bjdm,bj.xx_xxdm as xxdm,xx.xq_xqdm as xqdm,xq.ss as dqdm,  decode(ybc,null,0,ybc),  decode(xxtj,null,0,xxtj),  decode(xqtj,null,0,xqtj),  decode(dstj,null,0,dstj),  decode(zstg,null,0,zstg),  decode("sum",null,0,"sum"),  sysdate,flagfrom  (select zgjf.bjdm,     sum(decode(zgjf.zt, 1,1,0)) ybc,    sum(decode(zgjf.zt, 2, 1,0)) xxtj,    sum(decode(zgjf.zt, 3, 1,0)) xqtj,    sum(decode(zgjf.zt, 4, 1,0)) dstj,    sum(decode(zgjf.zt, 5, 1,0)) zstg,    count(bmxh)as "sum",    flag    from zgjf    group by flag,bjdm   )zgjftempright join bj on zgjftemp.bjdm=bj.bjdminner join xx on bj.xx_xxdm=xx.zxdminner join xq on xx.xq_xqdm=xq.xqdm;commit;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.