Close

Using a Java function to iterate large JSON with many keys.

In my previous article I provided a few PL/SQL options for returning a collection of keys from a JSON document. They are simple to use and work well enough for most JSON sources I’ve encountered. SQL> select * from json_keys(json(‘{“a”:”test 1″, “b”: “test 2”, “c” : “test 3”}’)); COLUMN_VALUE ——————————————————————————– a b c Iudith Mentzel…

Comparing 19c vs 21c JSON key lists

I found this functional surprise while responding to questions about my previous article. When you invoke the GET_KEYS method of JSON_OBJECT_T, if the collection is empty, 19c will return a NULL value; 21c will return a JSON_KEY_LIST collection of 0 elements. 19c SQL> DECLARE 2 v_version VARCHAR2(20); 3 v_compatible VARCHAR2(20); 4 v_keylist json_key_list; 5 BEGIN…

Calculating Skewness of a Population

After completing my article about skewness of a sample for Joel Kallman Day I decided I could do one more and write up the related functionality for skewness of a population. Like skewness of a sample, the purpose of the function is to indicate the degree and direction of asymmetry in a data distribution. Like…

23c adds PING to SQL*Plus

For all the amazing and grand new features coming in 23c for the database… sometimes it’s the little things that are really appreciated. SQL*Plus in 23c has a new PING command that mostly takes the place of TNSPING. This is fantastic news for all the fans of the Instant client that never included this handy…

Pipelined PL/SQL and Java with ODCI

In my previous article I showed how to build table functions, including pipelined functions with PL/SQL. To provide a simple, minimal example I created a function that would generate a list of numbers from 1 to some value provided by the invoker. CREATE OR REPLACE FUNCTION nt_function_pipelined(n IN INTEGER) RETURN numtab PIPELINED IS BEGIN FOR…

Working with Table Functions in SQL

In a previous article I looked at creating and using collections within SQL. I mentioned, but did not explore functions returning Nested Table and Varying Array collection types in that article. Those fuctions, known as table functions, will be the subject here. A table function can return either of the two collection types in their…

Exiting the OJVM in your db session

When you invoke a java stored procedure you will instantiate the internal JVM (Java Virtual Machine) to execute that code. Since 11gR1, you can clear your session state with functions in the DBMS_JAVA package. DBMS_JAVA.endsession – this will clear your Java session state. DBMS_JAVA.endsession_and_related_state – this will clear your Java session state. It will also…

Oracle 23c interval aggregates

