SQL

PL/SQL, SQL, Machine Learning

Looking for AI? You already have it!

TweetShareSharePin0 SharesThese days I meet many people who talk about how they have a project to find an AI-plattform to use on-premises. Using it in the cloud on Autonomous it is pretty obvious that you use one in a handful of AI-services Oracle has at your disposal there. The question is what you should use to build AI-services on the data in your on-prem Oracle database. You don’t need to get anything. This blog post assumes you have an Oracle […]

Database, SQL, Oracle Cloud

Ignoring errors on “alter session set”

TweetShareSharePin0 SharesThis tip is especially useful when migrating to autonomous. The reason is that to enable the magic of the the autonomous database there are things that cannot be done. One such thing is that there are a lot of session settings you cannot use. To see what APIs you can no longer use you can look at the documentation. If you look at alter session there are a number of “alter session set …” that are available. But many […]

Oracle, PL/SQL, SQL

Using package variables in SQL

TweetShareSharePin0 SharesI often want to use the constants defined in packages also in my SQL. It has in the past never worked and it for the most part still does not. If I have a a package like this to simplify my code for what department it is I’m looking at. This now allows using dept_info.c_accounting in PL/SQL instead of just hardcoding 10 and having to remember what department 10 is. This is how we usually use PL/SQL and especially […]

SQL, Database, Performance, DBA

Add hint to SQL you cannot modify

TweetShareSharePin0 SharesThe last post showed how to lock the plan for a SQL that switched plan every now and then. Another common issue one can encounter is that of a SQL that uses a suboptimal plan and for which you’d want it to use a different plan. The way to instruct the optimiser to use a different plan is to use a hint to cause it to change how it accesses the table. But often the SQL is in application […]

DBA, Performance, SQL

Lock the plan for a SQL

TweetShareSharePin0 SharesA SQL that sometimes just uses a plan you prefer it to not use is fairly common. There are always reasons for unstable plans, but more important than knowing the reason is often to make it stick to a certain plan. This has historically been done with a lots of ways from changing the SQL, adding hints, adding incorrect stats to influence the optimizer, using any of the techniques that came before SQL Plan Management (SPM). All of these […]

SQL

Set operators – Union, intersect and minus

TweetShareSharePin0 SharesYou’ve probably combined two queries with “union”, but have you looked at the different options for how to combine queries? The set operators are more combining result sets than they are combining queries even if we often think about it is combined queries. Thy need to return the same number of columns of the same datatypes. The lengths of the columns can differ but not the datatypes. Let’s start with a couple of tables and data so you have […]

Database, SQL

Longs in SQL

TweetShareSharePin0 SharesUsing long datatype is a problem we seldom face with new applications. But some old may still have it if they have not managed to convert to somethings easier to work with. But where I most often encounter it is in Oracles tables. The place that by far most often pops up its ugly head is high_value in *_tab_partitions. Just the other day a colleague was stuck on how to grab a portion of its content in SQL. “You […]

Performance, SQL, Oracle Cloud, SQL Developer, SQLcl

Grabbing sql_id for the SQL

TweetShareSharePin0 SharesI read Daniel’s recent blog about five ways to grab the sql_id and remembered reading Connor’s about getting it before you run a SQL. At the time it hit me that one ought to be able to use this to simplify the workflow. Often we run a SQL and then use some marker – typically in the form of a comment in the SQL – to look up the sql_id to then use for other lookups. It would of […]

PL/SQL, SQL

Accessing a website from the database

TweetShareSharePin0 SharesOne of the things people want more and more often is to somehow read from a web-resource using a database. It could be to just get the HTML off of a website or access REST via PL/SQL, or grab a JSON-file residing on a public website. No matter which it is we need to declare that it is a website we want the database user to reach. To have a simple example I’ll just show how to read the HTML off […]

SQL

Finding the query you never saved

TweetShareSharePin0 SharesYes, I admit it. I am sometimes not at all as structured as I would like to think. Recently I had worked on a query that had taken me many hours to get just right. When I was done I celebrated with a coffee break (I’m a Swede after all) and after it I started working on other pressing issues. A couple of weeks later that query is desperately needed as the same test needs be be done again and […]