This is the 2nd post on getting started with APEX…from the real basics…
- The first step is to download the following worksheet that contains data. It’s a wine list with 1,624 different products. You can find that here: WineMerchantsAsia
- Log into your workspace at apex.oracle.com. Enter your workspace name, username and password.
- The easiest way to build a table if you have the data in a worksheet is to simply load that worksheet to APEX and have the tool build the table for you. From the menu at the top, choose
SQL Workshop -> Utilities -> Data Workshop
- You will be brought to the following screen where you can choose to load or unload data. Choose “Spreadsheet Data”.
- Before we create the new table, we need to change the data type in the “Our_Price” column to a number instead of currency. Then, we will choose “New Table” and “Copy and paste” as how we are going to load the data.
- Next we are going to select the range of data, including headers, from the Excel worksheet from step 1 and paste it into the window.
- Since we have a tab delimited file, we need to change the delimiter to “\t”. Click “Next”.
- We need to give the table a name, “Wines”, then verify the columns are correct. The column “Vintage” should be changed to VARCHAR2 of 30 as not all values are numbers. Click “Next”.
- When we do this, we will get an error that one of our column names is an Oracle reserved word. Change the column named “Size” to “Liters”. Click “Next”.
- We are going to choose to use “Product_ID” as our primary key. Choose “Use an existing column” then choose “Product_ID” as that column. Allow APEX to create the sequence for you for new product id’s. Click “Load Data”.
- You will come to a validation screen. We can see that we had 1,623 records successfully loaded and 0 failed.
12. To view the table, click on SQL Workshop -> Object Browser
13. From the list of tables on the left, if we select “WINES”, we will see our table details to the right. Note that There are pre-loaded tables in APEX that are used with the same applications.
14. On the upper right-hand side of the screen, click the plus sign and choose Table to add a new table.
15. Enter the details shown below to our “TASTERS” table and click “Next”.
16. Choose the primary key and have APEX create the sequence SQL for you (cool, huh?). Click “Next”.
17. We are not creating any foreign keys right now, but if you needed them, APEX would create the code for you to do so in this step. Click “Next”.
18. If you need to add constraints, you would do it in this screen and APEX will generate the code for you. Click “Next”.
19. Right before we have APEX create the table for us, we can view the SQL that will be run to create the table and sequence. Click “Create Table”.
20. We can now see our table has been created.
21. To add data to the tables, we have a few methods to do this with. The first is to go to SQL Workshop -> SQL Commands.
22. We can enter data using SQL, listed below. When we click run, we will get confirmation that “1 row(s) inserted.” If there was an error, it would also show here.
23. We can also go to SQL Workshop -> Utilities -> Text Data
24. Since WordPress won’t allow me to load a .txt file, create one with the following details:
25. Choose to load data to an Existing Table and choose a comma separated or tab delimted file. Click “Next”.
26. Choose the file name, the delimiter and click “Next”.
27. Make sure the column headings are correct for the table we just created and click “Load Data”.
28. We can see that 3 records were uploaded and 0 failed.
29. If we go back to the SQL Commands screen, we can do a select * from the TASTERS table and see that the data did, in fact, load.
Now, you can see how to create tables and load data in APEX. Next, we will start putting it together in an application.