Oracle Apex数据加载:基于条件选择CSV列加载至BIKE表求助
Got it, let's walk through exactly how to set up that conditional transformation rule in your Apex Data Load Application. Here's a step-by-step breakdown tailored to your scenario:
Step 1: Navigate to Transformation Rules
After uploading your CSV and confirming Apex has recognized the columns (type, amount-a, amount-b), proceed to the Transformation Rules step in the data load wizard. This is where we’ll build our conditional logic.
Step 2: Create a Derived Column for BIKE.amount
Since we can’t map a single CSV column directly to BIKE.amount (we need to pick between two based on type), we’ll create a derived column rule:
- Click the Add Rule button.
- Select Derived Column as the rule type.
- For the Target Column, choose
BIKE.amount(this is the table column we’re populating).
Step 3: Write the Conditional Expression
In the expression editor, use a CASE statement to define your logic. Note: Apex may replace hyphens in CSV column names with underscores (e.g., amount-a becomes AMOUNT_A), so double-check the parsed column names in your data preview.
Use this expression (adjust column names if needed):
CASE WHEN :type = 'blue' THEN :"amount-b" ELSE :"amount-a" END
If Apex auto-renamed your columns to AMOUNT_A and AMOUNT_B, use this version instead:
CASE WHEN :TYPE = 'blue' THEN :AMOUNT_B ELSE :AMOUNT_A END
- Pro tip: To make the condition case-insensitive (e.g., match 'Blue' or 'BLUE'), modify it to
UPPER(:type) = 'BLUE'.
Step 4: Test the Rule
Before saving, click the Test button to verify the logic works with your sample data:
- For the row
blue,10,100, the result should be100. - For
green,20,200, it should return20.
If the test outputs match your expectations, save the rule.
Step 5: Finalize the Load
- Ensure the
typecolumn from your CSV is directly mapped toBIKE.type(no transformation needed here). - Review remaining load settings (like error handling and commit options) then run the data load.
That’s it! Your BIKE table will now populate the correct amount value based on the type column from your CSV.
内容的提问来源于stack exchange,提问作者Trango

