โOracle query builder? You mean to visually craft my query so that I click more and type less?โ, asked Dan.
Dan is an Oracle pro. He attacks SQL queries head-on. He crafts his joins, subqueries, and anything SQL by typing.
โBesides, code autocompletion and code suggestions are there to help. And I know my craft.โ, he explains.
There are pros like Dan who let an Oracle query builder just sit there unused.
But work today demands fast results. This tells us whether pros or otherwise to use all the productivity tools at our disposal.
So, before we proceedโฆ
Letโs Map Our Oracle Query Builder Journey First
This is a guide with you (a pro) in mind. But the steps later are equally useful for newbies or novices too.
So, hereโs how we go through this journey:
- An Oracle Query Builder is a Complement, not a Replacement. Letโs dispel the myth together that we are trying to replace good old typing with visual query building.
- This Oracle Query Builder is Your Bet for Faster Query Building. Youโll learn about dbForge Studio for Oracle and its visual query-building powers.
- How to Visually Craft Simple to Complex Oracle Queries. Learn using the visual Query Builder in dbForge Studio for Oracle. This is like a stairway of different steps from simple to complex queries.
Letโs start.
An Oracle Query Builder is a Complement, not a Replacement
Some pros worry about precision and control. They want to craft their queries without code generators interfering.
โI worry about query performance. Code generators like an Oracle query builder may not cut it.โ, said Dan.
Performance is a real concern. But is it true that Oracle query builders get in the way?
Hereโs the truth: Visual query building complements SQL query writing, not replace it.
Let me explain.
Oracle query builders today generate SQL code with joins, subqueries, GROUP BY, and much more. You use your mouse instead of typing columns, table names, join types, etc.
So, that means you drag the tables on a canvas. If there are foreign keys, it will use them to generate joins for you. But you can still replace the type of JOIN from INNER to LEFT, if thatโs what you need. Then, add a WHERE, GROUP BY, HAVING, and other clauses. You do most of them by clicking.
If you feel itโs still incomplete or doesnโt suit your level of control and precision,โฏyou can switch to typing. From there, code autocompletion, suggestions, and other code productivity hacks will help you.
An Oracle query builder can start the foundation of your query. And the more intricate parts are up to you to type.
Did you lose control and precision? Not at all.
So, visual query building makes it faster to write SQL code.
But what Oracle GUI tool can make this happen?
This Oracle Query Builder is Your Bet for Faster Query Building
My best bet isโฏdbForge Studio for Oracle. It can be yours too.
Devart made this outstanding GUI tool as an Oracle productivity booster. It is a jack-of-all-trades for anything Oracle. Coding is a breeze with a smart PL/SQL coding assistant. Talk about automatic code completion, code snippets, and much more. It also has a Database Designer, a Query Profiler, an SQL debugger, and all the works.
But thereโs more.
Its visual query-building abilities are the easiest to get used to. Here are some of them:
- Visually make SELECT statements like a walk in the park.
- See your queryโs tables and their relationships in a beautiful diagram.
- Automatic INNER JOIN if your tables have foreign keys. Then, change it to LEFT, RIGHT, or FULL with mouse clicks.
- Provided full support to subqueries and navigated from the main query to the subqueries.
- A neat Expression Editor for your WHERE, HAVING, and JOIN clauses with Oracle functions support.
- An easy switch between visual and manual query writing so you can have more control on the resulting query.
- A Document Outline to see your query in a neat tree structure. This is useful for complex queries with several database objects and subqueries.
- Edit the data in query results, export them, or send them to a report designer.
- andโฏmuch more.
Looks nice on paper. But check out the steps later to see its true power for yourself.
Note that my version of dbForge Studio for Oracle is 4.6.36. This version does not include visually creating INSERT, UPDATE, and DELETE statements, unlike dbForge Studio for SQL Server and MySQL. But Iโm sure itโs in the development pipeline.
You need toโฏdownloadโฏand install dbForge Studio for Oracle. If youโve done that already, letโs proceed.
How to Visually Craft Simple to Complex Oracle Queries
The number of steps differ depending on the complexity of your query. Letโs take this one step at a time by starting with simple queries.
But before that, weโre going to use this sales database:
We have 5 tables:โฏCUSTOMER, STORE, PRODUCT, SALES_HEADER,โฏandโฏSALES_DETAIL.
Letโs roll.
How to Craft Simple Queries in 2 to 3 Steps
dbForge Studio for Oracleโs visual Query Builder makes it easy to create simple SELECT statements. You can ask your 5-year-old kid to drag and click for you. Thatโs how easy it is.
Run your new dbForge Studio for Oracle and sign in to an Oracle server. Then, follow the steps below:
STEP 1: Drag the Customer Table from the Database Explorer into the Query Builder
Letโs use theโฏCUSTOMERโฏtable. ClickโฏNew Queryโฏfrom the toolbar. Then, from theโฏDatabase Explorer, drag this table into theโฏQuery Builderโฏas seen below:
The Query Builder canvas is white with grids. You can position the table and snap it to these lines to your liking.
STEP 2: Mark the Columns You Want to Appear in the Query
Again, this is easy. You wonโt need your keyboard.
There are checkboxes in each table column. Select the columns you want to appear in the query. Check it out below:
Selected columns appear in theโฏSelectionโฏtab. From here, you can add an alias, an aggregate function (like SUM or COUNT), and more for each column.
If this is what you need for now, you can switch to the SQL code window by clicking theโฏTextโฏbutton below theโฏSelectionโฏtab. See it below and check the generated SQL code:
If this is the only thing you need, the simple query steps end here. But you can do more like the one in the next step.
STEP 3: Add a WHERE Clause
Queries are rarely without filters because you only get what you need.
So, letโs filter the results by adding a WHERE clause. First, switch back to the visual Query Builder, and click the WHERE tab. You will see a similar screen below:
The WHERE tab is the place to form the expression for the WHERE condition.
Expressions have a left portion where you usually put one of the columns. Then, thereโs an operator like equal (=), greater than (>), BETWEEN, and more. Finally, thereโs a right portion where you put values or another expression you want to qualify against the left portion.
Press theโฏInsertโฏkey from your keyboard or click the little green plus (+) button to add an expression. After doing that, you will see a blank expression ready for you to configure. See below:
Then, you choose what goes to the left side of the expression by clickingโฏ<enter a value>. See below:
For our purpose, we will choose theโฏCUSTOMER_IDโฏcolumn as the left side of the expression.
Then, you need to change the operator. It defaults to the equal (=) operator. Click that. Then, choose BETWEEN. Check it out below:
Then, for the right side of the expression, we will enter 2 values needed by BETWEEN. This time, you need a keyboard to type the values. See below for the first value:
And the second value:
Finally, check the following edited SQL code below:
At last, you can run the query by clickingโฏExecuteโฏfrom the toolbar. See the results on my end below:
How to Craft Queries with Joins in 4 Steps
Letโs take this to the next level by adding some joins.
The dbForge Studio family of products, including dbForge Studio for Oracle, is known for superb code autocompletion and suggestions. But the ninja moves extend to the Query Builder as well.
Letโs begin.
STEP 1: Drag the Tables to the Query Builder
This is the same as earlier, but you must drag three tables instead of one. We will use the same Oracle database as before. So, clickโฏNew Queryโฏfrom the toolbar. Then, dragโฏSALES_HEADER, CUSTOMER,โฏandโฏSTOREโฏtables into the Query Builder.
It should be the same as the following:
STEP 2: Mark the Columns You Want to Appear in the Query
Since we want to see the transactions of a particular customer, the date, and the store, letโs choose the columns as seen below:
Simply mark the check boxes of the columns you want.
STEP 3: Add the Joins
TheโฏSALES_HEADERโฏtable has foreign keys for the store and customer IDs. Thatโs why the images earlier already contain arrows to theโฏCUSTOMERโฏandโฏSTOREโฏtables. It created INNER JOINs for you.
Nifty, isnโt it?
Click theโฏJoinsโฏtab to see them.
It should be the same as the illustration below:
That was too easy if you intend to use an INNER JOIN.
But if your tables donโt have foreign keys, you can still add a join in 2 ways:
- Click theโฏCUSTOMER_IDโฏof theโฏSALES_HEADERโฏtable and drag it to theโฏCUSTOMER_IDโฏof theโฏCUSTOMERโฏtable. An arrow will appear just like the above. Do the same forโฏSTORE_IDโฏand theโฏSTOREโฏtable.
- From theโฏJoinsโฏtab, press the Insert key from the keyboard or click the little plus button. Then, enter the related tables and the related columns. Do that for theโฏCUSTOMERโฏandโฏSTOREโฏtables. You should get the same result as the above.
See how to manually join tables below:
Simply clickโฏ<enter table name>โฏon both sides. You will selectโฏSALES_HEADERโฏandโฏCUSTOMER.
Then, manually relate columns as seen below:
Simply clickโฏ<enter column name>โฏfor both sides. You will choose theโฏCUSTOMER_IDโฏof theโฏSALES_HEADERโฏandโฏCUSTOMERโฏtables.
For the next join, click the little plus button from the top. Then, selectโฏSALES_HEADERโฏandโฏSTOREโฏtables. Then, relate theโฏSTORE_IDโฏof these 2 tables.
If you want to change the join type, clickโฏInner Join. Then, select another join type. Check out the screenshot below:
For less clicking, your tables should have foreign keys.
STEP 4: Add a WHERE Clause
We intend to filter the result to one customer only (CUSTOMER_IDโฏ= 56). So, click the WHERE tab. Then, add the same WHERE clause as below:
Finally, switch toโฏTextโฏto see the generated SQL code. See below:
Run the query by clickingโฏExecuteโฏfrom the toolbar. See the query results below:
How to Craft Queries with a Subquery in 3 Steps
For this exercise, we wanted to show all customers without any sales transactions.
We will use a subquery of all customers with sales transactions using theโฏSALES_HEADERโฏtable. Then, we will filter the results from theโฏCUSTOMERโฏtable withโฏCUSTOMER_IDโฏ, which is not in theโฏSALES_HEADER.
STEP 1: Drag the CUSTOMER Table into the Query Builder
You should have the same result for this step as the one below:
STEP 2: Choose the Columns You Want to Appear in the Query
We want the customerโs name, email, and mobile number. So, it should be the same as below:
STEP 3: Add the WHERE Clause with Subquery
The WHERE clause should filter theโฏCUSTOMER.CUSTOMER_IDโฏis not in the customer IDs inโฏSALES_HEADER.
First, click the WHERE tab and choose theโฏCUSTOMER_IDโฏfor the left side of the expression. See below:
Then, click the equal (=) operator and select NOT IN. See it below:
Creating the Subquery
Now, the condition’s right side should result from a subquery. So, clickโฏ<enter a value>. Then, click theโฏCreate subqueryโฏbutton. See it below:
A new tab will appear with the labelโฏUnnamed Query.โฏTheโฏDocument Outlineโฏwindow will also appear.
From here, drag theโฏSALES_HEADERโฏtable into the Query Builder under theโฏUnnamed Query. Then, choose theโฏCUSTOMER_IDโฏand clickโฏUnique records. See the result of this below:
Go back to the main query by clicking theโฏRoot Query. You should be in the WHERE tab. If not, click it, and you will see the new subquery in the WHERE clause. Check it out below:
Then, switch to the Text window to see the generated SQL code:
From here, you can optionally add an ORDER BY. Switch back to the Query Builder, then click the ORDER BY tab. Choose theโฏCUSTOMER_NAMEโฏcolumn as the sort order.
Finally, hereโs the query result on my end:
Note that the same results can be achieved using a LEFT JOIN instead of a subquery. You can use theโฏQuery Profilerโฏof dbForge Studio for Oracle to see which performs better.
But thereโs more to subqueries in the Query Builder.
Subqueries can be added as part of the SELECT column list by clicking theโฏCreate subqueryโฏin another row in theโฏSelectionโฏtab. See below:
The column in the subquery can result from an aggregate function like SUM. See below:
And of course, you can switch to typing anytime you want to add more complex query structures.
Takeaways
Danโs jaw dropped as a coworker demos the query magic in dbForge Studio for Oracle.
He realizes the speed it can give him to craft his queries. He will be on top of his game on every project, and his team can enjoy it, too.
And the result for all of them?
They can leave the office sooner, have a good time in a nice bar, or relax in the comfort of their homes.
And his boss?
Nothing but smiles on every KPI they meet.
So, remember: this Oracle query builder is a complement, not a replacement to typing SQL statements. It can do joins, subqueries, ORDER BY, and more.
Try it out today by downloading a copyโฏfrom Devart’s official website.