A few years ago I wrote a couple articles about Day to Second and Year to Month intervals. In those articles I included examples of user-defined aggregates allowing you to sum the corresponding interval values. 23c though has, thankfully, made those functions obsolete. As a quick recap for comparison… select dsintervalsum(result) odci_pre_23c from ( select…

Oracle 23c Boolean support in SQL

For all the great new functionality introduced in a new database release, sometimes it’s the simple and small things that generate the most buzz. The 23c introduction of Boolean data types in SQL may be one of the biggest. For many years in prior releases the argument against a Boolean SQL type is that it…

Date/Timestamp Cheat Sheet

A collection of conversions, formats, math, generators, and conditions for date and timestamp data types. I’ll show most examples as simple SQL statements from DUAL. Many of the expressions could be used directly in PL/SQL without a query. Unless otherwise specified my examples have NLS_DATE_LANGUAGE=American. If that is not the case for your sessions you…

Finding dates of holidays using PL/SQL

A common task for scheduling is to find when certain dates might occur. The package below includes functions to return various holidays observed in the U.S. for various years. The dates can be returned individually by calling specific holiday functions and passing in the year. For example: SQL> select holidays.independence_day(2023) from dual; HOLIDAYS.I ———- 2023-07-04…

Large Number Combinatoric calculations in PL/SQL

Calculating factorials quickly explode into large results. The SQL and PL/SQL numeric types can’t hold the extremely large values generated by factorial computation of even relatively small numbers. Since several numeric types are subtypes, they inherit the limits of their parent type. All of the types will eventually overflow when the results get too big.…

Let NULL work for you #JoelKallmanDay

Recently I was working on a SQL performance problem and looking at the statement I found an unusual clause of the form where NVL(date_column,sysdate) < date ‘2022-10-01′ Note: in the example I’ve used a date literal for the sake of illustration. The actual code used a variable; but the problem exists either way. Checking with…

Working with Collections in SQL

I’ve written about collections before; but usually in the context of solving some other problem rather than focusing on them specifically. I’ll begin with a quick review of some of those previous topics and then dig into the syntax details of working with collection types. Previous Examples Using the COLLECT operator we can create a…

SQL and Set Theory

I polled some friends for topics and one asked for an article on collections. I’ve written about collections before; but usually in the context of solving some other problem rather than focusing on them specifically. Before digging into the collection types and the SQL and PL/SQL syntax of using them; I want to start with…

Sending Email with Oracle, Part 6: MIME Content

Sending Email with Oracle At this point in the series you should be able to send simple, plain text email with UTL_SMTP. Often though, we’ll want to send emails with special formatting – different fonts, highlighting, tables, images, etc. We’ll want to send attachments too. It surprises many developers new to the UTL_SMTP package to…

Free Falling with PL/SQL

I needed to calculate some free fall timings recently and while I could have used a calculator I decided I’d write a package to encapsulate the math for more convenient reuse if I ever needed to do so again. Once I had a couple calculations I expanded it to add more. Using the package I…

Sending Email with Oracle, Part 2: APEX_MAIL

Sending Email with Oracle APEX_MAIL The APEX_MAIL package is a more robust version of what you’ll find with UTL_MAIL, but it is only available when APEX is installed. It also requires pre-configuration of the smtp server, port, authentication, wallets, and encryption. These features require APEX-administrative privileges to set. Since APEX might not be installed and…

SQL vs Towers of Hanoi

The Towers of Hanoi are a classic children’s puzzle. With 3 pegs and a set of disks of differing sizes, the goal is to move a stack of disks (arranged with largest on the bottom to smallest on top) from one peg to another moving only one disk at a time, never putting a larger…

Solving the Water Jug puzzle with SQL

The Water Jugs are a classic puzzle going back centuries with many variations. While the specific numbers involved may change from one telling to the next the general form is one small jug (cup, barrel, bucket, etc.) and one large one. Each with an integer capacity of units (liters, gallons, ounces, etc.) The goal of…

Recursive WITH clause join bug

I recently ran into a strange bug where I spent a lot of time banging my head trying to figure out why my recursion wasn’t working, causing ORA-32044: cycle detected while executing recursive WITH query errors to show up. After simplifying the query down to a single counter column I eventually discovered the problem was…

SQL meets Calculus

Yesterday, Connor McDonald posted an interesting article about a math puzzle he received asking him to calculate the integral of a function over a range. He posted two variations using the Trapezoidal Rule. In his post he mentions the Riemann sums method and I thought it would be interesting to explore that option as well.…

21c My easiest upgrade ever

21c was released for Linux a little over a week ago. I downloaded the zip file, unzipped it, and created an empty container database.Then I wanted to upgrade one of my 19c DBs but I didn’t want to lose the 19 version. I wanted to have a before and after image to compare. This is…

In memory of Joel Kallman

Like many, when I read the news of Joel’s passing I just couldn’t believe it. I spoke with Joel at several conferences, a local user group, as well as a visit to my workplace to talk about APEX (of course.) While his technical chops were without question – the most inspiring thing about Joel was…

ORA_COMPLEXITY_CHECK quirks and alternative

Most companies will have some standard for password complexity they follow and the Oracle database has long supported enforcement of those standards by attaching password verification functions, owned by SYS to profiles. These standards are so common and so important Oracle not only allows; but forces you to put those user-defined objects into their SYS…

Dynamic Action Link with APEX chart

A couple of great things about APEX charts are Dynamic Actions on the region and the easy to use Link option when clicking on a chart element. However, if you use a dynamic action, it doesn’t know about the fields within the clicked element. If you use the link option, it does allow you to…

How to TNSPING without TNSPING

While the Instant Client is a popular client installation for many applications, very often developers and admins become frustrated by the conspicuous absence of the TNSPING utility. Developers using jdbc thin clients may also miss having this handy tool at their disposal. Fortunately there are ways to replicate some of the functionality of TNSPING using…

LDAP – TNS service name package v2.3

I’ve released version 2.3 of my service name maintenance package for LDAP servers implementing the OID schema. I’ve exposed the get_entry function both as a stand alone function the opens, reads, and closes a connection to the ldap server, and as an API accepting an already established connection and using it. Along with the function…

How to put an “IF” inside SQL

Developers coming from a procedural coding background are familiar with traditional IF-THEN-ELSE constructs, possibly extended to SWITCH or CASE blocks that group a series of conditions. Depending on the language, those could either evalute the conditions until the first TRUE is found or until the first result breaks out. They might also be comfortable with…