Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question.

Asked: November 17, 2016 - 11:10 am UTC

Last updated: November 18, 2016 - 6:01 am UTC

Version: Oracle 11g

Viewed 10K+ times! This question is

You Asked

Hi, Tom!

I need some advice in what is the best way to solve the following task in PL/SQL.

I have the following link https://wiki.xmldation.com/Support/EPC/List_of_SEPA_countries

I need to get IBAN-s (the third column) from this site and compare it with the appropriate column (type is Varchar2) in the table. If they are the same, then, return true.

Can you give me some tips, how can I do this task or where to start from? Do I need to use XML parser; or need to save data into file and read data from it?

Thank you in advance.
Jeli.

and Connor said...

I took a subsection of the html, but this should get you started


SQL> drop table t purge;

Table dropped.

SQL> create table t ( c clob );

Table created.

SQL>
SQL> set define off
SQL> begin
  2  insert into t values (
  3  '/*]]>*/</script>
  4  </p>
  5  <div id="section_1"><span id="List_of_SEPA_countries_or_territories_and_their_ISO_country_and_currency_codes"></span><h5 class="editable">List of SEPA countries or territories and their ISO country and currency codes&nbsp;</h5>
  6  <div>SEPA consists of the 27 EU countries (including the Euro 16 countries) and the additional 3 EEA&nbsp;</div>
  7  <div>(European Economic Area) countries.&nbsp;</div>
  8  <div>&nbsp;</div>
  9  <div>In SEPA messages, countries are denominated by their ISO country codes contained in the BICs&nbsp;</div>
 10  <div>and the IBANs. Amounts are expressed in the currencies of these countries, denominated by their&nbsp;</div>
 11  <div>ISO currency codes. The list presents the name of the countries or territories with the corresponding&nbsp;</div>
 12  <div>ISO country and currency codes.&nbsp;</div>
 13  <div>&nbsp;</div>
 14  <table border="0" cellpadding="0" cellspacing="0" width="512"> <colgroup> <col /> <col span="3" /> </colgroup> <tbody> <tr> <td height="17"><strong>Country/territory&nbsp;</strong></td> <td><strong>BIC&nbsp;</strong></td> <td><strong>IBAN&nbsp;</strong></td> <td><strong>Currency code&nbsp;</strong>'||
 15  '</td> </tr> <tr> <td height="17">&Aring;land Islands&nbsp;</td> <td>FI&nbsp;</td> <td>FI&nbsp;</td> <td>EUR&nbsp;</td> </tr> <tr> <td height="17">Austria&nbsp;</td> <td>AT&nbsp;</td> <td>AT&nbsp;</td> <td>EUR&nbsp;</td> </tr> <tr> <td height="17">Belgium&nbsp;</td> <td>BE&nbsp;</td> <td>BE&nbsp;</td> '||
 16  '<td>EUR&nbsp;</td> </tr> <tr> <td height="17">Bulgaria&nbsp;</td> <td>BG&nbsp;</td> <td>BG&nbsp;</td> <td>BGN&nbsp;</td> </tr> <tr> <td height="17">Canary Islands &nbsp;</td> <td>ES &nbsp;</td> <td>ES &nbsp;</td> <td>EUR&nbsp;</td> </tr> <tr> <td height="17">Croatia</td> <td>HR</td> <td>HR</td> <td>HRK</td> </tr> <tr> '||
 17  '<td height="17">Cyprus&nbsp;</td> <td>CY&nbsp;</td> <td>CY&nbsp;</td> <td>EUR&nbsp;</td> </tr> <tr> <td height="17">Czech Republic&nbsp;</td> <td>CZ&nbsp;</td> <td>CZ&nbsp;</td> <td>CZK&nbsp;</td> </tr> <tr> <td height="17">Denmark&nbsp;</td> <td>DK&nbsp;</td> <td>DK&nbsp;</td> <td>DKK&nbsp;</td> </tr> <tr> <td height="17">'||
 18  'Estonia&nbsp;</td> <td>EE&nbsp;</td> <td>EE&nbsp;</td> <td>EEK&nbsp;</td> </tr> <tr> <td height="17">Finland&nbsp;</td> <td>FI&nbsp;</td> <td>FI&nbsp;</td> <td>EUR&nbsp;</td> </tr> <tr> <td height="17">France&nbsp;</td> <td>FR&nbsp;</td> <td>FR&nbsp;</td> <td>EUR&nbsp;</td> </tr> <tr> <td height="17">'||
 19  'French Guiana&nbsp;</td> <td>GF&nbsp;</td> <td>FR&nbsp;</td> <td>EUR&nbsp;</td> </tr> <tr> <td height="17">Germany&nbsp;</td> <td>DE&nbsp;</td> <td>DE&nbsp;</td> <td>EUR&nbsp;</td> </tr> <tr> <td height="17">Gibraltar&nbsp;</td> <td>GI&nbsp;</td> <td>GI&nbsp;</td> <td>GIP&nbsp;</td> </tr> <tr> <td height="17">'||
 20  'Greece&nbsp;</td> <td>GR&nbsp;</td> <td>GR&nbsp;</td> <td>EUR&nbsp;</td> </tr> <tr> <td height="17">Guadeloupe&nbsp;</td> <td>GP&nbsp;</td> <td>FR&nbsp;</td> <td>EUR&nbsp;</td> </tr> <tr> <td height="17">Hungary&nbsp;</td> <td>HU&nbsp;</td> <td>HU&nbsp;</td> <td>HUF&nbsp;</td> </tr> <tr> <td height="17">Iceland&nbsp;'||
 21  '</td> <td>IS&nbsp;</td> <td>IS&nbsp;</td> <td>ISK&nbsp;</td> </tr> <tr> <td height="17">Ireland&nbsp;</td> <td>IE&nbsp;</td> <td>IE&nbsp;</td> <td>EUR&nbsp;</td> </tr> <tr> <td height="17">Italy&nbsp;</td> <td>IT&nbsp;</td> <td>IT&nbsp;</td> <td>EUR&nbsp;</td> </tr> <tr> <td height="17">Latvia&nbsp;</td> <td>LV&nbsp;</td>'||
 22  ' <td>LV&nbsp;</td> <td>EUR</td> </tr> <tr> <td height="17">Liechtenstein&nbsp;</td> <td>LI&nbsp;</td> <td>LI&nbsp;</td> <td>CHF&nbsp;</td> </tr> <tr> <td height="17">Lithuania&nbsp;</td> <td>LT&nbsp;</td> <td>LT&nbsp;</td> <td>LTL&nbsp;</td> </tr> <tr> <td height="17">Luxembourg&nbsp;</td> <td>LU&nbsp;</td> <td>LU&nbsp;</td>'||
 23  ' <td>EUR&nbsp;</td> </tr> <tr> <td height="17">Malta&nbsp;</td> <td>MT&nbsp;</td> <td>MT&nbsp;</td> <td>EUR&nbsp;</td> </tr> <tr> <td height="17">Martinique&nbsp;</td> <td>MQ&nbsp;</td> <td>FR&nbsp;</td> <td>EUR&nbsp;</td> </tr> <tr> <td height="17">Mayotte&nbsp;</td> <td>YT&nbsp;</td> <td>FR&nbsp;</td> <td>EUR&nbsp;</td> '||
 24  '</tr> <tr> <td height="17">Monaco&nbsp;</td> <td>MC&nbsp;</td> <td>MC&nbsp;</td> <td>EUR&nbsp;</td> </tr> <tr> <td height="17">Netherlands&nbsp;</td> <td>NL&nbsp;</td> <td>NL&nbsp;</td> <td>EUR&nbsp;</td> </tr> <tr> <td height="17">Norway&nbsp;</td> <td>NO&nbsp;</td> <td>NO&nbsp;</td> <td>NOK&nbsp;</td> </tr> <tr> '||
 25  '<td height="17">Poland&nbsp;</td> <td>PL&nbsp;</td> <td>PL&nbsp;</td> <td>PLN&nbsp;</td> </tr> <tr> <td height="17">Portugal&nbsp;&nbsp;</td> <td>PT&nbsp;</td> <td>PT&nbsp;</td> <td>EUR&nbsp;</td> </tr> <tr> <td height="17">R&eacute;union&nbsp;</td> <td>RE&nbsp;</td> <td>FR&nbsp;</td> <td>EUR&nbsp;</td> </tr> <tr> '||
 26  '<td height="17">Romania&nbsp;</td> <td>RO&nbsp;</td> <td>RO&nbsp;</td> <td>RON&nbsp;</td> </tr> <tr> <td height="17">Saint Barth&eacute;lemy&nbsp;</td> <td>BL&nbsp;</td> <td>FR&nbsp;</td> <td>EUR&nbsp;</td> </tr> <tr> <td height="17">Saint Martin (French part)&nbsp;</td> <td>MF&nbsp;</td> <td>FR&nbsp;</td> <td>EUR&nbsp;</td> '||
 27  '</tr> <tr> <td height="17">Saint Pierre and Miquelon</td> <td>PM&nbsp;</td> <td>FR&nbsp;</td> <td>EUR&nbsp;</td> </tr> <tr> <td height="17">Slovakia&nbsp;</td> <td>SK&nbsp;</td> <td>SK&nbsp;</td> <td>EUR&nbsp;</td> </tr> <tr> <td height="17">Slovenia&nbsp;</td> <td>SI&nbsp;</td> <td>SI&nbsp;</td> <td>EUR&nbsp;</td> </tr> <tr> '||
 28  '<td height="17">Spain&nbsp;</td> <td>ES&nbsp;</td> <td>ES&nbsp;</td> <td>EUR&nbsp;</td> </tr> <tr> <td height="17">Sweden&nbsp;</td> <td>SE&nbsp;</td> <td>SE&nbsp;</td> <td>SEK&nbsp;</td> </tr> <tr> <td height="17">Switzerland&nbsp;</td> <td>CH&nbsp;</td> <td>CH&nbsp;</td> <td>CHF&nbsp;</td> </tr> <tr> <td height="17">'||
 29  'United Kingdom&nbsp;</td> <td>GB&nbsp;</td> <td>GB&nbsp;</td> <td>GBP&nbsp;</td> </tr> </tbody></table>');
 30  end;
 31  /

