Skip to main content

Tag: SQL

Creating an Oracle 12c Container for Development

Recently I had to set up an Oracle 12c database in a container with test data to be used during testing and development. This post is just a quick documentation of that process. The developer tier for Oracle Database 12c Enterprise Edition is available on Docker hub. It’s available through the store, but is free of charge. On Docker hub, you’ll need to click on the ‘Proceed to Checkout’ button, agree to the terms of service, enter your contact information, and click on the ‘Get Content’ button.

Oh crud, part 2

Using the database from the first in the SQL for the uninterested series, in this post we’ll cover inserts, updates and deletes. We’ll start with inserts of single rows, multiple rows, and inserts using subqueries. Then we’ll look at basic updates and performing multiple updates in a single transaction. Finally, we’ll cover deleting rows. Inserts The basic format for inserts is: insert into ( <list of non autogenerated columns> ) values ( <list of values to be inserted> ); Using the address table for our examples, if we could run the following

Unions

Again using the sample database available via the docker images from the first post in this series, lets cover unions. When using a union, you can combine results from two result sets into a single result set. This might be useful during reporting, or having your application make one call to your database instead of multiple, avoiding what might be an unnecessary round trip over the network to your database.

Subqueries

Continuing with the sample database available via the docker images from the first post in this series, let’s look at some examples demonstrating the syntax of subqueries. A subquery is where you have a select statement nested inside of another query. You might utilize this approach based on performance tuning, the readability of your queries, or out of necessity based on your database schemas. A discussion of performance tuning is out of scope of this post.

Aggregate Queries

Next in the SQL for the uninterested series, we’ll take a dive into aggregating your data, using some group by clauses. We’re still using the sample database available via the docker images from the first post in this series. The simplest aggregate query would be to get a count of the number of rows in a given table. We’ll start with a query to count the number of rows in the sales order table.

Join Now!

Continuing with the “SQL for the Uninterested” posts, let’s talk about joining two or more tables together to produce a single result set. There are 4 kinds of joins. To discuss these, let’s use the customer and address tables from our sample database. Join (aka Inner Join) Let’s start with our sales order data, writing a simple query. select * from sales_order; Data from the sales_order table Now what if we wanted to view the customer or address details?

Oh, Crud!

CRUD is an acronym for create, read, update, and delete. Given you already have a sample database populated with data, let’s start with some simple reads using the select statement. A simple select statement has the basic format of: SELECT column1, column2, … FROM some_table; Or to select all columns, use simply: SELECT * FROM some_table; Note the keywords are not case sensitive. Now let’s get our hands on some data.

SQL for the Uninterested

Ok, so maybe you’re not totally uninterested in SQL if you’re reading this. But your true passion lies in something else, like working on your hot new javascript project or whatever, and you really just need to brush up on a little SQL to knock out a quick task and then get back to the work you really love. If this describes you, the SQL for the Uninterested series was written for you.