Introduction
Executing SQL queries is a core task for anyone working with Oracle APEX or any Oracle database. Whether you're retrieving data, updating records, or performing calculations, knowing how to run SQL statements efficiently is essential. Oracle APEX provides multiple ways to execute SQL, including the SQL Workshop, SQL Commands interface, and SQL Developer Web. This blog will guide you through the steps to write and execute SQL queries within the APEX environment so you can work confidently with your data.
To execute SQL queries in Oracle APEX, you use the SQL Worksheet, a built-in tool that allows you to run SQL and PL/SQL statements directly against your database. This is useful for retrieving data, creating or modifying database objects, and performing data manipulation operations.
Start by opening the SQL Worksheet:
-
Log in to your Oracle APEX workspace.
-
Navigate to SQL Workshop.
-
Click SQL Commands or SQL Developer Web, then open the SQL Worksheet.
Once you're in the editor:
-
Type your SQL query in the editor window.
-
Click the Run button (a green triangle icon) or press Ctrl + Enter on your keyboard.
-
The results of the query will appear in the output panel below the editor, displaying rows affected or returned, and any error messages if applicable.
Here are some example queries you can try:
Selecting all records from a table
SELECT * FROM EMPLOYEES;
Creating a new table
CREATE TABLE DEPARTMENTS (
DEPT_ID NUMBER PRIMARY KEY,
DEPT_NAME VARCHAR2(100)
);
Inserting data into a table
INSERT INTO DEPARTMENTS (DEPT_ID, DEPT_NAME) VALUES (1, 'HR');
Updating records
UPDATE EMPLOYEES SET SALARY = SALARY * 1.1 WHERE DEPT_ID = 1;
Deleting a record
DELETE FROM EMPLOYEES WHERE EMP_ID = 5;
Each time you run a command, the results panel will show how many rows were affected or what data was retrieved. This immediate feedback makes it easy to test and adjust your SQL statements as needed. Whether you're working on data maintenance, reporting, or application development, the SQL Worksheet is your direct line to the database.
Conclusion
Running SQL queries in Oracle APEX is a straightforward process that gives you direct access to interact with your database. Whether you're testing a new query, performing updates, or exploring tables, APEX offers user-friendly tools to help you execute SQL with ease. Mastering these features will help you manage data more effectively and build more powerful, data-driven applications.