PL/SQL procedure successfully completed.

SQL>
SQL> commit;

Commit complete.

SQL>
SQL> set define off
SQL> set serverout on
SQL> declare
  2    c1 clob;
  3    l_list varchar2(32000);
  4    pos pls_integer;
  5    endpos pls_integer;
  6
  7    type str_array is table of varchar2(100) index by pls_integer;
  8    l_country str_array;
  9    l_bic str_array;
 10    l_iban str_array;
 11    l_curr str_array;
 12
 13    l_row_count pls_integer := 0;
 14    l_col_count pls_integer := 0;
 15    idx pls_integer;
 16  begin
 17    select c into c1 from t;
 18    pos := dbms_lob.instr(c1,'Country/territory');
 19    pos := dbms_lob.instr(c1,'<tr>',pos-50);
 20    endpos := dbms_lob.instr(c1,'</table>',pos);
 21
 22    l_list := dbms_lob.substr(c1,endpos-pos,pos);
 23    l_list := ltrim(rtrim(l_list));
 24
 25    l_list := replace(replace(replace(l_list,'<strong>'),'</strong>'),'&nbsp;');
 26
 27    loop
 28      exit when l_list = '</tbody>';
 29
 30      if substr(l_list,1,5) in ('</td>','</tr>') then
 31         l_list := ltrim(substr(l_list,6));
 32         continue;
 33      end if;
 34
 35      if substr(l_list,1,4) = '<tr>' then
 36         l_row_count := l_row_count + 1;
 37         l_list := ltrim(substr(l_list,5));
 38         l_col_count := 0;
 39      end if;
 40
 41      if substr(l_list,1,3) = '<td' then
 42         l_col_count := l_col_count + 1;
 43         l_list := ltrim(substr(l_list,instr(l_list,'>')+1));
 44      end if;
 45
 46      idx := instr(l_list,'<');
 47
 48      if l_col_count = 1 then
 49        l_country(l_row_count) := substr(l_list,1,idx-1);
 50      elsif l_col_count = 2 then
 51        l_bic(l_row_count) := substr(l_list,1,idx-1);
 52      elsif l_col_count = 3 then
 53        l_iban(l_row_count) := substr(l_list,1,idx-1);
 54      elsif l_col_count = 4 then
 55        l_curr(l_row_count) := substr(l_list,1,idx-1);
 56      end if;
 57
 58      l_list := ltrim(substr(l_list,idx));
 59
 60    end loop;
 61
 62    for i in 2 .. l_row_count loop
 63      dbms_output.put_line(
 64        rpad(l_country(i),30)||
 65        rpad(l_bic(i),10)||
 66        rpad(l_iban(i),10)||
 67        rpad(l_curr(i),10)
 68        );
 69    end loop;
 70
 71  end;
 72  /
