Skip to main content

Posts

How many times does my table function execute?

A left correlation join occurs when you pass as an argument to your table function a column value from a table or view referenced to the left in the table clause. This technique is used with XMLTABLE and JSON_TABLE built-in functions, but also applies to your own table functions. Here's the thing to remember: The table function will be called for each row in the table/view that is providing the column to the function.  Clearly, this could cause some performance issues, so be sure that is what you want and need to do. The following code demonstrates this behavior, for both pipelined and non-pipelined functions. CREATE TABLE things ( thing_id NUMBER, thing_name VARCHAR2 (100) ) / BEGIN INSERT INTO things VALUES (1, 'Thing 1'); INSERT INTO things VALUES (2, 'Thing 2'); COMMIT; END; / CREATE OR REPLACE TYPE numbers_t IS TABLE OF NUMBER / CREATE OR REPLACE FUNCTION more_numbers (id_in IN NUMBER) RETURN numbers_t IS l_numbers numb...

The SmartDB Resource Center

I put together this blog post for those interested in learning more about the SmartDB (also or formerly known as "ThickDB") architecture and how to apply it in your applications. I will update it as more resources become available. What is SmartDB? Here's a summary: Large software systems must be built from modules. A module hides its implementation behind an interface that exposes its functionality. This is computer science’s most famous principle. For applications that use an Oracle Database, the database is, of course, one of the modules. The implementation details are the tables and the SQL statements that manipulate them. These are hidden behind a PL/SQL interface. This is the Smart Database paradigm: select, insert, update, delete, merge, commit, and rollback are issued only from database PL/SQL. Developers and end-users of applications built this way are happy with their correctness, maintainability, security, and performance. But when developers follow the ...

Mutating table errors and multi-row inserts

When something mutates, it is changing. Something that is changing is hard to analyze and to quantify. A mutating table error (ORA-04091) occurs when a row-level trigger tries to examine or change a table that is already undergoing change (via an INSERT, UPDATE, or DELETE statement). In particular, this error occurs when a row-level trigger attempts to read or write the table from which the trigger was fired. Fortunately, the same restriction does not apply in statement-level triggers. In this post, I demonstrate the kind of scenario that will result in an ORA-04091 errors. I then show the "traditional" solution, using a collection defined in a package. Then I demonstrate how to use the compound trigger, added in Oracle Database 11g Release1,  to solve the problem much more simply. All the code shown in this example may be found in this LiveSQL script . How to Get a Mutating Table Error I need to implement this rule on my employees table: Your new salary cannot ...

Error stack function now (12.2) includes backtrace information!

The DBMS_UTILITY has long (since 10.2) offered three functions that are very handy when either tracing execution or logging errors: FORMAT_CALL_STACK - answering the question "How did I get here?" FORMAT_ERROR_STACK - answering the question "What was the error?" (or a stack of errors, depending on the situation) FORMAT_ERROR_BACKTRACE - answering the question "On what line was my error raised?" Therefore (and prior to 12.2), if you wanted to get the error information + the line number on which the error was raised, you would need to call both of the "*ERROR*" as in: CREATE OR REPLACE PROCEDURE p3 AUTHID DEFINER IS BEGIN p2; EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.put_line (DBMS_UTILITY.format_error_stack); DBMS_OUTPUT.put_line (DBMS_UTILITY.format_error_backtrace); RAISE; END; Of course, in the real world, you would not display the text on the screen. You would write them to a log table via an autonomous tra...

How do I get the attribute of my object type in SQL?

This question found its way into my In Box yesterday: I have a table with an object type column. I want to way to get the value of an attribute of that object type in my query. But Oracle keeps telling me "ORA-00904: invalid identifier". What am I doing wrong? Almost certainly what you are doing wrong is forgetting to use a table alias. Yeah, it's that simple. Don't forget the table alias. Let's take a look. I create an object type, use that object type as a column in a table, and insert a couple of rows: CREATE TYPE food_t AS OBJECT ( NAME VARCHAR2 (100) , food_group VARCHAR2 (100) , grown_in VARCHAR2 (100) ) / CREATE TABLE food_table (id number primary key, my_food food_t) / BEGIN INSERT INTO food_table VALUES (1, NEW food_t ('Mutter Paneer', 'Curry', 'India')); INSERT INTO food_table VALUES (2, NEW food_t ('Cantaloupe', 'Fruit', 'Backyard')); COMMIT; END; ...

Oracle Dev Gym gets a facelift - and more!

Over the weekend of April 21, we upgraded the Oracle Dev Gym site to v3 (code name: ORANGE). Here's the v2 home page: and now v3: Now you see the reason for the code name. It's orange! Here are the key changes you will find on the Dev Gym: Orange theme: all that red was hurting our eyes, but the main reason to switch to orange was to make it visually clear that this site, as with AskTOM , is part of the broader Oracle Developer initiative . Site search: type in a keyword, such as "FORALL" or "listagg" in the search bar on the home page, and we will find all quizzes, workouts and classes that match your criteria. You can further hone your search on the results page. The tournament quizzes are now offered on the home page; no need to click on the Tournaments tab to see them. These quizzes are produced fresh each week, and often focus on the latest features in SQL, PL/SQL and Oracle Database. Your recent activity on the site is a...

Tips for a great presentation

There's no shortage of people giving advice on how to improve your presentation skills and impact. I offer a short list of links at the bottom of this post.  I though I'd take a few moments to share some tips I follow to help me make the most of my time in front of audiences. Why listen to me? I've been doing talks on the  PL/SQL  language since 1992 and I am pretty sure that only 3 members of all those audiences ever fell asleep during my talk. What are the (at most) three key takeaways? Most attendees will forget most of what you said soon after leaving the session. Certainly almost every single technical detail  will be lost. So you need to decide before you start your talk what  are the at most three things you want an attendee to remember. Then put those in a slide and tell them right at a start. Remind them during your talk when you are getting to one of those top 3 things. Use the slide again at the end of your talk to drive the point...