MySQL IP string to digital storage process

Source: Internet
Author: User
Delimiter $

Use'Db _ im '$

Drop Procedure If Exists'P _ bi_parasip '$

Create Definer = 'Root' @ 'localhost' Procedure 'P _ bi_parasip '(
In Pi_ipstr Varchar ( 50 ),
Out po_int1 Int ,
Out po_int2 Int ,
Out po_int3 Int ,
Out po_int4 Int ,
Out po_ret Int
)
Begin
Declare V_strtempVarchar ( 50 );
Declare V_pos Int ;
Declare V_sub Varchar ( 10 );
Declare V_tail Varchar ( 50 );
Declare V_val Int ;


Set V_pos = 0 ;
Set Po_ret = 1 ;
Set V_strtemp = Trim (pi_ipstr );

P: Begin
/* 192.168.1.1 */
Set V_pos = Instr (v_strtemp, ' . ' );

If (V_pos > 0 And Length (v_strtemp) > V_pos) Then
Set V_sub = Substring (V_strtemp, 1 , V_pos - 1 );
Set V_tail = Substring (V_strtemp, v_pos + 1 );
Set V_val = V_sub + 0 ;

If (V_sub Regexp ' ^ [0-9] * $ ' ) = 0 ) Then
Set Po_ret =- 1 ;
Leave P;
Else
Set Po_int1 = V_val;
End If ;
Else
Set Po_ret =- 1 ;
Leave P;
End If ;

/* 168.1.1 */
Set V_pos = Instr (v_tail, ' . ' );

If (V_pos > 0 And Length (v_tail) > V_pos) Then
Set V_sub = Substring (V_tail, 1 , V_pos- 1 );
Set V_tail = Substring (V_tail, v_pos + 1 );
Set V_val = V_sub + 0 ;

If (V_sub Regexp ' ^ [0-9] * $ ' ) = 0 ) Then
Set Po_ret =- 1 ;
Leave P;
Else
Set Po_int2 = V_val;
End If ;
Else
Set Po_ret=- 1 ;
Leave P;
End If ;


/* 1.1 */
Set V_pos = Instr (v_tail,' . ' );

If (V_pos > 0 And Length (v_tail) > V_pos) Then
Set V_sub = Substring (V_tail, 1 , V_pos - 1 );
Set V_tail = Substring (V_tail, v_pos + 1 );
Set V_val = V_sub+ 0 ;

If (V_sub Regexp ' ^ [0-9] * $ ' ) = 0 ) Then
Set Po_ret =- 1 ;
Leave P;
Else
Set Po_int3 = V_val;
End If ;
Else
Set Po_ret =- 1 ;
Leave P;
End If ;

Set V_val = V_tail + 0 ;

If (V_tail Regexp ' ^ [0-9] * $ ' ) = 0 ) Then
Set Po_ret =- 1 ;
Leave P;
Else
Set Po_int4 = V_val;
End If ;

Set Po_ret = 1 ;

End P;
End $

Delimiter;

Related Article

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.