Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the keyword case when

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

How is the keyword case when used? In view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

The case when keyword of the database, which is actually similar to the format of if,else if,else, is a way to obtain judgment conditions.

The syntax format of the sql written in the stored procedure is basically the same as that written normally, and so is the usage call of case when.

Give an example in advance:

Select qzh from ywda_swjg_qzh_dzwhere swjg = (selectcase when substr ('11101823000'), 0jue 7) =' 1110182'then substr ('111019600010190000) | |' 000'else substr ('1110196000)) | |' 0000'endswjgdm from ywda_swjg_qzh_dzwhere a.swjg_dm = b.swjg_dm)

Case when can be used not only in the results of a query, but also as a judgment condition after a where condition.

This sql includes both cases. Of course, we don't have to add select to the following where condition, such as:

Select qzh from ywda_swjg_qzh_dzwhere swjg = case when substr ('11101823000'), 0Pie7) =' 1110182'then substr ('111019600010190000) | |' 000'else substr ('1110196000') | |' 0000'end

It is certainly more efficient to use case when directly in this format.

Note: case when must be used in conjunction with then and end.

Of course, my stored procedure is not written in this way. Today, the boss said that you don't have to be too responsible, just write in if,else format.

The if,else of the stored procedure is still a little different from the if and else format used in the front and background. The company does not have an external network, so we will not paste the java code and go directly to part of the content of the stored procedure.

If substr (AVC_QXSWJG,0,8) = '11100006' or substr (AVC_QXSWJG,0,7) = '1110182' thenselect qzh into avc_qch from ywda_swjg_qzh_dz where swjg_dm = substr (avc_qxswjg,0,8) | | '000' Elsif condition (without parentheses) then..sql omitted.. else.. .. SQL omitted.. end if Sql is over.

Note that the logical operator here uses the logical operator of sql, that is, the class and,or.

Note that the "| |" written above appends a string to the end of the field, not logical OR.

After the end of the if, be sure to add end if to indicate the end of the current if.

This is the answer to the question about how the keyword case when is used. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report