Learning APEX: The Real Basics, Post 1

 

This is the 2nd post on getting started with APEX…from the real basics…

  1. 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
  2. Log into your workspace at apex.oracle.com. Enter your workspace name, username and password.
  3. 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

    1

  4. You will be brought to the following screen where you can choose to load or unload data. Choose “Spreadsheet Data”.

    2

  5. 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.
  6. 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.

    3

  7. Since we have a tab delimited file, we need to change the delimiter to “\t”. Click “Next”.

    4

  8. 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”.

    5

  9. 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”.

    6

  10. 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”.

    7

  11. You will come to a validation screen. We can see that we had 1,623 records successfully loaded and 0 failed.

8

12. To view the table, click on SQL Workshop -> Object Browser

9

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.

10

14. On the upper right-hand side of the screen, click the plus sign and choose Table to add a new table.

11

15. Enter the details shown below to our “TASTERS” table and click “Next”.

12

16. Choose the primary key and have APEX create the sequence SQL for you (cool, huh?). Click “Next”.

13

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”.

14

18. If you need to add constraints, you would do it in this screen and APEX will generate the code for you. Click “Next”.

15

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”.

16

20. We can now see our table has been created.

17

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.

18

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.

19

23. We can also go to SQL Workshop -> Utilities -> Text Data

20

24. Since WordPress won’t allow me to load a .txt file, create one with the following details:

2,Jose,Cuervo
3,Jim,Beam
4,Jack,Daniels

25. Choose to load data to an Existing Table and choose a comma separated or tab delimted file. Click “Next”.

21

26. Choose the file name, the delimiter and click “Next”.

23

27. Make sure the column headings are correct for the table we just created and click “Load Data”.

24

28. We can see that 3 records were uploaded and 0 failed.

25

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.

26

 

Now, you can see how to create tables and load data in APEX. Next, we will start putting it together in an application.

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s