Use PLSQL to reverse the integer

Source: Internet
Author: User
Use PLSQL to reverse the integer. For example, if 123 is converted to 321, * Formattedon201571514: 56: 34 (QP5v5.163.1008.3004) * Average (idINNUMBER) limit (10); ls_last_itemVARCHAR2 (10 );

Use PLSQL to implement reverse order of integers. For example, 123 is converted to 321 without/* Formatted on 14:56:34 (QP5 v5.163.1008.3004) */create or replace function get_reverse_value (id in number) RETURN VARCHAR2IS ls_id VARCHAR2 (10); ls_last_item VARCHAR2 (10); ls_curr_it

Use PLSQL to reverse the integer, for example, 123 to 321 <无>
/* Formatted on 14:56:34 (QP5 success) */create or replace function get_reverse_value (id in number) RETURN VARCHAR2IS ls_id VARCHAR2 (10); ls_last_item VARCHAR2 (10 ); ls_curr_item VARCHAR2 (10); ls_zero VARCHAR2 (10); li_len INTEGER; lb_stop BOOLEAN; BEGIN ls_id: = TO_CHAR (id); li_len: = LENGTH (ls_id); ls_last_item: = ''; ls_zero: =''; lb_stop: = FALSE; WHILE li_len> 0 LOOP ls_curr_item: = SUBSTR (ls_id, li_len, 1 ); IF ls_curr_item = '0' AND lb_stop = false then ls_zero: = ls_zero | ls_curr_item; ELSE lb_stop: = TRUE; ls_last_item: = cursor | ls_curr_item; end if; ls_id: = SUBSTR (ls_id, 1, li_len-1); li_len: = LENGTH (ls_id); end loop; RETURN (ls_last_item | ls_zero); END get_reverse_value;/* this program is as follows: for example, 123 loop 1: ls_curr_item = 3, ls_last_item = '| 3 = 3, ls_id = 12, li_en = 2 loop 2: ls_curr_item = 2, ls_last_item = 3 | 2 = 32, ls_id = 1, li_en = 1 loop 3: ls_curr_item = 1, ls_last_item = 32 | 1 = 321, ls_id = '', li_en = 0 at this time, li_en = 0 jumps out of the loop and returns ls_last_item = 321 for example, 100 loop 1: ls_curr_item = 0, ls_zero = ''| 0 = 0, ls_id = 20, li_en = 2 loop 2: ls_curr_item = 0, ls_zero = 0 | 0 = 00, ls_id = 1, li_en = 1 loop 3: ls_curr_item = 1, ls_last_item = ''| 1 = 1, ls_id ='', li_en = 0 at this time, li_en = 0 jump out of the loop, return ls_last_item = 1, ls_zero = 00, ls_last_item | ls_zero = 100 * // The running result is SQL> select * from rebuild_test_cf where name <20; id name ---------- 1 1 2 2 3 3 4 4 5 5 6 6 7 8 8 9 9 10 11 11 id name ---------- 21 12 31 13 41 14 51 15 61 16 71 17 81 18 91 19

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.