&Aring;land Islands           FI        FI        EUR
Austria                       AT        AT        EUR
Belgium                       BE        BE        EUR
Bulgaria                      BG        BG        BGN
Canary Islands                ES        ES        EUR
Croatia                       HR        HR        HRK
Cyprus                        CY        CY        EUR
Czech Republic                CZ        CZ        CZK
Denmark                       DK        DK        DKK
Estonia                       EE        EE        EEK
Finland                       FI        FI        EUR
France                        FR        FR        EUR
French Guiana                 GF        FR        EUR
Germany                       DE        DE        EUR
Gibraltar                     GI        GI        GIP
Greece                        GR        GR        EUR
Guadeloupe                    GP        FR        EUR
Hungary                       HU        HU        HUF
Iceland                       IS        IS        ISK
Ireland                       IE        IE        EUR
Italy                         IT        IT        EUR
Latvia                        LV        LV        EUR
Liechtenstein                 LI        LI        CHF
Lithuania                     LT        LT        LTL
Luxembourg                    LU        LU        EUR
Malta                         MT        MT        EUR
Martinique                    MQ        FR        EUR
Mayotte                       YT        FR        EUR
Monaco                        MC        MC        EUR
Netherlands                   NL        NL        EUR
Norway                        NO        NO        NOK
Poland                        PL        PL        PLN
Portugal                      PT        PT        EUR
R&eacute;union                RE        FR        EUR
Romania                       RO        RO        RON
Saint Barth&eacute;lemy       BL        FR        EUR
Saint Martin (French part)    MF        FR        EUR
Saint Pierre and Miquelon     PM        FR        EUR
Slovakia                      SK        SK        EUR
Slovenia                      SI        SI        EUR
Spain                         ES        ES        EUR
Sweden                        SE        SE        SEK
Switzerland                   CH        CH        CHF
United Kingdom                GB        GB        GBP

PL/SQL procedure successfully completed.

SQL>


Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

And...

Steve, November 18, 2016 - 8:12 am UTC

You'll need to use utl_http package to retrieve the web page:

https://docs.oracle.com/cd/B28359_01/appdev.111/b28424/adfns_web.htm#CHEFFBFD

More to Explore

CLOB/BLOB/etc

Complete documentation on Securefiles and Large Objects here