Oracle Data Transformation method that displays the ID value of the dictionary table as text

Source: Internet
Author: User

  • (This article original, quote please specify source--zhangjieatbky)
  • Scenario: For example, to convert an ID value stored in a field, such as a to a text display, such as basketball, soccer, volleyball
    • Create two tables
    • 1 CreateA1 (ID Number(8),text varchar( the));//Create a dictionary table2 Insert  intoA1Values(Ten, football);3 Insert  intoA1Values( One, basketball);4 Insert  intoA1Values( A, badminton);5 Insert  intoA1Values( -, volleyball);6 7 CreateB1 (bid Number(8), Btextvarchar2( the));//Business Master Table8 Insert  intoB1Values( +,'10,11,13');9 Insert  intoB1Values( -,'11,12');
    • Create a transform function
    • 1 //Create a function2 Create or Replace functionConverter (3P_bid B1.bid%type)4 return varchar25  as6V_len Number(2);7V_dict_textvarchar( the);8V_index Binary_integer:=1;9V_resultvarchar( Max):="';TenV_temp1varchar2(3); OneV_temp2varchar2( -); A begin -   SelectB1.btext intoV_dict_text fromB1whereBid=P_bid; -   SelectLength (Translate (V_dict_text,'a0123456789',' ')) intoV_len fromdual; the    whileV_index<=V_len+1Loop -     SELECTRegexp_substr (V_dict_text,'[[: alnum:]]+',1, V_index) intoV_temp1 fromdual; -     SELECT TEXT  intoV_temp2 fromA1WHEREId=V_temp1; -V_result:=Concat (Concat (V_RESULT,V_TEMP2),','); +V_index:=V_index+1; -   EndLoop; +   RETURNSUBSTR (V_result,0, Length (V_result)-1); A EndConverter; at  - //test results, such as successful conversion of dictionary values to text values - SELECTBid,converter (BID)TEXT  fromB1
    • The results are as follows

Oracle Data Transformation method that displays the ID value of the dictionary table as text

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.