{
  "date": "2018-04-01T02:00:25",
  "slug": "after-iot-iop-makes-its-way-to-the-database",
  "link": "https://www.dbi-services.com/blog/after-iot-iop-makes-its-way-to-the-database/",
  "title": {
    "rendered": "After IoT, IoP makes its way to the database"
  },
  "content": {
    "rendered": "<h2>By Franck Pachot</h2>\n<p>.<br />\nAt each new Oracle version, I like to check what&#8217;s new, not only from the documentation, but also from exposed internals. I look (and sometimes diff) on catalog views definitions, undocumented parameters, and even the new C functions in the libraries. At last Oak Table World, I was intrigued by this V$SQLFN_METADATA view explained by Vit Spinka when digging into the internals of how execution plans are stored. This view has entries with all SQL functions, and a VERSION column going from &#8216;V6 Oracle&#8217; to &#8216;V11R1 Oracle&#8217;. The lastest functions has an &#8216;INVALID&#8217; entry and we also can see some functions with &#8216;SQL/DS&#8217;. Well, now that we have Oracle 18c on the Oracle Cloud, I came back to this view to see if anything is new, listing the highest FUNC_ID at the top and the first row attired my attention:</p>\n<pre><code>\nSQL&gt; select * from V$SQLFN_METADATA order by 1 desc fetch first 10 rows only;\n&nbsp;\nFUNC_ID   NAME                  MINARGS   MAXARGS   DATATYPE   VERSION      ANALYTIC   AGGREGATE   OFFLOADABLE   DISP_TYPE   USAGE   DESCR                                                     CON_ID   \n-------   ----                  -------   -------   --------   ----------   --------   ---------   -----------   ---------   -----   -----                                                     ------\n     1148 TO_DOG_YEAR                   1         4 NUMERIC    V13 Oracle   NO         NO          YES           NORMAL              TO_DOG_YEAR                                                      0\n     1147 JSON_MERGEPATCH               4         0 UNKNOWN    INVALID      NO         NO          NO            NORMAL              JSON_MERGEPATCH                                                  0 \n     1146 JSON_PATCH                    4         0 UNKNOWN    INVALID      NO         NO          NO            NORMAL              JSON_PATCH                                                       0 \n     1145 ROUND_TIES_TO_EVEN            1         2 NUMERIC    INVALID      NO         NO          YES           NORMAL              ROUND_TIES_TO_EVEN                                               0 \n     1144 CON_ID_TO_CON_NAME            1         0 UNKNOWN    INVALID      NO         NO          NO            NORMAL              CON_ID_TO_CON_NAME                                               0 \n     1143 TIMESTAMP_TO_NUMBER           1         1 UNKNOWN    INVALID      NO         NO          YES           NORMAL              TIMESTAMP_TO_NUMBER                                              0 \n     1142 TO_UTC_TIMESTAMP_TZ           1         0 UNKNOWN    INVALID      NO         NO          YES           NORMAL              TO_UTC_TIMESTAMP_TZ                                              0 \n     1141 OPTSYSAPPROXRANK              1         0 UNKNOWN    INVALID      NO         NO          NO            NORMAL              Internal evaluation function for multiple approx_rank's          0 \n     1140 APPROX_RANK                   1         1 NUMERIC    INVALID      NO         YES         NO            NORMAL              APPROX_RANK                                                      0 \n     1139 APPROX_SUM                    1         2 NUMERIC    INVALID      NO         YES         NO            NORMAL              APPROX_SUM                                                       0 \n</code></pre>\n<p>Because those functions are SQL functions, I searched this &#8216;TO_DOG_YEAR&#8217; on Google to see whether a new ANSI SQL function was implemented. But finally came upon something I didn&#8217;t expect: Dog Years Calculator. The trends in databases are really going crazy these times. All focus is on developers. XML, JSON, Docker&#8230; and now a function to calculate your age in dog years.<br />\nBut afterall, it makes sense. IoT (not &#8216;Index Organized Table&#8217; but &#8216;Internet Of Things&#8217;) is coming with sensors everywhere. And it is not only &#8216;things&#8217; but it comes to living beings. I have <a href=\"https://community.estimote.com/hc/en-us/articles/217490107-Internet-of-Pets-it-s-not-only-about-Things-\" target=\"_blank\" rel=\"noopener noreferrer\">read recently</a> about &#8216;Internet of Pets&#8217; where collars equipped with sensors detect where your domestic animal go and when he is hungry. </p>\n<p>Let&#8217;s test it. Tomorrow, my elder kid has his 13th birthday. Now Oracle can tell me that he will be 65 in dog years:</p>\n<pre><code>\nSQL&gt; select to_dog_year(date'2005-04-02') from dual;\n&nbsp;\nTO_DOG_YEAR(DATE'2005-04-02')\n-----------------------------\n                           65\n</code></pre>\n<p>Yes, here I learn that the calculation is a bit more complex than just multiplying by 7. Of course, adding a SQL standard function would not make sense if it was just a multiplication. </p>\n<p>But it seems to be even more complex. I searched for the C functions behind this one:</p>\n<pre><code>\n[oracle@CLOUD18C ~]$ nm /u01/app/oracle/product/18.0.0/dbhome_1/bin/oracle | grep -iE \"dog.*year\"\n000000001452e073 r KNCLG_TODOGYEAR\n0000000003ffcf40 T LdiJDaysDogYear\n000000000f3170c0 T LdiJulianDogYear\n000000000f316fc0 T LdiJulianDogYeararr\n000000000f3170f0 t LdiJulianDogYeari\n000000000f606e10 T OCIPConvertDateDogYearTime\n000000000ebf2380 t qerxjConvertDogYearTime\n0000000010de19e0 t qjsngConvStructDogYear\n0000000010de0320 T qjsngNumberDogYearDty\n0000000010de06f0 T sageStringDogYearDty\n0000000010de7110 T sageplsDogYear\n000000000bc5cd80 t sagerwAddDogYearTime\n0000000010bad3c0 T qmxtgrConvSaxDogYear\n0000000010bad400 T qmxtgrConvSaxDogYear_internal\n00000000025ae090 T qosDateTimeDogYear\n0000000004f22b60 T xsCHDogYeartime\n000000000438c230 T nlsBreedDogYear\n000000000438bb50 t nlsBreedDogYearCmn\n000000000438c060 T nlsBreedDogYearTime\n000000000438bc50 T nlsBreedDogYear\n00000000044d1da0 T xvopAddDTDurDogYear\n00000000044d1ac0 T xvopAddYMDurDogYear\n</code></pre>\n<p>Those &#8216;nlsBreed&#8217; functions ring a bell and I checked if there are new values in V$NLS_VALID_VALUES</p>\n<pre><code>\nSQL&gt; select distinct parameter from V$NLS_VALID_VALUES;\n&nbsp;\nPARAMETER                                                       \n----------------------------------------------------------------\nTERRITORY\nCHARACTERSET\nBREED\nLANGUAGE\nSORT\n</code></pre>\n<p>That &#8216;BREED&#8217; is a new one, with a lot of interesting values:</p>\n<p><a href=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/CaptureBREED.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/CaptureBREED.png\" alt=\"CaptureBREED\" width=\"547\" height=\"556\" class=\"aligncenter size-full wp-image-22061\" /></a></p>\n<p>And here is my example using this new NLS parameter.</p>\n<pre><code>\nSQL&gt; select to_dog_year(date'2005-04-02','','NLS_BREED=Saint Bernard') from dual;\n&nbsp;\nTO_DOG_YEAR(DATE'2005-04-02',\n----------------------------\n                          96\n</code></pre>\n<p>Note that I&#8217;ve no idea about the second parameter, I had to put a &#8216;null&#8217; for it to be able to mention the NLS one, or I got a &#8216;ORA-00909: invalid number of arguments&#8217;.</p>\n<p>I have to say that, for a DBA focused on the core database functions, it is hard to understand that new features go on things like this TO_DOG_YEAR function. But being realistic, it is clear that the budget for new features go into the new direction: all for developers, big data, IoT&#8230; Of course we can write those functions in PL/SQL or maybe one day with JavaScript thanks to the <a href=\"https://oracle.github.io/oracle-db-mle/\" target=\"_blank\" rel=\"noopener noreferrer\">Multi-Lingual Engine</a> currently in beta. But IoT is also about performance, and a standard function avoids context switches.</p>\n<h3>Added a few hours later</h3>\n<p>There are a lot of questions about this new function. Here are some links to go further as many people in the Oracle Community have analyzed it further:</p>\n<p>Martin Berger tested performance: <a href=\"http://berxblog.blogspot.ch/2018/04/more-fun-with-ages.html\" target=\"_blank\" rel=\"noopener noreferrer\">http://berxblog.blogspot.ch/2018/04/more-fun-with-ages.html</a><br />\nPieter Van Puymbroeck realized it was offloaded in Exadata: <a href=\"http://vanpupi.stepi.net/2018/04/01/exploring-18c-exadata-functions/\" target=\"_blank\" rel=\"noopener noreferrer\">http://vanpupi.stepi.net/2018/04/01/exploring-18c-exadata-functions/</a><br />\nBrendan Thierney reveald a project he worked on in beta: <a href=\"http://www.oralytics.com/2018/04/predicting-ibs-in-dogs-using-oracle-18c.html\" target=\"_blank\" rel=\"noopener noreferrer\">http://www.oralytics.com/2018/04/predicting-ibs-in-dogs-using-oracle-18c.html</a><br />\nØyvind Isene provides a way to test it with a cloud discount: <a href=\"http://oisene.blogspot.ch/2018/04/oracle-is-best-database-for-your-pets.html\" target=\"_blank\" rel=\"noopener noreferrer\">http://oisene.blogspot.ch/2018/04/oracle-is-best-database-for-your-pets.html</a></p>\n<h3>Update 2-APR-2018</h3>\n<p>A little update for those who didn&#8217;t realize this was posted on 1st of April. It was an April Fool common idea from some Oracle Community buddies on the post-UKOUG_TECH17 trip. And what remains true all the year is how this community is full of awesome people. And special thanks to Connor who added great ideas here 🙂</p>\n",
    "protected": false
  }
}
