Skip to main content

Manage Countries Coordinates and Flags in Database using RESTful Web Services and PLSQL



Here i am giving an example to manage countries coordinates and flag in database using RESTful web services and PLSQL.

Reference APIs:

CREATE TABLE fxgn_country_coordinates
  (
    id                           NUMBER,
    country_code        VARCHAR2(10),
    country                  VARCHAR2(200),
    capital                    VARCHAR2(100),
    latitude                   NUMBER,
    longitude                NUMBER,
    updated_by             VARCHAR2(30),
    updated_on             TIMESTAMP (6),
    country_flag_flat    VARCHAR2(100),
    country_flag_shiny VARCHAR2(100)
  );
 
Step 2: Create sequence as below,
 
CREATE SEQUENCE fxgn_country_coordinates_s MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE nokeep noscale GLOBAL;

Step 3: Create stored procedure as below, which will call API to get countries coordinates and flag.

CREATE OR REPLACE
PROCEDURE get_country_coordinates 
AS  
  l_response CLOB;
  l_url VARCHAR2(1000);
  BEGIN
    l_url:= 'https://gist.githubusercontent.com/erdem/8c7d26765831d0f9a8c62f02782ae00d/raw/248037cd701af0a4957cce340dabb0fd04e38f4c/countries.json';
   
    apex_web_service.g_request_headers.DELETE ;
    apex_web_service.g_request_headers(1).NAME  := q'#User-Agent#';
    apex_web_service.g_request_headers(1).VALUE := q'#Oracle Application Express / REST Client Assistant#';
    
    DELETE FROM fxgn_country_coordinates;
    
    INSERT INTO fxgn_country_coordinates (id, latitude, longitude, country, country_code, capital, 
                                          country_flag_flat, country_flag_shiny, updated_by, updated_on)
          SELECT fxgn_country_coordinates_s.nextval,
                 latitude,
                 longitude,
                 country,
                 country_code,
                 capital,
                 '<img src="https://www.countryflags.io/'||country_code||'/flat/64.png">',
                 '<img src="https://www.countryflags.io/'||country_code||'/shiny/64.png">',
                 'KARKUVELRAJA.T',
                 LOCALTIMESTAMP
            FROM dual,
                 json_table (apex_web_service.make_rest_request( p_url => l_url, 
                                                                 p_http_method => 'GET'),
                            '$[*]' COLUMNS ( country VARCHAR2(200) path '$.name', 
                                             country_code VARCHAR2(200) path '$.country_code', 
                                             capital VARCHAR2(200) path '$.capital', 
                                             latitude NUMBER path '$.latlng[0]', 
                                             longitude NUMBER path '$.latlng[1]' 
                                            ));
      COMMIT;
END get_country_coordinates
/

Step 3: Call the procedure. It will populate data into respective table.

BEGIN
get_country_coordinates();
END;
/

Output:

Comments

  1. Political signs for sale We are really grateful for your blog post. You will find a lot of approaches after visiting your post. I was exactly searching for. Thanks for such post and please keep it up. Great work.

    ReplyDelete
  2. Thank you for helping people get the information they need. Great stuff as usual. Keep up the great work!!! Birthday Yard Signs texas

    ReplyDelete
  3. We have sell some products of different custom boxes.it is very useful and very low price please visits this site thanks and please share this post with your friends. US Yard Sign Rentals

    ReplyDelete
  4. click here I would like to say that this blog really convinced me to do it! Thanks, very good post.

    ReplyDelete

Post a Comment

Popular posts from this blog

Printing Page Numbers in RTF Template [Oracle BI Publisher]

Here I am giving an example to print the page numbers dynamically in the RTF (Rich Text Format) template. Step 1:  Go to page footer and copy and paste the below script. Page |  <?fo:page-number?>  of  <?fo:page-number-citation:xdofo:lastpage-joinseq?> <fo:page-number> :   This is the object, which is used to represent the current page-number. <?fo:page-number-citation:xdofo:lastpage-joinseq?> :  This is the syntax, which is used to represent the total number of pages. Step 2:  Load the XML and preview the result. Output: That's it. References: fo:page-number Printing Page Number Code in Oracle XMLP RTF Template

Generating the report with APEX_DATA_EXPORT

With the APEX_DATA_EXPORT package, you are able to export data from Oracle Application Express in the following file types: PDF, XLSX, HTML, CSV, XML, and JSON. Step 1: Create a table and populate it with some sample records. CREATE TABLE emp   (     empno        NUMBER,     first_name   VARCHAR2(240),     last_name    VARCHAR2(240),     mgr          NUMBER,     deptno       NUMBER,     sal          NUMBER,     created_date TIMESTAMP (6),     comm         NUMBER,     hiredate     DATE,     JOB          VARCHAR2(240),     ename        VARCHAR2(240),     PRIMARY KEY (empno) USING INDEX ENABLE   ); /    INSERT INTO emp (empno, first_name, last_name, mgr,                   deptno, sal, created_date)         VALUES                 (1, 'Larry', 'Ellison', ,                  10, 5000, LOCALTIMESTAMP);   INSERT INTO emp (empno, first_name, last_name, mgr,                   deptno, sal, created_date)         VALUES                 (2, 'Juan', 'Juan', 1,  

Save Selected Interactive Grid Records into a Collection - Oracle APEX

Here I am giving an example to save selected interactive grid records into a oracle apex collection. Step 1: Create a new blank page. Note: Mine was page 20. You will need to update reference to " P20 " with your page number if it's different. Step 2: Create a new interactive grid report region to the page using below query. Set Static Id "EmpDetails" to the region. SELECT  *     FROM   ( SELECT  emp . empno ,                emp . ename ,                emp . JOB ,                dept . dname department ,                dept . loc  LOCATION ,                mgr . ename  manager ,                emp . hiredate ,                 nvl ( emp . sal , 0 )  salary ,                 nvl ( emp . comm , 0 )  commission            FROM  eba_demo_chart_emp emp ,                eba_demo_chart_dept dept ,                eba_demo_chart_emp mgr           WHERE  emp . deptno = dept . deptno             AND  emp . mgr      = mgr . empno  ( + )           ORDER   BY  emp . ename