Create a PLSQL function

Building a Check Printing Report with Spelled-Out Cash Amounts 31-7 Figure 31–6 Resized Data Model view

3. Click the Formula Column tool in the tool palette.

4. Click in the G_ORDER_ID group, in the space you just created, to create a new

formula column.

5. Double-click the new formula column object CF_1 to display the Property

Inspector, and set the following properties: ■ Under General Information, set the Name property to SPELLED_AMOUNT. ■ Under Column, set the Datatype property to CHARACTER, and the Width property to 100. ■ Under PlaceholderFormula, click the PLSQL Formula property field to display the PLSQL Editor.

6. In the PLSQL Editor, use the template to enter the following PLSQL code:

function SPELLED_AMOUNTFormula return Char is cents number; c_str varchar280; val number; begin val := :order_total; cents := val mod 1 100; if cents 0 then --creates string for cents c_str := and || TO_CHARcents || 100 Dollars; else c_str := Dollars; end if; if val 1000 and val 1 then return initcapspellfloorval || c_str; elsif val 1000 then returninitcapspellfloorval1000 || Thousand || spellfloorval mod 1000 || c_str; else returnZero||c_str; 31-8 Oracle Reports Users Guide to Building Reports end if; end;

7. Click Compile. If you see any errors, compare your code against the code we have

provided.

8. When your code successfully compiles, click Close.

Your new formula column, called SPELLED_AMOUNT, now displays in the data model. Figure 31–7 Data Model with SPELLED_AMOUNT formula column

9. Save your report.

31.4 Create a Query That Returns the Items in the Order

The steps in this section will show you how to manually create a query in the Data Model view that will return the items in the customers order. This data retrieved will be used to display the order details in the check stub. To manually create a query:

1. In the Data Model view, click the SQL Query tool in the tool palette, then click an

open area in the Data Model view to display the SQL Query Statement dialog box.

2. In the SQL Query Statement field, enter the following SELECT statement:

SELECT ALL ORDER_ITEMS.LINE_ITEM_ID, ORDER_ITEMS.ORDER_ID, Note: You can enter this code by copying and pasting it from the provided text file called spellcash_code.txt into the PLSQL Editor.