{"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150) -- Message printed on the remittance advice.\n);\n\n-- Prepayment application history: which prepayment invoices were applied to which standard invoices, with amounts and dates.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PREPAY_HISTORY_ALL (\n PREPAY_HISTORY_ID NUMBER, -- Unique prepayment application identifier. Primary key.\n PREPAY_INVOICE_ID NUMBER, -- Prepayment invoice being applied. FK to AP_INVOICES_ALL.INVOICE_ID.\n INVOICE_ID NUMBER, -- Standard invoice the prepayment is applied to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PREPAY_DIST_ID NUMBER, -- Prepayment distribution consumed. FK to AP_INVOICE_DISTRIBUTIONS_ALL.INVOICE_DISTRIBUTION_ID.\n INVOICE_LINE_NUMBER NUMBER, -- Line of the standard invoice receiving the application.\n ACCOUNTING_DATE DATE, -- Accounting date of the application.\n USED_AMOUNT NUMBER(18,2), -- Amount of the prepayment applied.\n TRANSACTION_TYPE VARCHAR2(25), -- Whether the row is an application or an unapplication. Values: PREPAYMENT APPLIED, PREPAYMENT UNAPPLIED.\n POSTED_FLAG VARCHAR2(1), -- Y if the application was accounted.\n DESCRIPTION VARCHAR2(240), -- Description of the application.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment history: status changes and accounting events for each payment (created, cleared, voided, reconciled).\n-- (showing 12 of 17 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_HISTORY_ALL (\n PAYMENT_HISTORY_ID NUMBER, -- Unique payment history identifier. Primary key.\n CHECK_ID NUMBER, -- Payment the history row describes. FK to AP_CHECKS_ALL.CHECK_ID.\n TRANSACTION_TYPE VARCHAR2(25), -- Kind of event recorded. Values: PAYMENT CREATED, PAYMENT CLEARING, PAYMENT UNCLEARING, PAYMENT CANCELLED.\n TRANSACTION_DATE DATE, -- Date of the event.\n ACCOUNTING_DATE DATE, -- Accounting date of the event.\n TRX_BANK_AMOUNT NUMBER(18,2), -- Amount at the bank for the event.\n TRX_PMT_AMOUNT NUMBER(18,2), -- Amount in payment currency for the event.\n HISTORICAL_FLAG VARCHAR2(1), -- Y if the row is superseded by a later event.\n POSTED_FLAG VARCHAR2(1), -- Y if the event was accounted.\n REV_PMT_HIST_ID NUMBER, -- Payment history row this event reverses.\n BANK_CURRENCY_CODE VARCHAR2(15), -- Currency of the bank statement line. FK to FND_CURRENCIES.CURRENCY_CODE.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n INT_BANK_ACCOUNT_ID NUMBER, -- Company bank account used. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXT_BANK_ACCOUNT_ID NUMBER, -- Payee bank account credited. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE -- Date the payment was voided.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n CANCELLED_DATE DATE, -- Date the invoice was cancelled; NULL if not cancelled.\n CANCELLED_BY VARCHAR2(64) -- User who cancelled the invoice.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25) -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n-- days to pay => AP_CHECKS_ALL.CHECK_DATE - AP_INVOICES_ALL.INVOICE_DATE (join AP_INVOICE_PAYMENTS_ALL on INVOICE_ID and CHECK_ID)\n"}, {"role": "user", "content": "Question: List the oldest 3 unpaid installments"}, {"role": "assistant", "content": "```sql\nSELECT INVOICE_ID, DUE_DATE, AMOUNT_REMAINING\nFROM AP_PAYMENT_SCHEDULES_ALL\nWHERE AMOUNT_REMAINING > 0\nORDER BY DUE_DATE ASC\nFETCH FIRST 3 ROWS ONLY;\n```"}], "meta": {"id": "a-00045", "tier": "T1", "family": "t1-topn", "kind": "ask", "source": "S2-templated", "group": "83ec3a581045", "tables": ["AP_PAYMENT_SCHEDULES_ALL"], "result_rows": 3, "approx_prompt_tokens": 3114, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payment history: status changes and accounting events for each payment (created, cleared, voided, reconciled).\n-- (showing 12 of 17 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_HISTORY_ALL (\n PAYMENT_HISTORY_ID NUMBER, -- Unique payment history identifier. Primary key.\n CHECK_ID NUMBER, -- Payment the history row describes. FK to AP_CHECKS_ALL.CHECK_ID.\n TRANSACTION_TYPE VARCHAR2(25), -- Kind of event recorded. Values: PAYMENT CREATED, PAYMENT CLEARING, PAYMENT UNCLEARING, PAYMENT CANCELLED.\n TRANSACTION_DATE DATE, -- Date of the event.\n ACCOUNTING_DATE DATE, -- Accounting date of the event.\n TRX_BANK_AMOUNT NUMBER(18,2), -- Amount at the bank for the event.\n TRX_PMT_AMOUNT NUMBER(18,2), -- Amount in payment currency for the event.\n HISTORICAL_FLAG VARCHAR2(1), -- Y if the row is superseded by a later event.\n POSTED_FLAG VARCHAR2(1), -- Y if the event was accounted.\n REV_PMT_HIST_ID NUMBER, -- Payment history row this event reverses.\n BANK_CURRENCY_CODE VARCHAR2(15), -- Currency of the bank statement line. FK to FND_CURRENCIES.CURRENCY_CODE.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n DOC_SEQUENCE_VALUE NUMBER -- Document sequence number of the payment.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n INT_BANK_ACCOUNT_ID NUMBER, -- Company bank account used. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE -- Date the payment was voided.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25) -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice will be paid in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAYMENT_STATUS_FLAG VARCHAR2(1) -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n"}, {"role": "user", "content": "Question: Show the total payment amount per payment method for payments that have cleared"}, {"role": "assistant", "content": "```sql\nSELECT c.PAYMENT_METHOD_CODE, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nWHERE c.STATUS_LOOKUP_CODE IN ('CLEARED', 'RECONCILED')\nGROUP BY c.PAYMENT_METHOD_CODE\nORDER BY TOTAL_PAYMENT_AMOUNT DESC;\n```"}], "meta": {"id": "a-00058", "tier": "T1", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "219da09535b5", "tables": ["AP_CHECKS_ALL"], "result_rows": 3, "approx_prompt_tokens": 2794, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n BATCH_ID NUMBER -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150) -- Message printed on the remittance advice.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25) -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n VOID_DATE DATE, -- Date the payment was voided.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n CHECKRUN_ID NUMBER, -- Payment process request identifier.\n DOC_SEQUENCE_VALUE NUMBER -- Document sequence number of the payment.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\n-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n-- days to pay => AP_CHECKS_ALL.CHECK_DATE - AP_INVOICES_ALL.INVOICE_DATE (join AP_INVOICE_PAYMENTS_ALL on INVOICE_ID and CHECK_ID)\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n"}, {"role": "user", "content": "Question: Top 5 payment methods by invoice total for approved invoices only"}, {"role": "assistant", "content": "```sql\nSELECT i.PAYMENT_METHOD_CODE, SUM(i.INVOICE_AMOUNT) AS TOTAL_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nWHERE i.WFAPPROVAL_STATUS = 'APPROVED'\nGROUP BY i.PAYMENT_METHOD_CODE\nORDER BY TOTAL_INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00042", "tier": "T1", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "8966c94cbe2f", "tables": ["AP_INVOICES_ALL"], "result_rows": 3, "approx_prompt_tokens": 2854, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment history: status changes and accounting events for each payment (created, cleared, voided, reconciled).\n-- (showing 12 of 17 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_HISTORY_ALL (\n PAYMENT_HISTORY_ID NUMBER, -- Unique payment history identifier. Primary key.\n CHECK_ID NUMBER, -- Payment the history row describes. FK to AP_CHECKS_ALL.CHECK_ID.\n TRANSACTION_TYPE VARCHAR2(25), -- Kind of event recorded. Values: PAYMENT CREATED, PAYMENT CLEARING, PAYMENT UNCLEARING, PAYMENT CANCELLED.\n TRANSACTION_DATE DATE, -- Date of the event.\n ACCOUNTING_DATE DATE, -- Accounting date of the event.\n TRX_BANK_AMOUNT NUMBER(18,2), -- Amount at the bank for the event.\n TRX_PMT_AMOUNT NUMBER(18,2), -- Amount in payment currency for the event.\n HISTORICAL_FLAG VARCHAR2(1), -- Y if the row is superseded by a later event.\n POSTED_FLAG VARCHAR2(1), -- Y if the event was accounted.\n REV_PMT_HIST_ID NUMBER, -- Payment history row this event reverses.\n BANK_CURRENCY_CODE VARCHAR2(15), -- Currency of the bank statement line. FK to FND_CURRENCIES.CURRENCY_CODE.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n INT_BANK_ACCOUNT_ID NUMBER, -- Company bank account used. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXT_BANK_ACCOUNT_ID NUMBER, -- Payee bank account credited. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE, -- Date the payment was voided.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n);\n\n-- Payees: the payment-engine record linking a supplier or site to its payment defaults (method, delivery channel, bank instructions).\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXTERNAL_PAYEES_ALL (\n EXT_PAYEE_ID NUMBER, -- Unique payee identifier. Primary key.\n PAYEE_PARTY_ID NUMBER, -- Party being paid. FK to HZ_PARTIES.PARTY_ID.\n SUPPLIER_SITE_ID NUMBER, -- Supplier site the payee record represents. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n PAYMENT_FUNCTION VARCHAR2(30), -- Payment function the payee is used for. Values: PAYABLES_DISB, EMPLOYEE_EXP.\n DEFAULT_PAYMENT_METHOD_CODE VARCHAR2(30), -- Default payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_FORMAT_CODE VARCHAR2(30), -- Format used for payment files. Values: NACHA, SEPA, POSITIVE PAY.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Default bank delivery channel. Values: ACH, CHAPS, SEPA.\n BANK_INSTRUCTION1_CODE VARCHAR2(30), -- First bank instruction code.\n REMIT_ADVICE_DELIVERY_METHOD VARCHAR2(30), -- How remittance advice is delivered. Values: EMAIL, PRINT.\n REMIT_ADVICE_EMAIL VARCHAR2(255), -- Email address remittance advice is sent to.\n INACTIVE_DATE DATE, -- Date the payee record stops being valid.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25), -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: List the most recent 20 payments"}, {"role": "assistant", "content": "```sql\nSELECT CHECK_NUMBER, CHECK_DATE, AMOUNT, VENDOR_NAME\nFROM AP_CHECKS_ALL\nORDER BY CHECK_DATE DESC\nFETCH FIRST 20 ROWS ONLY;\n```"}], "meta": {"id": "a-00048", "tier": "T1", "family": "t1-topn", "kind": "ask", "source": "S2-templated", "group": "3df7951ac5a4", "tables": ["AP_CHECKS_ALL"], "result_rows": 20, "approx_prompt_tokens": 3059, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n CURRENCY_CODE VARCHAR2(15), -- Currency the payment was made in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting payment currency to ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account the payment was drawn on. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n CHECKRUN_ID NUMBER, -- Payment process request identifier.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n ATTRIBUTE_CATEGORY VARCHAR2(30), -- Descriptive flexfield context (customer-defined extension fields).\n ATTRIBUTE1 VARCHAR2(150), -- Descriptive flexfield segment 1, customer-defined and normally unused.\n ATTRIBUTE2 VARCHAR2(150), -- Descriptive flexfield segment 2, customer-defined and normally unused.\n ATTRIBUTE3 VARCHAR2(150), -- Descriptive flexfield segment 3, customer-defined and normally unused.\n ATTRIBUTE4 VARCHAR2(150), -- Descriptive flexfield segment 4, customer-defined and normally unused.\n ATTRIBUTE5 VARCHAR2(150) -- Descriptive flexfield segment 5, customer-defined and normally unused.\n);\n\n-- Supplier addresses: physical and remit-to addresses of suppliers.\nCREATE TABLE POZ_SUPPLIER_ADDRESSES (\n ADDRESS_ID NUMBER, -- Unique address identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the address belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_NAME VARCHAR2(240), -- Name identifying the address.\n ADDRESS_LINE1 VARCHAR2(240), -- First address line.\n ADDRESS_LINE2 VARCHAR2(240), -- Second address line.\n CITY VARCHAR2(60), -- City.\n STATE VARCHAR2(60), -- State or province. Values: CA, NY, TX, WA, IL.\n POSTAL_CODE VARCHAR2(60), -- Postal or ZIP code.\n COUNTRY VARCHAR2(2), -- Country code.\n ADDRESS_PURPOSE VARCHAR2(30), -- What the address is used for. Values: REMIT_TO, PURCHASING, RFQ.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n LATITUDE NUMBER(12,6), -- Latitude of the address.\n LONGITUDE NUMBER(12,6), -- Longitude of the address.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 16 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_ID NUMBER, -- Address of the site. FK to POZ_SUPPLIER_ADDRESSES.ADDRESS_ID.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Payment method for this site. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Default payment currency at this site. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n INACTIVE_DATE DATE, -- Date the site becomes inactive.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n SHIP_TO_LOCATION_ID NUMBER, -- Default ship-to location for purchase orders.\n BILL_TO_LOCATION_ID NUMBER -- Default bill-to location.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n INT_BANK_ACCOUNT_ID NUMBER, -- Company bank account used. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXT_BANK_ACCOUNT_ID NUMBER, -- Payee bank account credited. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE, -- Date the payment was voided.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment history: status changes and accounting events for each payment (created, cleared, voided, reconciled).\n-- (showing 12 of 17 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_HISTORY_ALL (\n PAYMENT_HISTORY_ID NUMBER, -- Unique payment history identifier. Primary key.\n CHECK_ID NUMBER, -- Payment the history row describes. FK to AP_CHECKS_ALL.CHECK_ID.\n TRANSACTION_TYPE VARCHAR2(25), -- Kind of event recorded. Values: PAYMENT CREATED, PAYMENT CLEARING, PAYMENT UNCLEARING, PAYMENT CANCELLED.\n TRANSACTION_DATE DATE, -- Date of the event.\n ACCOUNTING_DATE DATE, -- Accounting date of the event.\n TRX_BANK_AMOUNT NUMBER(18,2), -- Amount at the bank for the event.\n TRX_PMT_AMOUNT NUMBER(18,2), -- Amount in payment currency for the event.\n HISTORICAL_FLAG VARCHAR2(1), -- Y if the row is superseded by a later event.\n POSTED_FLAG VARCHAR2(1), -- Y if the event was accounted.\n REV_PMT_HIST_ID NUMBER, -- Payment history row this event reverses.\n BANK_CURRENCY_CODE VARCHAR2(15), -- Currency of the bank statement line. FK to FND_CURRENCIES.CURRENCY_CODE.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Supplier bank accounts: external bank accounts that payments are sent to, with account holder, currency and validity dates.\n-- (showing 10 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXT_BANK_ACCOUNTS (\n EXT_BANK_ACCOUNT_ID NUMBER, -- Unique external bank account identifier. Primary key.\n BANK_PARTY_ID NUMBER, -- Bank holding the account. FK to CE_BANKS.BANK_PARTY_ID.\n ACCOUNT_OWNER_PARTY_ID NUMBER, -- Party that owns the account. FK to HZ_PARTIES.PARTY_ID.\n BANK_ACCOUNT_NAME VARCHAR2(80), -- Account holder name.\n CURRENCY_CODE VARCHAR2(15), -- Currency of the account. FK to FND_CURRENCIES.CURRENCY_CODE.\n COUNTRY_CODE VARCHAR2(2), -- Country of the account.\n START_DATE DATE, -- Date the account becomes valid.\n END_DATE DATE, -- Date the account stops being valid.\n ACCOUNT_SUFFIX VARCHAR2(30), -- Account suffix used by some banks.\n FOREIGN_PAYMENT_USE_FLAG VARCHAR2(1) -- Y if the account can receive foreign-currency payments.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- vendor spend / supplier spend => SUM(AP_INVOICES_ALL.INVOICE_AMOUNT) grouped by AP_INVOICES_ALL.VENDOR_ID (join POZ_SUPPLIERS for VENDOR_NAME)\n"}, {"role": "user", "content": "Question: Show the 5 supplier cities with the highest total payment amount over the last year\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT a.CITY, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = c.VENDOR_ID\nWHERE c.CHECK_DATE >= ADD_MONTHS(CURDATE(), -12)\nGROUP BY a.CITY\nORDER BY TOTAL_PAYMENT_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\nError: ORA-00904: \"CURDATE\": invalid identifier\nDiagnosis: No table in your query has a column named CURDATE. The columns are — AP_CHECKS_ALL: CHECK_ID, CHECK_NUMBER, VENDOR_ID, VENDOR_SITE_ID, VENDOR_NAME, CHECK_DATE, AMOUNT, BASE_AMOUNT, CURRENCY_CODE, EXCHANGE_RATE, PAYMENT_METHOD_CODE, PAYMENT_TYPE_FLAG, STATUS_LOOKUP_CODE, BANK_ACCOUNT_ID, EXTERNAL_BANK_ACCOUNT_ID, PAYMENT_ID, CLEARED_DATE, CLEARED_AMOUNT, VOID_DATE, VOID_REASON, STOPPED_DATE, FUTURE_PAY_DUE_DATE, CHECKRUN_NAME, CHECKRUN_ID, DOC_SEQUENCE_VALUE, CREATION_DATE, CREATED_BY, LAST_UPDATE_DATE, LAST_UPDATED_BY, OBJECT_VERSION_NUMBER, ORG_ID, ATTRIBUTE_CATEGORY, ATTRIBUTE1, ATTRIBUTE2, ATTRIBUTE3, ATTRIBUTE4, ATTRIBUTE5; POZ_SUPPLIER_ADDRESSES: ADDRESS_ID, VENDOR_ID, ADDRESS_NAME, ADDRESS_LINE1, ADDRESS_LINE2, CITY, STATE, POSTAL_CODE, COUNTRY, ADDRESS_PURPOSE, STATUS, LATITUDE, LONGITUDE, CREATION_DATE, CREATED_BY, LAST_UPDATE_DATE, LAST_UPDATED_BY, OBJECT_VERSION_NUMBER.\nWrite a corrected query. It must differ from the failed one. Use ONLY the tables and columns in the schema above, spelled exactly as shown; if a column you wanted does not exist, choose the closest one that does."}, {"role": "assistant", "content": "```sql\nSELECT a.CITY, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = c.VENDOR_ID\nWHERE c.CHECK_DATE >= ADD_MONTHS(TRUNC(SYSDATE), -12)\nGROUP BY a.CITY\nORDER BY TOTAL_PAYMENT_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "r-00063", "tier": "T3", "family": "spec-pay", "kind": "repair-exec", "source": "S6-repair", "group": "d464a57ab45e", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 0, "approx_prompt_tokens": 3376, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"CURDATE\": invalid identifier", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 17 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n DOC_SEQUENCE_VALUE NUMBER -- Document sequence number of the payment.\n);\n\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 16 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_ID NUMBER, -- Address of the site. FK to POZ_SUPPLIER_ADDRESSES.ADDRESS_ID.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Payment method for this site. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n INACTIVE_DATE DATE, -- Date the site becomes inactive.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n SHIP_TO_LOCATION_ID NUMBER, -- Default ship-to location for purchase orders.\n BILL_TO_LOCATION_ID NUMBER, -- Default bill-to location.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n EXT_BANK_ACCOUNT_ID NUMBER, -- Payee bank account credited. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE, -- Date the payment was voided.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\n-- (showing 16 of 38 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n VENDOR_NAME VARCHAR2(360), -- Supplier name.\n SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\n VENDOR_TYPE_LOOKUP_CODE VARCHAR2(30), -- Supplier type. Values: VENDOR, CONTRACTOR, EMPLOYEE, TAX AUTHORITY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n START_DATE_ACTIVE DATE, -- Date the supplier becomes active.\n END_DATE_ACTIVE DATE, -- Date the supplier stops being active.\n SMALL_BUSINESS_FLAG VARCHAR2(1), -- Y if the supplier is a small business.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Default payment method for the supplier. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Default pay group. Values: DOMESTIC, INTERNATIONAL.\n TERMS_ID NUMBER, -- Default payment terms. FK to AP_TERMS_B.TERM_ID.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if all payments to the supplier are blocked.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n FEDERAL_REPORTABLE_FLAG VARCHAR2(1), -- Y if the supplier is reportable for federal income tax.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2), -- Maximum credit extended to the supplier.\n RISK_RATING VARCHAR2(25) -- Internal supplier risk rating. Values: LOW, MEDIUM, HIGH.\n);\n\n-- Supplier bank accounts: external bank accounts that payments are sent to, with account holder, currency and validity dates.\n-- (showing 10 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXT_BANK_ACCOUNTS (\n EXT_BANK_ACCOUNT_ID NUMBER, -- Unique external bank account identifier. Primary key.\n BANK_PARTY_ID NUMBER, -- Bank holding the account. FK to CE_BANKS.BANK_PARTY_ID.\n ACCOUNT_OWNER_PARTY_ID NUMBER, -- Party that owns the account. FK to HZ_PARTIES.PARTY_ID.\n BANK_ACCOUNT_NAME VARCHAR2(80), -- Account holder name.\n CURRENCY_CODE VARCHAR2(15), -- Currency of the account. FK to FND_CURRENCIES.CURRENCY_CODE.\n COUNTRY_CODE VARCHAR2(2), -- Country of the account.\n START_DATE DATE, -- Date the account becomes valid.\n END_DATE DATE, -- Date the account stops being valid.\n ACCOUNT_SUFFIX VARCHAR2(30), -- Account suffix used by some banks.\n FOREIGN_PAYMENT_USE_FLAG VARCHAR2(1) -- Y if the account can receive foreign-currency payments.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Supplier addresses: physical and remit-to addresses of suppliers.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_ADDRESSES (\n ADDRESS_ID NUMBER, -- Unique address identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the address belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_NAME VARCHAR2(240), -- Name identifying the address.\n ADDRESS_LINE1 VARCHAR2(240), -- First address line.\n ADDRESS_LINE2 VARCHAR2(240), -- Second address line.\n CITY VARCHAR2(60), -- City.\n STATE VARCHAR2(60), -- State or province. Values: CA, NY, TX, WA, IL.\n POSTAL_CODE VARCHAR2(60), -- Postal or ZIP code.\n COUNTRY VARCHAR2(2), -- Country code.\n ADDRESS_PURPOSE VARCHAR2(30), -- What the address is used for. Values: REMIT_TO, PURCHASING, RFQ.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n LATITUDE NUMBER(12,6), -- Latitude of the address.\n LONGITUDE NUMBER(12,6) -- Longitude of the address.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- vendor spend / supplier spend => SUM(AP_INVOICES_ALL.INVOICE_AMOUNT) grouped by AP_INVOICES_ALL.VENDOR_ID (join POZ_SUPPLIERS for VENDOR_NAME)\n-- supplier state / vendor state / by state => POZ_SUPPLIER_ADDRESSES.STATE (join on VENDOR_ID)\n-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n"}, {"role": "user", "content": "Question: Show the 5 supplier states with the highest average payment this year"}, {"role": "assistant", "content": "```sql\nSELECT a.STATE, AVG(c.AMOUNT) AS AVG_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = c.VENDOR_ID\nWHERE c.CHECK_DATE >= TRUNC(SYSDATE, 'YYYY')\nGROUP BY a.STATE\nORDER BY AVG_PAYMENT_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-01109", "tier": "T3", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "85764f126187", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 3, "approx_prompt_tokens": 2973, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n PARTY_ID NUMBER, -- Trading-community party of the supplier. FK to HZ_PARTIES.PARTY_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n SELF_ASSESSED_TAX_AMOUNT NUMBER(18,2), -- Tax the buyer self-assesses instead of paying to the supplier.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice is denominated in. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice will be paid in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n EXCHANGE_RATE_TYPE VARCHAR2(30), -- Type of exchange rate used. Values: Corporate, Spot, User.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n SOURCE VARCHAR2(80), -- How the invoice entered the system. Values: MANUAL, IMPORT, SUPPLIER PORTAL, EMAIL.\n PO_HEADER_ID NUMBER, -- Purchase order the invoice is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n VALIDATION_STATUS VARCHAR2(25), -- Result of invoice validation. Values: VALIDATED, NEEDS REVALIDATION, NEVER VALIDATED.\n WFAPPROVAL_STATUS VARCHAR2(25), -- Approval workflow status of the invoice. Values: APPROVED, NOT REQUIRED, REJECTED, INITIATED.\n CANCELLED_DATE DATE, -- Date the invoice was cancelled; NULL if not cancelled.\n CANCELLED_BY VARCHAR2(64), -- User who cancelled the invoice.\n ACCTS_PAY_CODE_COMBINATION_ID NUMBER, -- Liability (accounts payable) account for the invoice. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n LEDGER_ID NUMBER, -- Ledger the invoice is accounted in. FK to GL_LEDGERS.LEDGER_ID.\n REQUESTER_ID NUMBER, -- Employee who requested the goods or services. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n LEGAL_ENTITY_ID NUMBER, -- Legal entity the invoice belongs to.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number assigned to the invoice.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n ATTRIBUTE_CATEGORY VARCHAR2(30), -- Descriptive flexfield context (customer-defined extension fields).\n ATTRIBUTE1 VARCHAR2(150), -- Descriptive flexfield segment 1, customer-defined and normally unused.\n ATTRIBUTE2 VARCHAR2(150), -- Descriptive flexfield segment 2, customer-defined and normally unused.\n ATTRIBUTE3 VARCHAR2(150), -- Descriptive flexfield segment 3, customer-defined and normally unused.\n ATTRIBUTE4 VARCHAR2(150), -- Descriptive flexfield segment 4, customer-defined and normally unused.\n ATTRIBUTE5 VARCHAR2(150), -- Descriptive flexfield segment 5, customer-defined and normally unused.\n ATTRIBUTE6 VARCHAR2(150), -- Descriptive flexfield segment 6, customer-defined and normally unused.\n ATTRIBUTE7 VARCHAR2(150), -- Descriptive flexfield segment 7, customer-defined and normally unused.\n ATTRIBUTE8 VARCHAR2(150), -- Descriptive flexfield segment 8, customer-defined and normally unused.\n ATTRIBUTE9 VARCHAR2(150), -- Descriptive flexfield segment 9, customer-defined and normally unused.\n ATTRIBUTE10 VARCHAR2(150), -- Descriptive flexfield segment 10, customer-defined and normally unused.\n);\n\n-- Invoice distributions: how each invoice line amount is split across general-ledger expense accounts, with accounting status. Use for spend-by-GL-account questions.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_DISTRIBUTIONS_ALL (\n INVOICE_DISTRIBUTION_ID NUMBER, -- Unique invoice distribution identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the distribution belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n INVOICE_LINE_ID NUMBER, -- Invoice line the distribution splits. FK to AP_INVOICE_LINES_ALL.INVOICE_LINE_ID.\n DISTRIBUTION_LINE_NUMBER NUMBER, -- Sequence of the distribution within the invoice.\n AMOUNT NUMBER(18,2), -- Distribution amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Distribution amount in ledger currency.\n ACCOUNTING_DATE DATE, -- Accounting date of the distribution.\n PERIOD_NAME VARCHAR2(15), -- Accounting period the distribution falls in.\n POSTED_FLAG VARCHAR2(1), -- Y if accounted and posted to the ledger, N if not yet accounted. Values: Y, N.\n QUANTITY_INVOICED NUMBER, -- Quantity billed for the distribution.\n UNIT_PRICE NUMBER(18,2), -- Unit price on the distribution.\n PO_DISTRIBUTION_ID NUMBER, -- Purchase order distribution matched to. FK to PO_DISTRIBUTIONS_ALL.PO_DISTRIBUTION_ID.\n TASK_ID NUMBER, -- Project task charged.\n INCOME_TAX_REGION VARCHAR2(10), -- Region used for income-tax reporting.\n DESCRIPTION VARCHAR2(240), -- Distribution description.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice batches: groups of invoices entered together, with control totals and entry status.\nCREATE TABLE AP_BATCHES_ALL (\n BATCH_ID NUMBER, -- Unique invoice batch identifier. Primary key.\n BATCH_NAME VARCHAR2(50), -- Name of the batch.\n BATCH_DATE DATE, -- Date the batch was created.\n INVOICE_COUNT NUMBER, -- Number of invoices entered in the batch.\n INVOICE_AMOUNT NUMBER(18,2), -- Total amount of the invoices in the batch.\n CONTROL_INVOICE_COUNT NUMBER, -- Expected invoice count entered as a control total.\n CONTROL_INVOICE_AMOUNT NUMBER(18,2), -- Expected batch amount entered as a control total.\n BATCH_STATUS VARCHAR2(25), -- Status of the batch. Values: OPEN, CLOSED, POSTED.\n SOURCE VARCHAR2(80), -- Source of the batch. Values: MANUAL, IMPORT, SUPPLIER PORTAL.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_NUMBER NUMBER, -- Sequence of the line within the invoice.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit billed.\n UNIT_MEAS_LOOKUP_CODE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\n ACCOUNTING_DATE DATE, -- Accounting date of the line.\n TAX_RATE NUMBER(12,6), -- Tax rate applied to the line.\n TAX_RATE_ID NUMBER, -- Tax rate record applied. FK to ZX_RATES_B.TAX_RATE_ID.\n DISCARDED_FLAG VARCHAR2(1), -- Y if the line was discarded during correction.\n REQUESTER_ID NUMBER, -- Employee who requested the line item. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n MATCH_TYPE VARCHAR2(25), -- How the line was matched. Values: ITEM_TO_PO, ITEM_TO_RECEIPT, NOT_MATCHED.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- unvalidated invoice => AP_INVOICES_ALL.VALIDATION_STATUS <> 'VALIDATED'\n"}, {"role": "user", "content": "Question: Average invoice amount by invoice source in the past 12 months\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT i.SOURCE, AVG(i.INVOICE_AMOUNT) AS AVG_INVOICE_AMOUNT FROM AP_INVOICES_ALL i WHERE i.INVOICE_DATE >= ADD_MONTHS(CURDATE(), -12) GROUP BY i.SOURCE ORDER BY AVG_INVOICE_AMOUNT DESC FETCH FIRST 200 ROWS ONLY;\nError: ORA-00904: \"CURDATE\": invalid identifier\nDiagnosis: No table in your query has a column named CURDATE. The columns are — AP_INVOICES_ALL: INVOICE_ID, VENDOR_ID, VENDOR_SITE_ID, PARTY_ID, INVOICE_NUM, INVOICE_TYPE_LOOKUP_CODE, INVOICE_DATE, INVOICE_RECEIVED_DATE, GOODS_RECEIVED_DATE, GL_DATE, INVOICE_AMOUNT, AMOUNT_PAID, TOTAL_TAX_AMOUNT, BASE_AMOUNT, APPROVED_AMOUNT, AMOUNT_APPLICABLE_TO_DISCOUNT, DISCOUNT_AMOUNT_TAKEN, PREPAY_AMOUNT_REMAINING, SELF_ASSESSED_TAX_AMOUNT, INVOICE_CURRENCY_CODE, PAYMENT_CURRENCY_CODE, EXCHANGE_RATE, EXCHANGE_DATE, EXCHANGE_RATE_TYPE, TERMS_ID, TERMS_DATE, PAYMENT_METHOD_CODE, PAY_GROUP_LOOKUP_CODE, PAYMENT_STATUS_FLAG, DESCRIPTION, SOURCE, PO_HEADER_ID, BATCH_ID, VALIDATION_STATUS, WFAPPROVAL_STATUS, CANCELLED_DATE, CANCELLED_BY, ACCTS_PAY_CODE_COMBINATION_ID, LEDGER_ID, REQUESTER_ID, LEGAL_ENTITY_ID, DOC_SEQUENCE_VALUE, CREATION_DATE, CREATED_BY, LAST_UPDATE_DATE, LAST_UPDATED_BY, OBJECT_VERSION_NUMBER, ORG_ID, ATTRIBUTE_CATEGORY, ATTRIBUTE1, ATTRIBUTE2, ATTRIBUTE3, ATTRIBUTE4, ATTRIBUTE5, ATTRIBUTE6, ATTRIBUTE7, ATTRIBUTE8, ATTRIBUTE9, ATTRIBUTE10.\nWrite a corrected query. It must differ from the failed one. Use ONLY the tables and columns in the schema above, spelled exactly as shown; if a column you wanted does not exist, choose the closest one that does."}, {"role": "assistant", "content": "```sql\nSELECT i.SOURCE, AVG(i.INVOICE_AMOUNT) AS AVG_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_DATE >= ADD_MONTHS(TRUNC(SYSDATE), -12)\nGROUP BY i.SOURCE\nORDER BY AVG_INVOICE_AMOUNT DESC;\n```"}], "meta": {"id": "r-00066", "tier": "T3", "family": "spec-inv", "kind": "repair-exec", "source": "S6-repair", "group": "7e128025c6a3", "tables": ["AP_INVOICES_ALL"], "result_rows": 0, "approx_prompt_tokens": 3466, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"CURDATE\": invalid identifier", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice will be paid in. FK to FND_CURRENCIES.CURRENCY_CODE.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n BATCH_ID NUMBER -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n);\n\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 15 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_ID NUMBER, -- Address of the site. FK to POZ_SUPPLIER_ADDRESSES.ADDRESS_ID.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Default invoice currency at this site. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n ALWAYS_TAKE_DISC_FLAG VARCHAR2(1), -- Y if the early-payment discount is always taken.\n TOLERANCE_ID NUMBER, -- Matching tolerance applied at the site.\n SHIP_TO_LOCATION_ID NUMBER, -- Default ship-to location for purchase orders.\n BILL_TO_LOCATION_ID NUMBER -- Default bill-to location.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Supplier addresses: physical and remit-to addresses of suppliers.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_ADDRESSES (\n ADDRESS_ID NUMBER, -- Unique address identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the address belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_NAME VARCHAR2(240), -- Name identifying the address.\n ADDRESS_LINE1 VARCHAR2(240), -- First address line.\n ADDRESS_LINE2 VARCHAR2(240), -- Second address line.\n CITY VARCHAR2(60), -- City.\n STATE VARCHAR2(60), -- State or province. Values: CA, NY, TX, WA, IL.\n POSTAL_CODE VARCHAR2(60), -- Postal or ZIP code.\n COUNTRY VARCHAR2(2), -- Country code.\n ADDRESS_PURPOSE VARCHAR2(30), -- What the address is used for. Values: REMIT_TO, PURCHASING, RFQ.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n LATITUDE NUMBER(12,6), -- Latitude of the address.\n LONGITUDE NUMBER(12,6) -- Longitude of the address.\n);\n\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n DESCRIPTION VARCHAR2(240), -- Description of the goods or service on the line.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit billed.\n UNIT_MEAS_LOOKUP_CODE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\n PO_LINE_LOCATION_ID NUMBER, -- Purchase order schedule this line is matched to. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n TAX_CLASSIFICATION_CODE VARCHAR2(30), -- Tax classification of the line. Values: STANDARD, REDUCED, EXEMPT.\n TAX_RATE NUMBER(12,6), -- Tax rate applied to the line.\n PRODUCT_CATEGORY VARCHAR2(80), -- Category of the product or service. Values: IT EQUIPMENT, OFFICE SUPPLIES, PROFESSIONAL SERVICES, LOGISTICS.\n REQUESTER_ID NUMBER, -- Employee who requested the line item. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n MATCH_TYPE VARCHAR2(25) -- How the line was matched. Values: ITEM_TO_PO, ITEM_TO_RECEIPT, NOT_MATCHED.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Purchase order schedules: delivery schedules of a line with need-by date, quantity received and billed, and the matching option (two-, three- or four-way).\n-- (showing 15 of 22 columns: join keys + those relevant to the question)\nCREATE TABLE PO_LINE_LOCATIONS_ALL (\n LINE_LOCATION_ID NUMBER, -- Unique schedule identifier. Primary key.\n SHIPMENT_NUM NUMBER, -- Schedule number within the line.\n QUANTITY NUMBER, -- Quantity scheduled.\n QUANTITY_RECEIVED NUMBER, -- Quantity received so far.\n QUANTITY_BILLED NUMBER, -- Quantity invoiced so far.\n QUANTITY_CANCELLED NUMBER, -- Quantity cancelled.\n NEED_BY_DATE DATE, -- Date the goods are needed.\n PROMISED_DATE DATE, -- Date the supplier promised delivery.\n PRICE_OVERRIDE NUMBER(18,2), -- Price for this schedule if different from the line.\n INVOICE_MATCH_OPTION VARCHAR2(1), -- P match to order (two-way), R match to receipt (three-way). Values: R, P.\n RECEIPT_REQUIRED_FLAG VARCHAR2(1), -- Y if receipt is required before payment.\n TAXABLE_FLAG VARCHAR2(1), -- Y if the schedule is taxable.\n SHIP_TO_LOCATION_ID NUMBER, -- Where the goods are delivered.\n CLOSED_CODE VARCHAR2(25), -- Closure state of the schedule. Values: OPEN, CLOSED FOR RECEIVING, CLOSED.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice batches: groups of invoices entered together, with control totals and entry status.\nCREATE TABLE AP_BATCHES_ALL (\n BATCH_ID NUMBER, -- Unique invoice batch identifier. Primary key.\n BATCH_NAME VARCHAR2(50), -- Name of the batch.\n BATCH_DATE DATE, -- Date the batch was created.\n INVOICE_COUNT NUMBER, -- Number of invoices entered in the batch.\n INVOICE_AMOUNT NUMBER(18,2), -- Total amount of the invoices in the batch.\n CONTROL_INVOICE_COUNT NUMBER, -- Expected invoice count entered as a control total.\n CONTROL_INVOICE_AMOUNT NUMBER(18,2), -- Expected batch amount entered as a control total.\n BATCH_STATUS VARCHAR2(25), -- Status of the batch. Values: OPEN, CLOSED, POSTED.\n SOURCE VARCHAR2(80), -- Source of the batch. Values: MANUAL, IMPORT, SUPPLIER PORTAL.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- vendor spend / supplier spend => SUM(AP_INVOICES_ALL.INVOICE_AMOUNT) grouped by AP_INVOICES_ALL.VENDOR_ID (join POZ_SUPPLIERS for VENDOR_NAME)\n"}, {"role": "user", "content": "Question: Top 5 supplier cities by total amount paid on invoices for standard invoices only"}, {"role": "assistant", "content": "```sql\nSELECT a.CITY, SUM(i.AMOUNT_PAID) AS TOTAL_AMOUNT_PAID\nFROM AP_INVOICES_ALL i\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = i.VENDOR_ID\nWHERE i.INVOICE_TYPE_LOOKUP_CODE = 'STANDARD'\nGROUP BY a.CITY\nORDER BY TOTAL_AMOUNT_PAID DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00734", "tier": "T2", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "5029c712ecf1", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 5, "approx_prompt_tokens": 3033, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n EXT_BANK_ACCOUNT_ID NUMBER, -- Payee bank account credited. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE, -- Date the payment was voided.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n);\n\n-- Payment history: status changes and accounting events for each payment (created, cleared, voided, reconciled).\n-- (showing 12 of 17 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_HISTORY_ALL (\n PAYMENT_HISTORY_ID NUMBER, -- Unique payment history identifier. Primary key.\n CHECK_ID NUMBER, -- Payment the history row describes. FK to AP_CHECKS_ALL.CHECK_ID.\n TRANSACTION_TYPE VARCHAR2(25), -- Kind of event recorded. Values: PAYMENT CREATED, PAYMENT CLEARING, PAYMENT UNCLEARING, PAYMENT CANCELLED.\n TRANSACTION_DATE DATE, -- Date of the event.\n ACCOUNTING_DATE DATE, -- Accounting date of the event.\n TRX_BANK_AMOUNT NUMBER(18,2), -- Amount at the bank for the event.\n TRX_PMT_AMOUNT NUMBER(18,2), -- Amount in payment currency for the event.\n HISTORICAL_FLAG VARCHAR2(1), -- Y if the row is superseded by a later event.\n POSTED_FLAG VARCHAR2(1), -- Y if the event was accounted.\n REV_PMT_HIST_ID NUMBER, -- Payment history row this event reverses.\n BANK_CURRENCY_CODE VARCHAR2(15), -- Currency of the bank statement line. FK to FND_CURRENCIES.CURRENCY_CODE.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25), -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Payees: the payment-engine record linking a supplier or site to its payment defaults (method, delivery channel, bank instructions).\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXTERNAL_PAYEES_ALL (\n EXT_PAYEE_ID NUMBER, -- Unique payee identifier. Primary key.\n PAYEE_PARTY_ID NUMBER, -- Party being paid. FK to HZ_PARTIES.PARTY_ID.\n SUPPLIER_SITE_ID NUMBER, -- Supplier site the payee record represents. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n PAYMENT_FUNCTION VARCHAR2(30), -- Payment function the payee is used for. Values: PAYABLES_DISB, EMPLOYEE_EXP.\n DEFAULT_PAYMENT_METHOD_CODE VARCHAR2(30), -- Default payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_FORMAT_CODE VARCHAR2(30), -- Format used for payment files. Values: NACHA, SEPA, POSITIVE PAY.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Default bank delivery channel. Values: ACH, CHAPS, SEPA.\n BANK_INSTRUCTION1_CODE VARCHAR2(30), -- First bank instruction code.\n REMIT_ADVICE_DELIVERY_METHOD VARCHAR2(30), -- How remittance advice is delivered. Values: EMAIL, PRINT.\n REMIT_ADVICE_EMAIL VARCHAR2(255), -- Email address remittance advice is sent to.\n INACTIVE_DATE DATE, -- Date the payee record stops being valid.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- days to pay => AP_CHECKS_ALL.CHECK_DATE - AP_INVOICES_ALL.INVOICE_DATE (join AP_INVOICE_PAYMENTS_ALL on INVOICE_ID and CHECK_ID)\n"}, {"role": "user", "content": "Question: What is the biggest payment for each payment status over the past 6 months?"}, {"role": "assistant", "content": "```sql\nSELECT c.STATUS_LOOKUP_CODE, MAX(c.AMOUNT) AS MAX_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nWHERE c.CHECK_DATE >= ADD_MONTHS(TRUNC(SYSDATE), -6)\nGROUP BY c.STATUS_LOOKUP_CODE\nORDER BY MAX_PAYMENT_AMOUNT DESC;\n```"}], "meta": {"id": "a-01181", "tier": "T3", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "7fd9e431b4d4", "tables": ["AP_CHECKS_ALL"], "result_rows": 4, "approx_prompt_tokens": 2760, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n CURRENCY_CODE VARCHAR2(15), -- Currency the payment was made in. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n);\n\n-- Invoice batches: groups of invoices entered together, with control totals and entry status.\nCREATE TABLE AP_BATCHES_ALL (\n BATCH_ID NUMBER, -- Unique invoice batch identifier. Primary key.\n BATCH_NAME VARCHAR2(50), -- Name of the batch.\n BATCH_DATE DATE, -- Date the batch was created.\n INVOICE_COUNT NUMBER, -- Number of invoices entered in the batch.\n INVOICE_AMOUNT NUMBER(18,2), -- Total amount of the invoices in the batch.\n CONTROL_INVOICE_COUNT NUMBER, -- Expected invoice count entered as a control total.\n CONTROL_INVOICE_AMOUNT NUMBER(18,2), -- Expected batch amount entered as a control total.\n BATCH_STATUS VARCHAR2(25), -- Status of the batch. Values: OPEN, CLOSED, POSTED.\n SOURCE VARCHAR2(80), -- Source of the batch. Values: MANUAL, IMPORT, SUPPLIER PORTAL.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE, -- Date the payment was voided.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\n"}, {"role": "user", "content": "Question: Show the total amount paid on invoices per payment term for approved invoices only"}, {"role": "assistant", "content": "```sql\nSELECT t.NAME, SUM(i.AMOUNT_PAID) AS TOTAL_AMOUNT_PAID\nFROM AP_INVOICES_ALL i\nJOIN AP_TERMS_B t ON t.TERM_ID = i.TERMS_ID\nWHERE i.WFAPPROVAL_STATUS = 'APPROVED'\nGROUP BY t.NAME\nORDER BY TOTAL_AMOUNT_PAID DESC;\n```"}], "meta": {"id": "a-00579", "tier": "T2", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "fd6e5ee5917e", "tables": ["AP_INVOICES_ALL", "AP_TERMS_B"], "result_rows": 10, "approx_prompt_tokens": 3153, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150) -- Message printed on the remittance advice.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE -- Date the payment was voided.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25) -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting payment currency to ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n VOID_DATE DATE, -- Date the payment was voided.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n CHECKRUN_ID NUMBER, -- Payment process request identifier.\n DOC_SEQUENCE_VALUE NUMBER -- Document sequence number of the payment.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240) -- Free-text invoice description.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- early payment discount => AP_PAYMENT_SCHEDULES_ALL.DISCOUNT_AMOUNT_AVAILABLE > 0\n-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n-- days to pay => AP_CHECKS_ALL.CHECK_DATE - AP_INVOICES_ALL.INVOICE_DATE (join AP_INVOICE_PAYMENTS_ALL on INVOICE_ID and CHECK_ID)\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n"}, {"role": "user", "content": "Question: Show the 5 payment methods with the highest total early-payment discount available"}, {"role": "assistant", "content": "```sql\nSELECT i.PAYMENT_METHOD_CODE, SUM(ps.DISCOUNT_AMOUNT_AVAILABLE) AS TOTAL_DISCOUNT_AVAILABLE\nFROM AP_PAYMENT_SCHEDULES_ALL ps\nJOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ps.INVOICE_ID\nWHERE ps.DISCOUNT_AMOUNT_AVAILABLE > 0\nGROUP BY i.PAYMENT_METHOD_CODE\nORDER BY TOTAL_DISCOUNT_AVAILABLE DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00542", "tier": "T2", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "bde5f42fd3f1", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL"], "result_rows": 3, "approx_prompt_tokens": 3131, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 17 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n);\n\n-- Purchase order schedules: delivery schedules of a line with need-by date, quantity received and billed, and the matching option (two-, three- or four-way).\n-- (showing 15 of 22 columns: join keys + those relevant to the question)\nCREATE TABLE PO_LINE_LOCATIONS_ALL (\n LINE_LOCATION_ID NUMBER, -- Unique schedule identifier. Primary key.\n SHIPMENT_NUM NUMBER, -- Schedule number within the line.\n QUANTITY NUMBER, -- Quantity scheduled.\n QUANTITY_RECEIVED NUMBER, -- Quantity received so far.\n QUANTITY_BILLED NUMBER, -- Quantity invoiced so far.\n QUANTITY_CANCELLED NUMBER, -- Quantity cancelled.\n NEED_BY_DATE DATE, -- Date the goods are needed.\n PROMISED_DATE DATE, -- Date the supplier promised delivery.\n PRICE_OVERRIDE NUMBER(18,2), -- Price for this schedule if different from the line.\n INVOICE_MATCH_OPTION VARCHAR2(1), -- P match to order (two-way), R match to receipt (three-way). Values: R, P.\n RECEIPT_REQUIRED_FLAG VARCHAR2(1), -- Y if receipt is required before payment.\n TAXABLE_FLAG VARCHAR2(1), -- Y if the schedule is taxable.\n SHIP_TO_LOCATION_ID NUMBER, -- Where the goods are delivered.\n CLOSED_CODE VARCHAR2(25), -- Closure state of the schedule. Values: OPEN, CLOSED FOR RECEIVING, CLOSED.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice batches: groups of invoices entered together, with control totals and entry status.\nCREATE TABLE AP_BATCHES_ALL (\n BATCH_ID NUMBER, -- Unique invoice batch identifier. Primary key.\n BATCH_NAME VARCHAR2(50), -- Name of the batch.\n BATCH_DATE DATE, -- Date the batch was created.\n INVOICE_COUNT NUMBER, -- Number of invoices entered in the batch.\n INVOICE_AMOUNT NUMBER(18,2), -- Total amount of the invoices in the batch.\n CONTROL_INVOICE_COUNT NUMBER, -- Expected invoice count entered as a control total.\n CONTROL_INVOICE_AMOUNT NUMBER(18,2), -- Expected batch amount entered as a control total.\n BATCH_STATUS VARCHAR2(25), -- Status of the batch. Values: OPEN, CLOSED, POSTED.\n SOURCE VARCHAR2(80), -- Source of the batch. Values: MANUAL, IMPORT, SUPPLIER PORTAL.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Supplier addresses: physical and remit-to addresses of suppliers.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_ADDRESSES (\n ADDRESS_ID NUMBER, -- Unique address identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the address belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_NAME VARCHAR2(240), -- Name identifying the address.\n ADDRESS_LINE1 VARCHAR2(240), -- First address line.\n ADDRESS_LINE2 VARCHAR2(240), -- Second address line.\n CITY VARCHAR2(60), -- City.\n STATE VARCHAR2(60), -- State or province. Values: CA, NY, TX, WA, IL.\n POSTAL_CODE VARCHAR2(60), -- Postal or ZIP code.\n COUNTRY VARCHAR2(2), -- Country code.\n ADDRESS_PURPOSE VARCHAR2(30), -- What the address is used for. Values: REMIT_TO, PURCHASING, RFQ.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n LATITUDE NUMBER(12,6), -- Latitude of the address.\n LONGITUDE NUMBER(12,6), -- Longitude of the address.\n);\n\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 16 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_ID NUMBER, -- Address of the site. FK to POZ_SUPPLIER_ADDRESSES.ADDRESS_ID.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Default invoice currency at this site. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n INACTIVE_DATE DATE, -- Date the site becomes inactive.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n ALWAYS_TAKE_DISC_FLAG VARCHAR2(1), -- Y if the early-payment discount is always taken.\n SHIP_TO_LOCATION_ID NUMBER, -- Default ship-to location for purchase orders.\n BILL_TO_LOCATION_ID NUMBER, -- Default bill-to location.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\n-- (showing 15 of 38 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n VENDOR_NAME VARCHAR2(360), -- Supplier name.\n SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\n VENDOR_TYPE_LOOKUP_CODE VARCHAR2(30), -- Supplier type. Values: VENDOR, CONTRACTOR, EMPLOYEE, TAX AUTHORITY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n START_DATE_ACTIVE DATE, -- Date the supplier becomes active.\n END_DATE_ACTIVE DATE, -- Date the supplier stops being active.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Default payment method for the supplier. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Default pay group. Values: DOMESTIC, INTERNATIONAL.\n TERMS_ID NUMBER, -- Default payment terms. FK to AP_TERMS_B.TERM_ID.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Default invoice currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2), -- Maximum credit extended to the supplier.\n RISK_RATING VARCHAR2(25), -- Internal supplier risk rating. Values: LOW, MEDIUM, HIGH.\n CREATION_SOURCE VARCHAR2(30), -- Where the supplier record originated. Values: REGISTRATION, MANUAL, IMPORT.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- vendor spend / supplier spend => SUM(AP_INVOICES_ALL.INVOICE_AMOUNT) grouped by AP_INVOICES_ALL.VENDOR_ID (join POZ_SUPPLIERS for VENDOR_NAME)\n-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n"}, {"role": "user", "content": "Question: Show the 5 supplier cities with the highest largest invoice amount this month"}, {"role": "assistant", "content": "```sql\nSELECT a.CITY, MAX(i.INVOICE_AMOUNT) AS MAX_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = i.VENDOR_ID\nWHERE i.INVOICE_DATE >= TRUNC(SYSDATE, 'MM')\nGROUP BY a.CITY\nORDER BY MAX_INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00922", "tier": "T3", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "b70f1872b3f9", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 5, "approx_prompt_tokens": 3035, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n CANCELLED_DATE DATE, -- Date the invoice was cancelled; NULL if not cancelled.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Invoice holds: matching exceptions, duplicates and variances that block payment, with hold reason, date placed and release date. NULL RELEASE_DATE means the hold is still active.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_HOLDS_ALL (\n HOLD_ID NUMBER, -- Unique hold identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the hold is placed on. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_LOCATION_ID NUMBER, -- Purchase order schedule that caused the hold. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n HOLD_LOOKUP_CODE VARCHAR2(30), -- Hold reason. FK to AP_HOLD_CODES.HOLD_LOOKUP_CODE.\n HOLD_DATE DATE, -- Date the hold was placed.\n HELD_BY NUMBER, -- User who placed the hold. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n HOLD_REASON VARCHAR2(240), -- Explanation of why the hold was placed.\n RELEASE_LOOKUP_CODE VARCHAR2(30), -- Reason the hold was released. Values: VARIANCE ACCEPTED, CORRECTED, OVERRIDE.\n RELEASE_DATE DATE, -- Date the hold was released; NULL if still active.\n RELEASE_REASON VARCHAR2(240), -- Comments recorded when the hold was released.\n STATUS_FLAG VARCHAR2(1), -- Hold status: S system-placed, R released. Values: S, R.\n RESPONSIBILITY_ID NUMBER, -- Responsibility able to release the hold.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Receipt headers: goods receipts recorded against shipments, with supplier, receipt number and date.\nCREATE TABLE RCV_SHIPMENT_HEADERS (\n SHIPMENT_HEADER_ID NUMBER, -- Unique shipment or receipt identifier. Primary key.\n RECEIPT_NUM VARCHAR2(30), -- Receipt number.\n VENDOR_ID NUMBER, -- Supplier that shipped the goods. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site shipped from. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n SHIPPED_DATE DATE, -- Date the supplier shipped the goods.\n EXPECTED_RECEIPT_DATE DATE, -- Date the receipt was expected.\n RECEIPT_SOURCE_CODE VARCHAR2(25), -- Source of the receipt. Values: VENDOR, INTERNAL.\n SHIPMENT_NUM VARCHAR2(30), -- Supplier's shipment or packing slip number.\n WAYBILL_AIRBILL_NUM VARCHAR2(30), -- Carrier waybill number.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_NUMBER NUMBER, -- Sequence of the line within the invoice.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_MEAS_LOOKUP_CODE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\n PO_LINE_LOCATION_ID NUMBER, -- Purchase order schedule this line is matched to. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n RCV_TRANSACTION_ID NUMBER, -- Receipt transaction this line is matched to. FK to RCV_TRANSACTIONS.TRANSACTION_ID.\n ACCOUNTING_DATE DATE, -- Accounting date of the line.\n TAX_CLASSIFICATION_CODE VARCHAR2(30), -- Tax classification of the line. Values: STANDARD, REDUCED, EXEMPT.\n DISCARDED_FLAG VARCHAR2(1), -- Y if the line was discarded during correction.\n CANCELLED_FLAG VARCHAR2(1), -- Y if the line was cancelled.\n PREPAY_INVOICE_ID NUMBER, -- Prepayment invoice applied on this line, if any.\n);\n\n-- Purchase order schedules: delivery schedules of a line with need-by date, quantity received and billed, and the matching option (two-, three- or four-way).\n-- (showing 15 of 22 columns: join keys + those relevant to the question)\nCREATE TABLE PO_LINE_LOCATIONS_ALL (\n LINE_LOCATION_ID NUMBER, -- Unique schedule identifier. Primary key.\n SHIPMENT_NUM NUMBER, -- Schedule number within the line.\n QUANTITY NUMBER, -- Quantity scheduled.\n QUANTITY_RECEIVED NUMBER, -- Quantity received so far.\n QUANTITY_BILLED NUMBER, -- Quantity invoiced so far.\n QUANTITY_CANCELLED NUMBER, -- Quantity cancelled.\n NEED_BY_DATE DATE, -- Date the goods are needed.\n PROMISED_DATE DATE, -- Date the supplier promised delivery.\n PRICE_OVERRIDE NUMBER(18,2), -- Price for this schedule if different from the line.\n INVOICE_MATCH_OPTION VARCHAR2(1), -- P match to order (two-way), R match to receipt (three-way). Values: R, P.\n RECEIPT_REQUIRED_FLAG VARCHAR2(1), -- Y if receipt is required before payment.\n TAXABLE_FLAG VARCHAR2(1), -- Y if the schedule is taxable.\n SHIP_TO_LOCATION_ID NUMBER, -- Where the goods are delivered.\n CLOSED_CODE VARCHAR2(25), -- Closure state of the schedule. Values: OPEN, CLOSED FOR RECEIVING, CLOSED.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: What is the remaining balance and due date of invoice INV-2026-5052?"}, {"role": "assistant", "content": "```sql\nSELECT ps.PAYMENT_NUM, ps.DUE_DATE, ps.AMOUNT_REMAINING\nFROM AP_PAYMENT_SCHEDULES_ALL ps\nJOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ps.INVOICE_ID\nWHERE i.INVOICE_NUM = 'INV-2026-5052'\nORDER BY ps.PAYMENT_NUM;\n```"}], "meta": {"id": "a-00337", "tier": "T2", "family": "t2-invoice-lookup", "kind": "ask", "source": "S2-templated", "group": "c6c7aa3af02f", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL"], "result_rows": 1, "approx_prompt_tokens": 2714, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n INT_BANK_ACCOUNT_ID NUMBER, -- Company bank account used. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE, -- Date the payment was voided.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25), -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n-- days to pay => AP_CHECKS_ALL.CHECK_DATE - AP_INVOICES_ALL.INVOICE_DATE (join AP_INVOICE_PAYMENTS_ALL on INVOICE_ID and CHECK_ID)\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n"}, {"role": "user", "content": "Question: What is the payment count for each payment method this quarter?"}, {"role": "assistant", "content": "```sql\nSELECT c.PAYMENT_METHOD_CODE, COUNT(*) AS PAYMENT_COUNT\nFROM AP_CHECKS_ALL c\nWHERE c.CHECK_DATE >= TRUNC(SYSDATE, 'Q')\nGROUP BY c.PAYMENT_METHOD_CODE\nORDER BY PAYMENT_COUNT DESC;\n```"}], "meta": {"id": "a-01032", "tier": "T3", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "e02954318475", "tables": ["AP_CHECKS_ALL"], "result_rows": 3, "approx_prompt_tokens": 2767, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting payment currency to ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n);\n\n-- Transaction tax lines: the tax calculated on each invoice line, with taxable amount, rate, tax amount and recoverability.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE ZX_LINES (\n TAX_LINE_ID NUMBER, -- Unique tax line identifier. Primary key.\n TRX_ID NUMBER, -- Invoice the tax line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n TRX_LINE_ID NUMBER, -- Invoice line the tax was calculated on. FK to AP_INVOICE_LINES_ALL.INVOICE_LINE_ID.\n TAX_RATE_ID NUMBER, -- Rate applied. FK to ZX_RATES_B.TAX_RATE_ID.\n TAX_ID NUMBER, -- Tax applied. FK to ZX_TAXES_B.TAX_ID.\n TAX_RATE NUMBER(12,6), -- Tax percentage applied.\n TAXABLE_AMT NUMBER(18,2), -- Amount the tax was calculated on.\n TAX_AMT NUMBER(18,2), -- Tax amount.\n TAX_AMT_TAX_CURR NUMBER(18,2), -- Tax amount in the tax currency.\n TAX_CURRENCY_CODE VARCHAR2(15), -- Currency of the tax amount. FK to FND_CURRENCIES.CURRENCY_CODE.\n TAX_DATE DATE, -- Date used to determine the tax rate.\n TAX_JURISDICTION_CODE VARCHAR2(30), -- Jurisdiction the tax was levied by. Values: FEDERAL, STATE, COUNTRY.\n RECOVERABLE_FLAG VARCHAR2(1), -- Y if the tax is recoverable.\n SELF_ASSESSED_FLAG VARCHAR2(1), -- Y if the tax is self-assessed.\n TAX_STATUS_CODE VARCHAR2(30), -- Tax status applied. Values: STANDARD, REDUCED, ZERO.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n SELF_ASSESSED_TAX_AMOUNT NUMBER(18,2), -- Tax the buyer self-assesses instead of paying to the supplier.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n);\n\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_NUMBER NUMBER, -- Sequence of the line within the invoice.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit billed.\n ACCOUNTING_DATE DATE, -- Accounting date of the line.\n DEFAULT_DIST_CCID NUMBER, -- Default account used to distribute the line. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n TAX_CLASSIFICATION_CODE VARCHAR2(30), -- Tax classification of the line. Values: STANDARD, REDUCED, EXEMPT.\n TAX_RATE NUMBER(12,6), -- Tax rate applied to the line.\n TAX_RATE_ID NUMBER, -- Tax rate record applied. FK to ZX_RATES_B.TAX_RATE_ID.\n REQUESTER_ID NUMBER, -- Employee who requested the line item. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n MATCH_TYPE VARCHAR2(25), -- How the line was matched. Values: ITEM_TO_PO, ITEM_TO_RECEIPT, NOT_MATCHED.\n);\n\n-- Invoice distributions: how each invoice line amount is split across general-ledger expense accounts, with accounting status. Use for spend-by-GL-account questions.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_DISTRIBUTIONS_ALL (\n INVOICE_DISTRIBUTION_ID NUMBER, -- Unique invoice distribution identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the distribution belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n INVOICE_LINE_ID NUMBER, -- Invoice line the distribution splits. FK to AP_INVOICE_LINES_ALL.INVOICE_LINE_ID.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Distribution type: ITEM, TAX, FREIGHT, MISCELLANEOUS. Values: ITEM, TAX, FREIGHT.\n AMOUNT NUMBER(18,2), -- Distribution amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Distribution amount in ledger currency.\n DIST_CODE_COMBINATION_ID NUMBER, -- General-ledger account charged by the distribution. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n ACCRUAL_POSTED_FLAG VARCHAR2(1), -- Y if accrual accounting entries were created.\n QUANTITY_INVOICED NUMBER, -- Quantity billed for the distribution.\n UNIT_PRICE NUMBER(18,2), -- Unit price on the distribution.\n PROJECT_ID NUMBER, -- Project charged, if project costing is used.\n TASK_ID NUMBER, -- Project task charged.\n TAX_CODE_ID NUMBER, -- Tax code applied to the distribution. FK to ZX_RATES_B.TAX_RATE_ID.\n INCOME_TAX_REGION VARCHAR2(10), -- Region used for income-tax reporting.\n DESCRIPTION VARCHAR2(240), -- Distribution description.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Tax rates: rate percentage per tax and status, with recovery and accounting settings.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE ZX_RATES_B (\n TAX_RATE_ID NUMBER, -- Unique tax rate identifier. Primary key.\n TAX_ID NUMBER, -- Tax the rate belongs to. FK to ZX_TAXES_B.TAX_ID.\n TAX_RATE_CODE VARCHAR2(30), -- Tax rate code. Values: STANDARD, REDUCED, ZERO, EXEMPT.\n TAX_STATUS_CODE VARCHAR2(30), -- Tax status the rate applies under. Values: STANDARD, REDUCED, ZERO.\n PERCENTAGE_RATE NUMBER(12,6), -- Tax percentage.\n EFFECTIVE_FROM DATE, -- Date the rate becomes effective.\n EFFECTIVE_TO DATE, -- Date the rate stops applying.\n ACTIVE_FLAG VARCHAR2(1), -- Y if the rate is active.\n TAX_ACCOUNT_CCID NUMBER, -- Account tax is posted to. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n RECOVERY_TYPE_CODE VARCHAR2(30), -- Recovery treatment. Values: STANDARD, PARTIAL.\n DEFAULT_RECOVERY_RATE NUMBER(12,6), -- Default recoverable percentage.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n"}, {"role": "user", "content": "Question: What is the total invoice tax amount for each payment method for invoices paid by wire?"}, {"role": "assistant", "content": "```sql\nSELECT i.PAYMENT_METHOD_CODE, SUM(i.TOTAL_TAX_AMOUNT) AS TOTAL_TAX_AMOUNT\nFROM AP_INVOICES_ALL i\nWHERE i.PAYMENT_METHOD_CODE = 'WIRE'\nGROUP BY i.PAYMENT_METHOD_CODE\nORDER BY TOTAL_TAX_AMOUNT DESC;\n```"}], "meta": {"id": "a-00062", "tier": "T1", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "c2c1cd71fc96", "tables": ["AP_INVOICES_ALL"], "result_rows": 1, "approx_prompt_tokens": 3003, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Transaction tax lines: the tax calculated on each invoice line, with taxable amount, rate, tax amount and recoverability.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE ZX_LINES (\n TAX_LINE_ID NUMBER, -- Unique tax line identifier. Primary key.\n TRX_ID NUMBER, -- Invoice the tax line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n TRX_LINE_ID NUMBER, -- Invoice line the tax was calculated on. FK to AP_INVOICE_LINES_ALL.INVOICE_LINE_ID.\n TAX_RATE_ID NUMBER, -- Rate applied. FK to ZX_RATES_B.TAX_RATE_ID.\n TAX_ID NUMBER, -- Tax applied. FK to ZX_TAXES_B.TAX_ID.\n TAX_RATE NUMBER(12,6), -- Tax percentage applied.\n TAXABLE_AMT NUMBER(18,2), -- Amount the tax was calculated on.\n TAX_AMT NUMBER(18,2), -- Tax amount.\n TAX_AMT_TAX_CURR NUMBER(18,2), -- Tax amount in the tax currency.\n TAX_CURRENCY_CODE VARCHAR2(15), -- Currency of the tax amount. FK to FND_CURRENCIES.CURRENCY_CODE.\n TAX_DATE DATE, -- Date used to determine the tax rate.\n TAX_JURISDICTION_CODE VARCHAR2(30), -- Jurisdiction the tax was levied by. Values: FEDERAL, STATE, COUNTRY.\n RECOVERABLE_FLAG VARCHAR2(1), -- Y if the tax is recoverable.\n SELF_ASSESSED_FLAG VARCHAR2(1), -- Y if the tax is self-assessed.\n TAX_STATUS_CODE VARCHAR2(30) -- Tax status applied. Values: STANDARD, REDUCED, ZERO.\n);\n\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_NUMBER NUMBER, -- Sequence of the line within the invoice.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit billed.\n UNIT_MEAS_LOOKUP_CODE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\n ACCOUNTING_DATE DATE, -- Accounting date of the line.\n TAX_CLASSIFICATION_CODE VARCHAR2(30), -- Tax classification of the line. Values: STANDARD, REDUCED, EXEMPT.\n TAX_RATE NUMBER(12,6), -- Tax rate applied to the line.\n TAX_RATE_ID NUMBER, -- Tax rate record applied. FK to ZX_RATES_B.TAX_RATE_ID.\n REQUESTER_ID NUMBER, -- Employee who requested the line item. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Tax rates: rate percentage per tax and status, with recovery and accounting settings.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE ZX_RATES_B (\n TAX_RATE_ID NUMBER, -- Unique tax rate identifier. Primary key.\n TAX_ID NUMBER, -- Tax the rate belongs to. FK to ZX_TAXES_B.TAX_ID.\n TAX_RATE_CODE VARCHAR2(30), -- Tax rate code. Values: STANDARD, REDUCED, ZERO, EXEMPT.\n TAX_STATUS_CODE VARCHAR2(30), -- Tax status the rate applies under. Values: STANDARD, REDUCED, ZERO.\n PERCENTAGE_RATE NUMBER(12,6), -- Tax percentage.\n EFFECTIVE_FROM DATE, -- Date the rate becomes effective.\n EFFECTIVE_TO DATE, -- Date the rate stops applying.\n ACTIVE_FLAG VARCHAR2(1), -- Y if the rate is active.\n TAX_ACCOUNT_CCID NUMBER, -- Account tax is posted to. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n RECOVERY_TYPE_CODE VARCHAR2(30), -- Recovery treatment. Values: STANDARD, PARTIAL.\n DEFAULT_RECOVERY_RATE NUMBER(12,6) -- Default recoverable percentage.\n);\n\n-- Taxes: tax definitions such as VAT, GST and sales tax by jurisdiction.\nCREATE TABLE ZX_TAXES_B (\n TAX_ID NUMBER, -- Unique tax identifier. Primary key.\n TAX VARCHAR2(30), -- Tax code such as VAT or GST. Values: VAT, GST, SALES TAX, CONSUMPTION TAX.\n TAX_REGIME_CODE VARCHAR2(30), -- Tax regime the tax belongs to. Values: US-SALES, UK-VAT, CA-GST, EU-VAT.\n TAX_TYPE_CODE VARCHAR2(30), -- Tax type classification. Values: VAT, SALES, GST.\n TAX_JURISDICTION_CODE VARCHAR2(30), -- Jurisdiction levying the tax. Values: FEDERAL, STATE, COUNTRY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the tax is active.\n EFFECTIVE_FROM DATE, -- Date the tax becomes effective.\n EFFECTIVE_TO DATE, -- Date the tax stops applying.\n RECOVERABLE_FLAG VARCHAR2(1), -- Y if the tax can be recovered from the authority.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Invoice distributions: how each invoice line amount is split across general-ledger expense accounts, with accounting status. Use for spend-by-GL-account questions.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_DISTRIBUTIONS_ALL (\n INVOICE_DISTRIBUTION_ID NUMBER, -- Unique invoice distribution identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the distribution belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n INVOICE_LINE_ID NUMBER, -- Invoice line the distribution splits. FK to AP_INVOICE_LINES_ALL.INVOICE_LINE_ID.\n AMOUNT NUMBER(18,2), -- Distribution amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Distribution amount in ledger currency.\n ACCOUNTING_DATE DATE, -- Accounting date of the distribution.\n POSTED_FLAG VARCHAR2(1), -- Y if accounted and posted to the ledger, N if not yet accounted. Values: Y, N.\n QUANTITY_INVOICED NUMBER, -- Quantity billed for the distribution.\n UNIT_PRICE NUMBER(18,2), -- Unit price on the distribution.\n PO_DISTRIBUTION_ID NUMBER, -- Purchase order distribution matched to. FK to PO_DISTRIBUTIONS_ALL.PO_DISTRIBUTION_ID.\n PROJECT_ID NUMBER, -- Project charged, if project costing is used.\n TASK_ID NUMBER, -- Project task charged.\n TAX_CODE_ID NUMBER, -- Tax code applied to the distribution. FK to ZX_RATES_B.TAX_RATE_ID.\n INCOME_TAX_REGION VARCHAR2(10), -- Region used for income-tax reporting.\n DESCRIPTION VARCHAR2(240) -- Distribution description.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n SELF_ASSESSED_TAX_AMOUNT NUMBER(18,2), -- Tax the buyer self-assesses instead of paying to the supplier.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240) -- Free-text invoice description.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n CURRENCY_CODE VARCHAR2(15), -- Currency the payment was made in. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account the payment was drawn on. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n DOC_SEQUENCE_VALUE NUMBER -- Document sequence number of the payment.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n"}, {"role": "user", "content": "Question: Show me the total tax on invoices for invoices paid by wire."}, {"role": "assistant", "content": "```sql\nSELECT SUM(i.TOTAL_TAX_AMOUNT) AS TOTAL_TAX_AMOUNT\nFROM AP_INVOICES_ALL i\nWHERE i.PAYMENT_METHOD_CODE = 'WIRE';\n```"}], "meta": {"id": "a-00097", "tier": "T1", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "bcaaa1510364", "tables": ["AP_INVOICES_ALL"], "result_rows": 1, "approx_prompt_tokens": 2947, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n EXT_BANK_ACCOUNT_ID NUMBER, -- Payee bank account credited. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE, -- Date the payment was voided.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25), -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n);\n\n-- Payment history: status changes and accounting events for each payment (created, cleared, voided, reconciled).\n-- (showing 12 of 17 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_HISTORY_ALL (\n PAYMENT_HISTORY_ID NUMBER, -- Unique payment history identifier. Primary key.\n CHECK_ID NUMBER, -- Payment the history row describes. FK to AP_CHECKS_ALL.CHECK_ID.\n TRANSACTION_TYPE VARCHAR2(25), -- Kind of event recorded. Values: PAYMENT CREATED, PAYMENT CLEARING, PAYMENT UNCLEARING, PAYMENT CANCELLED.\n TRANSACTION_DATE DATE, -- Date of the event.\n ACCOUNTING_DATE DATE, -- Accounting date of the event.\n TRX_BANK_AMOUNT NUMBER(18,2), -- Amount at the bank for the event.\n TRX_PMT_AMOUNT NUMBER(18,2), -- Amount in payment currency for the event.\n HISTORICAL_FLAG VARCHAR2(1), -- Y if the row is superseded by a later event.\n POSTED_FLAG VARCHAR2(1), -- Y if the event was accounted.\n REV_PMT_HIST_ID NUMBER, -- Payment history row this event reverses.\n BANK_CURRENCY_CODE VARCHAR2(15), -- Currency of the bank statement line. FK to FND_CURRENCIES.CURRENCY_CODE.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payees: the payment-engine record linking a supplier or site to its payment defaults (method, delivery channel, bank instructions).\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXTERNAL_PAYEES_ALL (\n EXT_PAYEE_ID NUMBER, -- Unique payee identifier. Primary key.\n PAYEE_PARTY_ID NUMBER, -- Party being paid. FK to HZ_PARTIES.PARTY_ID.\n SUPPLIER_SITE_ID NUMBER, -- Supplier site the payee record represents. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n PAYMENT_FUNCTION VARCHAR2(30), -- Payment function the payee is used for. Values: PAYABLES_DISB, EMPLOYEE_EXP.\n DEFAULT_PAYMENT_METHOD_CODE VARCHAR2(30), -- Default payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_FORMAT_CODE VARCHAR2(30), -- Format used for payment files. Values: NACHA, SEPA, POSITIVE PAY.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Default bank delivery channel. Values: ACH, CHAPS, SEPA.\n BANK_INSTRUCTION1_CODE VARCHAR2(30), -- First bank instruction code.\n REMIT_ADVICE_DELIVERY_METHOD VARCHAR2(30), -- How remittance advice is delivered. Values: EMAIL, PRINT.\n REMIT_ADVICE_EMAIL VARCHAR2(255), -- Email address remittance advice is sent to.\n INACTIVE_DATE DATE, -- Date the payee record stops being valid.\n);\n\n-- Supplier bank accounts: external bank accounts that payments are sent to, with account holder, currency and validity dates.\n-- (showing 10 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXT_BANK_ACCOUNTS (\n EXT_BANK_ACCOUNT_ID NUMBER, -- Unique external bank account identifier. Primary key.\n BANK_PARTY_ID NUMBER, -- Bank holding the account. FK to CE_BANKS.BANK_PARTY_ID.\n ACCOUNT_OWNER_PARTY_ID NUMBER, -- Party that owns the account. FK to HZ_PARTIES.PARTY_ID.\n BANK_ACCOUNT_NAME VARCHAR2(80), -- Account holder name.\n CURRENCY_CODE VARCHAR2(15), -- Currency of the account. FK to FND_CURRENCIES.CURRENCY_CODE.\n COUNTRY_CODE VARCHAR2(2), -- Country of the account.\n START_DATE DATE, -- Date the account becomes valid.\n END_DATE DATE, -- Date the account stops being valid.\n ACCOUNT_SUFFIX VARCHAR2(30), -- Account suffix used by some banks.\n FOREIGN_PAYMENT_USE_FLAG VARCHAR2(1), -- Y if the account can receive foreign-currency payments.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n"}, {"role": "user", "content": "Question: Which 5 payment methods have the highest number of payments for payments that have cleared?"}, {"role": "assistant", "content": "```sql\nSELECT c.PAYMENT_METHOD_CODE, COUNT(*) AS PAYMENT_COUNT\nFROM AP_CHECKS_ALL c\nWHERE c.STATUS_LOOKUP_CODE IN ('CLEARED', 'RECONCILED')\nGROUP BY c.PAYMENT_METHOD_CODE\nORDER BY PAYMENT_COUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00043", "tier": "T1", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "49ac98f1135b", "tables": ["AP_CHECKS_ALL"], "result_rows": 3, "approx_prompt_tokens": 3020, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150) -- Message printed on the remittance advice.\n);\n\n-- Purchase order distributions: charge accounts and quantities of a schedule, including amount ordered, delivered and billed.\n-- (showing 14 of 19 columns: join keys + those relevant to the question)\nCREATE TABLE PO_DISTRIBUTIONS_ALL (\n PO_DISTRIBUTION_ID NUMBER, -- Unique distribution identifier. Primary key.\n PO_HEADER_ID NUMBER, -- Order the distribution belongs to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n PO_LINE_ID NUMBER, -- Line the distribution belongs to. FK to PO_LINES_ALL.PO_LINE_ID.\n LINE_LOCATION_ID NUMBER, -- Schedule the distribution belongs to. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n DISTRIBUTION_NUM NUMBER, -- Distribution number within the schedule.\n CODE_COMBINATION_ID NUMBER, -- Expense account charged. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n QUANTITY_ORDERED NUMBER, -- Quantity ordered on the distribution.\n QUANTITY_DELIVERED NUMBER, -- Quantity delivered.\n QUANTITY_BILLED NUMBER, -- Quantity billed.\n AMOUNT_ORDERED NUMBER(18,2), -- Amount ordered.\n AMOUNT_BILLED NUMBER(18,2), -- Amount billed so far.\n DESTINATION_TYPE_CODE VARCHAR2(25), -- Where the goods go. Values: EXPENSE, INVENTORY.\n REQUESTER_ID NUMBER, -- Employee who requested the goods. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n PROJECT_ID NUMBER -- Project charged.\n);\n\n-- Invoice distributions: how each invoice line amount is split across general-ledger expense accounts, with accounting status. Use for spend-by-GL-account questions.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_DISTRIBUTIONS_ALL (\n INVOICE_DISTRIBUTION_ID NUMBER, -- Unique invoice distribution identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the distribution belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n DISTRIBUTION_LINE_NUMBER NUMBER, -- Sequence of the distribution within the invoice.\n AMOUNT NUMBER(18,2), -- Distribution amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Distribution amount in ledger currency.\n DIST_CODE_COMBINATION_ID NUMBER, -- General-ledger account charged by the distribution. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n PERIOD_NAME VARCHAR2(15), -- Accounting period the distribution falls in.\n POSTED_FLAG VARCHAR2(1), -- Y if accounted and posted to the ledger, N if not yet accounted. Values: Y, N.\n ACCRUAL_POSTED_FLAG VARCHAR2(1), -- Y if accrual accounting entries were created.\n QUANTITY_INVOICED NUMBER, -- Quantity billed for the distribution.\n UNIT_PRICE NUMBER(18,2), -- Unit price on the distribution.\n PO_DISTRIBUTION_ID NUMBER, -- Purchase order distribution matched to. FK to PO_DISTRIBUTIONS_ALL.PO_DISTRIBUTION_ID.\n TASK_ID NUMBER, -- Project task charged.\n INCOME_TAX_REGION VARCHAR2(10), -- Region used for income-tax reporting.\n DESCRIPTION VARCHAR2(240) -- Distribution description.\n);\n\n-- Subledger accounting entry lines: debit and credit lines of each accounting entry with account, amounts and the source transaction.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE XLA_AE_LINES (\n AE_LINE_ID NUMBER, -- Unique accounting line identifier. Primary key.\n AE_LINE_NUM NUMBER, -- Line number within the entry.\n CODE_COMBINATION_ID NUMBER, -- Account of the line. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n ACCOUNTING_CLASS_CODE VARCHAR2(30), -- Accounting class such as liability or expense. Values: LIABILITY, ITEM EXPENSE, CASH, TAX, PREPAID.\n ENTERED_DR NUMBER(18,2), -- Debit in entered currency.\n ENTERED_CR NUMBER(18,2), -- Credit in entered currency.\n ACCOUNTED_DR NUMBER(18,2), -- Debit in ledger currency.\n ACCOUNTED_CR NUMBER(18,2), -- Credit in ledger currency.\n CURRENCY_CODE VARCHAR2(15), -- Entered currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n CURRENCY_CONVERSION_RATE NUMBER(12,6), -- Rate used to convert to ledger currency.\n DESCRIPTION VARCHAR2(240), -- Line description.\n SOURCE_TABLE VARCHAR2(30), -- Source table of the transaction. Values: AP_INVOICES_ALL, AP_INVOICE_PAYMENTS_ALL.\n SOURCE_ID NUMBER, -- Identifier of the source transaction.\n PARTY_ID NUMBER, -- Supplier party of the line. FK to HZ_PARTIES.PARTY_ID.\n GL_SL_LINK_ID NUMBER -- Link to the general-ledger journal line.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n PO_HEADER_ID NUMBER, -- Purchase order the invoice is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n DOC_SEQUENCE_VALUE NUMBER -- Document sequence number assigned to the invoice.\n);\n\n-- Purchase order headers: one row per purchase order with supplier, buyer, status, total and terms.\n-- (showing 15 of 28 columns: join keys + those relevant to the question)\nCREATE TABLE PO_HEADERS_ALL (\n PO_HEADER_ID NUMBER, -- Unique purchase order identifier. Primary key.\n SEGMENT1 VARCHAR2(30), -- Purchase order number.\n CURRENCY_CODE VARCHAR2(15), -- Order currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n RATE NUMBER(12,6), -- Exchange rate on the order.\n TERMS_ID NUMBER, -- Payment terms on the order. FK to AP_TERMS_B.TERM_ID.\n DOCUMENT_STATUS VARCHAR2(25), -- Status of the order. Values: OPEN, CLOSED, CANCELLED, INCOMPLETE.\n APPROVED_FLAG VARCHAR2(1), -- Y if approved. Values: Y, N.\n APPROVED_DATE DATE, -- Date the order was approved.\n CREATION_DATE_ORDERED DATE, -- Date the order was placed.\n TOTAL_AMOUNT NUMBER(18,2), -- Total order amount.\n NOTE_TO_VENDOR VARCHAR2(480), -- Note printed for the supplier.\n BILL_TO_LOCATION_ID NUMBER, -- Bill-to location.\n CANCEL_FLAG VARCHAR2(1), -- Y if the order was cancelled.\n CLOSED_DATE DATE, -- Date the order was closed.\n CLOSED_CODE VARCHAR2(25) -- Closure state of the order. Values: OPEN, CLOSED, FINALLY CLOSED.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n"}, {"role": "user", "content": "Recent conversation (for follow-up questions like 'now filter to APAC'):\nQ: Show the outstanding balance per supplier\nSQL: SELECT s.VENDOR_NAME, SUM(ps.AMOUNT_REMAINING) AS TOTAL_UNPAID_AMOUNT FROM AP_PAYMENT_SCHEDULES_ALL ps JOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ps.INVOICE_ID JOIN POZ_SUPPLIERS s ON s.VENDOR_ID = i.VENDOR_ID WHERE ps.AMOUNT_REMAINING > 0 GROUP BY s.VENDOR_NAME ORDER BY TOTAL_UNPAID_AMOUNT DESC FETCH FIRST 200 ROWS ONLY;\n\nQuestion: How many open installments is that instead of the amount?"}, {"role": "assistant", "content": "```sql\nSELECT s.VENDOR_NAME, COUNT(*) AS OPEN_INSTALLMENTS\nFROM AP_PAYMENT_SCHEDULES_ALL ps\nJOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ps.INVOICE_ID\nJOIN POZ_SUPPLIERS s ON s.VENDOR_ID = i.VENDOR_ID\nWHERE ps.AMOUNT_REMAINING > 0\nGROUP BY s.VENDOR_NAME\nORDER BY OPEN_INSTALLMENTS DESC;\n```"}], "meta": {"id": "a-01557", "tier": "T2", "family": "followup", "kind": "followup", "source": "S2-templated", "group": "9afb1b537775", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "POZ_SUPPLIERS"], "result_rows": 9, "approx_prompt_tokens": 3204, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 15 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_CODE VARCHAR2(15), -- Short site code.\n ADDRESS_ID NUMBER, -- Address of the site. FK to POZ_SUPPLIER_ADDRESSES.ADDRESS_ID.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Payment method for this site. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Default payment currency at this site. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n TOLERANCE_ID NUMBER, -- Matching tolerance applied at the site.\n BILL_TO_LOCATION_ID NUMBER, -- Default bill-to location.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\n-- (showing 15 of 38 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n VENDOR_NAME VARCHAR2(360), -- Supplier name.\n VENDOR_NAME_ALT VARCHAR2(320), -- Alternate or trading name of the supplier.\n SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\n VENDOR_TYPE_LOOKUP_CODE VARCHAR2(30), -- Supplier type. Values: VENDOR, CONTRACTOR, EMPLOYEE, TAX AUTHORITY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n SMALL_BUSINESS_FLAG VARCHAR2(1), -- Y if the supplier is a small business.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Default payment method for the supplier. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Default pay group. Values: DOMESTIC, INTERNATIONAL.\n TERMS_ID NUMBER, -- Default payment terms. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Default payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if all payments to the supplier are blocked.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2), -- Maximum credit extended to the supplier.\n RISK_RATING VARCHAR2(25), -- Internal supplier risk rating. Values: LOW, MEDIUM, HIGH.\n);\n\n-- Supplier bank accounts: external bank accounts that payments are sent to, with account holder, currency and validity dates.\n-- (showing 10 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXT_BANK_ACCOUNTS (\n EXT_BANK_ACCOUNT_ID NUMBER, -- Unique external bank account identifier. Primary key.\n BANK_PARTY_ID NUMBER, -- Bank holding the account. FK to CE_BANKS.BANK_PARTY_ID.\n ACCOUNT_OWNER_PARTY_ID NUMBER, -- Party that owns the account. FK to HZ_PARTIES.PARTY_ID.\n BANK_ACCOUNT_NAME VARCHAR2(80), -- Account holder name.\n CURRENCY_CODE VARCHAR2(15), -- Currency of the account. FK to FND_CURRENCIES.CURRENCY_CODE.\n COUNTRY_CODE VARCHAR2(2), -- Country of the account.\n START_DATE DATE, -- Date the account becomes valid.\n END_DATE DATE, -- Date the account stops being valid.\n ACCOUNT_SUFFIX VARCHAR2(30), -- Account suffix used by some banks.\n FOREIGN_PAYMENT_USE_FLAG VARCHAR2(1), -- Y if the account can receive foreign-currency payments.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting payment currency to ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n);\n\n-- Payees: the payment-engine record linking a supplier or site to its payment defaults (method, delivery channel, bank instructions).\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXTERNAL_PAYEES_ALL (\n EXT_PAYEE_ID NUMBER, -- Unique payee identifier. Primary key.\n PAYEE_PARTY_ID NUMBER, -- Party being paid. FK to HZ_PARTIES.PARTY_ID.\n SUPPLIER_SITE_ID NUMBER, -- Supplier site the payee record represents. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n PAYMENT_FUNCTION VARCHAR2(30), -- Payment function the payee is used for. Values: PAYABLES_DISB, EMPLOYEE_EXP.\n DEFAULT_PAYMENT_METHOD_CODE VARCHAR2(30), -- Default payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_FORMAT_CODE VARCHAR2(30), -- Format used for payment files. Values: NACHA, SEPA, POSITIVE PAY.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Default bank delivery channel. Values: ACH, CHAPS, SEPA.\n BANK_INSTRUCTION1_CODE VARCHAR2(30), -- First bank instruction code.\n REMIT_ADVICE_DELIVERY_METHOD VARCHAR2(30), -- How remittance advice is delivered. Values: EMAIL, PRINT.\n REMIT_ADVICE_EMAIL VARCHAR2(255), -- Email address remittance advice is sent to.\n INACTIVE_DATE DATE, -- Date the payee record stops being valid.\n);\n\n-- Supplier addresses: physical and remit-to addresses of suppliers.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_ADDRESSES (\n ADDRESS_ID NUMBER, -- Unique address identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the address belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_NAME VARCHAR2(240), -- Name identifying the address.\n ADDRESS_LINE1 VARCHAR2(240), -- First address line.\n ADDRESS_LINE2 VARCHAR2(240), -- Second address line.\n CITY VARCHAR2(60), -- City.\n STATE VARCHAR2(60), -- State or province. Values: CA, NY, TX, WA, IL.\n POSTAL_CODE VARCHAR2(60), -- Postal or ZIP code.\n COUNTRY VARCHAR2(2), -- Country code.\n ADDRESS_PURPOSE VARCHAR2(30), -- What the address is used for. Values: REMIT_TO, PURCHASING, RFQ.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n LATITUDE NUMBER(12,6), -- Latitude of the address.\n LONGITUDE NUMBER(12,6), -- Longitude of the address.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n EXT_BANK_ACCOUNT_ID NUMBER, -- Payee bank account credited. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE, -- Date the payment was voided.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n\n"}, {"role": "user", "content": "Question: 5 suppliers with the lowest largest payment amount"}, {"role": "assistant", "content": "```sql\nSELECT s.VENDOR_NAME, MAX(c.AMOUNT) AS MAX_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nJOIN POZ_SUPPLIERS s ON s.VENDOR_ID = c.VENDOR_ID\nGROUP BY s.VENDOR_NAME\nORDER BY MAX_PAYMENT_AMOUNT ASC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00741", "tier": "T2", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "b866ecb056f2", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIERS"], "result_rows": 5, "approx_prompt_tokens": 2538, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice holds: matching exceptions, duplicates and variances that block payment, with hold reason, date placed and release date. NULL RELEASE_DATE means the hold is still active.\nCREATE TABLE AP_HOLDS_ALL (\n HOLD_ID NUMBER, -- Unique hold identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the hold is placed on. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_LOCATION_ID NUMBER, -- Purchase order schedule that caused the hold. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n HOLD_LOOKUP_CODE VARCHAR2(30), -- Hold reason. FK to AP_HOLD_CODES.HOLD_LOOKUP_CODE.\n HOLD_DATE DATE, -- Date the hold was placed.\n HELD_BY NUMBER, -- User who placed the hold. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n HOLD_REASON VARCHAR2(240), -- Explanation of why the hold was placed.\n RELEASE_LOOKUP_CODE VARCHAR2(30), -- Reason the hold was released. Values: VARIANCE ACCEPTED, CORRECTED, OVERRIDE.\n RELEASE_DATE DATE, -- Date the hold was released; NULL if still active.\n RELEASE_REASON VARCHAR2(240), -- Comments recorded when the hold was released.\n STATUS_FLAG VARCHAR2(1), -- Hold status: S system-placed, R released. Values: S, R.\n RESPONSIBILITY_ID NUMBER, -- Responsibility able to release the hold.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n PARTY_ID NUMBER, -- Trading-community party of the supplier. FK to HZ_PARTIES.PARTY_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n SELF_ASSESSED_TAX_AMOUNT NUMBER(18,2), -- Tax the buyer self-assesses instead of paying to the supplier.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice is denominated in. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice will be paid in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n EXCHANGE_RATE_TYPE VARCHAR2(30), -- Type of exchange rate used. Values: Corporate, Spot, User.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n SOURCE VARCHAR2(80), -- How the invoice entered the system. Values: MANUAL, IMPORT, SUPPLIER PORTAL, EMAIL.\n PO_HEADER_ID NUMBER, -- Purchase order the invoice is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n VALIDATION_STATUS VARCHAR2(25), -- Result of invoice validation. Values: VALIDATED, NEEDS REVALIDATION, NEVER VALIDATED.\n WFAPPROVAL_STATUS VARCHAR2(25), -- Approval workflow status of the invoice. Values: APPROVED, NOT REQUIRED, REJECTED, INITIATED.\n CANCELLED_DATE DATE, -- Date the invoice was cancelled; NULL if not cancelled.\n CANCELLED_BY VARCHAR2(64), -- User who cancelled the invoice.\n ACCTS_PAY_CODE_COMBINATION_ID NUMBER, -- Liability (accounts payable) account for the invoice. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n LEDGER_ID NUMBER, -- Ledger the invoice is accounted in. FK to GL_LEDGERS.LEDGER_ID.\n REQUESTER_ID NUMBER, -- Employee who requested the goods or services. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n LEGAL_ENTITY_ID NUMBER, -- Legal entity the invoice belongs to.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number assigned to the invoice.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n ATTRIBUTE_CATEGORY VARCHAR2(30), -- Descriptive flexfield context (customer-defined extension fields).\n ATTRIBUTE1 VARCHAR2(150), -- Descriptive flexfield segment 1, customer-defined and normally unused.\n ATTRIBUTE2 VARCHAR2(150), -- Descriptive flexfield segment 2, customer-defined and normally unused.\n ATTRIBUTE3 VARCHAR2(150), -- Descriptive flexfield segment 3, customer-defined and normally unused.\n ATTRIBUTE4 VARCHAR2(150), -- Descriptive flexfield segment 4, customer-defined and normally unused.\n ATTRIBUTE5 VARCHAR2(150), -- Descriptive flexfield segment 5, customer-defined and normally unused.\n ATTRIBUTE6 VARCHAR2(150), -- Descriptive flexfield segment 6, customer-defined and normally unused.\n ATTRIBUTE7 VARCHAR2(150), -- Descriptive flexfield segment 7, customer-defined and normally unused.\n ATTRIBUTE8 VARCHAR2(150), -- Descriptive flexfield segment 8, customer-defined and normally unused.\n ATTRIBUTE9 VARCHAR2(150), -- Descriptive flexfield segment 9, customer-defined and normally unused.\n ATTRIBUTE10 VARCHAR2(150) -- Descriptive flexfield segment 10, customer-defined and normally unused.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n PARTY_ID NUMBER, -- Trading-community party behind the supplier. FK to HZ_PARTIES.PARTY_ID.\n VENDOR_NAME VARCHAR2(360), -- Supplier name.\n VENDOR_NAME_ALT VARCHAR2(320), -- Alternate or trading name of the supplier.\n SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\n VENDOR_TYPE_LOOKUP_CODE VARCHAR2(30), -- Supplier type. Values: VENDOR, CONTRACTOR, EMPLOYEE, TAX AUTHORITY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n START_DATE_ACTIVE DATE, -- Date the supplier becomes active.\n END_DATE_ACTIVE DATE, -- Date the supplier stops being active.\n SUMMARY_FLAG VARCHAR2(1), -- Y if the supplier is a summary (parent) record.\n ONE_TIME_FLAG VARCHAR2(1), -- Y if the supplier is a one-time supplier.\n SMALL_BUSINESS_FLAG VARCHAR2(1), -- Y if the supplier is a small business.\n WOMEN_OWNED_FLAG VARCHAR2(1), -- Y if the supplier is women-owned.\n MINORITY_GROUP_LOOKUP_CODE VARCHAR2(30), -- Minority ownership classification. Values: MBE, DBE.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Default payment method for the supplier. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Default pay group. Values: DOMESTIC, INTERNATIONAL.\n TERMS_ID NUMBER, -- Default payment terms. FK to AP_TERMS_B.TERM_ID.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Default invoice currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Default payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if all payments to the supplier are blocked.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n NUM_1099 VARCHAR2(30), -- US taxpayer identification number for 1099 reporting.\n TAX_REGISTRATION_NUMBER VARCHAR2(50), -- VAT or GST registration number.\n FEDERAL_REPORTABLE_FLAG VARCHAR2(1), -- Y if the supplier is reportable for federal income tax.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2), -- Maximum credit extended to the supplier.\n RISK_RATING VARCHAR2(25), -- Internal supplier risk rating. Values: LOW, MEDIUM, HIGH.\n CREATION_SOURCE VARCHAR2(30), -- Where the supplier record originated. Values: REGISTRATION, MANUAL, IMPORT.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ATTRIBUTE_CATEGORY VARCHAR2(30), -- Descriptive flexfield context (customer-defined extension fields).\n ATTRIBUTE1 VARCHAR2(150), -- Descriptive flexfield segment 1, customer-defined and normally unused.\n ATTRIBUTE2 VARCHAR2(150), -- Descriptive flexfield segment 2, customer-defined and normally unused.\n ATTRIBUTE3 VARCHAR2(150), -- Descriptive flexfield segment 3, customer-defined and normally unused.\n ATTRIBUTE4 VARCHAR2(150), -- Descriptive flexfield segment 4, customer-defined and normally unused.\n ATTRIBUTE5 VARCHAR2(150) -- Descriptive flexfield segment 5, customer-defined and normally unused.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- duplicate invoice => AP_HOLDS_ALL.HOLD_LOOKUP_CODE = 'DUPLICATE INVOICE'\n-- cancelled invoice => AP_INVOICES_ALL.CANCELLED_DATE IS NOT NULL\n-- on hold => AP_HOLDS_ALL.RELEASE_DATE IS NULL (active hold; the reason is AP_HOLDS_ALL.HOLD_LOOKUP_CODE)\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: Show Massive Dynamic's invoices that are on hold\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT i.INVOICE_NUMBER, h.HOLD_LOOKUP_CODE, h.HOLD_DATE FROM AP_HOLDS_ALL h JOIN AP_INVOICES_ALL i ON i.INVOICE_ID = h.INVOICE_ID JOIN POZ_SUPPLIERS s ON s.VENDOR_ID = i.VENDOR_ID WHERE s.VENDOR_NAME = 'Massive Dynamic' AND h.RELEASE_DATE IS NULL ORDER BY h.HOLD_DATE FETCH FIRST 200 ROWS ONLY;\nError: ORA-00904: \"I\".\"INVOICE_NUMBER\": invalid identifier\nDiagnosis: I is AP_INVOICES_ALL, which has NO column named INVOICE_NUMBER. Its columns are: INVOICE_ID, VENDOR_ID, VENDOR_SITE_ID, PARTY_ID, INVOICE_NUM, INVOICE_TYPE_LOOKUP_CODE, INVOICE_DATE, INVOICE_RECEIVED_DATE, GOODS_RECEIVED_DATE, GL_DATE, INVOICE_AMOUNT, AMOUNT_PAID, TOTAL_TAX_AMOUNT, BASE_AMOUNT, APPROVED_AMOUNT, AMOUNT_APPLICABLE_TO_DISCOUNT, DISCOUNT_AMOUNT_TAKEN, PREPAY_AMOUNT_REMAINING, SELF_ASSESSED_TAX_AMOUNT, INVOICE_CURRENCY_CODE, PAYMENT_CURRENCY_CODE, EXCHANGE_RATE, EXCHANGE_DATE, EXCHANGE_RATE_TYPE, TERMS_ID, TERMS_DATE, PAYMENT_METHOD_CODE, PAY_GROUP_LOOKUP_CODE, PAYMENT_STATUS_FLAG, DESCRIPTION, SOURCE, PO_HEADER_ID, BATCH_ID, VALIDATION_STATUS, WFAPPROVAL_STATUS, CANCELLED_DATE, CANCELLED_BY, ACCTS_PAY_CODE_COMBINATION_ID, LEDGER_ID, REQUESTER_ID, LEGAL_ENTITY_ID, DOC_SEQUENCE_VALUE, CREATION_DATE, CREATED_BY, LAST_UPDATE_DATE, LAST_UPDATED_BY, OBJECT_VERSION_NUMBER, ORG_ID, ATTRIBUTE_CATEGORY, ATTRIBUTE1, ATTRIBUTE2, ATTRIBUTE3, ATTRIBUTE4, ATTRIBUTE5, ATTRIBUTE6, ATTRIBUTE7, ATTRIBUTE8, ATTRIBUTE9, ATTRIBUTE10. Closest names: INVOICE_NUM, INVOICE_DATE, INVOICE_ID.\nWrite a corrected query. It must differ from the failed one. Use ONLY the tables and columns in the schema above, spelled exactly as shown; if a column you wanted does not exist, choose the closest one that does."}, {"role": "assistant", "content": "```sql\nSELECT i.INVOICE_NUM, h.HOLD_LOOKUP_CODE, h.HOLD_DATE\nFROM AP_HOLDS_ALL h\nJOIN AP_INVOICES_ALL i ON i.INVOICE_ID = h.INVOICE_ID\nJOIN POZ_SUPPLIERS s ON s.VENDOR_ID = i.VENDOR_ID\nWHERE s.VENDOR_NAME = 'Massive Dynamic'\nAND h.RELEASE_DATE IS NULL\nORDER BY h.HOLD_DATE;\n```"}], "meta": {"id": "r-00006", "tier": "T2", "family": "t2-supplier-list", "kind": "repair-exec", "source": "S6-repair", "group": "d6bb244d7716", "tables": ["AP_HOLDS_ALL", "AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 0, "approx_prompt_tokens": 3446, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"I\".\"INVOICE_NUMBER\": invalid identifier", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice batches: groups of invoices entered together, with control totals and entry status.\nCREATE TABLE AP_BATCHES_ALL (\n BATCH_ID NUMBER, -- Unique invoice batch identifier. Primary key.\n BATCH_NAME VARCHAR2(50), -- Name of the batch.\n BATCH_DATE DATE, -- Date the batch was created.\n INVOICE_COUNT NUMBER, -- Number of invoices entered in the batch.\n INVOICE_AMOUNT NUMBER(18,2), -- Total amount of the invoices in the batch.\n CONTROL_INVOICE_COUNT NUMBER, -- Expected invoice count entered as a control total.\n CONTROL_INVOICE_AMOUNT NUMBER(18,2), -- Expected batch amount entered as a control total.\n BATCH_STATUS VARCHAR2(25), -- Status of the batch. Values: OPEN, CLOSED, POSTED.\n SOURCE VARCHAR2(80), -- Source of the batch. Values: MANUAL, IMPORT, SUPPLIER PORTAL.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_NUMBER NUMBER, -- Sequence of the line within the invoice.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n DESCRIPTION VARCHAR2(240), -- Description of the goods or service on the line.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit billed.\n UNIT_MEAS_LOOKUP_CODE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\n ACCOUNTING_DATE DATE, -- Accounting date of the line.\n DEFAULT_DIST_CCID NUMBER, -- Default account used to distribute the line. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n TAX_RATE NUMBER(12,6), -- Tax rate applied to the line.\n REQUESTER_ID NUMBER, -- Employee who requested the line item. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: Give me the 5 largest invoices"}, {"role": "assistant", "content": "```sql\nSELECT INVOICE_NUM, INVOICE_DATE, INVOICE_AMOUNT\nFROM AP_INVOICES_ALL\nORDER BY INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00027", "tier": "T1", "family": "t1-topn", "kind": "ask", "source": "S2-templated", "group": "9e8a0453211f", "tables": ["AP_INVOICES_ALL"], "result_rows": 5, "approx_prompt_tokens": 2304, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice will be paid in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n);\n\n-- Invoice holds: matching exceptions, duplicates and variances that block payment, with hold reason, date placed and release date. NULL RELEASE_DATE means the hold is still active.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_HOLDS_ALL (\n HOLD_ID NUMBER, -- Unique hold identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the hold is placed on. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_LOCATION_ID NUMBER, -- Purchase order schedule that caused the hold. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n HOLD_LOOKUP_CODE VARCHAR2(30), -- Hold reason. FK to AP_HOLD_CODES.HOLD_LOOKUP_CODE.\n HOLD_DATE DATE, -- Date the hold was placed.\n HELD_BY NUMBER, -- User who placed the hold. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n HOLD_REASON VARCHAR2(240), -- Explanation of why the hold was placed.\n RELEASE_LOOKUP_CODE VARCHAR2(30), -- Reason the hold was released. Values: VARIANCE ACCEPTED, CORRECTED, OVERRIDE.\n RELEASE_DATE DATE, -- Date the hold was released; NULL if still active.\n RELEASE_REASON VARCHAR2(240), -- Comments recorded when the hold was released.\n STATUS_FLAG VARCHAR2(1), -- Hold status: S system-placed, R released. Values: S, R.\n RESPONSIBILITY_ID NUMBER, -- Responsibility able to release the hold.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n CURRENCY_CODE VARCHAR2(15), -- Currency the payment was made in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting payment currency to ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- early payment discount => AP_PAYMENT_SCHEDULES_ALL.DISCOUNT_AMOUNT_AVAILABLE > 0\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- days to pay => AP_CHECKS_ALL.CHECK_DATE - AP_INVOICES_ALL.INVOICE_DATE (join AP_INVOICE_PAYMENTS_ALL on INVOICE_ID and CHECK_ID)\n"}, {"role": "user", "content": "Question: Show the total early-payment discount available per payment term for USD invoices only"}, {"role": "assistant", "content": "```sql\nSELECT t.NAME, SUM(ps.DISCOUNT_AMOUNT_AVAILABLE) AS TOTAL_DISCOUNT_AVAILABLE\nFROM AP_PAYMENT_SCHEDULES_ALL ps\nJOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ps.INVOICE_ID\nJOIN AP_TERMS_B t ON t.TERM_ID = i.TERMS_ID\nWHERE ps.DISCOUNT_AMOUNT_AVAILABLE > 0 AND i.INVOICE_CURRENCY_CODE = 'USD'\nGROUP BY t.NAME\nORDER BY TOTAL_DISCOUNT_AVAILABLE DESC;\n```"}], "meta": {"id": "a-00572", "tier": "T2", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "5347abde9d68", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "AP_TERMS_B"], "result_rows": 1, "approx_prompt_tokens": 2888, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 18 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n CANCELLED_DATE DATE -- Date the invoice was cancelled; NULL if not cancelled.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice batches: groups of invoices entered together, with control totals and entry status.\nCREATE TABLE AP_BATCHES_ALL (\n BATCH_ID NUMBER, -- Unique invoice batch identifier. Primary key.\n BATCH_NAME VARCHAR2(50), -- Name of the batch.\n BATCH_DATE DATE, -- Date the batch was created.\n INVOICE_COUNT NUMBER, -- Number of invoices entered in the batch.\n INVOICE_AMOUNT NUMBER(18,2), -- Total amount of the invoices in the batch.\n CONTROL_INVOICE_COUNT NUMBER, -- Expected invoice count entered as a control total.\n CONTROL_INVOICE_AMOUNT NUMBER(18,2), -- Expected batch amount entered as a control total.\n BATCH_STATUS VARCHAR2(25), -- Status of the batch. Values: OPEN, CLOSED, POSTED.\n SOURCE VARCHAR2(80), -- Source of the batch. Values: MANUAL, IMPORT, SUPPLIER PORTAL.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n DOC_SEQUENCE_VALUE NUMBER -- Document sequence number of the payment.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- days to pay => AP_CHECKS_ALL.CHECK_DATE - AP_INVOICES_ALL.INVOICE_DATE (join AP_INVOICE_PAYMENTS_ALL on INVOICE_ID and CHECK_ID)\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: What is the total paid against invoices for each payment term this month?"}, {"role": "assistant", "content": "```sql\nSELECT t.NAME, SUM(i.AMOUNT_PAID) AS TOTAL_AMOUNT_PAID\nFROM AP_INVOICES_ALL i\nJOIN AP_TERMS_B t ON t.TERM_ID = i.TERMS_ID\nWHERE i.INVOICE_DATE >= TRUNC(SYSDATE, 'MM')\nGROUP BY t.NAME\nORDER BY TOTAL_AMOUNT_PAID DESC;\n```"}], "meta": {"id": "a-00952", "tier": "T3", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "d9222c389cb3", "tables": ["AP_INVOICES_ALL", "AP_TERMS_B"], "result_rows": 5, "approx_prompt_tokens": 2845, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n DOC_SEQUENCE_VALUE NUMBER -- Document sequence number of the payment.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n INT_BANK_ACCOUNT_ID NUMBER, -- Company bank account used. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXT_BANK_ACCOUNT_ID NUMBER, -- Payee bank account credited. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE -- Date the payment was voided.\n);\n\n-- Payment history: status changes and accounting events for each payment (created, cleared, voided, reconciled).\n-- (showing 12 of 17 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_HISTORY_ALL (\n PAYMENT_HISTORY_ID NUMBER, -- Unique payment history identifier. Primary key.\n CHECK_ID NUMBER, -- Payment the history row describes. FK to AP_CHECKS_ALL.CHECK_ID.\n TRANSACTION_TYPE VARCHAR2(25), -- Kind of event recorded. Values: PAYMENT CREATED, PAYMENT CLEARING, PAYMENT UNCLEARING, PAYMENT CANCELLED.\n TRANSACTION_DATE DATE, -- Date of the event.\n ACCOUNTING_DATE DATE, -- Accounting date of the event.\n TRX_BANK_AMOUNT NUMBER(18,2), -- Amount at the bank for the event.\n TRX_PMT_AMOUNT NUMBER(18,2), -- Amount in payment currency for the event.\n HISTORICAL_FLAG VARCHAR2(1), -- Y if the row is superseded by a later event.\n POSTED_FLAG VARCHAR2(1), -- Y if the event was accounted.\n REV_PMT_HIST_ID NUMBER, -- Payment history row this event reverses.\n BANK_CURRENCY_CODE VARCHAR2(15), -- Currency of the bank statement line. FK to FND_CURRENCIES.CURRENCY_CODE.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150) -- Message printed on the remittance advice.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25) -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n EXCHANGE_RATE_TYPE VARCHAR2(30), -- Type of exchange rate used. Values: Corporate, Spot, User.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n PAYMENT_STATUS_FLAG VARCHAR2(1) -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n"}, {"role": "user", "content": "Question: Top 5 payment methods by average payment amount for payments that have cleared"}, {"role": "assistant", "content": "```sql\nSELECT c.PAYMENT_METHOD_CODE, AVG(c.AMOUNT) AS AVG_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nWHERE c.STATUS_LOOKUP_CODE IN ('CLEARED', 'RECONCILED')\nGROUP BY c.PAYMENT_METHOD_CODE\nORDER BY AVG_PAYMENT_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00074", "tier": "T1", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "1fd84335e295", "tables": ["AP_CHECKS_ALL"], "result_rows": 3, "approx_prompt_tokens": 2872, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Employee expense reports: reports submitted by employees with total, status, dates and approval. Reimbursed through Payables.\nCREATE TABLE AP_EXPENSE_REPORT_HEADERS_ALL (\n EXPENSE_REPORT_ID NUMBER, -- Unique expense report identifier. Primary key.\n EMPLOYEE_ID NUMBER, -- Employee who submitted the report. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n REPORT_NUMBER VARCHAR2(50), -- Expense report number.\n REPORT_DATE DATE, -- Date the report was submitted.\n TOTAL NUMBER(18,2), -- Total amount claimed.\n AMOUNT_REIMBURSABLE NUMBER(18,2), -- Amount to be reimbursed to the employee.\n CURRENCY_CODE VARCHAR2(15), -- Report currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n STATUS VARCHAR2(25), -- Report status. Values: PAID, APPROVED, SUBMITTED, REJECTED.\n PURPOSE VARCHAR2(240), -- Business purpose of the expenses.\n APPROVER_ID NUMBER, -- Manager who approved the report. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n APPROVED_DATE DATE, -- Date the report was approved.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the employee is reimbursed. Values: EFT, CHECK.\n INVOICE_ID NUMBER, -- Payables invoice created for reimbursement. FK to AP_INVOICES_ALL.INVOICE_ID.\n POLICY_VIOLATION_FLAG VARCHAR2(1), -- Y if the report breaks expense policy.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n PARTY_ID NUMBER, -- Trading-community party of the supplier. FK to HZ_PARTIES.PARTY_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n SELF_ASSESSED_TAX_AMOUNT NUMBER(18,2), -- Tax the buyer self-assesses instead of paying to the supplier.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice is denominated in. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice will be paid in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n EXCHANGE_RATE_TYPE VARCHAR2(30), -- Type of exchange rate used. Values: Corporate, Spot, User.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n SOURCE VARCHAR2(80), -- How the invoice entered the system. Values: MANUAL, IMPORT, SUPPLIER PORTAL, EMAIL.\n PO_HEADER_ID NUMBER, -- Purchase order the invoice is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n VALIDATION_STATUS VARCHAR2(25), -- Result of invoice validation. Values: VALIDATED, NEEDS REVALIDATION, NEVER VALIDATED.\n WFAPPROVAL_STATUS VARCHAR2(25), -- Approval workflow status of the invoice. Values: APPROVED, NOT REQUIRED, REJECTED, INITIATED.\n CANCELLED_DATE DATE, -- Date the invoice was cancelled; NULL if not cancelled.\n CANCELLED_BY VARCHAR2(64), -- User who cancelled the invoice.\n ACCTS_PAY_CODE_COMBINATION_ID NUMBER, -- Liability (accounts payable) account for the invoice. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n LEDGER_ID NUMBER, -- Ledger the invoice is accounted in. FK to GL_LEDGERS.LEDGER_ID.\n REQUESTER_ID NUMBER, -- Employee who requested the goods or services. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n LEGAL_ENTITY_ID NUMBER, -- Legal entity the invoice belongs to.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number assigned to the invoice.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n ATTRIBUTE_CATEGORY VARCHAR2(30), -- Descriptive flexfield context (customer-defined extension fields).\n ATTRIBUTE1 VARCHAR2(150), -- Descriptive flexfield segment 1, customer-defined and normally unused.\n ATTRIBUTE2 VARCHAR2(150), -- Descriptive flexfield segment 2, customer-defined and normally unused.\n ATTRIBUTE3 VARCHAR2(150), -- Descriptive flexfield segment 3, customer-defined and normally unused.\n ATTRIBUTE4 VARCHAR2(150), -- Descriptive flexfield segment 4, customer-defined and normally unused.\n ATTRIBUTE5 VARCHAR2(150), -- Descriptive flexfield segment 5, customer-defined and normally unused.\n ATTRIBUTE6 VARCHAR2(150), -- Descriptive flexfield segment 6, customer-defined and normally unused.\n ATTRIBUTE7 VARCHAR2(150), -- Descriptive flexfield segment 7, customer-defined and normally unused.\n ATTRIBUTE8 VARCHAR2(150), -- Descriptive flexfield segment 8, customer-defined and normally unused.\n ATTRIBUTE9 VARCHAR2(150), -- Descriptive flexfield segment 9, customer-defined and normally unused.\n ATTRIBUTE10 VARCHAR2(150), -- Descriptive flexfield segment 10, customer-defined and normally unused.\n);\n\n-- Business units: organizational units that own transactions, with primary ledger and default currency.\nCREATE TABLE FUN_BUSINESS_UNITS (\n BU_ID NUMBER, -- Unique business unit identifier. Primary key.\n BU_NAME VARCHAR2(240), -- Business unit name. Values: US Operations, EMEA Operations, APAC Operations, Canada Operations, Shared Services.\n SHORT_CODE VARCHAR2(30), -- Short code of the business unit.\n PRIMARY_LEDGER_ID NUMBER, -- Ledger the business unit posts to. FK to GL_LEDGERS.LEDGER_ID.\n DEFAULT_CURRENCY_CODE VARCHAR2(15), -- Default currency of the business unit. FK to FND_CURRENCIES.CURRENCY_CODE.\n LEGAL_ENTITY_ID NUMBER, -- Legal entity the business unit belongs to.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n DATE_FROM DATE, -- Date the business unit becomes effective.\n DATE_TO DATE, -- Date the business unit stops being effective.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Purchase order headers: one row per purchase order with supplier, buyer, status, total and terms.\nCREATE TABLE PO_HEADERS_ALL (\n PO_HEADER_ID NUMBER, -- Unique purchase order identifier. Primary key.\n SEGMENT1 VARCHAR2(30), -- Purchase order number.\n TYPE_LOOKUP_CODE VARCHAR2(25), -- Order type. Values: STANDARD, BLANKET, CONTRACT.\n VENDOR_ID NUMBER, -- Supplier the order is placed with. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the order is placed with. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n AGENT_ID NUMBER, -- Buyer who created the order. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n CURRENCY_CODE VARCHAR2(15), -- Order currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n RATE NUMBER(12,6), -- Exchange rate on the order.\n TERMS_ID NUMBER, -- Payment terms on the order. FK to AP_TERMS_B.TERM_ID.\n DOCUMENT_STATUS VARCHAR2(25), -- Status of the order. Values: OPEN, CLOSED, CANCELLED, INCOMPLETE.\n APPROVED_FLAG VARCHAR2(1), -- Y if approved. Values: Y, N.\n APPROVED_DATE DATE, -- Date the order was approved.\n CREATION_DATE_ORDERED DATE, -- Date the order was placed.\n TOTAL_AMOUNT NUMBER(18,2), -- Total order amount.\n NOTE_TO_VENDOR VARCHAR2(480), -- Note printed for the supplier.\n SHIP_TO_LOCATION_ID NUMBER, -- Ship-to location.\n BILL_TO_LOCATION_ID NUMBER, -- Bill-to location.\n FOB_LOOKUP_CODE VARCHAR2(25), -- Freight-on-board terms. Values: ORIGIN, DESTINATION.\n FREIGHT_TERMS_LOOKUP_CODE VARCHAR2(25), -- Who pays freight. Values: PAID, DUE.\n CANCEL_FLAG VARCHAR2(1), -- Y if the order was cancelled.\n CLOSED_DATE DATE, -- Date the order was closed.\n CLOSED_CODE VARCHAR2(25), -- Closure state of the order. Values: OPEN, CLOSED, FINALLY CLOSED.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\n"}, {"role": "user", "content": "Question: Which 5 business units have the highest biggest invoice amount in the last 90 days?\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT bu.BU_NAME, MAX(i.TOTAL_AMOUNT) AS MAX_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN FUN_BUSINESS_UNITS bu ON bu.BU_ID = i.ORG_ID\nWHERE i.INVOICE_DATE >= TRUNC(SYSDATE) - 90\nGROUP BY bu.BU_NAME\nORDER BY MAX_INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\nError: ORA-00904: \"I\".\"TOTAL_AMOUNT\": invalid identifier\nDiagnosis: None of your query's tables has a column meaning 'TOTAL_AMOUNT', but the schema has: PO_HEADERS_ALL.TOTAL_AMOUNT (Total order amount.) Join it to your query on PO_HEADER_ID, TERMS_ID, VENDOR_ID. AP_EXPENSE_REPORT_HEADERS_ALL.TOTAL (Total amount claimed.) Join it to your query on INVOICE_ID. Add that table to your query. I is AP_INVOICES_ALL, which has NO column named TOTAL_AMOUNT. Its columns are: INVOICE_ID, VENDOR_ID, VENDOR_SITE_ID, PARTY_ID, INVOICE_NUM, INVOICE_TYPE_LOOKUP_CODE, INVOICE_DATE, INVOICE_RECEIVED_DATE, GOODS_RECEIVED_DATE, GL_DATE, INVOICE_AMOUNT, AMOUNT_PAID, TOTAL_TAX_AMOUNT, BASE_AMOUNT, APPROVED_AMOUNT, AMOUNT_APPLICABLE_TO_DISCOUNT, DISCOUNT_AMOUNT_TAKEN, PREPAY_AMOUNT_REMAINING, SELF_ASSESSED_TAX_AMOUNT, INVOICE_CURRENCY_CODE, PAYMENT_CURRENCY_CODE, EXCHANGE_RATE, EXCHANGE_DATE, EXCHANGE_RATE_TYPE, TERMS_ID, TERMS_DATE, PAYMENT_METHOD_CODE, PAY_GROUP_LOOKUP_CODE, PAYMENT_STATUS_FLAG, DESCRIPTION, SOURCE, PO_HEADER_ID, BATCH_ID, VALIDATION_STATUS, WFAPPROVAL_STATUS, CANCELLED_DATE, CANCELLED_BY, ACCTS_PAY_CODE_COMBINATION_ID, LEDGER_ID, REQUESTER_ID, LEGAL_ENTITY_ID, DOC_SEQUENCE_VALUE, CREATION_DATE, CREATED_BY, LAST_UPDATE_DATE, LAST_UPDATED_BY, OBJECT_VERSION_NUMBER, ORG_ID, ATTRIBUTE_CATEGORY, ATTRIBUTE1, ATTRIBUTE2, ATTRIBUTE3, ATTRIBUTE4, ATTRIBUTE5, ATTRIBUTE6, ATTRIBUTE7, ATTRIBUTE8, ATTRIBUTE9, ATTRIBUTE10. Closest names: TOTAL_TAX_AMOUNT, BASE_AMOUNT, INVOICE_AMOUNT.\nWrite a corrected query. It must differ from the failed one. Use ONLY the tables and columns in the schema above, spelled exactly as shown; if a column you wanted does not exist, choose the closest one that does."}, {"role": "assistant", "content": "```sql\nSELECT bu.BU_NAME, MAX(i.INVOICE_AMOUNT) AS MAX_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN FUN_BUSINESS_UNITS bu ON bu.BU_ID = i.ORG_ID\nWHERE i.INVOICE_DATE >= TRUNC(SYSDATE) - 90\nGROUP BY bu.BU_NAME\nORDER BY MAX_INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "r-00036", "tier": "T3", "family": "spec-inv", "kind": "repair-exec", "source": "S6-repair", "group": "08a4c3b8d3e0", "tables": ["AP_INVOICES_ALL", "FUN_BUSINESS_UNITS"], "result_rows": 0, "approx_prompt_tokens": 3453, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"I\".\"TOTAL_AMOUNT\": invalid identifier", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n CURRENCY_CODE VARCHAR2(15), -- Currency the payment was made in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting payment currency to ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account the payment was drawn on. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n CHECKRUN_ID NUMBER, -- Payment process request identifier.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n ATTRIBUTE_CATEGORY VARCHAR2(30), -- Descriptive flexfield context (customer-defined extension fields).\n ATTRIBUTE1 VARCHAR2(150), -- Descriptive flexfield segment 1, customer-defined and normally unused.\n ATTRIBUTE2 VARCHAR2(150), -- Descriptive flexfield segment 2, customer-defined and normally unused.\n ATTRIBUTE3 VARCHAR2(150), -- Descriptive flexfield segment 3, customer-defined and normally unused.\n ATTRIBUTE4 VARCHAR2(150), -- Descriptive flexfield segment 4, customer-defined and normally unused.\n ATTRIBUTE5 VARCHAR2(150) -- Descriptive flexfield segment 5, customer-defined and normally unused.\n);\n\n-- Business units: organizational units that own transactions, with primary ledger and default currency.\nCREATE TABLE FUN_BUSINESS_UNITS (\n BU_ID NUMBER, -- Unique business unit identifier. Primary key.\n BU_NAME VARCHAR2(240), -- Business unit name. Values: US Operations, EMEA Operations, APAC Operations, Canada Operations, Shared Services.\n SHORT_CODE VARCHAR2(30), -- Short code of the business unit.\n PRIMARY_LEDGER_ID NUMBER, -- Ledger the business unit posts to. FK to GL_LEDGERS.LEDGER_ID.\n DEFAULT_CURRENCY_CODE VARCHAR2(15), -- Default currency of the business unit. FK to FND_CURRENCIES.CURRENCY_CODE.\n LEGAL_ENTITY_ID NUMBER, -- Legal entity the business unit belongs to.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n DATE_FROM DATE, -- Date the business unit becomes effective.\n DATE_TO DATE, -- Date the business unit stops being effective.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25) -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n-- voided payment => AP_CHECKS_ALL.STATUS_LOOKUP_CODE = 'VOIDED'\n"}, {"role": "user", "content": "Question: What is the average payment amount for each business unit excluding voided payments?\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT bu.BU_NAME, AVG(c.AMOUNT) AS AVG_PAYMENT_AMOUNT FROM AP_CHECKS_ALL c JOIN FUN_BUSINESS_UNITS bu ON bu.BU_ID = c.ORG_ID WHERE c.STATUS <> 'VOIDED' GROUP BY bu.BU_NAME ORDER BY AVG_PAYMENT_AMOUNT DESC FETCH FIRST 200 ROWS ONLY;\nError: ORA-00904: \"C\".\"STATUS\": invalid identifier\nDiagnosis: C is AP_CHECKS_ALL, which has NO column named STATUS. Its columns are: CHECK_ID, CHECK_NUMBER, VENDOR_ID, VENDOR_SITE_ID, VENDOR_NAME, CHECK_DATE, AMOUNT, BASE_AMOUNT, CURRENCY_CODE, EXCHANGE_RATE, PAYMENT_METHOD_CODE, PAYMENT_TYPE_FLAG, STATUS_LOOKUP_CODE, BANK_ACCOUNT_ID, EXTERNAL_BANK_ACCOUNT_ID, PAYMENT_ID, CLEARED_DATE, CLEARED_AMOUNT, VOID_DATE, VOID_REASON, STOPPED_DATE, FUTURE_PAY_DUE_DATE, CHECKRUN_NAME, CHECKRUN_ID, DOC_SEQUENCE_VALUE, CREATION_DATE, CREATED_BY, LAST_UPDATE_DATE, LAST_UPDATED_BY, OBJECT_VERSION_NUMBER, ORG_ID, ATTRIBUTE_CATEGORY, ATTRIBUTE1, ATTRIBUTE2, ATTRIBUTE3, ATTRIBUTE4, ATTRIBUTE5. Closest names: STATUS_LOOKUP_CODE, STOPPED_DATE.\nWrite a corrected query. It must differ from the failed one. Use ONLY the tables and columns in the schema above, spelled exactly as shown; if a column you wanted does not exist, choose the closest one that does."}, {"role": "assistant", "content": "```sql\nSELECT bu.BU_NAME, AVG(c.AMOUNT) AS AVG_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nJOIN FUN_BUSINESS_UNITS bu ON bu.BU_ID = c.ORG_ID\nWHERE c.STATUS_LOOKUP_CODE <> 'VOIDED'\nGROUP BY bu.BU_NAME\nORDER BY AVG_PAYMENT_AMOUNT DESC;\n```"}], "meta": {"id": "r-00010", "tier": "T2", "family": "spec-pay", "kind": "repair-exec", "source": "S6-repair", "group": "406646323e3b", "tables": ["AP_CHECKS_ALL", "FUN_BUSINESS_UNITS"], "result_rows": 0, "approx_prompt_tokens": 3170, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"C\".\"STATUS\": invalid identifier", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 18 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account the payment was drawn on. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n DOC_SEQUENCE_VALUE NUMBER -- Document sequence number of the payment.\n);\n\n-- Supplier bank accounts: external bank accounts that payments are sent to, with account holder, currency and validity dates.\n-- (showing 10 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXT_BANK_ACCOUNTS (\n EXT_BANK_ACCOUNT_ID NUMBER, -- Unique external bank account identifier. Primary key.\n BANK_PARTY_ID NUMBER, -- Bank holding the account. FK to CE_BANKS.BANK_PARTY_ID.\n ACCOUNT_OWNER_PARTY_ID NUMBER, -- Party that owns the account. FK to HZ_PARTIES.PARTY_ID.\n BANK_ACCOUNT_NAME VARCHAR2(80), -- Account holder name.\n CURRENCY_CODE VARCHAR2(15), -- Currency of the account. FK to FND_CURRENCIES.CURRENCY_CODE.\n COUNTRY_CODE VARCHAR2(2), -- Country of the account.\n START_DATE DATE, -- Date the account becomes valid.\n END_DATE DATE, -- Date the account stops being valid.\n ACCOUNT_SUFFIX VARCHAR2(30), -- Account suffix used by some banks.\n FOREIGN_PAYMENT_USE_FLAG VARCHAR2(1) -- Y if the account can receive foreign-currency payments.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n INT_BANK_ACCOUNT_ID NUMBER, -- Company bank account used. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXT_BANK_ACCOUNT_ID NUMBER, -- Payee bank account credited. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE, -- Date the payment was voided.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\n-- (showing 15 of 38 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n VENDOR_NAME VARCHAR2(360), -- Supplier name.\n SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\n VENDOR_TYPE_LOOKUP_CODE VARCHAR2(30), -- Supplier type. Values: VENDOR, CONTRACTOR, EMPLOYEE, TAX AUTHORITY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n START_DATE_ACTIVE DATE, -- Date the supplier becomes active.\n END_DATE_ACTIVE DATE, -- Date the supplier stops being active.\n ONE_TIME_FLAG VARCHAR2(1), -- Y if the supplier is a one-time supplier.\n SMALL_BUSINESS_FLAG VARCHAR2(1), -- Y if the supplier is a small business.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Default payment method for the supplier. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Default pay group. Values: DOMESTIC, INTERNATIONAL.\n TERMS_ID NUMBER, -- Default payment terms. FK to AP_TERMS_B.TERM_ID.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if all payments to the supplier are blocked.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2) -- Maximum credit extended to the supplier.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 16 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_ID NUMBER, -- Address of the site. FK to POZ_SUPPLIER_ADDRESSES.ADDRESS_ID.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Payment method for this site. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n INACTIVE_DATE DATE, -- Date the site becomes inactive.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n TOLERANCE_ID NUMBER, -- Matching tolerance applied at the site.\n BILL_TO_LOCATION_ID NUMBER, -- Default bill-to location.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 18 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n PARTY_ID NUMBER, -- Trading-community party of the supplier. FK to HZ_PARTIES.PARTY_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n PAYMENT_STATUS_FLAG VARCHAR2(1) -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n);\n\n-- Supplier addresses: physical and remit-to addresses of suppliers.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_ADDRESSES (\n ADDRESS_ID NUMBER, -- Unique address identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the address belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_NAME VARCHAR2(240), -- Name identifying the address.\n ADDRESS_LINE1 VARCHAR2(240), -- First address line.\n ADDRESS_LINE2 VARCHAR2(240), -- Second address line.\n CITY VARCHAR2(60), -- City.\n STATE VARCHAR2(60), -- State or province. Values: CA, NY, TX, WA, IL.\n POSTAL_CODE VARCHAR2(60), -- Postal or ZIP code.\n COUNTRY VARCHAR2(2), -- Country code.\n ADDRESS_PURPOSE VARCHAR2(30), -- What the address is used for. Values: REMIT_TO, PURCHASING, RFQ.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n LATITUDE NUMBER(12,6), -- Latitude of the address.\n LONGITUDE NUMBER(12,6) -- Longitude of the address.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- vendor spend / supplier spend => SUM(AP_INVOICES_ALL.INVOICE_AMOUNT) grouped by AP_INVOICES_ALL.VENDOR_ID (join POZ_SUPPLIERS for VENDOR_NAME)\n-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n"}, {"role": "user", "content": "Question: Show the 5 suppliers with the highest number of payments last year"}, {"role": "assistant", "content": "```sql\nSELECT s.VENDOR_NAME, COUNT(*) AS PAYMENT_COUNT\nFROM AP_CHECKS_ALL c\nJOIN POZ_SUPPLIERS s ON s.VENDOR_ID = c.VENDOR_ID\nWHERE c.CHECK_DATE >= ADD_MONTHS(TRUNC(SYSDATE, 'YYYY'), -12) AND c.CHECK_DATE < TRUNC(SYSDATE, 'YYYY')\nGROUP BY s.VENDOR_NAME\nORDER BY PAYMENT_COUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00867", "tier": "T3", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "c716f4691836", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIERS"], "result_rows": 5, "approx_prompt_tokens": 3104, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit billed.\n UNIT_MEAS_LOOKUP_CODE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\n PO_HEADER_ID NUMBER, -- Purchase order this line is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n PO_LINE_LOCATION_ID NUMBER, -- Purchase order schedule this line is matched to. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n TAX_CLASSIFICATION_CODE VARCHAR2(30), -- Tax classification of the line. Values: STANDARD, REDUCED, EXEMPT.\n TAX_RATE NUMBER(12,6), -- Tax rate applied to the line.\n TAX_RATE_ID NUMBER, -- Tax rate record applied. FK to ZX_RATES_B.TAX_RATE_ID.\n MATCH_TYPE VARCHAR2(25), -- How the line was matched. Values: ITEM_TO_PO, ITEM_TO_RECEIPT, NOT_MATCHED.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n SELF_ASSESSED_TAX_AMOUNT NUMBER(18,2), -- Tax the buyer self-assesses instead of paying to the supplier.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n LEGAL_ENTITY_ID NUMBER -- Legal entity the invoice belongs to.\n);\n\n-- Withholding tax groups: sets of withholding tax rates applied to supplier invoices.\nCREATE TABLE AP_AWT_GROUPS (\n GROUP_ID NUMBER, -- Unique withholding tax group identifier. Primary key.\n NAME VARCHAR2(25), -- Name of the withholding tax group.\n DESCRIPTION VARCHAR2(240), -- Description of the withholding group.\n INACTIVE_DATE DATE, -- Date the group stops being valid.\n TAX_AUTHORITY VARCHAR2(80), -- Tax authority receiving the withheld tax. Values: IRS, HMRC, CRA.\n WITHHOLDING_RATE NUMBER(12,6), -- Default withholding percentage for the group.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Transaction tax lines: the tax calculated on each invoice line, with taxable amount, rate, tax amount and recoverability.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE ZX_LINES (\n TAX_LINE_ID NUMBER, -- Unique tax line identifier. Primary key.\n TRX_ID NUMBER, -- Invoice the tax line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n TRX_LINE_ID NUMBER, -- Invoice line the tax was calculated on. FK to AP_INVOICE_LINES_ALL.INVOICE_LINE_ID.\n TAX_RATE_ID NUMBER, -- Rate applied. FK to ZX_RATES_B.TAX_RATE_ID.\n TAX_ID NUMBER, -- Tax applied. FK to ZX_TAXES_B.TAX_ID.\n TAX_RATE NUMBER(12,6), -- Tax percentage applied.\n TAXABLE_AMT NUMBER(18,2), -- Amount the tax was calculated on.\n TAX_AMT NUMBER(18,2), -- Tax amount.\n TAX_AMT_TAX_CURR NUMBER(18,2), -- Tax amount in the tax currency.\n TAX_CURRENCY_CODE VARCHAR2(15), -- Currency of the tax amount. FK to FND_CURRENCIES.CURRENCY_CODE.\n TAX_DATE DATE, -- Date used to determine the tax rate.\n TAX_JURISDICTION_CODE VARCHAR2(30), -- Jurisdiction the tax was levied by. Values: FEDERAL, STATE, COUNTRY.\n RECOVERABLE_FLAG VARCHAR2(1), -- Y if the tax is recoverable.\n SELF_ASSESSED_FLAG VARCHAR2(1), -- Y if the tax is self-assessed.\n TAX_STATUS_CODE VARCHAR2(30) -- Tax status applied. Values: STANDARD, REDUCED, ZERO.\n);\n\n-- Taxes: tax definitions such as VAT, GST and sales tax by jurisdiction.\nCREATE TABLE ZX_TAXES_B (\n TAX_ID NUMBER, -- Unique tax identifier. Primary key.\n TAX VARCHAR2(30), -- Tax code such as VAT or GST. Values: VAT, GST, SALES TAX, CONSUMPTION TAX.\n TAX_REGIME_CODE VARCHAR2(30), -- Tax regime the tax belongs to. Values: US-SALES, UK-VAT, CA-GST, EU-VAT.\n TAX_TYPE_CODE VARCHAR2(30), -- Tax type classification. Values: VAT, SALES, GST.\n TAX_JURISDICTION_CODE VARCHAR2(30), -- Jurisdiction levying the tax. Values: FEDERAL, STATE, COUNTRY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the tax is active.\n EFFECTIVE_FROM DATE, -- Date the tax becomes effective.\n EFFECTIVE_TO DATE, -- Date the tax stops applying.\n RECOVERABLE_FLAG VARCHAR2(1), -- Y if the tax can be recovered from the authority.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Supplier addresses: physical and remit-to addresses of suppliers.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_ADDRESSES (\n ADDRESS_ID NUMBER, -- Unique address identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the address belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_NAME VARCHAR2(240), -- Name identifying the address.\n ADDRESS_LINE1 VARCHAR2(240), -- First address line.\n ADDRESS_LINE2 VARCHAR2(240), -- Second address line.\n CITY VARCHAR2(60), -- City.\n STATE VARCHAR2(60), -- State or province. Values: CA, NY, TX, WA, IL.\n POSTAL_CODE VARCHAR2(60), -- Postal or ZIP code.\n COUNTRY VARCHAR2(2), -- Country code.\n ADDRESS_PURPOSE VARCHAR2(30), -- What the address is used for. Values: REMIT_TO, PURCHASING, RFQ.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n LATITUDE NUMBER(12,6), -- Latitude of the address.\n LONGITUDE NUMBER(12,6) -- Longitude of the address.\n);\n\n-- Tax rates: rate percentage per tax and status, with recovery and accounting settings.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE ZX_RATES_B (\n TAX_RATE_ID NUMBER, -- Unique tax rate identifier. Primary key.\n TAX_ID NUMBER, -- Tax the rate belongs to. FK to ZX_TAXES_B.TAX_ID.\n TAX_RATE_CODE VARCHAR2(30), -- Tax rate code. Values: STANDARD, REDUCED, ZERO, EXEMPT.\n TAX_STATUS_CODE VARCHAR2(30), -- Tax status the rate applies under. Values: STANDARD, REDUCED, ZERO.\n PERCENTAGE_RATE NUMBER(12,6), -- Tax percentage.\n EFFECTIVE_FROM DATE, -- Date the rate becomes effective.\n EFFECTIVE_TO DATE, -- Date the rate stops applying.\n ACTIVE_FLAG VARCHAR2(1), -- Y if the rate is active.\n TAX_ACCOUNT_CCID NUMBER, -- Account tax is posted to. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n RECOVERY_TYPE_CODE VARCHAR2(30), -- Recovery treatment. Values: STANDARD, PARTIAL.\n DEFAULT_RECOVERY_RATE NUMBER(12,6) -- Default recoverable percentage.\n);\n\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 15 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_CODE VARCHAR2(15), -- Short site code.\n ADDRESS_ID NUMBER, -- Address of the site. FK to POZ_SUPPLIER_ADDRESSES.ADDRESS_ID.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Default invoice currency at this site. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n SHIP_TO_LOCATION_ID NUMBER, -- Default ship-to location for purchase orders.\n BILL_TO_LOCATION_ID NUMBER, -- Default bill-to location.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n-- supplier state / vendor state / by state => POZ_SUPPLIER_ADDRESSES.STATE (join on VENDOR_ID)\n"}, {"role": "user", "content": "Question: Total tax on invoices by supplier city for invoices over 10,000"}, {"role": "assistant", "content": "```sql\nSELECT a.CITY, SUM(i.TOTAL_TAX_AMOUNT) AS TOTAL_TAX_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = i.VENDOR_ID\nWHERE i.INVOICE_AMOUNT > 10000\nGROUP BY a.CITY\nORDER BY TOTAL_TAX_AMOUNT DESC;\n```"}], "meta": {"id": "a-00741", "tier": "T2", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "83e83d8604b2", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 7, "approx_prompt_tokens": 3077, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n CURRENCY_CODE VARCHAR2(15), -- Currency the payment was made in. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n VOID_DATE DATE, -- Date the payment was voided.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n);\n\n-- Supplier bank accounts: external bank accounts that payments are sent to, with account holder, currency and validity dates.\n-- (showing 10 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXT_BANK_ACCOUNTS (\n EXT_BANK_ACCOUNT_ID NUMBER, -- Unique external bank account identifier. Primary key.\n BANK_PARTY_ID NUMBER, -- Bank holding the account. FK to CE_BANKS.BANK_PARTY_ID.\n ACCOUNT_OWNER_PARTY_ID NUMBER, -- Party that owns the account. FK to HZ_PARTIES.PARTY_ID.\n BANK_ACCOUNT_NAME VARCHAR2(80), -- Account holder name.\n CURRENCY_CODE VARCHAR2(15), -- Currency of the account. FK to FND_CURRENCIES.CURRENCY_CODE.\n COUNTRY_CODE VARCHAR2(2), -- Country of the account.\n START_DATE DATE, -- Date the account becomes valid.\n END_DATE DATE, -- Date the account stops being valid.\n ACCOUNT_SUFFIX VARCHAR2(30), -- Account suffix used by some banks.\n FOREIGN_PAYMENT_USE_FLAG VARCHAR2(1), -- Y if the account can receive foreign-currency payments.\n);\n\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 15 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_ID NUMBER, -- Address of the site. FK to POZ_SUPPLIER_ADDRESSES.ADDRESS_ID.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Payment method for this site. Values: CHECK, EFT, WIRE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n ALWAYS_TAKE_DISC_FLAG VARCHAR2(1), -- Y if the early-payment discount is always taken.\n TOLERANCE_ID NUMBER, -- Matching tolerance applied at the site.\n SHIP_TO_LOCATION_ID NUMBER, -- Default ship-to location for purchase orders.\n BILL_TO_LOCATION_ID NUMBER, -- Default bill-to location.\n);\n\n-- Payees: the payment-engine record linking a supplier or site to its payment defaults (method, delivery channel, bank instructions).\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXTERNAL_PAYEES_ALL (\n EXT_PAYEE_ID NUMBER, -- Unique payee identifier. Primary key.\n PAYEE_PARTY_ID NUMBER, -- Party being paid. FK to HZ_PARTIES.PARTY_ID.\n SUPPLIER_SITE_ID NUMBER, -- Supplier site the payee record represents. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n PAYMENT_FUNCTION VARCHAR2(30), -- Payment function the payee is used for. Values: PAYABLES_DISB, EMPLOYEE_EXP.\n DEFAULT_PAYMENT_METHOD_CODE VARCHAR2(30), -- Default payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_FORMAT_CODE VARCHAR2(30), -- Format used for payment files. Values: NACHA, SEPA, POSITIVE PAY.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Default bank delivery channel. Values: ACH, CHAPS, SEPA.\n BANK_INSTRUCTION1_CODE VARCHAR2(30), -- First bank instruction code.\n REMIT_ADVICE_DELIVERY_METHOD VARCHAR2(30), -- How remittance advice is delivered. Values: EMAIL, PRINT.\n REMIT_ADVICE_EMAIL VARCHAR2(255), -- Email address remittance advice is sent to.\n INACTIVE_DATE DATE, -- Date the payee record stops being valid.\n);\n\n-- Supplier addresses: physical and remit-to addresses of suppliers.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_ADDRESSES (\n ADDRESS_ID NUMBER, -- Unique address identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the address belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_NAME VARCHAR2(240), -- Name identifying the address.\n ADDRESS_LINE1 VARCHAR2(240), -- First address line.\n ADDRESS_LINE2 VARCHAR2(240), -- Second address line.\n CITY VARCHAR2(60), -- City.\n STATE VARCHAR2(60), -- State or province. Values: CA, NY, TX, WA, IL.\n POSTAL_CODE VARCHAR2(60), -- Postal or ZIP code.\n COUNTRY VARCHAR2(2), -- Country code.\n ADDRESS_PURPOSE VARCHAR2(30), -- What the address is used for. Values: REMIT_TO, PURCHASING, RFQ.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n LATITUDE NUMBER(12,6), -- Latitude of the address.\n LONGITUDE NUMBER(12,6), -- Longitude of the address.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n SELF_ASSESSED_TAX_AMOUNT NUMBER(18,2), -- Tax the buyer self-assesses instead of paying to the supplier.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice will be paid in. FK to FND_CURRENCIES.CURRENCY_CODE.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n PO_HEADER_ID NUMBER, -- Purchase order the invoice is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n ACCTS_PAY_CODE_COMBINATION_ID NUMBER, -- Liability (accounts payable) account for the invoice. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\n-- (showing 15 of 38 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n VENDOR_NAME VARCHAR2(360), -- Supplier name.\n VENDOR_NAME_ALT VARCHAR2(320), -- Alternate or trading name of the supplier.\n VENDOR_TYPE_LOOKUP_CODE VARCHAR2(30), -- Supplier type. Values: VENDOR, CONTRACTOR, EMPLOYEE, TAX AUTHORITY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n ONE_TIME_FLAG VARCHAR2(1), -- Y if the supplier is a one-time supplier.\n SMALL_BUSINESS_FLAG VARCHAR2(1), -- Y if the supplier is a small business.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Default payment method for the supplier. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Default pay group. Values: DOMESTIC, INTERNATIONAL.\n TERMS_ID NUMBER, -- Default payment terms. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Default payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if all payments to the supplier are blocked.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n FEDERAL_REPORTABLE_FLAG VARCHAR2(1), -- Y if the supplier is reportable for federal income tax.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2), -- Maximum credit extended to the supplier.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n EXT_BANK_ACCOUNT_ID NUMBER, -- Payee bank account credited. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE, -- Date the payment was voided.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- voided payment => AP_CHECKS_ALL.STATUS_LOOKUP_CODE = 'VOIDED'\n-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n-- vendor spend / supplier spend => SUM(AP_INVOICES_ALL.INVOICE_AMOUNT) grouped by AP_INVOICES_ALL.VENDOR_ID (join POZ_SUPPLIERS for VENDOR_NAME)\n"}, {"role": "user", "content": "Question: Suppliers that have both a voided payment and any payment"}, {"role": "assistant", "content": "```sql\nSELECT DISTINCT s.VENDOR_NAME\nFROM POZ_SUPPLIERS s\nWHERE EXISTS (SELECT 1 FROM AP_CHECKS_ALL c WHERE c.VENDOR_ID = s.VENDOR_ID AND c.STATUS_LOOKUP_CODE = 'VOIDED')\nAND EXISTS (SELECT 1 FROM AP_CHECKS_ALL c WHERE c.VENDOR_ID = s.VENDOR_ID)\nORDER BY s.VENDOR_NAME;\n```"}], "meta": {"id": "a-01622", "tier": "T4", "family": "t4-logic", "kind": "ask", "source": "S2-templated", "group": "b5a82f7a39e9", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIERS"], "result_rows": 6, "approx_prompt_tokens": 3084, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice is denominated in. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice will be paid in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n EXCHANGE_RATE_TYPE VARCHAR2(30), -- Type of exchange rate used. Values: Corporate, Spot, User.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAYMENT_STATUS_FLAG VARCHAR2(1) -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n CURRENCY_CODE VARCHAR2(15), -- Currency the payment was made in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting payment currency to ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account the payment was drawn on. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n DOC_SEQUENCE_VALUE NUMBER -- Document sequence number of the payment.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n INT_BANK_ACCOUNT_ID NUMBER, -- Company bank account used. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE -- Date the payment was voided.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n-- days to pay => AP_CHECKS_ALL.CHECK_DATE - AP_INVOICES_ALL.INVOICE_DATE (join AP_INVOICE_PAYMENTS_ALL on INVOICE_ID and CHECK_ID)\n-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n"}, {"role": "user", "content": "Question: What is the number of invoices for each payment term for invoices in a foreign currency?"}, {"role": "assistant", "content": "```sql\nSELECT t.NAME, COUNT(*) AS INVOICE_COUNT\nFROM AP_INVOICES_ALL i\nJOIN AP_TERMS_B t ON t.TERM_ID = i.TERMS_ID\nWHERE i.INVOICE_CURRENCY_CODE <> 'USD'\nGROUP BY t.NAME\nORDER BY INVOICE_COUNT DESC;\n```"}], "meta": {"id": "a-00400", "tier": "T2", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "2f8e50ecefcb", "tables": ["AP_INVOICES_ALL", "AP_TERMS_B"], "result_rows": 10, "approx_prompt_tokens": 2908, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n BATCH_ID NUMBER -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice batches: groups of invoices entered together, with control totals and entry status.\nCREATE TABLE AP_BATCHES_ALL (\n BATCH_ID NUMBER, -- Unique invoice batch identifier. Primary key.\n BATCH_NAME VARCHAR2(50), -- Name of the batch.\n BATCH_DATE DATE, -- Date the batch was created.\n INVOICE_COUNT NUMBER, -- Number of invoices entered in the batch.\n INVOICE_AMOUNT NUMBER(18,2), -- Total amount of the invoices in the batch.\n CONTROL_INVOICE_COUNT NUMBER, -- Expected invoice count entered as a control total.\n CONTROL_INVOICE_AMOUNT NUMBER(18,2), -- Expected batch amount entered as a control total.\n BATCH_STATUS VARCHAR2(25), -- Status of the batch. Values: OPEN, CLOSED, POSTED.\n SOURCE VARCHAR2(80), -- Source of the batch. Values: MANUAL, IMPORT, SUPPLIER PORTAL.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_NUMBER NUMBER, -- Sequence of the line within the invoice.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n DESCRIPTION VARCHAR2(240), -- Description of the goods or service on the line.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit billed.\n UNIT_MEAS_LOOKUP_CODE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\n ACCOUNTING_DATE DATE, -- Accounting date of the line.\n TAX_RATE NUMBER(12,6), -- Tax rate applied to the line.\n PRODUCT_CATEGORY VARCHAR2(80), -- Category of the product or service. Values: IT EQUIPMENT, OFFICE SUPPLIES, PROFESSIONAL SERVICES, LOGISTICS.\n REQUESTER_ID NUMBER, -- Employee who requested the line item. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n CHECKRUN_ID NUMBER, -- Payment process request identifier.\n DOC_SEQUENCE_VALUE NUMBER -- Document sequence number of the payment.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- days to pay => AP_CHECKS_ALL.CHECK_DATE - AP_INVOICES_ALL.INVOICE_DATE (join AP_INVOICE_PAYMENTS_ALL on INVOICE_ID and CHECK_ID)\n"}, {"role": "user", "content": "Question: What is the largest of the fully paid invoices?"}, {"role": "assistant", "content": "```sql\nSELECT MAX(i.INVOICE_AMOUNT)\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_ID NOT IN (SELECT ps.INVOICE_ID FROM AP_PAYMENT_SCHEDULES_ALL ps WHERE ps.AMOUNT_REMAINING > 0);\n```"}], "meta": {"id": "a-01508", "tier": "T5", "family": "t5-glossary", "kind": "ask", "source": "S2-templated", "group": "2acf62131dd8", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL"], "result_rows": 1, "approx_prompt_tokens": 3080, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice will be paid in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n EXCHANGE_RATE_TYPE VARCHAR2(30), -- Type of exchange rate used. Values: Corporate, Spot, User.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n BATCH_ID NUMBER -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n);\n\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_NUMBER NUMBER, -- Sequence of the line within the invoice.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit billed.\n UNIT_MEAS_LOOKUP_CODE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\n PO_LINE_ID NUMBER, -- Purchase order line this line is matched to. FK to PO_LINES_ALL.PO_LINE_ID.\n PO_LINE_LOCATION_ID NUMBER, -- Purchase order schedule this line is matched to. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n TAX_RATE NUMBER(12,6), -- Tax rate applied to the line.\n PRODUCT_CATEGORY VARCHAR2(80), -- Category of the product or service. Values: IT EQUIPMENT, OFFICE SUPPLIES, PROFESSIONAL SERVICES, LOGISTICS.\n REQUESTER_ID NUMBER, -- Employee who requested the line item. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n MATCH_TYPE VARCHAR2(25) -- How the line was matched. Values: ITEM_TO_PO, ITEM_TO_RECEIPT, NOT_MATCHED.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\n-- (showing 15 of 38 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n VENDOR_NAME VARCHAR2(360), -- Supplier name.\n SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\n VENDOR_TYPE_LOOKUP_CODE VARCHAR2(30), -- Supplier type. Values: VENDOR, CONTRACTOR, EMPLOYEE, TAX AUTHORITY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n ONE_TIME_FLAG VARCHAR2(1), -- Y if the supplier is a one-time supplier.\n SMALL_BUSINESS_FLAG VARCHAR2(1), -- Y if the supplier is a small business.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Default payment method for the supplier. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Default pay group. Values: DOMESTIC, INTERNATIONAL.\n TERMS_ID NUMBER, -- Default payment terms. FK to AP_TERMS_B.TERM_ID.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Default invoice currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if all payments to the supplier are blocked.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n FEDERAL_REPORTABLE_FLAG VARCHAR2(1), -- Y if the supplier is reportable for federal income tax.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2) -- Maximum credit extended to the supplier.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n CURRENCY_CODE VARCHAR2(15), -- Currency the payment was made in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting payment currency to ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment process request identifier.\n DOC_SEQUENCE_VALUE NUMBER -- Document sequence number of the payment.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- vendor spend / supplier spend => SUM(AP_INVOICES_ALL.INVOICE_AMOUNT) grouped by AP_INVOICES_ALL.VENDOR_ID (join POZ_SUPPLIERS for VENDOR_NAME)\n-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: Top 5 suppliers by invoice count counting only USD invoices"}, {"role": "assistant", "content": "```sql\nSELECT s.VENDOR_NAME, COUNT(*) AS INVOICE_COUNT\nFROM AP_INVOICES_ALL i\nJOIN POZ_SUPPLIERS s ON s.VENDOR_ID = i.VENDOR_ID\nWHERE i.INVOICE_CURRENCY_CODE = 'USD'\nGROUP BY s.VENDOR_NAME\nORDER BY INVOICE_COUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00665", "tier": "T2", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "fbb3eae80e9d", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 5, "approx_prompt_tokens": 2875, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n PARTY_ID NUMBER, -- Trading-community party of the supplier. FK to HZ_PARTIES.PARTY_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n SELF_ASSESSED_TAX_AMOUNT NUMBER(18,2), -- Tax the buyer self-assesses instead of paying to the supplier.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice is denominated in. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice will be paid in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n EXCHANGE_RATE_TYPE VARCHAR2(30), -- Type of exchange rate used. Values: Corporate, Spot, User.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n SOURCE VARCHAR2(80), -- How the invoice entered the system. Values: MANUAL, IMPORT, SUPPLIER PORTAL, EMAIL.\n PO_HEADER_ID NUMBER, -- Purchase order the invoice is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n VALIDATION_STATUS VARCHAR2(25), -- Result of invoice validation. Values: VALIDATED, NEEDS REVALIDATION, NEVER VALIDATED.\n WFAPPROVAL_STATUS VARCHAR2(25), -- Approval workflow status of the invoice. Values: APPROVED, NOT REQUIRED, REJECTED, INITIATED.\n CANCELLED_DATE DATE, -- Date the invoice was cancelled; NULL if not cancelled.\n CANCELLED_BY VARCHAR2(64), -- User who cancelled the invoice.\n ACCTS_PAY_CODE_COMBINATION_ID NUMBER, -- Liability (accounts payable) account for the invoice. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n LEDGER_ID NUMBER, -- Ledger the invoice is accounted in. FK to GL_LEDGERS.LEDGER_ID.\n REQUESTER_ID NUMBER, -- Employee who requested the goods or services. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n LEGAL_ENTITY_ID NUMBER, -- Legal entity the invoice belongs to.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number assigned to the invoice.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n ATTRIBUTE_CATEGORY VARCHAR2(30), -- Descriptive flexfield context (customer-defined extension fields).\n ATTRIBUTE1 VARCHAR2(150), -- Descriptive flexfield segment 1, customer-defined and normally unused.\n ATTRIBUTE2 VARCHAR2(150), -- Descriptive flexfield segment 2, customer-defined and normally unused.\n ATTRIBUTE3 VARCHAR2(150), -- Descriptive flexfield segment 3, customer-defined and normally unused.\n ATTRIBUTE4 VARCHAR2(150), -- Descriptive flexfield segment 4, customer-defined and normally unused.\n ATTRIBUTE5 VARCHAR2(150), -- Descriptive flexfield segment 5, customer-defined and normally unused.\n ATTRIBUTE6 VARCHAR2(150), -- Descriptive flexfield segment 6, customer-defined and normally unused.\n ATTRIBUTE7 VARCHAR2(150), -- Descriptive flexfield segment 7, customer-defined and normally unused.\n ATTRIBUTE8 VARCHAR2(150), -- Descriptive flexfield segment 8, customer-defined and normally unused.\n ATTRIBUTE9 VARCHAR2(150), -- Descriptive flexfield segment 9, customer-defined and normally unused.\n ATTRIBUTE10 VARCHAR2(150), -- Descriptive flexfield segment 10, customer-defined and normally unused.\n);\n\n-- Supplier addresses: physical and remit-to addresses of suppliers.\nCREATE TABLE POZ_SUPPLIER_ADDRESSES (\n ADDRESS_ID NUMBER, -- Unique address identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the address belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_NAME VARCHAR2(240), -- Name identifying the address.\n ADDRESS_LINE1 VARCHAR2(240), -- First address line.\n ADDRESS_LINE2 VARCHAR2(240), -- Second address line.\n CITY VARCHAR2(60), -- City.\n STATE VARCHAR2(60), -- State or province. Values: CA, NY, TX, WA, IL.\n POSTAL_CODE VARCHAR2(60), -- Postal or ZIP code.\n COUNTRY VARCHAR2(2), -- Country code.\n ADDRESS_PURPOSE VARCHAR2(30), -- What the address is used for. Values: REMIT_TO, PURCHASING, RFQ.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n LATITUDE NUMBER(12,6), -- Latitude of the address.\n LONGITUDE NUMBER(12,6), -- Longitude of the address.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Purchase order schedules: delivery schedules of a line with need-by date, quantity received and billed, and the matching option (two-, three- or four-way).\n-- (showing 15 of 22 columns: join keys + those relevant to the question)\nCREATE TABLE PO_LINE_LOCATIONS_ALL (\n LINE_LOCATION_ID NUMBER, -- Unique schedule identifier. Primary key.\n SHIPMENT_NUM NUMBER, -- Schedule number within the line.\n QUANTITY NUMBER, -- Quantity scheduled.\n QUANTITY_RECEIVED NUMBER, -- Quantity received so far.\n QUANTITY_BILLED NUMBER, -- Quantity invoiced so far.\n QUANTITY_CANCELLED NUMBER, -- Quantity cancelled.\n NEED_BY_DATE DATE, -- Date the goods are needed.\n PROMISED_DATE DATE, -- Date the supplier promised delivery.\n PRICE_OVERRIDE NUMBER(18,2), -- Price for this schedule if different from the line.\n INVOICE_MATCH_OPTION VARCHAR2(1), -- P match to order (two-way), R match to receipt (three-way). Values: R, P.\n RECEIPT_REQUIRED_FLAG VARCHAR2(1), -- Y if receipt is required before payment.\n TAXABLE_FLAG VARCHAR2(1), -- Y if the schedule is taxable.\n SHIP_TO_LOCATION_ID NUMBER, -- Where the goods are delivered.\n CLOSED_CODE VARCHAR2(25), -- Closure state of the schedule. Values: OPEN, CLOSED FOR RECEIVING, CLOSED.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice batches: groups of invoices entered together, with control totals and entry status.\nCREATE TABLE AP_BATCHES_ALL (\n BATCH_ID NUMBER, -- Unique invoice batch identifier. Primary key.\n BATCH_NAME VARCHAR2(50), -- Name of the batch.\n BATCH_DATE DATE, -- Date the batch was created.\n INVOICE_COUNT NUMBER, -- Number of invoices entered in the batch.\n INVOICE_AMOUNT NUMBER(18,2), -- Total amount of the invoices in the batch.\n CONTROL_INVOICE_COUNT NUMBER, -- Expected invoice count entered as a control total.\n CONTROL_INVOICE_AMOUNT NUMBER(18,2), -- Expected batch amount entered as a control total.\n BATCH_STATUS VARCHAR2(25), -- Status of the batch. Values: OPEN, CLOSED, POSTED.\n SOURCE VARCHAR2(80), -- Source of the batch. Values: MANUAL, IMPORT, SUPPLIER PORTAL.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- vendor spend / supplier spend => SUM(AP_INVOICES_ALL.INVOICE_AMOUNT) grouped by AP_INVOICES_ALL.VENDOR_ID (join POZ_SUPPLIERS for VENDOR_NAME)\n-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n"}, {"role": "user", "content": "Question: Show the 5 supplier cities with the highest largest invoice amount this month\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT a.CITY, MAX(i.INVOICE_AMOUNT) AS MAX_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = i.VENDOR_ID\nWHERE i.INVOICE_CREATION_DATE >= TRUNC(SYSDATE, 'MM')\nGROUP BY a.CITY\nORDER BY MAX_INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\nError: ORA-00904: \"I\".\"INVOICE_CREATION_DATE\": invalid identifier\nDiagnosis: I is AP_INVOICES_ALL, which has NO column named INVOICE_CREATION_DATE. Its columns are: INVOICE_ID, VENDOR_ID, VENDOR_SITE_ID, PARTY_ID, INVOICE_NUM, INVOICE_TYPE_LOOKUP_CODE, INVOICE_DATE, INVOICE_RECEIVED_DATE, GOODS_RECEIVED_DATE, GL_DATE, INVOICE_AMOUNT, AMOUNT_PAID, TOTAL_TAX_AMOUNT, BASE_AMOUNT, APPROVED_AMOUNT, AMOUNT_APPLICABLE_TO_DISCOUNT, DISCOUNT_AMOUNT_TAKEN, PREPAY_AMOUNT_REMAINING, SELF_ASSESSED_TAX_AMOUNT, INVOICE_CURRENCY_CODE, PAYMENT_CURRENCY_CODE, EXCHANGE_RATE, EXCHANGE_DATE, EXCHANGE_RATE_TYPE, TERMS_ID, TERMS_DATE, PAYMENT_METHOD_CODE, PAY_GROUP_LOOKUP_CODE, PAYMENT_STATUS_FLAG, DESCRIPTION, SOURCE, PO_HEADER_ID, BATCH_ID, VALIDATION_STATUS, WFAPPROVAL_STATUS, CANCELLED_DATE, CANCELLED_BY, ACCTS_PAY_CODE_COMBINATION_ID, LEDGER_ID, REQUESTER_ID, LEGAL_ENTITY_ID, DOC_SEQUENCE_VALUE, CREATION_DATE, CREATED_BY, LAST_UPDATE_DATE, LAST_UPDATED_BY, OBJECT_VERSION_NUMBER, ORG_ID, ATTRIBUTE_CATEGORY, ATTRIBUTE1, ATTRIBUTE2, ATTRIBUTE3, ATTRIBUTE4, ATTRIBUTE5, ATTRIBUTE6, ATTRIBUTE7, ATTRIBUTE8, ATTRIBUTE9, ATTRIBUTE10. Closest names: CREATION_DATE, INVOICE_RECEIVED_DATE, INVOICE_DATE.\nWrite a corrected query. It must differ from the failed one. Use ONLY the tables and columns in the schema above, spelled exactly as shown; if a column you wanted does not exist, choose the closest one that does."}, {"role": "assistant", "content": "```sql\nSELECT a.CITY, MAX(i.INVOICE_AMOUNT) AS MAX_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = i.VENDOR_ID\nWHERE i.INVOICE_DATE >= TRUNC(SYSDATE, 'MM')\nGROUP BY a.CITY\nORDER BY MAX_INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "r-00003", "tier": "T3", "family": "spec-inv", "kind": "repair-exec", "source": "S6-repair", "group": "b70f1872b3f9", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 0, "approx_prompt_tokens": 3411, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"I\".\"INVOICE_CREATION_DATE\": invalid identifier", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment history: status changes and accounting events for each payment (created, cleared, voided, reconciled).\n-- (showing 12 of 17 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_HISTORY_ALL (\n PAYMENT_HISTORY_ID NUMBER, -- Unique payment history identifier. Primary key.\n CHECK_ID NUMBER, -- Payment the history row describes. FK to AP_CHECKS_ALL.CHECK_ID.\n TRANSACTION_TYPE VARCHAR2(25), -- Kind of event recorded. Values: PAYMENT CREATED, PAYMENT CLEARING, PAYMENT UNCLEARING, PAYMENT CANCELLED.\n TRANSACTION_DATE DATE, -- Date of the event.\n ACCOUNTING_DATE DATE, -- Accounting date of the event.\n TRX_BANK_AMOUNT NUMBER(18,2), -- Amount at the bank for the event.\n TRX_PMT_AMOUNT NUMBER(18,2), -- Amount in payment currency for the event.\n HISTORICAL_FLAG VARCHAR2(1), -- Y if the row is superseded by a later event.\n POSTED_FLAG VARCHAR2(1), -- Y if the event was accounted.\n REV_PMT_HIST_ID NUMBER, -- Payment history row this event reverses.\n BANK_CURRENCY_CODE VARCHAR2(15), -- Currency of the bank statement line. FK to FND_CURRENCIES.CURRENCY_CODE.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting payment currency to ledger currency.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account the payment was drawn on. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n DOC_SEQUENCE_VALUE NUMBER -- Document sequence number of the payment.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150) -- Message printed on the remittance advice.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 18 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice will be paid in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n EXCHANGE_RATE_TYPE VARCHAR2(30), -- Type of exchange rate used. Values: Corporate, Spot, User.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_STATUS_FLAG VARCHAR2(1) -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n INT_BANK_ACCOUNT_ID NUMBER, -- Company bank account used. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXT_BANK_ACCOUNT_ID NUMBER, -- Payee bank account credited. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE, -- Date the payment was voided.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n"}, {"role": "user", "content": "Question: Number of payments per quarter over the last year"}, {"role": "assistant", "content": "```sql\nSELECT TRUNC(c.CHECK_DATE, 'Q') AS QUARTER_START, COUNT(*) AS PAYMENT_COUNT\nFROM AP_CHECKS_ALL c\nWHERE c.CHECK_DATE >= ADD_MONTHS(TRUNC(SYSDATE), -12)\nGROUP BY TRUNC(c.CHECK_DATE, 'Q')\nORDER BY QUARTER_START;\n```"}], "meta": {"id": "a-01007", "tier": "T3", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "279e4dcea47b", "tables": ["AP_CHECKS_ALL"], "result_rows": 4, "approx_prompt_tokens": 2867, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payment history: status changes and accounting events for each payment (created, cleared, voided, reconciled).\n-- (showing 12 of 17 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_HISTORY_ALL (\n PAYMENT_HISTORY_ID NUMBER, -- Unique payment history identifier. Primary key.\n CHECK_ID NUMBER, -- Payment the history row describes. FK to AP_CHECKS_ALL.CHECK_ID.\n TRANSACTION_TYPE VARCHAR2(25), -- Kind of event recorded. Values: PAYMENT CREATED, PAYMENT CLEARING, PAYMENT UNCLEARING, PAYMENT CANCELLED.\n TRANSACTION_DATE DATE, -- Date of the event.\n ACCOUNTING_DATE DATE, -- Accounting date of the event.\n TRX_BANK_AMOUNT NUMBER(18,2), -- Amount at the bank for the event.\n TRX_PMT_AMOUNT NUMBER(18,2), -- Amount in payment currency for the event.\n HISTORICAL_FLAG VARCHAR2(1), -- Y if the row is superseded by a later event.\n POSTED_FLAG VARCHAR2(1), -- Y if the event was accounted.\n REV_PMT_HIST_ID NUMBER, -- Payment history row this event reverses.\n BANK_CURRENCY_CODE VARCHAR2(15), -- Currency of the bank statement line. FK to FND_CURRENCIES.CURRENCY_CODE.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n);\n\n-- Tax rates: rate percentage per tax and status, with recovery and accounting settings.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE ZX_RATES_B (\n TAX_RATE_ID NUMBER, -- Unique tax rate identifier. Primary key.\n TAX_ID NUMBER, -- Tax the rate belongs to. FK to ZX_TAXES_B.TAX_ID.\n TAX_RATE_CODE VARCHAR2(30), -- Tax rate code. Values: STANDARD, REDUCED, ZERO, EXEMPT.\n TAX_STATUS_CODE VARCHAR2(30), -- Tax status the rate applies under. Values: STANDARD, REDUCED, ZERO.\n PERCENTAGE_RATE NUMBER(12,6), -- Tax percentage.\n EFFECTIVE_FROM DATE, -- Date the rate becomes effective.\n EFFECTIVE_TO DATE, -- Date the rate stops applying.\n ACTIVE_FLAG VARCHAR2(1), -- Y if the rate is active.\n TAX_ACCOUNT_CCID NUMBER, -- Account tax is posted to. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n RECOVERY_TYPE_CODE VARCHAR2(30), -- Recovery treatment. Values: STANDARD, PARTIAL.\n DEFAULT_RECOVERY_RATE NUMBER(12,6), -- Default recoverable percentage.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account the payment was drawn on. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n INT_BANK_ACCOUNT_ID NUMBER, -- Company bank account used. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE, -- Date the payment was voided.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n"}, {"role": "user", "content": "Question: Percentage change in payments versus the previous month"}, {"role": "assistant", "content": "```sql\nSELECT MONTH_START, TOTAL_PAYMENT_AMOUNT, ROUND(100 * (TOTAL_PAYMENT_AMOUNT - LAG(TOTAL_PAYMENT_AMOUNT) OVER (ORDER BY MONTH_START)) / NULLIF(LAG(TOTAL_PAYMENT_AMOUNT) OVER (ORDER BY MONTH_START), 0), 1) AS PCT_CHANGE\nFROM (\n SELECT TRUNC(c.CHECK_DATE, 'MM') AS MONTH_START, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT\n FROM AP_CHECKS_ALL c\n GROUP BY TRUNC(c.CHECK_DATE, 'MM')\n)\nORDER BY MONTH_START;\n```"}], "meta": {"id": "a-01322", "tier": "T4", "family": "t4-mom", "kind": "ask", "source": "S2-templated", "group": "de06703db870", "tables": ["AP_CHECKS_ALL"], "result_rows": 11, "approx_prompt_tokens": 2576, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account the payment was drawn on. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Business units: organizational units that own transactions, with primary ledger and default currency.\nCREATE TABLE FUN_BUSINESS_UNITS (\n BU_ID NUMBER, -- Unique business unit identifier. Primary key.\n BU_NAME VARCHAR2(240), -- Business unit name. Values: US Operations, EMEA Operations, APAC Operations, Canada Operations, Shared Services.\n SHORT_CODE VARCHAR2(30), -- Short code of the business unit.\n PRIMARY_LEDGER_ID NUMBER, -- Ledger the business unit posts to. FK to GL_LEDGERS.LEDGER_ID.\n DEFAULT_CURRENCY_CODE VARCHAR2(15), -- Default currency of the business unit. FK to FND_CURRENCIES.CURRENCY_CODE.\n LEGAL_ENTITY_ID NUMBER, -- Legal entity the business unit belongs to.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n DATE_FROM DATE, -- Date the business unit becomes effective.\n DATE_TO DATE, -- Date the business unit stops being effective.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25) -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n INT_BANK_ACCOUNT_ID NUMBER, -- Company bank account used. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE, -- Date the payment was voided.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Company bank accounts: internal bank accounts used to fund payments and receive cash, with currency, ledger and reconciliation settings.\n-- (showing 15 of 22 columns: join keys + those relevant to the question)\nCREATE TABLE CE_BANK_ACCOUNTS (\n BANK_ACCOUNT_ID NUMBER, -- Unique bank account identifier. Primary key.\n BANK_PARTY_ID NUMBER, -- Bank holding the account. FK to CE_BANKS.BANK_PARTY_ID.\n BANK_ACCOUNT_NAME VARCHAR2(80), -- Name of the bank account.\n CURRENCY_CODE VARCHAR2(15), -- Currency of the account. FK to FND_CURRENCIES.CURRENCY_CODE.\n ACCOUNT_TYPE VARCHAR2(25), -- Type of bank account. Values: CHECKING, SAVINGS, PAYROLL.\n ACCOUNT_CLASSIFICATION VARCHAR2(30), -- Whether the account is internal or external.\n AP_USE_ALLOWED_FLAG VARCHAR2(1), -- Y if the account can be used for payables payments.\n AR_USE_ALLOWED_FLAG VARCHAR2(1), -- Y if the account can be used for receivables.\n CASH_CCID NUMBER, -- Cash general-ledger account. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n LEDGER_ID NUMBER, -- Ledger the account is accounted in. FK to GL_LEDGERS.LEDGER_ID.\n END_DATE DATE, -- Date the account is closed.\n MAX_CHECK_AMOUNT NUMBER(18,2), -- Maximum single payment allowed on the account.\n MULTI_CURRENCY_ALLOWED_FLAG VARCHAR2(1), -- Y if payments in other currencies are allowed.\n ACCOUNT_OWNER_PARTY_ID NUMBER, -- Party that owns the account. FK to HZ_PARTIES.PARTY_ID.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n-- voided payment => AP_CHECKS_ALL.STATUS_LOOKUP_CODE = 'VOIDED'\n"}, {"role": "user", "content": "Question: What is the average payment amount for each business unit excluding voided payments?"}, {"role": "assistant", "content": "```sql\nSELECT bu.BU_NAME, AVG(c.AMOUNT) AS AVG_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nJOIN FUN_BUSINESS_UNITS bu ON bu.BU_ID = c.ORG_ID\nWHERE c.STATUS_LOOKUP_CODE <> 'VOIDED'\nGROUP BY bu.BU_NAME\nORDER BY AVG_PAYMENT_AMOUNT DESC;\n```"}], "meta": {"id": "a-00337", "tier": "T2", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "406646323e3b", "tables": ["AP_CHECKS_ALL", "FUN_BUSINESS_UNITS"], "result_rows": 10, "approx_prompt_tokens": 3141, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n CURRENCY_CODE VARCHAR2(15), -- Currency the payment was made in. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account the payment was drawn on. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n);\n\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 15 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_ID NUMBER, -- Address of the site. FK to POZ_SUPPLIER_ADDRESSES.ADDRESS_ID.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Payment method for this site. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Default payment currency at this site. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n TOLERANCE_ID NUMBER, -- Matching tolerance applied at the site.\n BILL_TO_LOCATION_ID NUMBER, -- Default bill-to location.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Supplier addresses: physical and remit-to addresses of suppliers.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_ADDRESSES (\n ADDRESS_ID NUMBER, -- Unique address identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the address belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_NAME VARCHAR2(240), -- Name identifying the address.\n ADDRESS_LINE1 VARCHAR2(240), -- First address line.\n ADDRESS_LINE2 VARCHAR2(240), -- Second address line.\n CITY VARCHAR2(60), -- City.\n STATE VARCHAR2(60), -- State or province. Values: CA, NY, TX, WA, IL.\n POSTAL_CODE VARCHAR2(60), -- Postal or ZIP code.\n COUNTRY VARCHAR2(2), -- Country code.\n ADDRESS_PURPOSE VARCHAR2(30), -- What the address is used for. Values: REMIT_TO, PURCHASING, RFQ.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n LATITUDE NUMBER(12,6), -- Latitude of the address.\n LONGITUDE NUMBER(12,6), -- Longitude of the address.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n SELF_ASSESSED_TAX_AMOUNT NUMBER(18,2), -- Tax the buyer self-assesses instead of paying to the supplier.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice will be paid in. FK to FND_CURRENCIES.CURRENCY_CODE.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n PO_HEADER_ID NUMBER, -- Purchase order the invoice is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n);\n\n-- Purchase order headers: one row per purchase order with supplier, buyer, status, total and terms.\n-- (showing 15 of 28 columns: join keys + those relevant to the question)\nCREATE TABLE PO_HEADERS_ALL (\n PO_HEADER_ID NUMBER, -- Unique purchase order identifier. Primary key.\n SEGMENT1 VARCHAR2(30), -- Purchase order number.\n VENDOR_ID NUMBER, -- Supplier the order is placed with. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the order is placed with. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n AGENT_ID NUMBER, -- Buyer who created the order. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n CURRENCY_CODE VARCHAR2(15), -- Order currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n RATE NUMBER(12,6), -- Exchange rate on the order.\n TERMS_ID NUMBER, -- Payment terms on the order. FK to AP_TERMS_B.TERM_ID.\n APPROVED_FLAG VARCHAR2(1), -- Y if approved. Values: Y, N.\n TOTAL_AMOUNT NUMBER(18,2), -- Total order amount.\n NOTE_TO_VENDOR VARCHAR2(480), -- Note printed for the supplier.\n SHIP_TO_LOCATION_ID NUMBER, -- Ship-to location.\n BILL_TO_LOCATION_ID NUMBER, -- Bill-to location.\n FOB_LOOKUP_CODE VARCHAR2(25), -- Freight-on-board terms. Values: ORIGIN, DESTINATION.\n FREIGHT_TERMS_LOOKUP_CODE VARCHAR2(25), -- Who pays freight. Values: PAID, DUE.\n);\n\n-- Supplier bank accounts: external bank accounts that payments are sent to, with account holder, currency and validity dates.\n-- (showing 10 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXT_BANK_ACCOUNTS (\n EXT_BANK_ACCOUNT_ID NUMBER, -- Unique external bank account identifier. Primary key.\n BANK_PARTY_ID NUMBER, -- Bank holding the account. FK to CE_BANKS.BANK_PARTY_ID.\n ACCOUNT_OWNER_PARTY_ID NUMBER, -- Party that owns the account. FK to HZ_PARTIES.PARTY_ID.\n BANK_ACCOUNT_NAME VARCHAR2(80), -- Account holder name.\n CURRENCY_CODE VARCHAR2(15), -- Currency of the account. FK to FND_CURRENCIES.CURRENCY_CODE.\n COUNTRY_CODE VARCHAR2(2), -- Country of the account.\n START_DATE DATE, -- Date the account becomes valid.\n END_DATE DATE, -- Date the account stops being valid.\n ACCOUNT_SUFFIX VARCHAR2(30), -- Account suffix used by some banks.\n FOREIGN_PAYMENT_USE_FLAG VARCHAR2(1), -- Y if the account can receive foreign-currency payments.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\n-- (showing 15 of 38 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\n VENDOR_TYPE_LOOKUP_CODE VARCHAR2(30), -- Supplier type. Values: VENDOR, CONTRACTOR, EMPLOYEE, TAX AUTHORITY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n SUMMARY_FLAG VARCHAR2(1), -- Y if the supplier is a summary (parent) record.\n ONE_TIME_FLAG VARCHAR2(1), -- Y if the supplier is a one-time supplier.\n SMALL_BUSINESS_FLAG VARCHAR2(1), -- Y if the supplier is a small business.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Default payment method for the supplier. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Default pay group. Values: DOMESTIC, INTERNATIONAL.\n TERMS_ID NUMBER, -- Default payment terms. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Default payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if all payments to the supplier are blocked.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n FEDERAL_REPORTABLE_FLAG VARCHAR2(1), -- Y if the supplier is reportable for federal income tax.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2), -- Maximum credit extended to the supplier.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- vendor spend / supplier spend => SUM(AP_INVOICES_ALL.INVOICE_AMOUNT) grouped by AP_INVOICES_ALL.VENDOR_ID (join POZ_SUPPLIERS for VENDOR_NAME)\n-- supplier state / vendor state / by state => POZ_SUPPLIER_ADDRESSES.STATE (join on VENDOR_ID)\n"}, {"role": "user", "content": "Question: Total payment amount by supplier state for check payments only"}, {"role": "assistant", "content": "```sql\nSELECT a.STATE, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = c.VENDOR_ID\nWHERE c.PAYMENT_METHOD_CODE = 'CHECK'\nGROUP BY a.STATE\nORDER BY TOTAL_PAYMENT_AMOUNT DESC;\n```"}], "meta": {"id": "a-00636", "tier": "T2", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "2831e08382e5", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 3, "approx_prompt_tokens": 3071, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 17 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE, -- Date the payment was voided.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25), -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n-- days to pay => AP_CHECKS_ALL.CHECK_DATE - AP_INVOICES_ALL.INVOICE_DATE (join AP_INVOICE_PAYMENTS_ALL on INVOICE_ID and CHECK_ID)\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: What is the invoice count for each payment method this year?"}, {"role": "assistant", "content": "```sql\nSELECT i.PAYMENT_METHOD_CODE, COUNT(*) AS INVOICE_COUNT\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_DATE >= TRUNC(SYSDATE, 'YYYY')\nGROUP BY i.PAYMENT_METHOD_CODE\nORDER BY INVOICE_COUNT DESC;\n```"}], "meta": {"id": "a-01107", "tier": "T3", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "dac6b02a0045", "tables": ["AP_INVOICES_ALL"], "result_rows": 3, "approx_prompt_tokens": 2852, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Business units: organizational units that own transactions, with primary ledger and default currency.\nCREATE TABLE FUN_BUSINESS_UNITS (\n BU_ID NUMBER, -- Unique business unit identifier. Primary key.\n BU_NAME VARCHAR2(240), -- Business unit name. Values: US Operations, EMEA Operations, APAC Operations, Canada Operations, Shared Services.\n SHORT_CODE VARCHAR2(30), -- Short code of the business unit.\n PRIMARY_LEDGER_ID NUMBER, -- Ledger the business unit posts to. FK to GL_LEDGERS.LEDGER_ID.\n DEFAULT_CURRENCY_CODE VARCHAR2(15), -- Default currency of the business unit. FK to FND_CURRENCIES.CURRENCY_CODE.\n LEGAL_ENTITY_ID NUMBER, -- Legal entity the business unit belongs to.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n DATE_FROM DATE, -- Date the business unit becomes effective.\n DATE_TO DATE, -- Date the business unit stops being effective.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Subledger accounting entry lines: debit and credit lines of each accounting entry with account, amounts and the source transaction.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE XLA_AE_LINES (\n AE_LINE_ID NUMBER, -- Unique accounting line identifier. Primary key.\n AE_HEADER_ID NUMBER, -- Entry the line belongs to. FK to XLA_AE_HEADERS.AE_HEADER_ID.\n AE_LINE_NUM NUMBER, -- Line number within the entry.\n CODE_COMBINATION_ID NUMBER, -- Account of the line. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n ACCOUNTING_CLASS_CODE VARCHAR2(30), -- Accounting class such as liability or expense. Values: LIABILITY, ITEM EXPENSE, CASH, TAX, PREPAID.\n ENTERED_DR NUMBER(18,2), -- Debit in entered currency.\n ENTERED_CR NUMBER(18,2), -- Credit in entered currency.\n ACCOUNTED_DR NUMBER(18,2), -- Debit in ledger currency.\n ACCOUNTED_CR NUMBER(18,2), -- Credit in ledger currency.\n CURRENCY_CODE VARCHAR2(15), -- Entered currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n CURRENCY_CONVERSION_RATE NUMBER(12,6), -- Rate used to convert to ledger currency.\n DESCRIPTION VARCHAR2(240), -- Line description.\n SOURCE_TABLE VARCHAR2(30), -- Source table of the transaction. Values: AP_INVOICES_ALL, AP_INVOICE_PAYMENTS_ALL.\n SOURCE_ID NUMBER, -- Identifier of the source transaction.\n GL_SL_LINK_ID NUMBER -- Link to the general-ledger journal line.\n);\n\n-- Employee expense reports: reports submitted by employees with total, status, dates and approval. Reimbursed through Payables.\n-- (showing 15 of 20 columns: join keys + those relevant to the question)\nCREATE TABLE AP_EXPENSE_REPORT_HEADERS_ALL (\n EXPENSE_REPORT_ID NUMBER, -- Unique expense report identifier. Primary key.\n EMPLOYEE_ID NUMBER, -- Employee who submitted the report. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n REPORT_NUMBER VARCHAR2(50), -- Expense report number.\n REPORT_DATE DATE, -- Date the report was submitted.\n TOTAL NUMBER(18,2), -- Total amount claimed.\n AMOUNT_REIMBURSABLE NUMBER(18,2), -- Amount to be reimbursed to the employee.\n CURRENCY_CODE VARCHAR2(15), -- Report currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n STATUS VARCHAR2(25), -- Report status. Values: PAID, APPROVED, SUBMITTED, REJECTED.\n PURPOSE VARCHAR2(240), -- Business purpose of the expenses.\n APPROVER_ID NUMBER, -- Manager who approved the report. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n APPROVED_DATE DATE, -- Date the report was approved.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the employee is reimbursed. Values: EFT, CHECK.\n INVOICE_ID NUMBER, -- Payables invoice created for reimbursement. FK to AP_INVOICES_ALL.INVOICE_ID.\n POLICY_VIOLATION_FLAG VARCHAR2(1), -- Y if the report breaks expense policy.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Subledger accounting entry headers: accounting entries generated from payables transactions, with event type, accounting date and transfer status to the general ledger.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE XLA_AE_HEADERS (\n AE_HEADER_ID NUMBER, -- Unique accounting entry identifier. Primary key.\n APPLICATION_ID NUMBER, -- Subledger application, 200 for Payables.\n EVENT_TYPE_CODE VARCHAR2(30), -- Type of accounting event. Values: INVOICE VALIDATED, PAYMENT CREATED, PAYMENT CANCELLED, INVOICE CANCELLED.\n ENTITY_ID NUMBER, -- Source transaction entity.\n ACCOUNTING_DATE DATE, -- Accounting date of the entry.\n PERIOD_NAME VARCHAR2(15), -- Accounting period.\n DESCRIPTION VARCHAR2(240), -- Entry description.\n ACCOUNTING_ENTRY_STATUS_CODE VARCHAR2(1), -- F final, D draft, I incomplete. Values: F, D.\n GL_TRANSFER_STATUS_CODE VARCHAR2(1), -- Y transferred to general ledger, N not yet transferred. Values: Y, N.\n GL_TRANSFER_DATE DATE, -- Date transferred to the general ledger.\n JE_CATEGORY_NAME VARCHAR2(30), -- Journal category on transfer. Values: Purchase Invoices, Payments.\n BALANCE_TYPE_CODE VARCHAR2(1), -- A actual, B budget.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number.\n PRODUCT_RULE_CODE VARCHAR2(30), -- Accounting rule applied.\n FUNDS_STATUS_CODE VARCHAR2(1) -- Funds check status.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 17 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n ACCTS_PAY_CODE_COMBINATION_ID NUMBER, -- Liability (accounts payable) account for the invoice. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Chart of accounts: every valid account code combination (company, cost center, natural account) with type and enabled flag. Joined from invoice distributions to name the expense account.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE GL_CODE_COMBINATIONS (\n CODE_COMBINATION_ID NUMBER, -- Unique account combination identifier. Primary key.\n CHART_OF_ACCOUNTS_ID NUMBER, -- Chart of accounts the combination belongs to.\n CONCATENATED_SEGMENTS VARCHAR2(240), -- Full account string, for example 01-520-7110-0000.\n SEGMENT1 VARCHAR2(25), -- Company segment.\n SEGMENT2 VARCHAR2(25), -- Cost center segment.\n SEGMENT3 VARCHAR2(25), -- Natural account segment.\n SEGMENT4 VARCHAR2(25), -- Sub-account segment.\n SEGMENT5 VARCHAR2(25), -- Product segment.\n SEGMENT6 VARCHAR2(25), -- Intercompany segment.\n ACCOUNT_TYPE VARCHAR2(1), -- A asset, L liability, E expense, O owner equity, R revenue. Values: E, L, A.\n ACCOUNT_DESCRIPTION VARCHAR2(240), -- Description of the natural account. Values: Accounts Payable, Office Supplies, Professional Fees, Travel, Freight, Software, Cash, Prepaid Expenses, Utilities, Rent.\n SUMMARY_FLAG VARCHAR2(1), -- Y if the combination is a summary account.\n DETAIL_POSTING_ALLOWED_FLAG VARCHAR2(1), -- Y if posting is allowed to the account.\n START_DATE_ACTIVE DATE, -- Date the combination becomes active.\n END_DATE_ACTIVE DATE -- Date the combination stops being active.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n"}, {"role": "user", "content": "Question: Outstanding balance by business unit that came due in the last 90 days"}, {"role": "assistant", "content": "```sql\nSELECT bu.BU_NAME, SUM(ps.AMOUNT_REMAINING) AS TOTAL_UNPAID_AMOUNT\nFROM AP_PAYMENT_SCHEDULES_ALL ps\nJOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ps.INVOICE_ID\nJOIN FUN_BUSINESS_UNITS bu ON bu.BU_ID = i.ORG_ID\nWHERE ps.AMOUNT_REMAINING > 0 AND ps.DUE_DATE >= TRUNC(SYSDATE) - 90\nGROUP BY bu.BU_NAME\nORDER BY TOTAL_UNPAID_AMOUNT DESC;\n```"}], "meta": {"id": "a-01110", "tier": "T3", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "d3cf527b3d56", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "FUN_BUSINESS_UNITS"], "result_rows": 10, "approx_prompt_tokens": 3120, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n PARTY_ID NUMBER, -- Trading-community party of the supplier. FK to HZ_PARTIES.PARTY_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n SELF_ASSESSED_TAX_AMOUNT NUMBER(18,2), -- Tax the buyer self-assesses instead of paying to the supplier.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice is denominated in. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice will be paid in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n EXCHANGE_RATE_TYPE VARCHAR2(30), -- Type of exchange rate used. Values: Corporate, Spot, User.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n SOURCE VARCHAR2(80), -- How the invoice entered the system. Values: MANUAL, IMPORT, SUPPLIER PORTAL, EMAIL.\n PO_HEADER_ID NUMBER, -- Purchase order the invoice is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n VALIDATION_STATUS VARCHAR2(25), -- Result of invoice validation. Values: VALIDATED, NEEDS REVALIDATION, NEVER VALIDATED.\n WFAPPROVAL_STATUS VARCHAR2(25), -- Approval workflow status of the invoice. Values: APPROVED, NOT REQUIRED, REJECTED, INITIATED.\n CANCELLED_DATE DATE, -- Date the invoice was cancelled; NULL if not cancelled.\n CANCELLED_BY VARCHAR2(64), -- User who cancelled the invoice.\n ACCTS_PAY_CODE_COMBINATION_ID NUMBER, -- Liability (accounts payable) account for the invoice. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n LEDGER_ID NUMBER, -- Ledger the invoice is accounted in. FK to GL_LEDGERS.LEDGER_ID.\n REQUESTER_ID NUMBER, -- Employee who requested the goods or services. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n LEGAL_ENTITY_ID NUMBER, -- Legal entity the invoice belongs to.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number assigned to the invoice.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n ATTRIBUTE_CATEGORY VARCHAR2(30), -- Descriptive flexfield context (customer-defined extension fields).\n ATTRIBUTE1 VARCHAR2(150), -- Descriptive flexfield segment 1, customer-defined and normally unused.\n ATTRIBUTE2 VARCHAR2(150), -- Descriptive flexfield segment 2, customer-defined and normally unused.\n ATTRIBUTE3 VARCHAR2(150), -- Descriptive flexfield segment 3, customer-defined and normally unused.\n ATTRIBUTE4 VARCHAR2(150), -- Descriptive flexfield segment 4, customer-defined and normally unused.\n ATTRIBUTE5 VARCHAR2(150), -- Descriptive flexfield segment 5, customer-defined and normally unused.\n ATTRIBUTE6 VARCHAR2(150), -- Descriptive flexfield segment 6, customer-defined and normally unused.\n ATTRIBUTE7 VARCHAR2(150), -- Descriptive flexfield segment 7, customer-defined and normally unused.\n ATTRIBUTE8 VARCHAR2(150), -- Descriptive flexfield segment 8, customer-defined and normally unused.\n ATTRIBUTE9 VARCHAR2(150), -- Descriptive flexfield segment 9, customer-defined and normally unused.\n ATTRIBUTE10 VARCHAR2(150), -- Descriptive flexfield segment 10, customer-defined and normally unused.\n);\n\n-- Business units: organizational units that own transactions, with primary ledger and default currency.\nCREATE TABLE FUN_BUSINESS_UNITS (\n BU_ID NUMBER, -- Unique business unit identifier. Primary key.\n BU_NAME VARCHAR2(240), -- Business unit name. Values: US Operations, EMEA Operations, APAC Operations, Canada Operations, Shared Services.\n SHORT_CODE VARCHAR2(30), -- Short code of the business unit.\n PRIMARY_LEDGER_ID NUMBER, -- Ledger the business unit posts to. FK to GL_LEDGERS.LEDGER_ID.\n DEFAULT_CURRENCY_CODE VARCHAR2(15), -- Default currency of the business unit. FK to FND_CURRENCIES.CURRENCY_CODE.\n LEGAL_ENTITY_ID NUMBER, -- Legal entity the business unit belongs to.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n DATE_FROM DATE, -- Date the business unit becomes effective.\n DATE_TO DATE, -- Date the business unit stops being effective.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_NUMBER NUMBER, -- Sequence of the line within the invoice.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n DESCRIPTION VARCHAR2(240), -- Description of the goods or service on the line.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit billed.\n UNIT_MEAS_LOOKUP_CODE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\n ACCOUNTING_DATE DATE, -- Accounting date of the line.\n TAX_RATE NUMBER(12,6), -- Tax rate applied to the line.\n PRODUCT_CATEGORY VARCHAR2(80), -- Category of the product or service. Values: IT EQUIPMENT, OFFICE SUPPLIES, PROFESSIONAL SERVICES, LOGISTICS.\n REQUESTER_ID NUMBER, -- Employee who requested the line item. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice distributions: how each invoice line amount is split across general-ledger expense accounts, with accounting status. Use for spend-by-GL-account questions.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_DISTRIBUTIONS_ALL (\n INVOICE_DISTRIBUTION_ID NUMBER, -- Unique invoice distribution identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the distribution belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n INVOICE_LINE_ID NUMBER, -- Invoice line the distribution splits. FK to AP_INVOICE_LINES_ALL.INVOICE_LINE_ID.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Distribution type: ITEM, TAX, FREIGHT, MISCELLANEOUS. Values: ITEM, TAX, FREIGHT.\n AMOUNT NUMBER(18,2), -- Distribution amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Distribution amount in ledger currency.\n ACCOUNTING_DATE DATE, -- Accounting date of the distribution.\n PERIOD_NAME VARCHAR2(15), -- Accounting period the distribution falls in.\n QUANTITY_INVOICED NUMBER, -- Quantity billed for the distribution.\n UNIT_PRICE NUMBER(18,2), -- Unit price on the distribution.\n PO_DISTRIBUTION_ID NUMBER, -- Purchase order distribution matched to. FK to PO_DISTRIBUTIONS_ALL.PO_DISTRIBUTION_ID.\n TASK_ID NUMBER, -- Project task charged.\n INCOME_TAX_REGION VARCHAR2(10), -- Region used for income-tax reporting.\n DESCRIPTION VARCHAR2(240), -- Distribution description.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\n"}, {"role": "user", "content": "Question: Which 5 business units have the highest biggest invoice amount in the last 90 days?\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT bu.BU_NAME, MAX(i.INVOICE_AMOUNT) AS MAX_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN FUN_BUSINESS_UNITS bu ON bu.BU_ID = i.ORG_ID\nWHERE i.INVOICE_DATE >= CURDATE() - 90\nGROUP BY bu.BU_NAME\nORDER BY MAX_INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\nError: ORA-00904: \"CURDATE\": invalid identifier\nDiagnosis: No table in your query has a column named CURDATE. The columns are — AP_INVOICES_ALL: INVOICE_ID, VENDOR_ID, VENDOR_SITE_ID, PARTY_ID, INVOICE_NUM, INVOICE_TYPE_LOOKUP_CODE, INVOICE_DATE, INVOICE_RECEIVED_DATE, GOODS_RECEIVED_DATE, GL_DATE, INVOICE_AMOUNT, AMOUNT_PAID, TOTAL_TAX_AMOUNT, BASE_AMOUNT, APPROVED_AMOUNT, AMOUNT_APPLICABLE_TO_DISCOUNT, DISCOUNT_AMOUNT_TAKEN, PREPAY_AMOUNT_REMAINING, SELF_ASSESSED_TAX_AMOUNT, INVOICE_CURRENCY_CODE, PAYMENT_CURRENCY_CODE, EXCHANGE_RATE, EXCHANGE_DATE, EXCHANGE_RATE_TYPE, TERMS_ID, TERMS_DATE, PAYMENT_METHOD_CODE, PAY_GROUP_LOOKUP_CODE, PAYMENT_STATUS_FLAG, DESCRIPTION, SOURCE, PO_HEADER_ID, BATCH_ID, VALIDATION_STATUS, WFAPPROVAL_STATUS, CANCELLED_DATE, CANCELLED_BY, ACCTS_PAY_CODE_COMBINATION_ID, LEDGER_ID, REQUESTER_ID, LEGAL_ENTITY_ID, DOC_SEQUENCE_VALUE, CREATION_DATE, CREATED_BY, LAST_UPDATE_DATE, LAST_UPDATED_BY, OBJECT_VERSION_NUMBER, ORG_ID, ATTRIBUTE_CATEGORY, ATTRIBUTE1, ATTRIBUTE2, ATTRIBUTE3, ATTRIBUTE4, ATTRIBUTE5, ATTRIBUTE6, ATTRIBUTE7, ATTRIBUTE8, ATTRIBUTE9, ATTRIBUTE10; FUN_BUSINESS_UNITS: BU_ID, BU_NAME, SHORT_CODE, PRIMARY_LEDGER_ID, DEFAULT_CURRENCY_CODE, LEGAL_ENTITY_ID, STATUS, DATE_FROM, DATE_TO, CREATION_DATE, CREATED_BY, LAST_UPDATE_DATE, LAST_UPDATED_BY, OBJECT_VERSION_NUMBER.\nWrite a corrected query. It must differ from the failed one. Use ONLY the tables and columns in the schema above, spelled exactly as shown; if a column you wanted does not exist, choose the closest one that does."}, {"role": "assistant", "content": "```sql\nSELECT bu.BU_NAME, MAX(i.INVOICE_AMOUNT) AS MAX_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN FUN_BUSINESS_UNITS bu ON bu.BU_ID = i.ORG_ID\nWHERE i.INVOICE_DATE >= TRUNC(SYSDATE) - 90\nGROUP BY bu.BU_NAME\nORDER BY MAX_INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "r-00070", "tier": "T3", "family": "spec-inv", "kind": "repair-exec", "source": "S6-repair", "group": "08a4c3b8d3e0", "tables": ["AP_INVOICES_ALL", "FUN_BUSINESS_UNITS"], "result_rows": 0, "approx_prompt_tokens": 3502, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"CURDATE\": invalid identifier", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Withholding tax groups: sets of withholding tax rates applied to supplier invoices.\nCREATE TABLE AP_AWT_GROUPS (\n GROUP_ID NUMBER, -- Unique withholding tax group identifier. Primary key.\n NAME VARCHAR2(25), -- Name of the withholding tax group.\n DESCRIPTION VARCHAR2(240), -- Description of the withholding group.\n INACTIVE_DATE DATE, -- Date the group stops being valid.\n TAX_AUTHORITY VARCHAR2(80), -- Tax authority receiving the withheld tax. Values: IRS, HMRC, CRA.\n WITHHOLDING_RATE NUMBER(12,6), -- Default withholding percentage for the group.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit billed.\n UNIT_MEAS_LOOKUP_CODE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\n PO_LINE_LOCATION_ID NUMBER, -- Purchase order schedule this line is matched to. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n DEFAULT_DIST_CCID NUMBER, -- Default account used to distribute the line. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n TAX_CLASSIFICATION_CODE VARCHAR2(30), -- Tax classification of the line. Values: STANDARD, REDUCED, EXEMPT.\n TAX_RATE NUMBER(12,6), -- Tax rate applied to the line.\n TAX_RATE_ID NUMBER, -- Tax rate record applied. FK to ZX_RATES_B.TAX_RATE_ID.\n REQUESTER_ID NUMBER, -- Employee who requested the line item. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Taxes: tax definitions such as VAT, GST and sales tax by jurisdiction.\nCREATE TABLE ZX_TAXES_B (\n TAX_ID NUMBER, -- Unique tax identifier. Primary key.\n TAX VARCHAR2(30), -- Tax code such as VAT or GST. Values: VAT, GST, SALES TAX, CONSUMPTION TAX.\n TAX_REGIME_CODE VARCHAR2(30), -- Tax regime the tax belongs to. Values: US-SALES, UK-VAT, CA-GST, EU-VAT.\n TAX_TYPE_CODE VARCHAR2(30), -- Tax type classification. Values: VAT, SALES, GST.\n TAX_JURISDICTION_CODE VARCHAR2(30), -- Jurisdiction levying the tax. Values: FEDERAL, STATE, COUNTRY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the tax is active.\n EFFECTIVE_FROM DATE, -- Date the tax becomes effective.\n EFFECTIVE_TO DATE, -- Date the tax stops applying.\n RECOVERABLE_FLAG VARCHAR2(1), -- Y if the tax can be recovered from the authority.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Transaction tax lines: the tax calculated on each invoice line, with taxable amount, rate, tax amount and recoverability.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE ZX_LINES (\n TAX_LINE_ID NUMBER, -- Unique tax line identifier. Primary key.\n TRX_ID NUMBER, -- Invoice the tax line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n TRX_LINE_ID NUMBER, -- Invoice line the tax was calculated on. FK to AP_INVOICE_LINES_ALL.INVOICE_LINE_ID.\n TAX_RATE_ID NUMBER, -- Rate applied. FK to ZX_RATES_B.TAX_RATE_ID.\n TAX_ID NUMBER, -- Tax applied. FK to ZX_TAXES_B.TAX_ID.\n TAX_RATE NUMBER(12,6), -- Tax percentage applied.\n TAXABLE_AMT NUMBER(18,2), -- Amount the tax was calculated on.\n TAX_AMT NUMBER(18,2), -- Tax amount.\n TAX_AMT_TAX_CURR NUMBER(18,2), -- Tax amount in the tax currency.\n TAX_CURRENCY_CODE VARCHAR2(15), -- Currency of the tax amount. FK to FND_CURRENCIES.CURRENCY_CODE.\n TAX_DATE DATE, -- Date used to determine the tax rate.\n TAX_JURISDICTION_CODE VARCHAR2(30), -- Jurisdiction the tax was levied by. Values: FEDERAL, STATE, COUNTRY.\n RECOVERABLE_FLAG VARCHAR2(1), -- Y if the tax is recoverable.\n SELF_ASSESSED_FLAG VARCHAR2(1), -- Y if the tax is self-assessed.\n TAX_STATUS_CODE VARCHAR2(30) -- Tax status applied. Values: STANDARD, REDUCED, ZERO.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n PARTY_ID NUMBER, -- Trading-community party of the supplier. FK to HZ_PARTIES.PARTY_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n SELF_ASSESSED_TAX_AMOUNT NUMBER(18,2), -- Tax the buyer self-assesses instead of paying to the supplier.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n ACCTS_PAY_CODE_COMBINATION_ID NUMBER -- Liability (accounts payable) account for the invoice. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n);\n\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 15 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n ADDRESS_ID NUMBER, -- Address of the site. FK to POZ_SUPPLIER_ADDRESSES.ADDRESS_ID.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Payment method for this site. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Default invoice currency at this site. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n SHIP_TO_LOCATION_ID NUMBER, -- Default ship-to location for purchase orders.\n BILL_TO_LOCATION_ID NUMBER, -- Default bill-to location.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Supplier addresses: physical and remit-to addresses of suppliers.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_ADDRESSES (\n ADDRESS_ID NUMBER, -- Unique address identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the address belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_NAME VARCHAR2(240), -- Name identifying the address.\n ADDRESS_LINE1 VARCHAR2(240), -- First address line.\n ADDRESS_LINE2 VARCHAR2(240), -- Second address line.\n CITY VARCHAR2(60), -- City.\n STATE VARCHAR2(60), -- State or province. Values: CA, NY, TX, WA, IL.\n POSTAL_CODE VARCHAR2(60), -- Postal or ZIP code.\n COUNTRY VARCHAR2(2), -- Country code.\n ADDRESS_PURPOSE VARCHAR2(30), -- What the address is used for. Values: REMIT_TO, PURCHASING, RFQ.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n LATITUDE NUMBER(12,6), -- Latitude of the address.\n LONGITUDE NUMBER(12,6) -- Longitude of the address.\n);\n\n-- Tax rates: rate percentage per tax and status, with recovery and accounting settings.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE ZX_RATES_B (\n TAX_RATE_ID NUMBER, -- Unique tax rate identifier. Primary key.\n TAX_ID NUMBER, -- Tax the rate belongs to. FK to ZX_TAXES_B.TAX_ID.\n TAX_RATE_CODE VARCHAR2(30), -- Tax rate code. Values: STANDARD, REDUCED, ZERO, EXEMPT.\n TAX_STATUS_CODE VARCHAR2(30), -- Tax status the rate applies under. Values: STANDARD, REDUCED, ZERO.\n PERCENTAGE_RATE NUMBER(12,6), -- Tax percentage.\n EFFECTIVE_FROM DATE, -- Date the rate becomes effective.\n EFFECTIVE_TO DATE, -- Date the rate stops applying.\n ACTIVE_FLAG VARCHAR2(1), -- Y if the rate is active.\n TAX_ACCOUNT_CCID NUMBER, -- Account tax is posted to. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n RECOVERY_TYPE_CODE VARCHAR2(30), -- Recovery treatment. Values: STANDARD, PARTIAL.\n DEFAULT_RECOVERY_RATE NUMBER(12,6) -- Default recoverable percentage.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- supplier state / vendor state / by state => POZ_SUPPLIER_ADDRESSES.STATE (join on VENDOR_ID)\n"}, {"role": "user", "content": "Question: Show the 5 supplier cities with the highest total tax on invoices for invoices paid by wire"}, {"role": "assistant", "content": "```sql\nSELECT a.CITY, SUM(i.TOTAL_TAX_AMOUNT) AS TOTAL_TAX_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = i.VENDOR_ID\nWHERE i.PAYMENT_METHOD_CODE = 'WIRE'\nGROUP BY a.CITY\nORDER BY TOTAL_TAX_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00800", "tier": "T2", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "6083e1e295cc", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 5, "approx_prompt_tokens": 2820, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n SOURCE VARCHAR2(80), -- How the invoice entered the system. Values: MANUAL, IMPORT, SUPPLIER PORTAL, EMAIL.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n VALIDATION_STATUS VARCHAR2(25), -- Result of invoice validation. Values: VALIDATED, NEEDS REVALIDATION, NEVER VALIDATED.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\n-- (showing 15 of 38 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n VENDOR_NAME VARCHAR2(360), -- Supplier name.\n VENDOR_NAME_ALT VARCHAR2(320), -- Alternate or trading name of the supplier.\n SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\n VENDOR_TYPE_LOOKUP_CODE VARCHAR2(30), -- Supplier type. Values: VENDOR, CONTRACTOR, EMPLOYEE, TAX AUTHORITY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n ONE_TIME_FLAG VARCHAR2(1), -- Y if the supplier is a one-time supplier.\n MINORITY_GROUP_LOOKUP_CODE VARCHAR2(30), -- Minority ownership classification. Values: MBE, DBE.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Default payment method for the supplier. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Default pay group. Values: DOMESTIC, INTERNATIONAL.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Default invoice currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2), -- Maximum credit extended to the supplier.\n RISK_RATING VARCHAR2(25), -- Internal supplier risk rating. Values: LOW, MEDIUM, HIGH.\n CREATION_SOURCE VARCHAR2(30), -- Where the supplier record originated. Values: REGISTRATION, MANUAL, IMPORT.\n);\n\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_NUMBER NUMBER, -- Sequence of the line within the invoice.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit billed.\n UNIT_MEAS_LOOKUP_CODE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\n PO_HEADER_ID NUMBER, -- Purchase order this line is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n PO_LINE_ID NUMBER, -- Purchase order line this line is matched to. FK to PO_LINES_ALL.PO_LINE_ID.\n PO_LINE_LOCATION_ID NUMBER, -- Purchase order schedule this line is matched to. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n TAX_CLASSIFICATION_CODE VARCHAR2(30), -- Tax classification of the line. Values: STANDARD, REDUCED, EXEMPT.\n PRODUCT_CATEGORY VARCHAR2(80), -- Category of the product or service. Values: IT EQUIPMENT, OFFICE SUPPLIES, PROFESSIONAL SERVICES, LOGISTICS.\n MATCH_TYPE VARCHAR2(25), -- How the line was matched. Values: ITEM_TO_PO, ITEM_TO_RECEIPT, NOT_MATCHED.\n);\n\n-- Invoice import staging: invoices loaded from external sources awaiting import, with import status and rejection reason.\nCREATE TABLE AP_INVOICES_INTERFACE (\n INVOICE_INTERFACE_ID NUMBER, -- Unique interface row identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Invoice number from the source system.\n VENDOR_NUM VARCHAR2(30), -- Supplier number from the source system.\n INVOICE_AMOUNT NUMBER(18,2), -- Invoice total from the source system.\n INVOICE_DATE DATE, -- Invoice date from the source system.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Currency from the source system. FK to FND_CURRENCIES.CURRENCY_CODE.\n SOURCE VARCHAR2(80), -- Source system that supplied the row. Values: SUPPLIER PORTAL, EDI, EMAIL, OCR.\n STATUS VARCHAR2(25), -- Import status. Values: PROCESSED, REJECTED, PENDING.\n REJECT_REASON VARCHAR2(240), -- Why the row was rejected during import.\n GROUP_ID VARCHAR2(80), -- Load group identifier.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n CHECKRUN_ID NUMBER, -- Payment process request identifier.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n);\n\n-- Purchase order schedules: delivery schedules of a line with need-by date, quantity received and billed, and the matching option (two-, three- or four-way).\n-- (showing 15 of 22 columns: join keys + those relevant to the question)\nCREATE TABLE PO_LINE_LOCATIONS_ALL (\n LINE_LOCATION_ID NUMBER, -- Unique schedule identifier. Primary key.\n SHIPMENT_NUM NUMBER, -- Schedule number within the line.\n QUANTITY NUMBER, -- Quantity scheduled.\n QUANTITY_RECEIVED NUMBER, -- Quantity received so far.\n QUANTITY_BILLED NUMBER, -- Quantity invoiced so far.\n QUANTITY_CANCELLED NUMBER, -- Quantity cancelled.\n NEED_BY_DATE DATE, -- Date the goods are needed.\n PROMISED_DATE DATE, -- Date the supplier promised delivery.\n PRICE_OVERRIDE NUMBER(18,2), -- Price for this schedule if different from the line.\n INVOICE_MATCH_OPTION VARCHAR2(1), -- P match to order (two-way), R match to receipt (three-way). Values: R, P.\n RECEIPT_REQUIRED_FLAG VARCHAR2(1), -- Y if receipt is required before payment.\n TAXABLE_FLAG VARCHAR2(1), -- Y if the schedule is taxable.\n SHIP_TO_LOCATION_ID NUMBER, -- Where the goods are delivered.\n CLOSED_CODE VARCHAR2(25), -- Closure state of the schedule. Values: OPEN, CLOSED FOR RECEIVING, CLOSED.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- unvalidated invoice => AP_INVOICES_ALL.VALIDATION_STATUS <> 'VALIDATED'\n-- vendor spend / supplier spend => SUM(AP_INVOICES_ALL.INVOICE_AMOUNT) grouped by AP_INVOICES_ALL.VENDOR_ID (join POZ_SUPPLIERS for VENDOR_NAME)\n-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: Top 3 suppliers by number of unvalidated invoices"}, {"role": "assistant", "content": "```sql\nSELECT s.VENDOR_NAME, COUNT(*) AS INVOICE_COUNT\nFROM AP_INVOICES_ALL i\nJOIN POZ_SUPPLIERS s ON s.VENDOR_ID = i.VENDOR_ID\nWHERE i.VALIDATION_STATUS <> 'VALIDATED'\nGROUP BY s.VENDOR_NAME\nORDER BY INVOICE_COUNT DESC\nFETCH FIRST 3 ROWS ONLY;\n```"}], "meta": {"id": "a-01716", "tier": "T5", "family": "t5-glossary", "kind": "ask", "source": "S2-templated", "group": "bd35bdf2e934", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 3, "approx_prompt_tokens": 2883, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n PARTY_ID NUMBER, -- Trading-community party of the supplier. FK to HZ_PARTIES.PARTY_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n SELF_ASSESSED_TAX_AMOUNT NUMBER(18,2), -- Tax the buyer self-assesses instead of paying to the supplier.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice is denominated in. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice will be paid in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n EXCHANGE_RATE_TYPE VARCHAR2(30), -- Type of exchange rate used. Values: Corporate, Spot, User.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n SOURCE VARCHAR2(80), -- How the invoice entered the system. Values: MANUAL, IMPORT, SUPPLIER PORTAL, EMAIL.\n PO_HEADER_ID NUMBER, -- Purchase order the invoice is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n VALIDATION_STATUS VARCHAR2(25), -- Result of invoice validation. Values: VALIDATED, NEEDS REVALIDATION, NEVER VALIDATED.\n WFAPPROVAL_STATUS VARCHAR2(25), -- Approval workflow status of the invoice. Values: APPROVED, NOT REQUIRED, REJECTED, INITIATED.\n CANCELLED_DATE DATE, -- Date the invoice was cancelled; NULL if not cancelled.\n CANCELLED_BY VARCHAR2(64), -- User who cancelled the invoice.\n ACCTS_PAY_CODE_COMBINATION_ID NUMBER, -- Liability (accounts payable) account for the invoice. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n LEDGER_ID NUMBER, -- Ledger the invoice is accounted in. FK to GL_LEDGERS.LEDGER_ID.\n REQUESTER_ID NUMBER, -- Employee who requested the goods or services. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n LEGAL_ENTITY_ID NUMBER, -- Legal entity the invoice belongs to.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number assigned to the invoice.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n ATTRIBUTE_CATEGORY VARCHAR2(30), -- Descriptive flexfield context (customer-defined extension fields).\n ATTRIBUTE1 VARCHAR2(150), -- Descriptive flexfield segment 1, customer-defined and normally unused.\n ATTRIBUTE2 VARCHAR2(150), -- Descriptive flexfield segment 2, customer-defined and normally unused.\n ATTRIBUTE3 VARCHAR2(150), -- Descriptive flexfield segment 3, customer-defined and normally unused.\n ATTRIBUTE4 VARCHAR2(150), -- Descriptive flexfield segment 4, customer-defined and normally unused.\n ATTRIBUTE5 VARCHAR2(150), -- Descriptive flexfield segment 5, customer-defined and normally unused.\n ATTRIBUTE6 VARCHAR2(150), -- Descriptive flexfield segment 6, customer-defined and normally unused.\n ATTRIBUTE7 VARCHAR2(150), -- Descriptive flexfield segment 7, customer-defined and normally unused.\n ATTRIBUTE8 VARCHAR2(150), -- Descriptive flexfield segment 8, customer-defined and normally unused.\n ATTRIBUTE9 VARCHAR2(150), -- Descriptive flexfield segment 9, customer-defined and normally unused.\n ATTRIBUTE10 VARCHAR2(150), -- Descriptive flexfield segment 10, customer-defined and normally unused.\n);\n\n-- Supplier addresses: physical and remit-to addresses of suppliers.\nCREATE TABLE POZ_SUPPLIER_ADDRESSES (\n ADDRESS_ID NUMBER, -- Unique address identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the address belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_NAME VARCHAR2(240), -- Name identifying the address.\n ADDRESS_LINE1 VARCHAR2(240), -- First address line.\n ADDRESS_LINE2 VARCHAR2(240), -- Second address line.\n CITY VARCHAR2(60), -- City.\n STATE VARCHAR2(60), -- State or province. Values: CA, NY, TX, WA, IL.\n POSTAL_CODE VARCHAR2(60), -- Postal or ZIP code.\n COUNTRY VARCHAR2(2), -- Country code.\n ADDRESS_PURPOSE VARCHAR2(30), -- What the address is used for. Values: REMIT_TO, PURCHASING, RFQ.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n LATITUDE NUMBER(12,6), -- Latitude of the address.\n LONGITUDE NUMBER(12,6), -- Longitude of the address.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Purchase order schedules: delivery schedules of a line with need-by date, quantity received and billed, and the matching option (two-, three- or four-way).\n-- (showing 15 of 22 columns: join keys + those relevant to the question)\nCREATE TABLE PO_LINE_LOCATIONS_ALL (\n LINE_LOCATION_ID NUMBER, -- Unique schedule identifier. Primary key.\n SHIPMENT_NUM NUMBER, -- Schedule number within the line.\n QUANTITY NUMBER, -- Quantity scheduled.\n QUANTITY_RECEIVED NUMBER, -- Quantity received so far.\n QUANTITY_BILLED NUMBER, -- Quantity invoiced so far.\n QUANTITY_CANCELLED NUMBER, -- Quantity cancelled.\n NEED_BY_DATE DATE, -- Date the goods are needed.\n PROMISED_DATE DATE, -- Date the supplier promised delivery.\n PRICE_OVERRIDE NUMBER(18,2), -- Price for this schedule if different from the line.\n INVOICE_MATCH_OPTION VARCHAR2(1), -- P match to order (two-way), R match to receipt (three-way). Values: R, P.\n RECEIPT_REQUIRED_FLAG VARCHAR2(1), -- Y if receipt is required before payment.\n TAXABLE_FLAG VARCHAR2(1), -- Y if the schedule is taxable.\n SHIP_TO_LOCATION_ID NUMBER, -- Where the goods are delivered.\n CLOSED_CODE VARCHAR2(25), -- Closure state of the schedule. Values: OPEN, CLOSED FOR RECEIVING, CLOSED.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice batches: groups of invoices entered together, with control totals and entry status.\nCREATE TABLE AP_BATCHES_ALL (\n BATCH_ID NUMBER, -- Unique invoice batch identifier. Primary key.\n BATCH_NAME VARCHAR2(50), -- Name of the batch.\n BATCH_DATE DATE, -- Date the batch was created.\n INVOICE_COUNT NUMBER, -- Number of invoices entered in the batch.\n INVOICE_AMOUNT NUMBER(18,2), -- Total amount of the invoices in the batch.\n CONTROL_INVOICE_COUNT NUMBER, -- Expected invoice count entered as a control total.\n CONTROL_INVOICE_AMOUNT NUMBER(18,2), -- Expected batch amount entered as a control total.\n BATCH_STATUS VARCHAR2(25), -- Status of the batch. Values: OPEN, CLOSED, POSTED.\n SOURCE VARCHAR2(80), -- Source of the batch. Values: MANUAL, IMPORT, SUPPLIER PORTAL.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- vendor spend / supplier spend => SUM(AP_INVOICES_ALL.INVOICE_AMOUNT) grouped by AP_INVOICES_ALL.VENDOR_ID (join POZ_SUPPLIERS for VENDOR_NAME)\n-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n"}, {"role": "user", "content": "Question: Show the 5 supplier cities with the highest largest invoice amount this month\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT a.CITY, MAX(i.INVOICE_AMOUNT) AS MAX_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = i.VENDOR_ID\nWHERE i.INVOICE_DATE >= TRUNC(NOW(), 'MM')\nGROUP BY a.CITY\nORDER BY MAX_INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\nError: ORA-00904: \"NOW\": invalid identifier\nDiagnosis: No table in your query has a column named NOW. The columns are — AP_INVOICES_ALL: INVOICE_ID, VENDOR_ID, VENDOR_SITE_ID, PARTY_ID, INVOICE_NUM, INVOICE_TYPE_LOOKUP_CODE, INVOICE_DATE, INVOICE_RECEIVED_DATE, GOODS_RECEIVED_DATE, GL_DATE, INVOICE_AMOUNT, AMOUNT_PAID, TOTAL_TAX_AMOUNT, BASE_AMOUNT, APPROVED_AMOUNT, AMOUNT_APPLICABLE_TO_DISCOUNT, DISCOUNT_AMOUNT_TAKEN, PREPAY_AMOUNT_REMAINING, SELF_ASSESSED_TAX_AMOUNT, INVOICE_CURRENCY_CODE, PAYMENT_CURRENCY_CODE, EXCHANGE_RATE, EXCHANGE_DATE, EXCHANGE_RATE_TYPE, TERMS_ID, TERMS_DATE, PAYMENT_METHOD_CODE, PAY_GROUP_LOOKUP_CODE, PAYMENT_STATUS_FLAG, DESCRIPTION, SOURCE, PO_HEADER_ID, BATCH_ID, VALIDATION_STATUS, WFAPPROVAL_STATUS, CANCELLED_DATE, CANCELLED_BY, ACCTS_PAY_CODE_COMBINATION_ID, LEDGER_ID, REQUESTER_ID, LEGAL_ENTITY_ID, DOC_SEQUENCE_VALUE, CREATION_DATE, CREATED_BY, LAST_UPDATE_DATE, LAST_UPDATED_BY, OBJECT_VERSION_NUMBER, ORG_ID, ATTRIBUTE_CATEGORY, ATTRIBUTE1, ATTRIBUTE2, ATTRIBUTE3, ATTRIBUTE4, ATTRIBUTE5, ATTRIBUTE6, ATTRIBUTE7, ATTRIBUTE8, ATTRIBUTE9, ATTRIBUTE10; POZ_SUPPLIER_ADDRESSES: ADDRESS_ID, VENDOR_ID, ADDRESS_NAME, ADDRESS_LINE1, ADDRESS_LINE2, CITY, STATE, POSTAL_CODE, COUNTRY, ADDRESS_PURPOSE, STATUS, LATITUDE, LONGITUDE, CREATION_DATE, CREATED_BY, LAST_UPDATE_DATE, LAST_UPDATED_BY, OBJECT_VERSION_NUMBER.\nWrite a corrected query. It must differ from the failed one. Use ONLY the tables and columns in the schema above, spelled exactly as shown; if a column you wanted does not exist, choose the closest one that does."}, {"role": "assistant", "content": "```sql\nSELECT a.CITY, MAX(i.INVOICE_AMOUNT) AS MAX_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = i.VENDOR_ID\nWHERE i.INVOICE_DATE >= TRUNC(SYSDATE, 'MM')\nGROUP BY a.CITY\nORDER BY MAX_INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "r-00064", "tier": "T3", "family": "spec-inv", "kind": "repair-exec", "source": "S6-repair", "group": "b70f1872b3f9", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 0, "approx_prompt_tokens": 3448, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"NOW\": invalid identifier", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n PARTY_ID NUMBER, -- Trading-community party of the supplier. FK to HZ_PARTIES.PARTY_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n SELF_ASSESSED_TAX_AMOUNT NUMBER(18,2), -- Tax the buyer self-assesses instead of paying to the supplier.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice is denominated in. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice will be paid in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n EXCHANGE_RATE_TYPE VARCHAR2(30), -- Type of exchange rate used. Values: Corporate, Spot, User.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n SOURCE VARCHAR2(80), -- How the invoice entered the system. Values: MANUAL, IMPORT, SUPPLIER PORTAL, EMAIL.\n PO_HEADER_ID NUMBER, -- Purchase order the invoice is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n VALIDATION_STATUS VARCHAR2(25), -- Result of invoice validation. Values: VALIDATED, NEEDS REVALIDATION, NEVER VALIDATED.\n WFAPPROVAL_STATUS VARCHAR2(25), -- Approval workflow status of the invoice. Values: APPROVED, NOT REQUIRED, REJECTED, INITIATED.\n CANCELLED_DATE DATE, -- Date the invoice was cancelled; NULL if not cancelled.\n CANCELLED_BY VARCHAR2(64), -- User who cancelled the invoice.\n ACCTS_PAY_CODE_COMBINATION_ID NUMBER, -- Liability (accounts payable) account for the invoice. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n LEDGER_ID NUMBER, -- Ledger the invoice is accounted in. FK to GL_LEDGERS.LEDGER_ID.\n REQUESTER_ID NUMBER, -- Employee who requested the goods or services. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n LEGAL_ENTITY_ID NUMBER, -- Legal entity the invoice belongs to.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number assigned to the invoice.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n ATTRIBUTE_CATEGORY VARCHAR2(30), -- Descriptive flexfield context (customer-defined extension fields).\n ATTRIBUTE1 VARCHAR2(150), -- Descriptive flexfield segment 1, customer-defined and normally unused.\n ATTRIBUTE2 VARCHAR2(150), -- Descriptive flexfield segment 2, customer-defined and normally unused.\n ATTRIBUTE3 VARCHAR2(150), -- Descriptive flexfield segment 3, customer-defined and normally unused.\n ATTRIBUTE4 VARCHAR2(150), -- Descriptive flexfield segment 4, customer-defined and normally unused.\n ATTRIBUTE5 VARCHAR2(150), -- Descriptive flexfield segment 5, customer-defined and normally unused.\n ATTRIBUTE6 VARCHAR2(150), -- Descriptive flexfield segment 6, customer-defined and normally unused.\n ATTRIBUTE7 VARCHAR2(150), -- Descriptive flexfield segment 7, customer-defined and normally unused.\n ATTRIBUTE8 VARCHAR2(150), -- Descriptive flexfield segment 8, customer-defined and normally unused.\n ATTRIBUTE9 VARCHAR2(150), -- Descriptive flexfield segment 9, customer-defined and normally unused.\n ATTRIBUTE10 VARCHAR2(150), -- Descriptive flexfield segment 10, customer-defined and normally unused.\n);\n\n-- Invoice distributions: how each invoice line amount is split across general-ledger expense accounts, with accounting status. Use for spend-by-GL-account questions.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_DISTRIBUTIONS_ALL (\n INVOICE_DISTRIBUTION_ID NUMBER, -- Unique invoice distribution identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the distribution belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n INVOICE_LINE_ID NUMBER, -- Invoice line the distribution splits. FK to AP_INVOICE_LINES_ALL.INVOICE_LINE_ID.\n DISTRIBUTION_LINE_NUMBER NUMBER, -- Sequence of the distribution within the invoice.\n AMOUNT NUMBER(18,2), -- Distribution amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Distribution amount in ledger currency.\n ACCOUNTING_DATE DATE, -- Accounting date of the distribution.\n PERIOD_NAME VARCHAR2(15), -- Accounting period the distribution falls in.\n POSTED_FLAG VARCHAR2(1), -- Y if accounted and posted to the ledger, N if not yet accounted. Values: Y, N.\n QUANTITY_INVOICED NUMBER, -- Quantity billed for the distribution.\n UNIT_PRICE NUMBER(18,2), -- Unit price on the distribution.\n PO_DISTRIBUTION_ID NUMBER, -- Purchase order distribution matched to. FK to PO_DISTRIBUTIONS_ALL.PO_DISTRIBUTION_ID.\n TASK_ID NUMBER, -- Project task charged.\n INCOME_TAX_REGION VARCHAR2(10), -- Region used for income-tax reporting.\n DESCRIPTION VARCHAR2(240), -- Distribution description.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice batches: groups of invoices entered together, with control totals and entry status.\nCREATE TABLE AP_BATCHES_ALL (\n BATCH_ID NUMBER, -- Unique invoice batch identifier. Primary key.\n BATCH_NAME VARCHAR2(50), -- Name of the batch.\n BATCH_DATE DATE, -- Date the batch was created.\n INVOICE_COUNT NUMBER, -- Number of invoices entered in the batch.\n INVOICE_AMOUNT NUMBER(18,2), -- Total amount of the invoices in the batch.\n CONTROL_INVOICE_COUNT NUMBER, -- Expected invoice count entered as a control total.\n CONTROL_INVOICE_AMOUNT NUMBER(18,2), -- Expected batch amount entered as a control total.\n BATCH_STATUS VARCHAR2(25), -- Status of the batch. Values: OPEN, CLOSED, POSTED.\n SOURCE VARCHAR2(80), -- Source of the batch. Values: MANUAL, IMPORT, SUPPLIER PORTAL.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_NUMBER NUMBER, -- Sequence of the line within the invoice.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit billed.\n UNIT_MEAS_LOOKUP_CODE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\n ACCOUNTING_DATE DATE, -- Accounting date of the line.\n TAX_RATE NUMBER(12,6), -- Tax rate applied to the line.\n TAX_RATE_ID NUMBER, -- Tax rate record applied. FK to ZX_RATES_B.TAX_RATE_ID.\n DISCARDED_FLAG VARCHAR2(1), -- Y if the line was discarded during correction.\n REQUESTER_ID NUMBER, -- Employee who requested the line item. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n MATCH_TYPE VARCHAR2(25), -- How the line was matched. Values: ITEM_TO_PO, ITEM_TO_RECEIPT, NOT_MATCHED.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- unvalidated invoice => AP_INVOICES_ALL.VALIDATION_STATUS <> 'VALIDATED'\n"}, {"role": "user", "content": "Question: Average invoice amount by invoice source in the past 12 months\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT i.SOURCE, AVG(i.INVOICE_AMOUNT) AS AVG_INVOICE_AMOUNT FROM AP_INVOICES_ALL i WHERE i.INVOICE_CREATION_DATE >= ADD_MONTHS(TRUNC(SYSDATE, 'DD'), -12) GROUP BY i.SOURCE ORDER BY AVG_INVOICE_AMOUNT DESC FETCH FIRST 200 ROWS ONLY;\nError: ORA-00904: \"I\".\"INVOICE_CREATION_DATE\": invalid identifier\nDiagnosis: I is AP_INVOICES_ALL, which has NO column named INVOICE_CREATION_DATE. Its columns are: INVOICE_ID, VENDOR_ID, VENDOR_SITE_ID, PARTY_ID, INVOICE_NUM, INVOICE_TYPE_LOOKUP_CODE, INVOICE_DATE, INVOICE_RECEIVED_DATE, GOODS_RECEIVED_DATE, GL_DATE, INVOICE_AMOUNT, AMOUNT_PAID, TOTAL_TAX_AMOUNT, BASE_AMOUNT, APPROVED_AMOUNT, AMOUNT_APPLICABLE_TO_DISCOUNT, DISCOUNT_AMOUNT_TAKEN, PREPAY_AMOUNT_REMAINING, SELF_ASSESSED_TAX_AMOUNT, INVOICE_CURRENCY_CODE, PAYMENT_CURRENCY_CODE, EXCHANGE_RATE, EXCHANGE_DATE, EXCHANGE_RATE_TYPE, TERMS_ID, TERMS_DATE, PAYMENT_METHOD_CODE, PAY_GROUP_LOOKUP_CODE, PAYMENT_STATUS_FLAG, DESCRIPTION, SOURCE, PO_HEADER_ID, BATCH_ID, VALIDATION_STATUS, WFAPPROVAL_STATUS, CANCELLED_DATE, CANCELLED_BY, ACCTS_PAY_CODE_COMBINATION_ID, LEDGER_ID, REQUESTER_ID, LEGAL_ENTITY_ID, DOC_SEQUENCE_VALUE, CREATION_DATE, CREATED_BY, LAST_UPDATE_DATE, LAST_UPDATED_BY, OBJECT_VERSION_NUMBER, ORG_ID, ATTRIBUTE_CATEGORY, ATTRIBUTE1, ATTRIBUTE2, ATTRIBUTE3, ATTRIBUTE4, ATTRIBUTE5, ATTRIBUTE6, ATTRIBUTE7, ATTRIBUTE8, ATTRIBUTE9, ATTRIBUTE10. Closest names: CREATION_DATE, INVOICE_RECEIVED_DATE, INVOICE_DATE.\nWrite a corrected query. It must differ from the failed one. Use ONLY the tables and columns in the schema above, spelled exactly as shown; if a column you wanted does not exist, choose the closest one that does."}, {"role": "assistant", "content": "```sql\nSELECT i.SOURCE, AVG(i.INVOICE_AMOUNT) AS AVG_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_DATE >= ADD_MONTHS(TRUNC(SYSDATE), -12)\nGROUP BY i.SOURCE\nORDER BY AVG_INVOICE_AMOUNT DESC;\n```"}], "meta": {"id": "r-00019", "tier": "T3", "family": "spec-inv", "kind": "repair-exec", "source": "S6-repair", "group": "7e128025c6a3", "tables": ["AP_INVOICES_ALL"], "result_rows": 0, "approx_prompt_tokens": 3493, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"I\".\"INVOICE_CREATION_DATE\": invalid identifier", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_NUMBER NUMBER, -- Sequence of the line within the invoice.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n DESCRIPTION VARCHAR2(240), -- Description of the goods or service on the line.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit billed.\n PO_LINE_LOCATION_ID NUMBER, -- Purchase order schedule this line is matched to. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n TAX_RATE NUMBER(12,6), -- Tax rate applied to the line.\n DISCARDED_FLAG VARCHAR2(1), -- Y if the line was discarded during correction.\n REQUESTER_ID NUMBER, -- Employee who requested the line item. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n MATCH_TYPE VARCHAR2(25), -- How the line was matched. Values: ITEM_TO_PO, ITEM_TO_RECEIPT, NOT_MATCHED.\n PREPAY_INVOICE_ID NUMBER, -- Prepayment invoice applied on this line, if any.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice distributions: how each invoice line amount is split across general-ledger expense accounts, with accounting status. Use for spend-by-GL-account questions.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_DISTRIBUTIONS_ALL (\n INVOICE_DISTRIBUTION_ID NUMBER, -- Unique invoice distribution identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the distribution belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n INVOICE_LINE_ID NUMBER, -- Invoice line the distribution splits. FK to AP_INVOICE_LINES_ALL.INVOICE_LINE_ID.\n DISTRIBUTION_LINE_NUMBER NUMBER, -- Sequence of the distribution within the invoice.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Distribution type: ITEM, TAX, FREIGHT, MISCELLANEOUS. Values: ITEM, TAX, FREIGHT.\n AMOUNT NUMBER(18,2), -- Distribution amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Distribution amount in ledger currency.\n ACCRUAL_POSTED_FLAG VARCHAR2(1), -- Y if accrual accounting entries were created.\n QUANTITY_INVOICED NUMBER, -- Quantity billed for the distribution.\n UNIT_PRICE NUMBER(18,2), -- Unit price on the distribution.\n PO_DISTRIBUTION_ID NUMBER, -- Purchase order distribution matched to. FK to PO_DISTRIBUTIONS_ALL.PO_DISTRIBUTION_ID.\n PROJECT_ID NUMBER, -- Project charged, if project costing is used.\n TASK_ID NUMBER, -- Project task charged.\n INCOME_TAX_REGION VARCHAR2(10), -- Region used for income-tax reporting.\n DESCRIPTION VARCHAR2(240), -- Distribution description.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Invoice batches: groups of invoices entered together, with control totals and entry status.\nCREATE TABLE AP_BATCHES_ALL (\n BATCH_ID NUMBER, -- Unique invoice batch identifier. Primary key.\n BATCH_NAME VARCHAR2(50), -- Name of the batch.\n BATCH_DATE DATE, -- Date the batch was created.\n INVOICE_COUNT NUMBER, -- Number of invoices entered in the batch.\n INVOICE_AMOUNT NUMBER(18,2), -- Total amount of the invoices in the batch.\n CONTROL_INVOICE_COUNT NUMBER, -- Expected invoice count entered as a control total.\n CONTROL_INVOICE_AMOUNT NUMBER(18,2), -- Expected batch amount entered as a control total.\n BATCH_STATUS VARCHAR2(25), -- Status of the batch. Values: OPEN, CLOSED, POSTED.\n SOURCE VARCHAR2(80), -- Source of the batch. Values: MANUAL, IMPORT, SUPPLIER PORTAL.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Purchase order schedules: delivery schedules of a line with need-by date, quantity received and billed, and the matching option (two-, three- or four-way).\n-- (showing 15 of 22 columns: join keys + those relevant to the question)\nCREATE TABLE PO_LINE_LOCATIONS_ALL (\n LINE_LOCATION_ID NUMBER, -- Unique schedule identifier. Primary key.\n SHIPMENT_NUM NUMBER, -- Schedule number within the line.\n QUANTITY NUMBER, -- Quantity scheduled.\n QUANTITY_RECEIVED NUMBER, -- Quantity received so far.\n QUANTITY_BILLED NUMBER, -- Quantity invoiced so far.\n QUANTITY_CANCELLED NUMBER, -- Quantity cancelled.\n NEED_BY_DATE DATE, -- Date the goods are needed.\n PROMISED_DATE DATE, -- Date the supplier promised delivery.\n PRICE_OVERRIDE NUMBER(18,2), -- Price for this schedule if different from the line.\n INVOICE_MATCH_OPTION VARCHAR2(1), -- P match to order (two-way), R match to receipt (three-way). Values: R, P.\n RECEIPT_REQUIRED_FLAG VARCHAR2(1), -- Y if receipt is required before payment.\n TAXABLE_FLAG VARCHAR2(1), -- Y if the schedule is taxable.\n SHIP_TO_LOCATION_ID NUMBER, -- Where the goods are delivered.\n CLOSED_CODE VARCHAR2(25), -- Closure state of the schedule. Values: OPEN, CLOSED FOR RECEIVING, CLOSED.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n\n"}, {"role": "user", "content": "Question: How much miscellaneous did we pay on invoice lines?"}, {"role": "assistant", "content": "```sql\nSELECT SUM(l.AMOUNT)\nFROM AP_INVOICE_LINES_ALL l\nWHERE l.LINE_TYPE_LOOKUP_CODE = 'MISCELLANEOUS';\n```"}], "meta": {"id": "a-00417", "tier": "T2", "family": "t2-lines", "kind": "ask", "source": "S2-templated", "group": "414623c6626e", "tables": ["AP_INVOICE_LINES_ALL"], "result_rows": 1, "approx_prompt_tokens": 2994, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice holds: matching exceptions, duplicates and variances that block payment, with hold reason, date placed and release date. NULL RELEASE_DATE means the hold is still active.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_HOLDS_ALL (\n HOLD_ID NUMBER, -- Unique hold identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the hold is placed on. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_LOCATION_ID NUMBER, -- Purchase order schedule that caused the hold. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n HOLD_LOOKUP_CODE VARCHAR2(30), -- Hold reason. FK to AP_HOLD_CODES.HOLD_LOOKUP_CODE.\n HOLD_DATE DATE, -- Date the hold was placed.\n HELD_BY NUMBER, -- User who placed the hold. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n HOLD_REASON VARCHAR2(240), -- Explanation of why the hold was placed.\n RELEASE_LOOKUP_CODE VARCHAR2(30), -- Reason the hold was released. Values: VARIANCE ACCEPTED, CORRECTED, OVERRIDE.\n RELEASE_DATE DATE, -- Date the hold was released; NULL if still active.\n RELEASE_REASON VARCHAR2(240), -- Comments recorded when the hold was released.\n STATUS_FLAG VARCHAR2(1), -- Hold status: S system-placed, R released. Values: S, R.\n RESPONSIBILITY_ID NUMBER, -- Responsibility able to release the hold.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice batches: groups of invoices entered together, with control totals and entry status.\nCREATE TABLE AP_BATCHES_ALL (\n BATCH_ID NUMBER, -- Unique invoice batch identifier. Primary key.\n BATCH_NAME VARCHAR2(50), -- Name of the batch.\n BATCH_DATE DATE, -- Date the batch was created.\n INVOICE_COUNT NUMBER, -- Number of invoices entered in the batch.\n INVOICE_AMOUNT NUMBER(18,2), -- Total amount of the invoices in the batch.\n CONTROL_INVOICE_COUNT NUMBER, -- Expected invoice count entered as a control total.\n CONTROL_INVOICE_AMOUNT NUMBER(18,2), -- Expected batch amount entered as a control total.\n BATCH_STATUS VARCHAR2(25), -- Status of the batch. Values: OPEN, CLOSED, POSTED.\n SOURCE VARCHAR2(80), -- Source of the batch. Values: MANUAL, IMPORT, SUPPLIER PORTAL.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_NUMBER NUMBER, -- Sequence of the line within the invoice.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit billed.\n PO_LINE_ID NUMBER, -- Purchase order line this line is matched to. FK to PO_LINES_ALL.PO_LINE_ID.\n RCV_TRANSACTION_ID NUMBER, -- Receipt transaction this line is matched to. FK to RCV_TRANSACTIONS.TRANSACTION_ID.\n TAX_RATE NUMBER(12,6), -- Tax rate applied to the line.\n DISCARDED_FLAG VARCHAR2(1), -- Y if the line was discarded during correction.\n CANCELLED_FLAG VARCHAR2(1), -- Y if the line was cancelled.\n REQUESTER_ID NUMBER, -- Employee who requested the line item. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n MATCH_TYPE VARCHAR2(25), -- How the line was matched. Values: ITEM_TO_PO, ITEM_TO_RECEIPT, NOT_MATCHED.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n CANCELLED_DATE DATE, -- Date the invoice was cancelled; NULL if not cancelled.\n CANCELLED_BY VARCHAR2(64), -- User who cancelled the invoice.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number assigned to the invoice.\n);\n\n-- Invoice distributions: how each invoice line amount is split across general-ledger expense accounts, with accounting status. Use for spend-by-GL-account questions.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_DISTRIBUTIONS_ALL (\n INVOICE_DISTRIBUTION_ID NUMBER, -- Unique invoice distribution identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the distribution belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n INVOICE_LINE_ID NUMBER, -- Invoice line the distribution splits. FK to AP_INVOICE_LINES_ALL.INVOICE_LINE_ID.\n DISTRIBUTION_LINE_NUMBER NUMBER, -- Sequence of the distribution within the invoice.\n AMOUNT NUMBER(18,2), -- Distribution amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Distribution amount in ledger currency.\n ACCOUNTING_DATE DATE, -- Accounting date of the distribution.\n POSTED_FLAG VARCHAR2(1), -- Y if accounted and posted to the ledger, N if not yet accounted. Values: Y, N.\n ACCRUAL_POSTED_FLAG VARCHAR2(1), -- Y if accrual accounting entries were created.\n QUANTITY_INVOICED NUMBER, -- Quantity billed for the distribution.\n UNIT_PRICE NUMBER(18,2), -- Unit price on the distribution.\n PO_DISTRIBUTION_ID NUMBER, -- Purchase order distribution matched to. FK to PO_DISTRIBUTIONS_ALL.PO_DISTRIBUTION_ID.\n REVERSAL_FLAG VARCHAR2(1), -- Y if this distribution reverses another.\n TASK_ID NUMBER, -- Project task charged.\n DESCRIPTION VARCHAR2(240), -- Distribution description.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Purchase order distributions: charge accounts and quantities of a schedule, including amount ordered, delivered and billed.\n-- (showing 14 of 19 columns: join keys + those relevant to the question)\nCREATE TABLE PO_DISTRIBUTIONS_ALL (\n PO_DISTRIBUTION_ID NUMBER, -- Unique distribution identifier. Primary key.\n PO_HEADER_ID NUMBER, -- Order the distribution belongs to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n PO_LINE_ID NUMBER, -- Line the distribution belongs to. FK to PO_LINES_ALL.PO_LINE_ID.\n LINE_LOCATION_ID NUMBER, -- Schedule the distribution belongs to. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n DISTRIBUTION_NUM NUMBER, -- Distribution number within the schedule.\n CODE_COMBINATION_ID NUMBER, -- Expense account charged. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n QUANTITY_ORDERED NUMBER, -- Quantity ordered on the distribution.\n QUANTITY_DELIVERED NUMBER, -- Quantity delivered.\n QUANTITY_BILLED NUMBER, -- Quantity billed.\n AMOUNT_ORDERED NUMBER(18,2), -- Amount ordered.\n AMOUNT_BILLED NUMBER(18,2), -- Amount billed so far.\n DESTINATION_TYPE_CODE VARCHAR2(25), -- Where the goods go. Values: EXPENSE, INVENTORY.\n REQUESTER_ID NUMBER, -- Employee who requested the goods. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n PROJECT_ID NUMBER, -- Project charged.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- duplicate invoice => AP_HOLDS_ALL.HOLD_LOOKUP_CODE = 'DUPLICATE INVOICE'\n-- three-way match failure => AP_HOLDS_ALL.HOLD_LOOKUP_CODE IN ('QTY VARIANCE', 'PRICE VARIANCE', 'MISSING RECEIPT')\n"}, {"role": "user", "content": "Question: Count the duplicate invoice holds."}, {"role": "assistant", "content": "```sql\nSELECT COUNT(*)\nFROM AP_HOLDS_ALL\nWHERE HOLD_LOOKUP_CODE = 'DUPLICATE INVOICE';\n```"}], "meta": {"id": "a-00111", "tier": "T1", "family": "t1-count", "kind": "ask", "source": "S2-templated", "group": "6ae66664212c", "tables": ["AP_HOLDS_ALL"], "result_rows": 1, "approx_prompt_tokens": 3016, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n CURRENCY_CODE VARCHAR2(15), -- Currency the payment was made in. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account the payment was drawn on. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n CHECKRUN_ID NUMBER, -- Payment process request identifier.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n);\n\n-- Supplier bank accounts: external bank accounts that payments are sent to, with account holder, currency and validity dates.\n-- (showing 10 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXT_BANK_ACCOUNTS (\n EXT_BANK_ACCOUNT_ID NUMBER, -- Unique external bank account identifier. Primary key.\n BANK_PARTY_ID NUMBER, -- Bank holding the account. FK to CE_BANKS.BANK_PARTY_ID.\n ACCOUNT_OWNER_PARTY_ID NUMBER, -- Party that owns the account. FK to HZ_PARTIES.PARTY_ID.\n BANK_ACCOUNT_NAME VARCHAR2(80), -- Account holder name.\n CURRENCY_CODE VARCHAR2(15), -- Currency of the account. FK to FND_CURRENCIES.CURRENCY_CODE.\n COUNTRY_CODE VARCHAR2(2), -- Country of the account.\n START_DATE DATE, -- Date the account becomes valid.\n END_DATE DATE, -- Date the account stops being valid.\n ACCOUNT_SUFFIX VARCHAR2(30), -- Account suffix used by some banks.\n FOREIGN_PAYMENT_USE_FLAG VARCHAR2(1), -- Y if the account can receive foreign-currency payments.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n INT_BANK_ACCOUNT_ID NUMBER, -- Company bank account used. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXT_BANK_ACCOUNT_ID NUMBER, -- Payee bank account credited. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n);\n\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 15 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_ID NUMBER, -- Address of the site. FK to POZ_SUPPLIER_ADDRESSES.ADDRESS_ID.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Payment method for this site. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Default payment currency at this site. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n TOLERANCE_ID NUMBER, -- Matching tolerance applied at the site.\n SHIP_TO_LOCATION_ID NUMBER, -- Default ship-to location for purchase orders.\n BILL_TO_LOCATION_ID NUMBER, -- Default bill-to location.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25), -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Supplier addresses: physical and remit-to addresses of suppliers.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_ADDRESSES (\n ADDRESS_ID NUMBER, -- Unique address identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the address belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_NAME VARCHAR2(240), -- Name identifying the address.\n ADDRESS_LINE1 VARCHAR2(240), -- First address line.\n ADDRESS_LINE2 VARCHAR2(240), -- Second address line.\n CITY VARCHAR2(60), -- City.\n STATE VARCHAR2(60), -- State or province. Values: CA, NY, TX, WA, IL.\n POSTAL_CODE VARCHAR2(60), -- Postal or ZIP code.\n COUNTRY VARCHAR2(2), -- Country code.\n ADDRESS_PURPOSE VARCHAR2(30), -- What the address is used for. Values: REMIT_TO, PURCHASING, RFQ.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n LATITUDE NUMBER(12,6), -- Latitude of the address.\n LONGITUDE NUMBER(12,6), -- Longitude of the address.\n);\n\n-- Payees: the payment-engine record linking a supplier or site to its payment defaults (method, delivery channel, bank instructions).\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXTERNAL_PAYEES_ALL (\n EXT_PAYEE_ID NUMBER, -- Unique payee identifier. Primary key.\n PAYEE_PARTY_ID NUMBER, -- Party being paid. FK to HZ_PARTIES.PARTY_ID.\n SUPPLIER_SITE_ID NUMBER, -- Supplier site the payee record represents. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n PAYMENT_FUNCTION VARCHAR2(30), -- Payment function the payee is used for. Values: PAYABLES_DISB, EMPLOYEE_EXP.\n DEFAULT_PAYMENT_METHOD_CODE VARCHAR2(30), -- Default payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_FORMAT_CODE VARCHAR2(30), -- Format used for payment files. Values: NACHA, SEPA, POSITIVE PAY.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Default bank delivery channel. Values: ACH, CHAPS, SEPA.\n BANK_INSTRUCTION1_CODE VARCHAR2(30), -- First bank instruction code.\n REMIT_ADVICE_DELIVERY_METHOD VARCHAR2(30), -- How remittance advice is delivered. Values: EMAIL, PRINT.\n REMIT_ADVICE_EMAIL VARCHAR2(255), -- Email address remittance advice is sent to.\n INACTIVE_DATE DATE, -- Date the payee record stops being valid.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n-- vendor spend / supplier spend => SUM(AP_INVOICES_ALL.INVOICE_AMOUNT) grouped by AP_INVOICES_ALL.VENDOR_ID (join POZ_SUPPLIERS for VENDOR_NAME)\n"}, {"role": "user", "content": "Question: Number of payments by supplier city for EFT payments only"}, {"role": "assistant", "content": "```sql\nSELECT a.CITY, COUNT(*) AS PAYMENT_COUNT\nFROM AP_CHECKS_ALL c\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = c.VENDOR_ID\nWHERE c.PAYMENT_METHOD_CODE = 'EFT'\nGROUP BY a.CITY\nORDER BY PAYMENT_COUNT DESC;\n```"}], "meta": {"id": "a-00767", "tier": "T2", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "2619de386cd3", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 7, "approx_prompt_tokens": 2836, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Business units: organizational units that own transactions, with primary ledger and default currency.\nCREATE TABLE FUN_BUSINESS_UNITS (\n BU_ID NUMBER, -- Unique business unit identifier. Primary key.\n BU_NAME VARCHAR2(240), -- Business unit name. Values: US Operations, EMEA Operations, APAC Operations, Canada Operations, Shared Services.\n SHORT_CODE VARCHAR2(30), -- Short code of the business unit.\n PRIMARY_LEDGER_ID NUMBER, -- Ledger the business unit posts to. FK to GL_LEDGERS.LEDGER_ID.\n DEFAULT_CURRENCY_CODE VARCHAR2(15), -- Default currency of the business unit. FK to FND_CURRENCIES.CURRENCY_CODE.\n LEGAL_ENTITY_ID NUMBER, -- Legal entity the business unit belongs to.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n DATE_FROM DATE, -- Date the business unit becomes effective.\n DATE_TO DATE, -- Date the business unit stops being effective.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n INT_BANK_ACCOUNT_ID NUMBER, -- Company bank account used. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXT_BANK_ACCOUNT_ID NUMBER, -- Payee bank account credited. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting payment currency to ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account the payment was drawn on. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 15 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Payment method for this site. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Default payment currency at this site. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n ALWAYS_TAKE_DISC_FLAG VARCHAR2(1), -- Y if the early-payment discount is always taken.\n SHIP_TO_LOCATION_ID NUMBER, -- Default ship-to location for purchase orders.\n BILL_TO_LOCATION_ID NUMBER, -- Default bill-to location.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Supplier bank accounts: external bank accounts that payments are sent to, with account holder, currency and validity dates.\n-- (showing 10 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXT_BANK_ACCOUNTS (\n EXT_BANK_ACCOUNT_ID NUMBER, -- Unique external bank account identifier. Primary key.\n BANK_PARTY_ID NUMBER, -- Bank holding the account. FK to CE_BANKS.BANK_PARTY_ID.\n ACCOUNT_OWNER_PARTY_ID NUMBER, -- Party that owns the account. FK to HZ_PARTIES.PARTY_ID.\n BANK_ACCOUNT_NAME VARCHAR2(80), -- Account holder name.\n CURRENCY_CODE VARCHAR2(15), -- Currency of the account. FK to FND_CURRENCIES.CURRENCY_CODE.\n COUNTRY_CODE VARCHAR2(2), -- Country of the account.\n START_DATE DATE, -- Date the account becomes valid.\n END_DATE DATE, -- Date the account stops being valid.\n ACCOUNT_SUFFIX VARCHAR2(30), -- Account suffix used by some banks.\n FOREIGN_PAYMENT_USE_FLAG VARCHAR2(1), -- Y if the account can receive foreign-currency payments.\n);\n\n-- Payees: the payment-engine record linking a supplier or site to its payment defaults (method, delivery channel, bank instructions).\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXTERNAL_PAYEES_ALL (\n EXT_PAYEE_ID NUMBER, -- Unique payee identifier. Primary key.\n PAYEE_PARTY_ID NUMBER, -- Party being paid. FK to HZ_PARTIES.PARTY_ID.\n SUPPLIER_SITE_ID NUMBER, -- Supplier site the payee record represents. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n PAYMENT_FUNCTION VARCHAR2(30), -- Payment function the payee is used for. Values: PAYABLES_DISB, EMPLOYEE_EXP.\n DEFAULT_PAYMENT_METHOD_CODE VARCHAR2(30), -- Default payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_FORMAT_CODE VARCHAR2(30), -- Format used for payment files. Values: NACHA, SEPA, POSITIVE PAY.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Default bank delivery channel. Values: ACH, CHAPS, SEPA.\n BANK_INSTRUCTION1_CODE VARCHAR2(30), -- First bank instruction code.\n REMIT_ADVICE_DELIVERY_METHOD VARCHAR2(30), -- How remittance advice is delivered. Values: EMAIL, PRINT.\n REMIT_ADVICE_EMAIL VARCHAR2(255), -- Email address remittance advice is sent to.\n INACTIVE_DATE DATE, -- Date the payee record stops being valid.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25), -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n"}, {"role": "user", "content": "Question: Which 5 business units have the highest biggest payment for payments over 10,000?"}, {"role": "assistant", "content": "```sql\nSELECT bu.BU_NAME, MAX(c.AMOUNT) AS MAX_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nJOIN FUN_BUSINESS_UNITS bu ON bu.BU_ID = c.ORG_ID\nWHERE c.AMOUNT > 10000\nGROUP BY bu.BU_NAME\nORDER BY MAX_PAYMENT_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00362", "tier": "T2", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "676829cde8b4", "tables": ["AP_CHECKS_ALL", "FUN_BUSINESS_UNITS"], "result_rows": 5, "approx_prompt_tokens": 2939, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 15 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_ID NUMBER, -- Address of the site. FK to POZ_SUPPLIER_ADDRESSES.ADDRESS_ID.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Payment method for this site. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n TOLERANCE_ID NUMBER, -- Matching tolerance applied at the site.\n SHIP_TO_LOCATION_ID NUMBER, -- Default ship-to location for purchase orders.\n BILL_TO_LOCATION_ID NUMBER, -- Default bill-to location.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account the payment was drawn on. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n CHECKRUN_ID NUMBER, -- Payment process request identifier.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n EXT_BANK_ACCOUNT_ID NUMBER, -- Payee bank account credited. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Supplier addresses: physical and remit-to addresses of suppliers.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_ADDRESSES (\n ADDRESS_ID NUMBER, -- Unique address identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the address belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_NAME VARCHAR2(240), -- Name identifying the address.\n ADDRESS_LINE1 VARCHAR2(240), -- First address line.\n ADDRESS_LINE2 VARCHAR2(240), -- Second address line.\n CITY VARCHAR2(60), -- City.\n STATE VARCHAR2(60), -- State or province. Values: CA, NY, TX, WA, IL.\n POSTAL_CODE VARCHAR2(60), -- Postal or ZIP code.\n COUNTRY VARCHAR2(2), -- Country code.\n ADDRESS_PURPOSE VARCHAR2(30), -- What the address is used for. Values: REMIT_TO, PURCHASING, RFQ.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n LATITUDE NUMBER(12,6), -- Latitude of the address.\n LONGITUDE NUMBER(12,6), -- Longitude of the address.\n);\n\n-- Supplier bank accounts: external bank accounts that payments are sent to, with account holder, currency and validity dates.\n-- (showing 10 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXT_BANK_ACCOUNTS (\n EXT_BANK_ACCOUNT_ID NUMBER, -- Unique external bank account identifier. Primary key.\n BANK_PARTY_ID NUMBER, -- Bank holding the account. FK to CE_BANKS.BANK_PARTY_ID.\n ACCOUNT_OWNER_PARTY_ID NUMBER, -- Party that owns the account. FK to HZ_PARTIES.PARTY_ID.\n BANK_ACCOUNT_NAME VARCHAR2(80), -- Account holder name.\n CURRENCY_CODE VARCHAR2(15), -- Currency of the account. FK to FND_CURRENCIES.CURRENCY_CODE.\n COUNTRY_CODE VARCHAR2(2), -- Country of the account.\n START_DATE DATE, -- Date the account becomes valid.\n END_DATE DATE, -- Date the account stops being valid.\n ACCOUNT_SUFFIX VARCHAR2(30), -- Account suffix used by some banks.\n FOREIGN_PAYMENT_USE_FLAG VARCHAR2(1), -- Y if the account can receive foreign-currency payments.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\n-- (showing 15 of 38 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n VENDOR_NAME VARCHAR2(360), -- Supplier name.\n VENDOR_NAME_ALT VARCHAR2(320), -- Alternate or trading name of the supplier.\n SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\n VENDOR_TYPE_LOOKUP_CODE VARCHAR2(30), -- Supplier type. Values: VENDOR, CONTRACTOR, EMPLOYEE, TAX AUTHORITY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n ONE_TIME_FLAG VARCHAR2(1), -- Y if the supplier is a one-time supplier.\n SMALL_BUSINESS_FLAG VARCHAR2(1), -- Y if the supplier is a small business.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Default payment method for the supplier. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Default pay group. Values: DOMESTIC, INTERNATIONAL.\n TERMS_ID NUMBER, -- Default payment terms. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Default payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if all payments to the supplier are blocked.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2), -- Maximum credit extended to the supplier.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25), -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n-- supplier state / vendor state / by state => POZ_SUPPLIER_ADDRESSES.STATE (join on VENDOR_ID)\n"}, {"role": "user", "content": "Question: Show the 5 supplier cities with the highest payment count"}, {"role": "assistant", "content": "```sql\nSELECT a.CITY, COUNT(*) AS PAYMENT_COUNT\nFROM AP_CHECKS_ALL c\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = c.VENDOR_ID\nGROUP BY a.CITY\nORDER BY PAYMENT_COUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00411", "tier": "T2", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "4e8f9d17a922", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 5, "approx_prompt_tokens": 2896, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n VOID_DATE DATE, -- Date the payment was voided.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n CHECKRUN_NAME VARCHAR2(255) -- Payment process request that created the payment.\n);\n\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 15 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_CODE VARCHAR2(15), -- Short site code.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Payment method for this site. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n ALWAYS_TAKE_DISC_FLAG VARCHAR2(1), -- Y if the early-payment discount is always taken.\n SHIP_TO_LOCATION_ID NUMBER, -- Default ship-to location for purchase orders.\n BILL_TO_LOCATION_ID NUMBER -- Default bill-to location.\n);\n\n-- Supplier bank accounts: external bank accounts that payments are sent to, with account holder, currency and validity dates.\n-- (showing 10 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXT_BANK_ACCOUNTS (\n EXT_BANK_ACCOUNT_ID NUMBER, -- Unique external bank account identifier. Primary key.\n BANK_PARTY_ID NUMBER, -- Bank holding the account. FK to CE_BANKS.BANK_PARTY_ID.\n ACCOUNT_OWNER_PARTY_ID NUMBER, -- Party that owns the account. FK to HZ_PARTIES.PARTY_ID.\n BANK_ACCOUNT_NAME VARCHAR2(80), -- Account holder name.\n CURRENCY_CODE VARCHAR2(15), -- Currency of the account. FK to FND_CURRENCIES.CURRENCY_CODE.\n COUNTRY_CODE VARCHAR2(2), -- Country of the account.\n START_DATE DATE, -- Date the account becomes valid.\n END_DATE DATE, -- Date the account stops being valid.\n ACCOUNT_SUFFIX VARCHAR2(30), -- Account suffix used by some banks.\n FOREIGN_PAYMENT_USE_FLAG VARCHAR2(1) -- Y if the account can receive foreign-currency payments.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n EXT_BANK_ACCOUNT_ID NUMBER, -- Payee bank account credited. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE -- Date the payment was voided.\n);\n\n-- Payees: the payment-engine record linking a supplier or site to its payment defaults (method, delivery channel, bank instructions).\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXTERNAL_PAYEES_ALL (\n EXT_PAYEE_ID NUMBER, -- Unique payee identifier. Primary key.\n PAYEE_PARTY_ID NUMBER, -- Party being paid. FK to HZ_PARTIES.PARTY_ID.\n SUPPLIER_SITE_ID NUMBER, -- Supplier site the payee record represents. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n PAYMENT_FUNCTION VARCHAR2(30), -- Payment function the payee is used for. Values: PAYABLES_DISB, EMPLOYEE_EXP.\n DEFAULT_PAYMENT_METHOD_CODE VARCHAR2(30), -- Default payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_FORMAT_CODE VARCHAR2(30), -- Format used for payment files. Values: NACHA, SEPA, POSITIVE PAY.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Default bank delivery channel. Values: ACH, CHAPS, SEPA.\n BANK_INSTRUCTION1_CODE VARCHAR2(30), -- First bank instruction code.\n REMIT_ADVICE_DELIVERY_METHOD VARCHAR2(30), -- How remittance advice is delivered. Values: EMAIL, PRINT.\n REMIT_ADVICE_EMAIL VARCHAR2(255), -- Email address remittance advice is sent to.\n INACTIVE_DATE DATE -- Date the payee record stops being valid.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25) -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\n-- (showing 15 of 38 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n VENDOR_NAME VARCHAR2(360), -- Supplier name.\n VENDOR_NAME_ALT VARCHAR2(320), -- Alternate or trading name of the supplier.\n SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n START_DATE_ACTIVE DATE, -- Date the supplier becomes active.\n ONE_TIME_FLAG VARCHAR2(1), -- Y if the supplier is a one-time supplier.\n SMALL_BUSINESS_FLAG VARCHAR2(1), -- Y if the supplier is a small business.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Default payment method for the supplier. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Default pay group. Values: DOMESTIC, INTERNATIONAL.\n TERMS_ID NUMBER, -- Default payment terms. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Default payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if all payments to the supplier are blocked.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2) -- Maximum credit extended to the supplier.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- vendor spend / supplier spend => SUM(AP_INVOICES_ALL.INVOICE_AMOUNT) grouped by AP_INVOICES_ALL.VENDOR_ID (join POZ_SUPPLIERS for VENDOR_NAME)\n"}, {"role": "user", "content": "Question: For every supplier, list the top 2 earliest payments"}, {"role": "assistant", "content": "```sql\nSELECT VENDOR_NAME, CHECK_NUMBER, CHECK_DATE, AMOUNT\nFROM (\n SELECT s.VENDOR_NAME, c.CHECK_NUMBER, c.CHECK_DATE, c.AMOUNT,\n ROW_NUMBER() OVER (PARTITION BY s.VENDOR_NAME ORDER BY c.CHECK_DATE ASC) AS RN\n FROM AP_CHECKS_ALL c\n JOIN POZ_SUPPLIERS s ON s.VENDOR_ID = c.VENDOR_ID\n)\nWHERE RN <= 2\nORDER BY VENDOR_NAME, RN;\n```"}], "meta": {"id": "a-01346", "tier": "T4", "family": "t4-topk", "kind": "ask", "source": "S2-templated", "group": "b6f1ad0a9126", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIERS"], "result_rows": 18, "approx_prompt_tokens": 2916, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Hold and release reason codes: definitions of the hold types that can be placed on invoices.\nCREATE TABLE AP_HOLD_CODES (\n HOLD_LOOKUP_CODE VARCHAR2(30), -- Hold or release reason code. Values: MATCHING, DUPLICATE INVOICE, TAX VARIANCE, PRICE VARIANCE, QTY VARIANCE, MISSING RECEIPT, AMOUNT LIMIT, UNAPPROVED, CURRENCY MISMATCH, TERMS MISMATCH. Primary key.\n HOLD_TYPE VARCHAR2(25), -- Whether the code is a hold or a release reason. Values: HOLD, RELEASE.\n DESCRIPTION VARCHAR2(240), -- Meaning of the hold code.\n USER_RELEASEABLE_FLAG VARCHAR2(1), -- Y if users may release this hold manually.\n USER_ALLOWED_FLAG VARCHAR2(1), -- Y if users may place this hold manually.\n POSTABLE_FLAG VARCHAR2(1), -- Y if invoices with this hold can still be accounted.\n INACTIVE_DATE DATE, -- Date the code stops being valid.\n HOLD_INSTRUCTION VARCHAR2(240), -- Guidance to the analyst on resolving the hold.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Invoice holds: matching exceptions, duplicates and variances that block payment, with hold reason, date placed and release date. NULL RELEASE_DATE means the hold is still active.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_HOLDS_ALL (\n HOLD_ID NUMBER, -- Unique hold identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the hold is placed on. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_LOCATION_ID NUMBER, -- Purchase order schedule that caused the hold. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n HOLD_LOOKUP_CODE VARCHAR2(30), -- Hold reason. FK to AP_HOLD_CODES.HOLD_LOOKUP_CODE.\n HOLD_DATE DATE, -- Date the hold was placed.\n HELD_BY NUMBER, -- User who placed the hold. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n HOLD_REASON VARCHAR2(240), -- Explanation of why the hold was placed.\n RELEASE_LOOKUP_CODE VARCHAR2(30), -- Reason the hold was released. Values: VARIANCE ACCEPTED, CORRECTED, OVERRIDE.\n RELEASE_DATE DATE, -- Date the hold was released; NULL if still active.\n RELEASE_REASON VARCHAR2(240), -- Comments recorded when the hold was released.\n STATUS_FLAG VARCHAR2(1), -- Hold status: S system-placed, R released. Values: S, R.\n RESPONSIBILITY_ID NUMBER, -- Responsibility able to release the hold.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Subledger accounting entry lines: debit and credit lines of each accounting entry with account, amounts and the source transaction.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE XLA_AE_LINES (\n AE_LINE_ID NUMBER, -- Unique accounting line identifier. Primary key.\n AE_HEADER_ID NUMBER, -- Entry the line belongs to. FK to XLA_AE_HEADERS.AE_HEADER_ID.\n AE_LINE_NUM NUMBER, -- Line number within the entry.\n CODE_COMBINATION_ID NUMBER, -- Account of the line. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n ACCOUNTING_CLASS_CODE VARCHAR2(30), -- Accounting class such as liability or expense. Values: LIABILITY, ITEM EXPENSE, CASH, TAX, PREPAID.\n ENTERED_DR NUMBER(18,2), -- Debit in entered currency.\n ENTERED_CR NUMBER(18,2), -- Credit in entered currency.\n ACCOUNTED_DR NUMBER(18,2), -- Debit in ledger currency.\n ACCOUNTED_CR NUMBER(18,2), -- Credit in ledger currency.\n CURRENCY_CONVERSION_RATE NUMBER(12,6), -- Rate used to convert to ledger currency.\n DESCRIPTION VARCHAR2(240), -- Line description.\n SOURCE_TABLE VARCHAR2(30), -- Source table of the transaction. Values: AP_INVOICES_ALL, AP_INVOICE_PAYMENTS_ALL.\n SOURCE_ID NUMBER, -- Identifier of the source transaction.\n PARTY_ID NUMBER, -- Supplier party of the line. FK to HZ_PARTIES.PARTY_ID.\n GL_SL_LINK_ID NUMBER -- Link to the general-ledger journal line.\n);\n\n-- Subledger accounting entry headers: accounting entries generated from payables transactions, with event type, accounting date and transfer status to the general ledger.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE XLA_AE_HEADERS (\n AE_HEADER_ID NUMBER, -- Unique accounting entry identifier. Primary key.\n APPLICATION_ID NUMBER, -- Subledger application, 200 for Payables.\n EVENT_TYPE_CODE VARCHAR2(30), -- Type of accounting event. Values: INVOICE VALIDATED, PAYMENT CREATED, PAYMENT CANCELLED, INVOICE CANCELLED.\n ENTITY_ID NUMBER, -- Source transaction entity.\n ACCOUNTING_DATE DATE, -- Accounting date of the entry.\n PERIOD_NAME VARCHAR2(15), -- Accounting period.\n DESCRIPTION VARCHAR2(240), -- Entry description.\n ACCOUNTING_ENTRY_STATUS_CODE VARCHAR2(1), -- F final, D draft, I incomplete. Values: F, D.\n GL_TRANSFER_STATUS_CODE VARCHAR2(1), -- Y transferred to general ledger, N not yet transferred. Values: Y, N.\n GL_TRANSFER_DATE DATE, -- Date transferred to the general ledger.\n JE_CATEGORY_NAME VARCHAR2(30), -- Journal category on transfer. Values: Purchase Invoices, Payments.\n BALANCE_TYPE_CODE VARCHAR2(1), -- A actual, B budget.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number.\n PRODUCT_RULE_CODE VARCHAR2(30), -- Accounting rule applied.\n FUNDS_STATUS_CODE VARCHAR2(1) -- Funds check status.\n);\n\n-- Purchase order schedules: delivery schedules of a line with need-by date, quantity received and billed, and the matching option (two-, three- or four-way).\n-- (showing 15 of 22 columns: join keys + those relevant to the question)\nCREATE TABLE PO_LINE_LOCATIONS_ALL (\n LINE_LOCATION_ID NUMBER, -- Unique schedule identifier. Primary key.\n PO_HEADER_ID NUMBER, -- Order the schedule belongs to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n PO_LINE_ID NUMBER, -- Line the schedule belongs to. FK to PO_LINES_ALL.PO_LINE_ID.\n SHIPMENT_NUM NUMBER, -- Schedule number within the line.\n QUANTITY NUMBER, -- Quantity scheduled.\n QUANTITY_RECEIVED NUMBER, -- Quantity received so far.\n QUANTITY_BILLED NUMBER, -- Quantity invoiced so far.\n QUANTITY_CANCELLED NUMBER, -- Quantity cancelled.\n NEED_BY_DATE DATE, -- Date the goods are needed.\n PRICE_OVERRIDE NUMBER(18,2), -- Price for this schedule if different from the line.\n INVOICE_MATCH_OPTION VARCHAR2(1), -- P match to order (two-way), R match to receipt (three-way). Values: R, P.\n RECEIPT_REQUIRED_FLAG VARCHAR2(1), -- Y if receipt is required before payment.\n TAXABLE_FLAG VARCHAR2(1), -- Y if the schedule is taxable.\n CLOSED_CODE VARCHAR2(25), -- Closure state of the schedule. Values: OPEN, CLOSED FOR RECEIVING, CLOSED.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Chart of accounts: every valid account code combination (company, cost center, natural account) with type and enabled flag. Joined from invoice distributions to name the expense account.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE GL_CODE_COMBINATIONS (\n CODE_COMBINATION_ID NUMBER, -- Unique account combination identifier. Primary key.\n CHART_OF_ACCOUNTS_ID NUMBER, -- Chart of accounts the combination belongs to.\n CONCATENATED_SEGMENTS VARCHAR2(240), -- Full account string, for example 01-520-7110-0000.\n SEGMENT1 VARCHAR2(25), -- Company segment.\n SEGMENT2 VARCHAR2(25), -- Cost center segment.\n SEGMENT3 VARCHAR2(25), -- Natural account segment.\n SEGMENT4 VARCHAR2(25), -- Sub-account segment.\n SEGMENT5 VARCHAR2(25), -- Product segment.\n SEGMENT6 VARCHAR2(25), -- Intercompany segment.\n ACCOUNT_TYPE VARCHAR2(1), -- A asset, L liability, E expense, O owner equity, R revenue. Values: E, L, A.\n ACCOUNT_DESCRIPTION VARCHAR2(240), -- Description of the natural account. Values: Accounts Payable, Office Supplies, Professional Fees, Travel, Freight, Software, Cash, Prepaid Expenses, Utilities, Rent.\n ENABLED_FLAG VARCHAR2(1), -- Y if the combination can be used.\n DETAIL_POSTING_ALLOWED_FLAG VARCHAR2(1), -- Y if posting is allowed to the account.\n START_DATE_ACTIVE DATE, -- Date the combination becomes active.\n END_DATE_ACTIVE DATE -- Date the combination stops being active.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- on hold => AP_HOLDS_ALL.RELEASE_DATE IS NULL (active hold; the reason is AP_HOLDS_ALL.HOLD_LOOKUP_CODE)\n-- three-way match failure => AP_HOLDS_ALL.HOLD_LOOKUP_CODE IN ('QTY VARIANCE', 'PRICE VARIANCE', 'MISSING RECEIPT')\n-- early payment discount => AP_PAYMENT_SCHEDULES_ALL.DISCOUNT_AMOUNT_AVAILABLE > 0\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: How many active holds are there?"}, {"role": "assistant", "content": "```sql\nSELECT COUNT(*)\nFROM AP_HOLDS_ALL\nWHERE RELEASE_DATE IS NULL;\n```"}], "meta": {"id": "a-00081", "tier": "T1", "family": "t1-count", "kind": "ask", "source": "S2-templated", "group": "8d658993edd6", "tables": ["AP_HOLDS_ALL"], "result_rows": 1, "approx_prompt_tokens": 3070, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Business units: organizational units that own transactions, with primary ledger and default currency.\nCREATE TABLE FUN_BUSINESS_UNITS (\n BU_ID NUMBER, -- Unique business unit identifier. Primary key.\n BU_NAME VARCHAR2(240), -- Business unit name. Values: US Operations, EMEA Operations, APAC Operations, Canada Operations, Shared Services.\n SHORT_CODE VARCHAR2(30), -- Short code of the business unit.\n PRIMARY_LEDGER_ID NUMBER, -- Ledger the business unit posts to. FK to GL_LEDGERS.LEDGER_ID.\n DEFAULT_CURRENCY_CODE VARCHAR2(15), -- Default currency of the business unit. FK to FND_CURRENCIES.CURRENCY_CODE.\n LEGAL_ENTITY_ID NUMBER, -- Legal entity the business unit belongs to.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n DATE_FROM DATE, -- Date the business unit becomes effective.\n DATE_TO DATE, -- Date the business unit stops being effective.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Supplier bank accounts: external bank accounts that payments are sent to, with account holder, currency and validity dates.\n-- (showing 10 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXT_BANK_ACCOUNTS (\n EXT_BANK_ACCOUNT_ID NUMBER, -- Unique external bank account identifier. Primary key.\n BANK_PARTY_ID NUMBER, -- Bank holding the account. FK to CE_BANKS.BANK_PARTY_ID.\n ACCOUNT_OWNER_PARTY_ID NUMBER, -- Party that owns the account. FK to HZ_PARTIES.PARTY_ID.\n BANK_ACCOUNT_NAME VARCHAR2(80), -- Account holder name.\n CURRENCY_CODE VARCHAR2(15), -- Currency of the account. FK to FND_CURRENCIES.CURRENCY_CODE.\n COUNTRY_CODE VARCHAR2(2), -- Country of the account.\n START_DATE DATE, -- Date the account becomes valid.\n END_DATE DATE, -- Date the account stops being valid.\n ACCOUNT_SUFFIX VARCHAR2(30), -- Account suffix used by some banks.\n FOREIGN_PAYMENT_USE_FLAG VARCHAR2(1) -- Y if the account can receive foreign-currency payments.\n);\n\n-- Company bank accounts: internal bank accounts used to fund payments and receive cash, with currency, ledger and reconciliation settings.\n-- (showing 15 of 22 columns: join keys + those relevant to the question)\nCREATE TABLE CE_BANK_ACCOUNTS (\n BANK_ACCOUNT_ID NUMBER, -- Unique bank account identifier. Primary key.\n BANK_PARTY_ID NUMBER, -- Bank holding the account. FK to CE_BANKS.BANK_PARTY_ID.\n BANK_ACCOUNT_NAME VARCHAR2(80), -- Name of the bank account.\n CURRENCY_CODE VARCHAR2(15), -- Currency of the account. FK to FND_CURRENCIES.CURRENCY_CODE.\n ACCOUNT_TYPE VARCHAR2(25), -- Type of bank account. Values: CHECKING, SAVINGS, PAYROLL.\n ACCOUNT_CLASSIFICATION VARCHAR2(30), -- Whether the account is internal or external.\n AP_USE_ALLOWED_FLAG VARCHAR2(1), -- Y if the account can be used for payables payments.\n AR_USE_ALLOWED_FLAG VARCHAR2(1), -- Y if the account can be used for receivables.\n CASH_CCID NUMBER, -- Cash general-ledger account. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n LEDGER_ID NUMBER, -- Ledger the account is accounted in. FK to GL_LEDGERS.LEDGER_ID.\n END_DATE DATE, -- Date the account is closed.\n MAX_CHECK_AMOUNT NUMBER(18,2), -- Maximum single payment allowed on the account.\n MULTI_CURRENCY_ALLOWED_FLAG VARCHAR2(1), -- Y if payments in other currencies are allowed.\n ACCOUNT_OWNER_PARTY_ID NUMBER, -- Party that owns the account. FK to HZ_PARTIES.PARTY_ID.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 16 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account the payment was drawn on. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n INT_BANK_ACCOUNT_ID NUMBER, -- Company bank account used. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXT_BANK_ACCOUNT_ID NUMBER, -- Payee bank account credited. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE, -- Date the payment was voided.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 16 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Payment method for this site. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n INACTIVE_DATE DATE, -- Date the site becomes inactive.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n ALWAYS_TAKE_DISC_FLAG VARCHAR2(1), -- Y if the early-payment discount is always taken.\n TOLERANCE_ID NUMBER, -- Matching tolerance applied at the site.\n SHIP_TO_LOCATION_ID NUMBER, -- Default ship-to location for purchase orders.\n BILL_TO_LOCATION_ID NUMBER, -- Default bill-to location.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: Which 5 business units have the highest total amount paid out over the past 30 days?"}, {"role": "assistant", "content": "```sql\nSELECT bu.BU_NAME, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nJOIN FUN_BUSINESS_UNITS bu ON bu.BU_ID = c.ORG_ID\nWHERE c.CHECK_DATE >= TRUNC(SYSDATE) - 30\nGROUP BY bu.BU_NAME\nORDER BY TOTAL_PAYMENT_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-01206", "tier": "T3", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "915f6c399cf1", "tables": ["AP_CHECKS_ALL", "FUN_BUSINESS_UNITS"], "result_rows": 5, "approx_prompt_tokens": 3025, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Invoice batches: groups of invoices entered together, with control totals and entry status.\nCREATE TABLE AP_BATCHES_ALL (\n BATCH_ID NUMBER, -- Unique invoice batch identifier. Primary key.\n BATCH_NAME VARCHAR2(50), -- Name of the batch.\n BATCH_DATE DATE, -- Date the batch was created.\n INVOICE_COUNT NUMBER, -- Number of invoices entered in the batch.\n INVOICE_AMOUNT NUMBER(18,2), -- Total amount of the invoices in the batch.\n CONTROL_INVOICE_COUNT NUMBER, -- Expected invoice count entered as a control total.\n CONTROL_INVOICE_AMOUNT NUMBER(18,2), -- Expected batch amount entered as a control total.\n BATCH_STATUS VARCHAR2(25), -- Status of the batch. Values: OPEN, CLOSED, POSTED.\n SOURCE VARCHAR2(80), -- Source of the batch. Values: MANUAL, IMPORT, SUPPLIER PORTAL.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Prepayment application history: which prepayment invoices were applied to which standard invoices, with amounts and dates.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PREPAY_HISTORY_ALL (\n PREPAY_HISTORY_ID NUMBER, -- Unique prepayment application identifier. Primary key.\n PREPAY_INVOICE_ID NUMBER, -- Prepayment invoice being applied. FK to AP_INVOICES_ALL.INVOICE_ID.\n INVOICE_ID NUMBER, -- Standard invoice the prepayment is applied to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PREPAY_DIST_ID NUMBER, -- Prepayment distribution consumed. FK to AP_INVOICE_DISTRIBUTIONS_ALL.INVOICE_DISTRIBUTION_ID.\n INVOICE_LINE_NUMBER NUMBER, -- Line of the standard invoice receiving the application.\n ACCOUNTING_DATE DATE, -- Accounting date of the application.\n USED_AMOUNT NUMBER(18,2), -- Amount of the prepayment applied.\n TRANSACTION_TYPE VARCHAR2(25), -- Whether the row is an application or an unapplication. Values: PREPAYMENT APPLIED, PREPAYMENT UNAPPLIED.\n POSTED_FLAG VARCHAR2(1), -- Y if the application was accounted.\n DESCRIPTION VARCHAR2(240), -- Description of the application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n CANCELLED_DATE DATE, -- Date the invoice was cancelled; NULL if not cancelled.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number assigned to the invoice.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: Count of overdue installments by age bucket: 15, 30 and 60 days"}, {"role": "assistant", "content": "```sql\nSELECT CASE WHEN TRUNC(SYSDATE) - ps.DUE_DATE <= 15 THEN '1-15' WHEN TRUNC(SYSDATE) - ps.DUE_DATE <= 30 THEN '16-30' WHEN TRUNC(SYSDATE) - ps.DUE_DATE <= 60 THEN '31-60' ELSE 'Over 60' END AS AGING_BUCKET, COUNT(*) AS INSTALLMENT_COUNT\nFROM AP_PAYMENT_SCHEDULES_ALL ps\nWHERE ps.DUE_DATE < TRUNC(SYSDATE) AND ps.AMOUNT_REMAINING > 0\nGROUP BY CASE WHEN TRUNC(SYSDATE) - ps.DUE_DATE <= 15 THEN '1-15' WHEN TRUNC(SYSDATE) - ps.DUE_DATE <= 30 THEN '16-30' WHEN TRUNC(SYSDATE) - ps.DUE_DATE <= 60 THEN '31-60' ELSE 'Over 60' END\nORDER BY MAX(ps.DUE_DATE) DESC;\n```"}], "meta": {"id": "a-00862", "tier": "T3", "family": "t3-aging", "kind": "ask", "source": "S2-templated", "group": "065fa358c3a7", "tables": ["AP_PAYMENT_SCHEDULES_ALL"], "result_rows": 4, "approx_prompt_tokens": 2296, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n SOURCE VARCHAR2(80), -- How the invoice entered the system. Values: MANUAL, IMPORT, SUPPLIER PORTAL, EMAIL.\n PO_HEADER_ID NUMBER, -- Purchase order the invoice is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account the payment was drawn on. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n DOC_SEQUENCE_VALUE NUMBER -- Document sequence number of the payment.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Purchase order headers: one row per purchase order with supplier, buyer, status, total and terms.\n-- (showing 15 of 28 columns: join keys + those relevant to the question)\nCREATE TABLE PO_HEADERS_ALL (\n PO_HEADER_ID NUMBER, -- Unique purchase order identifier. Primary key.\n SEGMENT1 VARCHAR2(30), -- Purchase order number.\n TYPE_LOOKUP_CODE VARCHAR2(25), -- Order type. Values: STANDARD, BLANKET, CONTRACT.\n VENDOR_ID NUMBER, -- Supplier the order is placed with. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the order is placed with. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n AGENT_ID NUMBER, -- Buyer who created the order. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n CURRENCY_CODE VARCHAR2(15), -- Order currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n RATE NUMBER(12,6), -- Exchange rate on the order.\n TERMS_ID NUMBER, -- Payment terms on the order. FK to AP_TERMS_B.TERM_ID.\n DOCUMENT_STATUS VARCHAR2(25), -- Status of the order. Values: OPEN, CLOSED, CANCELLED, INCOMPLETE.\n APPROVED_FLAG VARCHAR2(1), -- Y if approved. Values: Y, N.\n TOTAL_AMOUNT NUMBER(18,2), -- Total order amount.\n NOTE_TO_VENDOR VARCHAR2(480), -- Note printed for the supplier.\n FREIGHT_TERMS_LOOKUP_CODE VARCHAR2(25), -- Who pays freight. Values: PAID, DUE.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25) -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 15 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_CODE VARCHAR2(15), -- Short site code.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Payment method for this site. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n TOLERANCE_ID NUMBER, -- Matching tolerance applied at the site.\n BILL_TO_LOCATION_ID NUMBER, -- Default bill-to location.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\n-- (showing 15 of 38 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n VENDOR_NAME VARCHAR2(360), -- Supplier name.\n SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\n VENDOR_TYPE_LOOKUP_CODE VARCHAR2(30), -- Supplier type. Values: VENDOR, CONTRACTOR, EMPLOYEE, TAX AUTHORITY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n SUMMARY_FLAG VARCHAR2(1), -- Y if the supplier is a summary (parent) record.\n ONE_TIME_FLAG VARCHAR2(1), -- Y if the supplier is a one-time supplier.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Default payment method for the supplier. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Default pay group. Values: DOMESTIC, INTERNATIONAL.\n TERMS_ID NUMBER, -- Default payment terms. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Default payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if all payments to the supplier are blocked.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n FEDERAL_REPORTABLE_FLAG VARCHAR2(1), -- Y if the supplier is reportable for federal income tax.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2) -- Maximum credit extended to the supplier.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- vendor spend / supplier spend => SUM(AP_INVOICES_ALL.INVOICE_AMOUNT) grouped by AP_INVOICES_ALL.VENDOR_ID (join POZ_SUPPLIERS for VENDOR_NAME)\n-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n"}, {"role": "user", "content": "Question: Show every supplier with a comma-separated list of the payment statuses of their payments"}, {"role": "assistant", "content": "```sql\nSELECT VENDOR_NAME, LISTAGG(STATUS_LOOKUP_CODE, ', ') WITHIN GROUP (ORDER BY STATUS_LOOKUP_CODE) AS VALUES_LIST\nFROM (\n SELECT DISTINCT s.VENDOR_NAME, c.STATUS_LOOKUP_CODE\n FROM AP_CHECKS_ALL c\n JOIN POZ_SUPPLIERS s ON s.VENDOR_ID = c.VENDOR_ID\n)\nGROUP BY VENDOR_NAME\nORDER BY VENDOR_NAME;\n```"}], "meta": {"id": "a-00905", "tier": "T3", "family": "t3-listagg", "kind": "ask", "source": "S2-templated", "group": "0874243a92d7", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIERS"], "result_rows": 9, "approx_prompt_tokens": 3151, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 19 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n SOURCE VARCHAR2(80), -- How the invoice entered the system. Values: MANUAL, IMPORT, SUPPLIER PORTAL, EMAIL.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n);\n\n-- Invoice distributions: how each invoice line amount is split across general-ledger expense accounts, with accounting status. Use for spend-by-GL-account questions.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_DISTRIBUTIONS_ALL (\n INVOICE_DISTRIBUTION_ID NUMBER, -- Unique invoice distribution identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the distribution belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n INVOICE_LINE_ID NUMBER, -- Invoice line the distribution splits. FK to AP_INVOICE_LINES_ALL.INVOICE_LINE_ID.\n DISTRIBUTION_LINE_NUMBER NUMBER, -- Sequence of the distribution within the invoice.\n AMOUNT NUMBER(18,2), -- Distribution amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Distribution amount in ledger currency.\n ACCOUNTING_DATE DATE, -- Accounting date of the distribution.\n PERIOD_NAME VARCHAR2(15), -- Accounting period the distribution falls in.\n POSTED_FLAG VARCHAR2(1), -- Y if accounted and posted to the ledger, N if not yet accounted. Values: Y, N.\n QUANTITY_INVOICED NUMBER, -- Quantity billed for the distribution.\n UNIT_PRICE NUMBER(18,2), -- Unit price on the distribution.\n PO_DISTRIBUTION_ID NUMBER, -- Purchase order distribution matched to. FK to PO_DISTRIBUTIONS_ALL.PO_DISTRIBUTION_ID.\n TASK_ID NUMBER, -- Project task charged.\n INCOME_TAX_REGION VARCHAR2(10), -- Region used for income-tax reporting.\n DESCRIPTION VARCHAR2(240), -- Distribution description.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice batches: groups of invoices entered together, with control totals and entry status.\nCREATE TABLE AP_BATCHES_ALL (\n BATCH_ID NUMBER, -- Unique invoice batch identifier. Primary key.\n BATCH_NAME VARCHAR2(50), -- Name of the batch.\n BATCH_DATE DATE, -- Date the batch was created.\n INVOICE_COUNT NUMBER, -- Number of invoices entered in the batch.\n INVOICE_AMOUNT NUMBER(18,2), -- Total amount of the invoices in the batch.\n CONTROL_INVOICE_COUNT NUMBER, -- Expected invoice count entered as a control total.\n CONTROL_INVOICE_AMOUNT NUMBER(18,2), -- Expected batch amount entered as a control total.\n BATCH_STATUS VARCHAR2(25), -- Status of the batch. Values: OPEN, CLOSED, POSTED.\n SOURCE VARCHAR2(80), -- Source of the batch. Values: MANUAL, IMPORT, SUPPLIER PORTAL.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_NUMBER NUMBER, -- Sequence of the line within the invoice.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit billed.\n UNIT_MEAS_LOOKUP_CODE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\n ACCOUNTING_DATE DATE, -- Accounting date of the line.\n TAX_RATE NUMBER(12,6), -- Tax rate applied to the line.\n TAX_RATE_ID NUMBER, -- Tax rate record applied. FK to ZX_RATES_B.TAX_RATE_ID.\n DISCARDED_FLAG VARCHAR2(1), -- Y if the line was discarded during correction.\n REQUESTER_ID NUMBER, -- Employee who requested the line item. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n MATCH_TYPE VARCHAR2(25), -- How the line was matched. Values: ITEM_TO_PO, ITEM_TO_RECEIPT, NOT_MATCHED.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Purchase order distributions: charge accounts and quantities of a schedule, including amount ordered, delivered and billed.\n-- (showing 14 of 19 columns: join keys + those relevant to the question)\nCREATE TABLE PO_DISTRIBUTIONS_ALL (\n PO_DISTRIBUTION_ID NUMBER, -- Unique distribution identifier. Primary key.\n PO_HEADER_ID NUMBER, -- Order the distribution belongs to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n PO_LINE_ID NUMBER, -- Line the distribution belongs to. FK to PO_LINES_ALL.PO_LINE_ID.\n LINE_LOCATION_ID NUMBER, -- Schedule the distribution belongs to. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n DISTRIBUTION_NUM NUMBER, -- Distribution number within the schedule.\n CODE_COMBINATION_ID NUMBER, -- Expense account charged. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n QUANTITY_ORDERED NUMBER, -- Quantity ordered on the distribution.\n QUANTITY_DELIVERED NUMBER, -- Quantity delivered.\n QUANTITY_BILLED NUMBER, -- Quantity billed.\n AMOUNT_ORDERED NUMBER(18,2), -- Amount ordered.\n AMOUNT_BILLED NUMBER(18,2), -- Amount billed so far.\n DESTINATION_TYPE_CODE VARCHAR2(25), -- Where the goods go. Values: EXPENSE, INVENTORY.\n REQUESTER_ID NUMBER, -- Employee who requested the goods. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n PROJECT_ID NUMBER, -- Project charged.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 16 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- unvalidated invoice => AP_INVOICES_ALL.VALIDATION_STATUS <> 'VALIDATED'\n"}, {"role": "user", "content": "Question: Average invoice amount by invoice source in the past 12 months"}, {"role": "assistant", "content": "```sql\nSELECT i.SOURCE, AVG(i.INVOICE_AMOUNT) AS AVG_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_DATE >= ADD_MONTHS(TRUNC(SYSDATE), -12)\nGROUP BY i.SOURCE\nORDER BY AVG_INVOICE_AMOUNT DESC;\n```"}], "meta": {"id": "a-01031", "tier": "T3", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "7e128025c6a3", "tables": ["AP_INVOICES_ALL"], "result_rows": 4, "approx_prompt_tokens": 3085, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account the payment was drawn on. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Payment history: status changes and accounting events for each payment (created, cleared, voided, reconciled).\n-- (showing 12 of 17 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_HISTORY_ALL (\n PAYMENT_HISTORY_ID NUMBER, -- Unique payment history identifier. Primary key.\n CHECK_ID NUMBER, -- Payment the history row describes. FK to AP_CHECKS_ALL.CHECK_ID.\n TRANSACTION_TYPE VARCHAR2(25), -- Kind of event recorded. Values: PAYMENT CREATED, PAYMENT CLEARING, PAYMENT UNCLEARING, PAYMENT CANCELLED.\n TRANSACTION_DATE DATE, -- Date of the event.\n ACCOUNTING_DATE DATE, -- Accounting date of the event.\n TRX_BANK_AMOUNT NUMBER(18,2), -- Amount at the bank for the event.\n TRX_PMT_AMOUNT NUMBER(18,2), -- Amount in payment currency for the event.\n HISTORICAL_FLAG VARCHAR2(1), -- Y if the row is superseded by a later event.\n POSTED_FLAG VARCHAR2(1), -- Y if the event was accounted.\n REV_PMT_HIST_ID NUMBER, -- Payment history row this event reverses.\n BANK_CURRENCY_CODE VARCHAR2(15), -- Currency of the bank statement line. FK to FND_CURRENCIES.CURRENCY_CODE.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25), -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n INT_BANK_ACCOUNT_ID NUMBER, -- Company bank account used. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE, -- Date the payment was voided.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 16 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- days to pay => AP_CHECKS_ALL.CHECK_DATE - AP_INVOICES_ALL.INVOICE_DATE (join AP_INVOICE_PAYMENTS_ALL on INVOICE_ID and CHECK_ID)\n"}, {"role": "user", "content": "Question: Month by month, what is the cumulative payments over the last 6 months?"}, {"role": "assistant", "content": "```sql\nSELECT MONTH_START, TOTAL_PAYMENT_AMOUNT, SUM(TOTAL_PAYMENT_AMOUNT) OVER (ORDER BY MONTH_START) AS RUNNING_TOTAL\nFROM (\n SELECT TRUNC(c.CHECK_DATE, 'MM') AS MONTH_START, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT\n FROM AP_CHECKS_ALL c\n WHERE c.CHECK_DATE >= ADD_MONTHS(TRUNC(SYSDATE), -6)\n GROUP BY TRUNC(c.CHECK_DATE, 'MM')\n)\nORDER BY MONTH_START;\n```"}], "meta": {"id": "a-01332", "tier": "T4", "family": "t4-running", "kind": "ask", "source": "S2-templated", "group": "a80f55350464", "tables": ["AP_CHECKS_ALL"], "result_rows": 7, "approx_prompt_tokens": 3156, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 17 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n SELF_ASSESSED_TAX_AMOUNT NUMBER(18,2), -- Tax the buyer self-assesses instead of paying to the supplier.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n CANCELLED_DATE DATE, -- Date the invoice was cancelled; NULL if not cancelled.\n);\n\n-- Supplier bank accounts: external bank accounts that payments are sent to, with account holder, currency and validity dates.\n-- (showing 10 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXT_BANK_ACCOUNTS (\n EXT_BANK_ACCOUNT_ID NUMBER, -- Unique external bank account identifier. Primary key.\n BANK_PARTY_ID NUMBER, -- Bank holding the account. FK to CE_BANKS.BANK_PARTY_ID.\n ACCOUNT_OWNER_PARTY_ID NUMBER, -- Party that owns the account. FK to HZ_PARTIES.PARTY_ID.\n BANK_ACCOUNT_NAME VARCHAR2(80), -- Account holder name.\n CURRENCY_CODE VARCHAR2(15), -- Currency of the account. FK to FND_CURRENCIES.CURRENCY_CODE.\n COUNTRY_CODE VARCHAR2(2), -- Country of the account.\n START_DATE DATE, -- Date the account becomes valid.\n END_DATE DATE, -- Date the account stops being valid.\n ACCOUNT_SUFFIX VARCHAR2(30), -- Account suffix used by some banks.\n FOREIGN_PAYMENT_USE_FLAG VARCHAR2(1), -- Y if the account can receive foreign-currency payments.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 15 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_CODE VARCHAR2(15), -- Short site code.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n INACTIVE_DATE DATE, -- Date the site becomes inactive.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n ALWAYS_TAKE_DISC_FLAG VARCHAR2(1), -- Y if the early-payment discount is always taken.\n TOLERANCE_ID NUMBER, -- Matching tolerance applied at the site.\n BILL_TO_LOCATION_ID NUMBER, -- Default bill-to location.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\n-- (showing 15 of 38 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n VENDOR_NAME VARCHAR2(360), -- Supplier name.\n SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\n VENDOR_TYPE_LOOKUP_CODE VARCHAR2(30), -- Supplier type. Values: VENDOR, CONTRACTOR, EMPLOYEE, TAX AUTHORITY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n START_DATE_ACTIVE DATE, -- Date the supplier becomes active.\n END_DATE_ACTIVE DATE, -- Date the supplier stops being active.\n SUMMARY_FLAG VARCHAR2(1), -- Y if the supplier is a summary (parent) record.\n ONE_TIME_FLAG VARCHAR2(1), -- Y if the supplier is a one-time supplier.\n TERMS_ID NUMBER, -- Default payment terms. FK to AP_TERMS_B.TERM_ID.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if all payments to the supplier are blocked.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n FEDERAL_REPORTABLE_FLAG VARCHAR2(1), -- Y if the supplier is reportable for federal income tax.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2), -- Maximum credit extended to the supplier.\n CREATION_SOURCE VARCHAR2(30), -- Where the supplier record originated. Values: REGISTRATION, MANUAL, IMPORT.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n"}, {"role": "user", "content": "Question: What is the amount still owed for each supplier that came due in the last 30 days?"}, {"role": "assistant", "content": "```sql\nSELECT s.VENDOR_NAME, SUM(ps.AMOUNT_REMAINING) AS TOTAL_UNPAID_AMOUNT\nFROM AP_PAYMENT_SCHEDULES_ALL ps\nJOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ps.INVOICE_ID\nJOIN POZ_SUPPLIERS s ON s.VENDOR_ID = i.VENDOR_ID\nWHERE ps.AMOUNT_REMAINING > 0 AND ps.DUE_DATE >= TRUNC(SYSDATE) - 30\nGROUP BY s.VENDOR_NAME\nORDER BY TOTAL_UNPAID_AMOUNT DESC;\n```"}], "meta": {"id": "a-00964", "tier": "T3", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "6332aba4d127", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "POZ_SUPPLIERS"], "result_rows": 7, "approx_prompt_tokens": 2840, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 15 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_ID NUMBER, -- Address of the site. FK to POZ_SUPPLIER_ADDRESSES.ADDRESS_ID.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Default invoice currency at this site. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n ALWAYS_TAKE_DISC_FLAG VARCHAR2(1), -- Y if the early-payment discount is always taken.\n SHIP_TO_LOCATION_ID NUMBER, -- Default ship-to location for purchase orders.\n BILL_TO_LOCATION_ID NUMBER, -- Default bill-to location.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n);\n\n-- Supplier addresses: physical and remit-to addresses of suppliers.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_ADDRESSES (\n ADDRESS_ID NUMBER, -- Unique address identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the address belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_NAME VARCHAR2(240), -- Name identifying the address.\n ADDRESS_LINE1 VARCHAR2(240), -- First address line.\n ADDRESS_LINE2 VARCHAR2(240), -- Second address line.\n CITY VARCHAR2(60), -- City.\n STATE VARCHAR2(60), -- State or province. Values: CA, NY, TX, WA, IL.\n POSTAL_CODE VARCHAR2(60), -- Postal or ZIP code.\n COUNTRY VARCHAR2(2), -- Country code.\n ADDRESS_PURPOSE VARCHAR2(30), -- What the address is used for. Values: REMIT_TO, PURCHASING, RFQ.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n LATITUDE NUMBER(12,6), -- Latitude of the address.\n LONGITUDE NUMBER(12,6), -- Longitude of the address.\n);\n\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n DESCRIPTION VARCHAR2(240), -- Description of the goods or service on the line.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit billed.\n UNIT_MEAS_LOOKUP_CODE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\n PO_LINE_ID NUMBER, -- Purchase order line this line is matched to. FK to PO_LINES_ALL.PO_LINE_ID.\n PO_LINE_LOCATION_ID NUMBER, -- Purchase order schedule this line is matched to. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n TAX_RATE NUMBER(12,6), -- Tax rate applied to the line.\n PRODUCT_CATEGORY VARCHAR2(80), -- Category of the product or service. Values: IT EQUIPMENT, OFFICE SUPPLIES, PROFESSIONAL SERVICES, LOGISTICS.\n REQUESTER_ID NUMBER, -- Employee who requested the line item. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice batches: groups of invoices entered together, with control totals and entry status.\nCREATE TABLE AP_BATCHES_ALL (\n BATCH_ID NUMBER, -- Unique invoice batch identifier. Primary key.\n BATCH_NAME VARCHAR2(50), -- Name of the batch.\n BATCH_DATE DATE, -- Date the batch was created.\n INVOICE_COUNT NUMBER, -- Number of invoices entered in the batch.\n INVOICE_AMOUNT NUMBER(18,2), -- Total amount of the invoices in the batch.\n CONTROL_INVOICE_COUNT NUMBER, -- Expected invoice count entered as a control total.\n CONTROL_INVOICE_AMOUNT NUMBER(18,2), -- Expected batch amount entered as a control total.\n BATCH_STATUS VARCHAR2(25), -- Status of the batch. Values: OPEN, CLOSED, POSTED.\n SOURCE VARCHAR2(80), -- Source of the batch. Values: MANUAL, IMPORT, SUPPLIER PORTAL.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Purchase order schedules: delivery schedules of a line with need-by date, quantity received and billed, and the matching option (two-, three- or four-way).\n-- (showing 15 of 22 columns: join keys + those relevant to the question)\nCREATE TABLE PO_LINE_LOCATIONS_ALL (\n LINE_LOCATION_ID NUMBER, -- Unique schedule identifier. Primary key.\n SHIPMENT_NUM NUMBER, -- Schedule number within the line.\n QUANTITY NUMBER, -- Quantity scheduled.\n QUANTITY_RECEIVED NUMBER, -- Quantity received so far.\n QUANTITY_BILLED NUMBER, -- Quantity invoiced so far.\n QUANTITY_CANCELLED NUMBER, -- Quantity cancelled.\n NEED_BY_DATE DATE, -- Date the goods are needed.\n PROMISED_DATE DATE, -- Date the supplier promised delivery.\n PRICE_OVERRIDE NUMBER(18,2), -- Price for this schedule if different from the line.\n INVOICE_MATCH_OPTION VARCHAR2(1), -- P match to order (two-way), R match to receipt (three-way). Values: R, P.\n RECEIPT_REQUIRED_FLAG VARCHAR2(1), -- Y if receipt is required before payment.\n TAXABLE_FLAG VARCHAR2(1), -- Y if the schedule is taxable.\n SHIP_TO_LOCATION_ID NUMBER, -- Where the goods are delivered.\n CLOSED_CODE VARCHAR2(25), -- Closure state of the schedule. Values: OPEN, CLOSED FOR RECEIVING, CLOSED.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- vendor spend / supplier spend => SUM(AP_INVOICES_ALL.INVOICE_AMOUNT) grouped by AP_INVOICES_ALL.VENDOR_ID (join POZ_SUPPLIERS for VENDOR_NAME)\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n"}, {"role": "user", "content": "Question: Which 10 supplier cities have the highest total invoiced?"}, {"role": "assistant", "content": "```sql\nSELECT a.CITY, SUM(i.INVOICE_AMOUNT) AS TOTAL_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = i.VENDOR_ID\nGROUP BY a.CITY\nORDER BY TOTAL_INVOICE_AMOUNT DESC\nFETCH FIRST 10 ROWS ONLY;\n```"}], "meta": {"id": "a-00668", "tier": "T2", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "df86d00cfef9", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 7, "approx_prompt_tokens": 3011, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice holds: matching exceptions, duplicates and variances that block payment, with hold reason, date placed and release date. NULL RELEASE_DATE means the hold is still active.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_HOLDS_ALL (\n HOLD_ID NUMBER, -- Unique hold identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the hold is placed on. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_LOCATION_ID NUMBER, -- Purchase order schedule that caused the hold. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n HOLD_LOOKUP_CODE VARCHAR2(30), -- Hold reason. FK to AP_HOLD_CODES.HOLD_LOOKUP_CODE.\n HOLD_DATE DATE, -- Date the hold was placed.\n HELD_BY NUMBER, -- User who placed the hold. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n HOLD_REASON VARCHAR2(240), -- Explanation of why the hold was placed.\n RELEASE_LOOKUP_CODE VARCHAR2(30), -- Reason the hold was released. Values: VARIANCE ACCEPTED, CORRECTED, OVERRIDE.\n RELEASE_DATE DATE, -- Date the hold was released; NULL if still active.\n RELEASE_REASON VARCHAR2(240), -- Comments recorded when the hold was released.\n STATUS_FLAG VARCHAR2(1), -- Hold status: S system-placed, R released. Values: S, R.\n RESPONSIBILITY_ID NUMBER, -- Responsibility able to release the hold.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Hold and release reason codes: definitions of the hold types that can be placed on invoices.\nCREATE TABLE AP_HOLD_CODES (\n HOLD_LOOKUP_CODE VARCHAR2(30), -- Hold or release reason code. Values: MATCHING, DUPLICATE INVOICE, TAX VARIANCE, PRICE VARIANCE, QTY VARIANCE, MISSING RECEIPT, AMOUNT LIMIT, UNAPPROVED, CURRENCY MISMATCH, TERMS MISMATCH. Primary key.\n HOLD_TYPE VARCHAR2(25), -- Whether the code is a hold or a release reason. Values: HOLD, RELEASE.\n DESCRIPTION VARCHAR2(240), -- Meaning of the hold code.\n USER_RELEASEABLE_FLAG VARCHAR2(1), -- Y if users may release this hold manually.\n USER_ALLOWED_FLAG VARCHAR2(1), -- Y if users may place this hold manually.\n POSTABLE_FLAG VARCHAR2(1), -- Y if invoices with this hold can still be accounted.\n INACTIVE_DATE DATE, -- Date the code stops being valid.\n HOLD_INSTRUCTION VARCHAR2(240), -- Guidance to the analyst on resolving the hold.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Purchase order distributions: charge accounts and quantities of a schedule, including amount ordered, delivered and billed.\n-- (showing 14 of 19 columns: join keys + those relevant to the question)\nCREATE TABLE PO_DISTRIBUTIONS_ALL (\n PO_DISTRIBUTION_ID NUMBER, -- Unique distribution identifier. Primary key.\n PO_HEADER_ID NUMBER, -- Order the distribution belongs to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n PO_LINE_ID NUMBER, -- Line the distribution belongs to. FK to PO_LINES_ALL.PO_LINE_ID.\n LINE_LOCATION_ID NUMBER, -- Schedule the distribution belongs to. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n DISTRIBUTION_NUM NUMBER, -- Distribution number within the schedule.\n CODE_COMBINATION_ID NUMBER, -- Expense account charged. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n QUANTITY_ORDERED NUMBER, -- Quantity ordered on the distribution.\n QUANTITY_DELIVERED NUMBER, -- Quantity delivered.\n QUANTITY_BILLED NUMBER, -- Quantity billed.\n AMOUNT_ORDERED NUMBER(18,2), -- Amount ordered.\n AMOUNT_BILLED NUMBER(18,2), -- Amount billed so far.\n DESTINATION_TYPE_CODE VARCHAR2(25), -- Where the goods go. Values: EXPENSE, INVENTORY.\n REQUESTER_ID NUMBER, -- Employee who requested the goods. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n PROJECT_ID NUMBER, -- Project charged.\n);\n\n-- Purchase order schedules: delivery schedules of a line with need-by date, quantity received and billed, and the matching option (two-, three- or four-way).\n-- (showing 15 of 22 columns: join keys + those relevant to the question)\nCREATE TABLE PO_LINE_LOCATIONS_ALL (\n LINE_LOCATION_ID NUMBER, -- Unique schedule identifier. Primary key.\n PO_HEADER_ID NUMBER, -- Order the schedule belongs to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n PO_LINE_ID NUMBER, -- Line the schedule belongs to. FK to PO_LINES_ALL.PO_LINE_ID.\n SHIPMENT_NUM NUMBER, -- Schedule number within the line.\n QUANTITY NUMBER, -- Quantity scheduled.\n QUANTITY_RECEIVED NUMBER, -- Quantity received so far.\n QUANTITY_BILLED NUMBER, -- Quantity invoiced so far.\n QUANTITY_CANCELLED NUMBER, -- Quantity cancelled.\n NEED_BY_DATE DATE, -- Date the goods are needed.\n PROMISED_DATE DATE, -- Date the supplier promised delivery.\n PRICE_OVERRIDE NUMBER(18,2), -- Price for this schedule if different from the line.\n INVOICE_MATCH_OPTION VARCHAR2(1), -- P match to order (two-way), R match to receipt (three-way). Values: R, P.\n RECEIPT_REQUIRED_FLAG VARCHAR2(1), -- Y if receipt is required before payment.\n TAXABLE_FLAG VARCHAR2(1), -- Y if the schedule is taxable.\n CLOSED_CODE VARCHAR2(25), -- Closure state of the schedule. Values: OPEN, CLOSED FOR RECEIVING, CLOSED.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n CANCELLED_DATE DATE, -- Date the invoice was cancelled; NULL if not cancelled.\n CANCELLED_BY VARCHAR2(64), -- User who cancelled the invoice.\n ACCTS_PAY_CODE_COMBINATION_ID NUMBER, -- Liability (accounts payable) account for the invoice. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number assigned to the invoice.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- on hold => AP_HOLDS_ALL.RELEASE_DATE IS NULL (active hold; the reason is AP_HOLDS_ALL.HOLD_LOOKUP_CODE)\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- early payment discount => AP_PAYMENT_SCHEDULES_ALL.DISCOUNT_AMOUNT_AVAILABLE > 0\n-- duplicate invoice => AP_HOLDS_ALL.HOLD_LOOKUP_CODE = 'DUPLICATE INVOICE'\n"}, {"role": "user", "content": "Question: How many open installments are there for installments on hold?"}, {"role": "assistant", "content": "```sql\nSELECT COUNT(*) AS OPEN_INSTALLMENTS\nFROM AP_PAYMENT_SCHEDULES_ALL ps\nJOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ps.INVOICE_ID\nWHERE ps.AMOUNT_REMAINING > 0 AND ps.HOLD_FLAG = 'Y';\n```"}], "meta": {"id": "a-00370", "tier": "T2", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "235f3bfe9230", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL"], "result_rows": 1, "approx_prompt_tokens": 3081, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n CURRENCY_CODE VARCHAR2(15), -- Currency the payment was made in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting payment currency to ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account the payment was drawn on. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n CHECKRUN_ID NUMBER, -- Payment process request identifier.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n ATTRIBUTE_CATEGORY VARCHAR2(30), -- Descriptive flexfield context (customer-defined extension fields).\n ATTRIBUTE1 VARCHAR2(150), -- Descriptive flexfield segment 1, customer-defined and normally unused.\n ATTRIBUTE2 VARCHAR2(150), -- Descriptive flexfield segment 2, customer-defined and normally unused.\n ATTRIBUTE3 VARCHAR2(150), -- Descriptive flexfield segment 3, customer-defined and normally unused.\n ATTRIBUTE4 VARCHAR2(150), -- Descriptive flexfield segment 4, customer-defined and normally unused.\n ATTRIBUTE5 VARCHAR2(150), -- Descriptive flexfield segment 5, customer-defined and normally unused.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n PARTY_ID NUMBER, -- Trading-community party behind the supplier. FK to HZ_PARTIES.PARTY_ID.\n VENDOR_NAME VARCHAR2(360), -- Supplier name.\n VENDOR_NAME_ALT VARCHAR2(320), -- Alternate or trading name of the supplier.\n SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\n VENDOR_TYPE_LOOKUP_CODE VARCHAR2(30), -- Supplier type. Values: VENDOR, CONTRACTOR, EMPLOYEE, TAX AUTHORITY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n START_DATE_ACTIVE DATE, -- Date the supplier becomes active.\n END_DATE_ACTIVE DATE, -- Date the supplier stops being active.\n SUMMARY_FLAG VARCHAR2(1), -- Y if the supplier is a summary (parent) record.\n ONE_TIME_FLAG VARCHAR2(1), -- Y if the supplier is a one-time supplier.\n SMALL_BUSINESS_FLAG VARCHAR2(1), -- Y if the supplier is a small business.\n WOMEN_OWNED_FLAG VARCHAR2(1), -- Y if the supplier is women-owned.\n MINORITY_GROUP_LOOKUP_CODE VARCHAR2(30), -- Minority ownership classification. Values: MBE, DBE.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Default payment method for the supplier. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Default pay group. Values: DOMESTIC, INTERNATIONAL.\n TERMS_ID NUMBER, -- Default payment terms. FK to AP_TERMS_B.TERM_ID.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Default invoice currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Default payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if all payments to the supplier are blocked.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n NUM_1099 VARCHAR2(30), -- US taxpayer identification number for 1099 reporting.\n TAX_REGISTRATION_NUMBER VARCHAR2(50), -- VAT or GST registration number.\n FEDERAL_REPORTABLE_FLAG VARCHAR2(1), -- Y if the supplier is reportable for federal income tax.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2), -- Maximum credit extended to the supplier.\n RISK_RATING VARCHAR2(25), -- Internal supplier risk rating. Values: LOW, MEDIUM, HIGH.\n CREATION_SOURCE VARCHAR2(30), -- Where the supplier record originated. Values: REGISTRATION, MANUAL, IMPORT.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ATTRIBUTE_CATEGORY VARCHAR2(30), -- Descriptive flexfield context (customer-defined extension fields).\n ATTRIBUTE1 VARCHAR2(150), -- Descriptive flexfield segment 1, customer-defined and normally unused.\n ATTRIBUTE2 VARCHAR2(150), -- Descriptive flexfield segment 2, customer-defined and normally unused.\n ATTRIBUTE3 VARCHAR2(150), -- Descriptive flexfield segment 3, customer-defined and normally unused.\n ATTRIBUTE4 VARCHAR2(150), -- Descriptive flexfield segment 4, customer-defined and normally unused.\n ATTRIBUTE5 VARCHAR2(150), -- Descriptive flexfield segment 5, customer-defined and normally unused.\n);\n\n-- Supplier bank accounts: external bank accounts that payments are sent to, with account holder, currency and validity dates.\n-- (showing 10 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXT_BANK_ACCOUNTS (\n EXT_BANK_ACCOUNT_ID NUMBER, -- Unique external bank account identifier. Primary key.\n BANK_PARTY_ID NUMBER, -- Bank holding the account. FK to CE_BANKS.BANK_PARTY_ID.\n ACCOUNT_OWNER_PARTY_ID NUMBER, -- Party that owns the account. FK to HZ_PARTIES.PARTY_ID.\n BANK_ACCOUNT_NAME VARCHAR2(80), -- Account holder name.\n CURRENCY_CODE VARCHAR2(15), -- Currency of the account. FK to FND_CURRENCIES.CURRENCY_CODE.\n COUNTRY_CODE VARCHAR2(2), -- Country of the account.\n START_DATE DATE, -- Date the account becomes valid.\n END_DATE DATE, -- Date the account stops being valid.\n ACCOUNT_SUFFIX VARCHAR2(30), -- Account suffix used by some banks.\n FOREIGN_PAYMENT_USE_FLAG VARCHAR2(1), -- Y if the account can receive foreign-currency payments.\n);\n\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 15 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_CODE VARCHAR2(15), -- Short site code.\n ADDRESS_ID NUMBER, -- Address of the site. FK to POZ_SUPPLIER_ADDRESSES.ADDRESS_ID.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Payment method for this site. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n TOLERANCE_ID NUMBER, -- Matching tolerance applied at the site.\n BILL_TO_LOCATION_ID NUMBER, -- Default bill-to location.\n);\n\n-- Supplier contacts: people at a supplier with role, phone and email.\n-- (showing 12 of 17 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_CONTACTS (\n CONTACT_ID NUMBER, -- Unique contact identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the contact works for. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Site the contact is associated with. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n FIRST_NAME VARCHAR2(150), -- Contact first name.\n LAST_NAME VARCHAR2(150), -- Contact last name.\n JOB_TITLE VARCHAR2(100), -- Contact job title. Values: ACCOUNTS RECEIVABLE, SALES MANAGER, CFO, CREDIT CONTROLLER.\n EMAIL_ADDRESS VARCHAR2(320), -- Contact email address.\n PHONE_NUMBER VARCHAR2(40), -- Contact phone number.\n PRIMARY_FLAG VARCHAR2(1), -- Y if this is the primary contact.\n INACTIVE_DATE DATE, -- Date the contact is no longer active.\n DEPARTMENT VARCHAR2(80), -- Contact department. Values: FINANCE, SALES, OPERATIONS.\n PREFERRED_CONTACT_METHOD VARCHAR2(25), -- How the contact prefers to be reached. Values: EMAIL, PHONE.\n);\n\n-- Supplier addresses: physical and remit-to addresses of suppliers.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_ADDRESSES (\n ADDRESS_ID NUMBER, -- Unique address identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the address belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_NAME VARCHAR2(240), -- Name identifying the address.\n ADDRESS_LINE1 VARCHAR2(240), -- First address line.\n ADDRESS_LINE2 VARCHAR2(240), -- Second address line.\n CITY VARCHAR2(60), -- City.\n STATE VARCHAR2(60), -- State or province. Values: CA, NY, TX, WA, IL.\n POSTAL_CODE VARCHAR2(60), -- Postal or ZIP code.\n COUNTRY VARCHAR2(2), -- Country code.\n ADDRESS_PURPOSE VARCHAR2(30), -- What the address is used for. Values: REMIT_TO, PURCHASING, RFQ.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n LATITUDE NUMBER(12,6), -- Latitude of the address.\n LONGITUDE NUMBER(12,6), -- Longitude of the address.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n\n"}, {"role": "user", "content": "Question: Suppliers whose total payments is below average\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT s.SUPPLIER_NAME, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT FROM AP_CHECKS_ALL c JOIN POZ_SUPPLIERS s ON s.VENDOR_ID = c.VENDOR_ID GROUP BY s.SUPPLIER_NAME HAVING SUM(c.AMOUNT) < (SELECT AVG(t.TOTAL_PAYMENT_AMOUNT) FROM (SELECT s.SUPPLIER_NAME, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT FROM AP_CHECKS_ALL c JOIN POZ_SUPPLIERS s ON s.VENDOR_ID = c.VENDOR_ID GROUP BY s.SUPPLIER_NAME) t) ORDER BY TOTAL_PAYMENT_AMOUNT DESC FETCH FIRST 200 ROWS ONLY;\nError: ORA-00904: \"S\".\"SUPPLIER_NAME\": invalid identifier\nDiagnosis: S is POZ_SUPPLIERS, which has NO column named SUPPLIER_NAME. Its columns are: VENDOR_ID, PARTY_ID, VENDOR_NAME, VENDOR_NAME_ALT, SEGMENT1, VENDOR_TYPE_LOOKUP_CODE, ENABLED_FLAG, START_DATE_ACTIVE, END_DATE_ACTIVE, SUMMARY_FLAG, ONE_TIME_FLAG, SMALL_BUSINESS_FLAG, WOMEN_OWNED_FLAG, MINORITY_GROUP_LOOKUP_CODE, PAYMENT_METHOD_LOOKUP_CODE, PAY_GROUP_LOOKUP_CODE, TERMS_ID, INVOICE_CURRENCY_CODE, PAYMENT_CURRENCY_CODE, HOLD_ALL_PAYMENTS_FLAG, HOLD_REASON, FEDERAL_REPORTABLE_FLAG, CREDIT_LIMIT_AMOUNT, RISK_RATING, CREATION_SOURCE, CREATION_DATE, CREATED_BY, LAST_UPDATE_DATE, LAST_UPDATED_BY, OBJECT_VERSION_NUMBER, ATTRIBUTE_CATEGORY, ATTRIBUTE1, ATTRIBUTE2, ATTRIBUTE3, ATTRIBUTE4, ATTRIBUTE5. Closest names: VENDOR_NAME, VENDOR_NAME_ALT.\nWrite a corrected query. It must differ from the failed one. Use ONLY the tables and columns in the schema above, spelled exactly as shown; if a column you wanted does not exist, choose the closest one that does."}, {"role": "assistant", "content": "```sql\nSELECT s.VENDOR_NAME, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nJOIN POZ_SUPPLIERS s ON s.VENDOR_ID = c.VENDOR_ID\nGROUP BY s.VENDOR_NAME\nHAVING SUM(c.AMOUNT) < (\n SELECT AVG(t.TOTAL_PAYMENT_AMOUNT)\n FROM (\n SELECT s.VENDOR_NAME, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT\n FROM AP_CHECKS_ALL c\n JOIN POZ_SUPPLIERS s ON s.VENDOR_ID = c.VENDOR_ID\n GROUP BY s.VENDOR_NAME\n ) t\n)\nORDER BY TOTAL_PAYMENT_AMOUNT DESC;\n```"}], "meta": {"id": "r-00023", "tier": "T4", "family": "t4-average", "kind": "repair-exec", "source": "S6-repair", "group": "77683da129a4", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIERS"], "result_rows": 0, "approx_prompt_tokens": 3419, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"S\".\"SUPPLIER_NAME\": invalid identifier", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number assigned to the invoice.\n);\n\n-- Invoice distributions: how each invoice line amount is split across general-ledger expense accounts, with accounting status. Use for spend-by-GL-account questions.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_DISTRIBUTIONS_ALL (\n INVOICE_DISTRIBUTION_ID NUMBER, -- Unique invoice distribution identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the distribution belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n INVOICE_LINE_ID NUMBER, -- Invoice line the distribution splits. FK to AP_INVOICE_LINES_ALL.INVOICE_LINE_ID.\n DISTRIBUTION_LINE_NUMBER NUMBER, -- Sequence of the distribution within the invoice.\n AMOUNT NUMBER(18,2), -- Distribution amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Distribution amount in ledger currency.\n POSTED_FLAG VARCHAR2(1), -- Y if accounted and posted to the ledger, N if not yet accounted. Values: Y, N.\n ACCRUAL_POSTED_FLAG VARCHAR2(1), -- Y if accrual accounting entries were created.\n QUANTITY_INVOICED NUMBER, -- Quantity billed for the distribution.\n UNIT_PRICE NUMBER(18,2), -- Unit price on the distribution.\n PO_DISTRIBUTION_ID NUMBER, -- Purchase order distribution matched to. FK to PO_DISTRIBUTIONS_ALL.PO_DISTRIBUTION_ID.\n TASK_ID NUMBER, -- Project task charged.\n EXPENDITURE_TYPE VARCHAR2(80), -- Project expenditure type. Values: TRAVEL, MATERIALS, LABOR.\n INCOME_TAX_REGION VARCHAR2(10), -- Region used for income-tax reporting.\n DESCRIPTION VARCHAR2(240), -- Distribution description.\n);\n\n-- Invoice batches: groups of invoices entered together, with control totals and entry status.\nCREATE TABLE AP_BATCHES_ALL (\n BATCH_ID NUMBER, -- Unique invoice batch identifier. Primary key.\n BATCH_NAME VARCHAR2(50), -- Name of the batch.\n BATCH_DATE DATE, -- Date the batch was created.\n INVOICE_COUNT NUMBER, -- Number of invoices entered in the batch.\n INVOICE_AMOUNT NUMBER(18,2), -- Total amount of the invoices in the batch.\n CONTROL_INVOICE_COUNT NUMBER, -- Expected invoice count entered as a control total.\n CONTROL_INVOICE_AMOUNT NUMBER(18,2), -- Expected batch amount entered as a control total.\n BATCH_STATUS VARCHAR2(25), -- Status of the batch. Values: OPEN, CLOSED, POSTED.\n SOURCE VARCHAR2(80), -- Source of the batch. Values: MANUAL, IMPORT, SUPPLIER PORTAL.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_NUMBER NUMBER, -- Sequence of the line within the invoice.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n DESCRIPTION VARCHAR2(240), -- Description of the goods or service on the line.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit billed.\n UNIT_MEAS_LOOKUP_CODE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\n ACCOUNTING_DATE DATE, -- Accounting date of the line.\n DEFAULT_DIST_CCID NUMBER, -- Default account used to distribute the line. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n TAX_RATE NUMBER(12,6), -- Tax rate applied to the line.\n REQUESTER_ID NUMBER, -- Employee who requested the line item. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n MATCH_TYPE VARCHAR2(25), -- How the line was matched. Values: ITEM_TO_PO, ITEM_TO_RECEIPT, NOT_MATCHED.\n);\n\n-- Invoice import staging: invoices loaded from external sources awaiting import, with import status and rejection reason.\nCREATE TABLE AP_INVOICES_INTERFACE (\n INVOICE_INTERFACE_ID NUMBER, -- Unique interface row identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Invoice number from the source system.\n VENDOR_NUM VARCHAR2(30), -- Supplier number from the source system.\n INVOICE_AMOUNT NUMBER(18,2), -- Invoice total from the source system.\n INVOICE_DATE DATE, -- Invoice date from the source system.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Currency from the source system. FK to FND_CURRENCIES.CURRENCY_CODE.\n SOURCE VARCHAR2(80), -- Source system that supplied the row. Values: SUPPLIER PORTAL, EDI, EMAIL, OCR.\n STATUS VARCHAR2(25), -- Import status. Values: PROCESSED, REJECTED, PENDING.\n REJECT_REASON VARCHAR2(240), -- Why the row was rejected during import.\n GROUP_ID VARCHAR2(80), -- Load group identifier.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Purchase order distributions: charge accounts and quantities of a schedule, including amount ordered, delivered and billed.\n-- (showing 14 of 19 columns: join keys + those relevant to the question)\nCREATE TABLE PO_DISTRIBUTIONS_ALL (\n PO_DISTRIBUTION_ID NUMBER, -- Unique distribution identifier. Primary key.\n PO_HEADER_ID NUMBER, -- Order the distribution belongs to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n PO_LINE_ID NUMBER, -- Line the distribution belongs to. FK to PO_LINES_ALL.PO_LINE_ID.\n LINE_LOCATION_ID NUMBER, -- Schedule the distribution belongs to. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n DISTRIBUTION_NUM NUMBER, -- Distribution number within the schedule.\n CODE_COMBINATION_ID NUMBER, -- Expense account charged. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n QUANTITY_ORDERED NUMBER, -- Quantity ordered on the distribution.\n QUANTITY_DELIVERED NUMBER, -- Quantity delivered.\n QUANTITY_BILLED NUMBER, -- Quantity billed.\n AMOUNT_ORDERED NUMBER(18,2), -- Amount ordered.\n AMOUNT_BILLED NUMBER(18,2), -- Amount billed so far.\n DESTINATION_TYPE_CODE VARCHAR2(25), -- Where the goods go. Values: EXPENSE, INVENTORY.\n REQUESTER_ID NUMBER, -- Employee who requested the goods. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n PROJECT_ID NUMBER, -- Project charged.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: Average invoice amount across invoices over 20,000"}, {"role": "assistant", "content": "```sql\nSELECT AVG(INVOICE_AMOUNT)\nFROM AP_INVOICES_ALL\nWHERE INVOICE_AMOUNT > 20000;\n```"}], "meta": {"id": "a-00136", "tier": "T1", "family": "t1-agg", "kind": "ask", "source": "S2-templated", "group": "c225537da385", "tables": ["AP_INVOICES_ALL"], "result_rows": 1, "approx_prompt_tokens": 3006, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice holds: matching exceptions, duplicates and variances that block payment, with hold reason, date placed and release date. NULL RELEASE_DATE means the hold is still active.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_HOLDS_ALL (\n HOLD_ID NUMBER, -- Unique hold identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the hold is placed on. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_LOCATION_ID NUMBER, -- Purchase order schedule that caused the hold. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n HOLD_LOOKUP_CODE VARCHAR2(30), -- Hold reason. FK to AP_HOLD_CODES.HOLD_LOOKUP_CODE.\n HOLD_DATE DATE, -- Date the hold was placed.\n HELD_BY NUMBER, -- User who placed the hold. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n HOLD_REASON VARCHAR2(240), -- Explanation of why the hold was placed.\n RELEASE_LOOKUP_CODE VARCHAR2(30), -- Reason the hold was released. Values: VARIANCE ACCEPTED, CORRECTED, OVERRIDE.\n RELEASE_DATE DATE, -- Date the hold was released; NULL if still active.\n RELEASE_REASON VARCHAR2(240), -- Comments recorded when the hold was released.\n STATUS_FLAG VARCHAR2(1), -- Hold status: S system-placed, R released. Values: S, R.\n RESPONSIBILITY_ID NUMBER, -- Responsibility able to release the hold.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Hold and release reason codes: definitions of the hold types that can be placed on invoices.\nCREATE TABLE AP_HOLD_CODES (\n HOLD_LOOKUP_CODE VARCHAR2(30), -- Hold or release reason code. Values: MATCHING, DUPLICATE INVOICE, TAX VARIANCE, PRICE VARIANCE, QTY VARIANCE, MISSING RECEIPT, AMOUNT LIMIT, UNAPPROVED, CURRENCY MISMATCH, TERMS MISMATCH. Primary key.\n HOLD_TYPE VARCHAR2(25), -- Whether the code is a hold or a release reason. Values: HOLD, RELEASE.\n DESCRIPTION VARCHAR2(240), -- Meaning of the hold code.\n USER_RELEASEABLE_FLAG VARCHAR2(1), -- Y if users may release this hold manually.\n USER_ALLOWED_FLAG VARCHAR2(1), -- Y if users may place this hold manually.\n POSTABLE_FLAG VARCHAR2(1), -- Y if invoices with this hold can still be accounted.\n INACTIVE_DATE DATE, -- Date the code stops being valid.\n HOLD_INSTRUCTION VARCHAR2(240), -- Guidance to the analyst on resolving the hold.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Chart of accounts: every valid account code combination (company, cost center, natural account) with type and enabled flag. Joined from invoice distributions to name the expense account.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE GL_CODE_COMBINATIONS (\n CODE_COMBINATION_ID NUMBER, -- Unique account combination identifier. Primary key.\n CHART_OF_ACCOUNTS_ID NUMBER, -- Chart of accounts the combination belongs to.\n CONCATENATED_SEGMENTS VARCHAR2(240), -- Full account string, for example 01-520-7110-0000.\n SEGMENT1 VARCHAR2(25), -- Company segment.\n SEGMENT2 VARCHAR2(25), -- Cost center segment.\n SEGMENT3 VARCHAR2(25), -- Natural account segment.\n SEGMENT4 VARCHAR2(25), -- Sub-account segment.\n SEGMENT5 VARCHAR2(25), -- Product segment.\n SEGMENT6 VARCHAR2(25), -- Intercompany segment.\n ACCOUNT_TYPE VARCHAR2(1), -- A asset, L liability, E expense, O owner equity, R revenue. Values: E, L, A.\n ENABLED_FLAG VARCHAR2(1), -- Y if the combination can be used.\n SUMMARY_FLAG VARCHAR2(1), -- Y if the combination is a summary account.\n DETAIL_POSTING_ALLOWED_FLAG VARCHAR2(1), -- Y if posting is allowed to the account.\n START_DATE_ACTIVE DATE, -- Date the combination becomes active.\n END_DATE_ACTIVE DATE, -- Date the combination stops being active.\n);\n\n-- Subledger accounting entry lines: debit and credit lines of each accounting entry with account, amounts and the source transaction.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE XLA_AE_LINES (\n AE_LINE_ID NUMBER, -- Unique accounting line identifier. Primary key.\n AE_HEADER_ID NUMBER, -- Entry the line belongs to. FK to XLA_AE_HEADERS.AE_HEADER_ID.\n AE_LINE_NUM NUMBER, -- Line number within the entry.\n CODE_COMBINATION_ID NUMBER, -- Account of the line. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n ACCOUNTING_CLASS_CODE VARCHAR2(30), -- Accounting class such as liability or expense. Values: LIABILITY, ITEM EXPENSE, CASH, TAX, PREPAID.\n ENTERED_DR NUMBER(18,2), -- Debit in entered currency.\n ENTERED_CR NUMBER(18,2), -- Credit in entered currency.\n ACCOUNTED_DR NUMBER(18,2), -- Debit in ledger currency.\n ACCOUNTED_CR NUMBER(18,2), -- Credit in ledger currency.\n CURRENCY_CONVERSION_RATE NUMBER(12,6), -- Rate used to convert to ledger currency.\n DESCRIPTION VARCHAR2(240), -- Line description.\n SOURCE_TABLE VARCHAR2(30), -- Source table of the transaction. Values: AP_INVOICES_ALL, AP_INVOICE_PAYMENTS_ALL.\n SOURCE_ID NUMBER, -- Identifier of the source transaction.\n PARTY_ID NUMBER, -- Supplier party of the line. FK to HZ_PARTIES.PARTY_ID.\n GL_SL_LINK_ID NUMBER, -- Link to the general-ledger journal line.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Purchase order schedules: delivery schedules of a line with need-by date, quantity received and billed, and the matching option (two-, three- or four-way).\n-- (showing 15 of 22 columns: join keys + those relevant to the question)\nCREATE TABLE PO_LINE_LOCATIONS_ALL (\n LINE_LOCATION_ID NUMBER, -- Unique schedule identifier. Primary key.\n PO_HEADER_ID NUMBER, -- Order the schedule belongs to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n PO_LINE_ID NUMBER, -- Line the schedule belongs to. FK to PO_LINES_ALL.PO_LINE_ID.\n SHIPMENT_NUM NUMBER, -- Schedule number within the line.\n QUANTITY NUMBER, -- Quantity scheduled.\n QUANTITY_RECEIVED NUMBER, -- Quantity received so far.\n QUANTITY_BILLED NUMBER, -- Quantity invoiced so far.\n QUANTITY_CANCELLED NUMBER, -- Quantity cancelled.\n NEED_BY_DATE DATE, -- Date the goods are needed.\n PRICE_OVERRIDE NUMBER(18,2), -- Price for this schedule if different from the line.\n INVOICE_MATCH_OPTION VARCHAR2(1), -- P match to order (two-way), R match to receipt (three-way). Values: R, P.\n RECEIPT_REQUIRED_FLAG VARCHAR2(1), -- Y if receipt is required before payment.\n TAXABLE_FLAG VARCHAR2(1), -- Y if the schedule is taxable.\n CLOSED_CODE VARCHAR2(25), -- Closure state of the schedule. Values: OPEN, CLOSED FOR RECEIVING, CLOSED.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- three-way match failure => AP_HOLDS_ALL.HOLD_LOOKUP_CODE IN ('QTY VARIANCE', 'PRICE VARIANCE', 'MISSING RECEIPT')\n-- duplicate invoice => AP_HOLDS_ALL.HOLD_LOOKUP_CODE = 'DUPLICATE INVOICE'\n-- on hold => AP_HOLDS_ALL.RELEASE_DATE IS NULL (active hold; the reason is AP_HOLDS_ALL.HOLD_LOOKUP_CODE)\n"}, {"role": "user", "content": "Question: Count the distinct hold reasons"}, {"role": "assistant", "content": "```sql\nSELECT COUNT(DISTINCT HOLD_LOOKUP_CODE)\nFROM AP_HOLDS_ALL;\n```"}], "meta": {"id": "a-00117", "tier": "T1", "family": "t1-distinct", "kind": "ask", "source": "S2-templated", "group": "a5f66590d499", "tables": ["AP_HOLDS_ALL"], "result_rows": 1, "approx_prompt_tokens": 2671, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 17 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account the payment was drawn on. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n DOC_SEQUENCE_VALUE NUMBER -- Document sequence number of the payment.\n);\n\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 16 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_ID NUMBER, -- Address of the site. FK to POZ_SUPPLIER_ADDRESSES.ADDRESS_ID.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Payment method for this site. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Default payment currency at this site. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n INACTIVE_DATE DATE, -- Date the site becomes inactive.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n SHIP_TO_LOCATION_ID NUMBER, -- Default ship-to location for purchase orders.\n BILL_TO_LOCATION_ID NUMBER -- Default bill-to location.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n INT_BANK_ACCOUNT_ID NUMBER, -- Company bank account used. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXT_BANK_ACCOUNT_ID NUMBER, -- Payee bank account credited. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE, -- Date the payment was voided.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment history: status changes and accounting events for each payment (created, cleared, voided, reconciled).\n-- (showing 12 of 17 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_HISTORY_ALL (\n PAYMENT_HISTORY_ID NUMBER, -- Unique payment history identifier. Primary key.\n CHECK_ID NUMBER, -- Payment the history row describes. FK to AP_CHECKS_ALL.CHECK_ID.\n TRANSACTION_TYPE VARCHAR2(25), -- Kind of event recorded. Values: PAYMENT CREATED, PAYMENT CLEARING, PAYMENT UNCLEARING, PAYMENT CANCELLED.\n TRANSACTION_DATE DATE, -- Date of the event.\n ACCOUNTING_DATE DATE, -- Accounting date of the event.\n TRX_BANK_AMOUNT NUMBER(18,2), -- Amount at the bank for the event.\n TRX_PMT_AMOUNT NUMBER(18,2), -- Amount in payment currency for the event.\n HISTORICAL_FLAG VARCHAR2(1), -- Y if the row is superseded by a later event.\n POSTED_FLAG VARCHAR2(1), -- Y if the event was accounted.\n REV_PMT_HIST_ID NUMBER, -- Payment history row this event reverses.\n BANK_CURRENCY_CODE VARCHAR2(15), -- Currency of the bank statement line. FK to FND_CURRENCIES.CURRENCY_CODE.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Supplier bank accounts: external bank accounts that payments are sent to, with account holder, currency and validity dates.\n-- (showing 10 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXT_BANK_ACCOUNTS (\n EXT_BANK_ACCOUNT_ID NUMBER, -- Unique external bank account identifier. Primary key.\n BANK_PARTY_ID NUMBER, -- Bank holding the account. FK to CE_BANKS.BANK_PARTY_ID.\n ACCOUNT_OWNER_PARTY_ID NUMBER, -- Party that owns the account. FK to HZ_PARTIES.PARTY_ID.\n BANK_ACCOUNT_NAME VARCHAR2(80), -- Account holder name.\n CURRENCY_CODE VARCHAR2(15), -- Currency of the account. FK to FND_CURRENCIES.CURRENCY_CODE.\n COUNTRY_CODE VARCHAR2(2), -- Country of the account.\n START_DATE DATE, -- Date the account becomes valid.\n END_DATE DATE, -- Date the account stops being valid.\n ACCOUNT_SUFFIX VARCHAR2(30), -- Account suffix used by some banks.\n FOREIGN_PAYMENT_USE_FLAG VARCHAR2(1) -- Y if the account can receive foreign-currency payments.\n);\n\n-- Supplier addresses: physical and remit-to addresses of suppliers.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_ADDRESSES (\n ADDRESS_ID NUMBER, -- Unique address identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the address belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_NAME VARCHAR2(240), -- Name identifying the address.\n ADDRESS_LINE1 VARCHAR2(240), -- First address line.\n ADDRESS_LINE2 VARCHAR2(240), -- Second address line.\n CITY VARCHAR2(60), -- City.\n STATE VARCHAR2(60), -- State or province. Values: CA, NY, TX, WA, IL.\n POSTAL_CODE VARCHAR2(60), -- Postal or ZIP code.\n COUNTRY VARCHAR2(2), -- Country code.\n ADDRESS_PURPOSE VARCHAR2(30), -- What the address is used for. Values: REMIT_TO, PURCHASING, RFQ.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n LATITUDE NUMBER(12,6), -- Latitude of the address.\n LONGITUDE NUMBER(12,6) -- Longitude of the address.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 18 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice will be paid in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n PAYMENT_STATUS_FLAG VARCHAR2(1) -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- vendor spend / supplier spend => SUM(AP_INVOICES_ALL.INVOICE_AMOUNT) grouped by AP_INVOICES_ALL.VENDOR_ID (join POZ_SUPPLIERS for VENDOR_NAME)\n"}, {"role": "user", "content": "Question: Show the 5 supplier cities with the highest total payment amount over the last year"}, {"role": "assistant", "content": "```sql\nSELECT a.CITY, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = c.VENDOR_ID\nWHERE c.CHECK_DATE >= ADD_MONTHS(TRUNC(SYSDATE), -12)\nGROUP BY a.CITY\nORDER BY TOTAL_PAYMENT_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-01075", "tier": "T3", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "d464a57ab45e", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 5, "approx_prompt_tokens": 3016, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE, -- Date the payment was voided.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25), -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 17 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice will be paid in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n CANCELLED_DATE DATE, -- Date the invoice was cancelled; NULL if not cancelled.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n"}, {"role": "user", "content": "Question: What is the amount still owed for each payment method that came due in the last 30 days?"}, {"role": "assistant", "content": "```sql\nSELECT i.PAYMENT_METHOD_CODE, SUM(ps.AMOUNT_REMAINING) AS TOTAL_UNPAID_AMOUNT\nFROM AP_PAYMENT_SCHEDULES_ALL ps\nJOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ps.INVOICE_ID\nWHERE ps.AMOUNT_REMAINING > 0 AND ps.DUE_DATE >= TRUNC(SYSDATE) - 30\nGROUP BY i.PAYMENT_METHOD_CODE\nORDER BY TOTAL_UNPAID_AMOUNT DESC;\n```"}], "meta": {"id": "a-01146", "tier": "T3", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "a03ddbe6a57a", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL"], "result_rows": 3, "approx_prompt_tokens": 2873, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n EXT_BANK_ACCOUNT_ID NUMBER, -- Payee bank account credited. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE -- Date the payment was voided.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n DOC_SEQUENCE_VALUE NUMBER -- Document sequence number of the payment.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment history: status changes and accounting events for each payment (created, cleared, voided, reconciled).\n-- (showing 12 of 17 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_HISTORY_ALL (\n PAYMENT_HISTORY_ID NUMBER, -- Unique payment history identifier. Primary key.\n CHECK_ID NUMBER, -- Payment the history row describes. FK to AP_CHECKS_ALL.CHECK_ID.\n TRANSACTION_TYPE VARCHAR2(25), -- Kind of event recorded. Values: PAYMENT CREATED, PAYMENT CLEARING, PAYMENT UNCLEARING, PAYMENT CANCELLED.\n TRANSACTION_DATE DATE, -- Date of the event.\n ACCOUNTING_DATE DATE, -- Accounting date of the event.\n TRX_BANK_AMOUNT NUMBER(18,2), -- Amount at the bank for the event.\n TRX_PMT_AMOUNT NUMBER(18,2), -- Amount in payment currency for the event.\n HISTORICAL_FLAG VARCHAR2(1), -- Y if the row is superseded by a later event.\n POSTED_FLAG VARCHAR2(1), -- Y if the event was accounted.\n REV_PMT_HIST_ID NUMBER, -- Payment history row this event reverses.\n BANK_CURRENCY_CODE VARCHAR2(15), -- Currency of the bank statement line. FK to FND_CURRENCIES.CURRENCY_CODE.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25) -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Supplier bank accounts: external bank accounts that payments are sent to, with account holder, currency and validity dates.\n-- (showing 10 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXT_BANK_ACCOUNTS (\n EXT_BANK_ACCOUNT_ID NUMBER, -- Unique external bank account identifier. Primary key.\n BANK_PARTY_ID NUMBER, -- Bank holding the account. FK to CE_BANKS.BANK_PARTY_ID.\n ACCOUNT_OWNER_PARTY_ID NUMBER, -- Party that owns the account. FK to HZ_PARTIES.PARTY_ID.\n BANK_ACCOUNT_NAME VARCHAR2(80), -- Account holder name.\n CURRENCY_CODE VARCHAR2(15), -- Currency of the account. FK to FND_CURRENCIES.CURRENCY_CODE.\n COUNTRY_CODE VARCHAR2(2), -- Country of the account.\n START_DATE DATE, -- Date the account becomes valid.\n END_DATE DATE, -- Date the account stops being valid.\n ACCOUNT_SUFFIX VARCHAR2(30), -- Account suffix used by some banks.\n FOREIGN_PAYMENT_USE_FLAG VARCHAR2(1) -- Y if the account can receive foreign-currency payments.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n-- days to pay => AP_CHECKS_ALL.CHECK_DATE - AP_INVOICES_ALL.INVOICE_DATE (join AP_INVOICE_PAYMENTS_ALL on INVOICE_ID and CHECK_ID)\n"}, {"role": "user", "content": "Question: List the largest 3 payments"}, {"role": "assistant", "content": "```sql\nSELECT CHECK_NUMBER, CHECK_DATE, AMOUNT, VENDOR_NAME\nFROM AP_CHECKS_ALL\nORDER BY AMOUNT DESC\nFETCH FIRST 3 ROWS ONLY;\n```"}], "meta": {"id": "a-00089", "tier": "T1", "family": "t1-topn", "kind": "ask", "source": "S2-templated", "group": "c37388576706", "tables": ["AP_CHECKS_ALL"], "result_rows": 3, "approx_prompt_tokens": 3022, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n);\n\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_NUMBER NUMBER, -- Sequence of the line within the invoice.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n DESCRIPTION VARCHAR2(240), -- Description of the goods or service on the line.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit billed.\n PO_LINE_LOCATION_ID NUMBER, -- Purchase order schedule this line is matched to. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n ACCOUNTING_DATE DATE, -- Accounting date of the line.\n TAX_RATE NUMBER(12,6), -- Tax rate applied to the line.\n CANCELLED_FLAG VARCHAR2(1), -- Y if the line was cancelled.\n REQUESTER_ID NUMBER, -- Employee who requested the line item. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n PREPAY_INVOICE_ID NUMBER, -- Prepayment invoice applied on this line, if any.\n);\n\n-- Invoice batches: groups of invoices entered together, with control totals and entry status.\nCREATE TABLE AP_BATCHES_ALL (\n BATCH_ID NUMBER, -- Unique invoice batch identifier. Primary key.\n BATCH_NAME VARCHAR2(50), -- Name of the batch.\n BATCH_DATE DATE, -- Date the batch was created.\n INVOICE_COUNT NUMBER, -- Number of invoices entered in the batch.\n INVOICE_AMOUNT NUMBER(18,2), -- Total amount of the invoices in the batch.\n CONTROL_INVOICE_COUNT NUMBER, -- Expected invoice count entered as a control total.\n CONTROL_INVOICE_AMOUNT NUMBER(18,2), -- Expected batch amount entered as a control total.\n BATCH_STATUS VARCHAR2(25), -- Status of the batch. Values: OPEN, CLOSED, POSTED.\n SOURCE VARCHAR2(80), -- Source of the batch. Values: MANUAL, IMPORT, SUPPLIER PORTAL.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- early payment discount => AP_PAYMENT_SCHEDULES_ALL.DISCOUNT_AMOUNT_AVAILABLE > 0\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: How many invoices with an early-payment discount available are there?"}, {"role": "assistant", "content": "```sql\nSELECT COUNT(*)\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_ID IN (SELECT ps.INVOICE_ID FROM AP_PAYMENT_SCHEDULES_ALL ps WHERE ps.DISCOUNT_AMOUNT_AVAILABLE > 0);\n```"}], "meta": {"id": "a-01679", "tier": "T5", "family": "t5-glossary", "kind": "ask", "source": "S2-templated", "group": "51751eff7368", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL"], "result_rows": 1, "approx_prompt_tokens": 2747, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n PARTY_ID NUMBER, -- Trading-community party of the supplier. FK to HZ_PARTIES.PARTY_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n SELF_ASSESSED_TAX_AMOUNT NUMBER(18,2), -- Tax the buyer self-assesses instead of paying to the supplier.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice is denominated in. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice will be paid in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n EXCHANGE_RATE_TYPE VARCHAR2(30), -- Type of exchange rate used. Values: Corporate, Spot, User.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n SOURCE VARCHAR2(80), -- How the invoice entered the system. Values: MANUAL, IMPORT, SUPPLIER PORTAL, EMAIL.\n PO_HEADER_ID NUMBER, -- Purchase order the invoice is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n VALIDATION_STATUS VARCHAR2(25), -- Result of invoice validation. Values: VALIDATED, NEEDS REVALIDATION, NEVER VALIDATED.\n WFAPPROVAL_STATUS VARCHAR2(25), -- Approval workflow status of the invoice. Values: APPROVED, NOT REQUIRED, REJECTED, INITIATED.\n CANCELLED_DATE DATE, -- Date the invoice was cancelled; NULL if not cancelled.\n CANCELLED_BY VARCHAR2(64), -- User who cancelled the invoice.\n ACCTS_PAY_CODE_COMBINATION_ID NUMBER, -- Liability (accounts payable) account for the invoice. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n LEDGER_ID NUMBER, -- Ledger the invoice is accounted in. FK to GL_LEDGERS.LEDGER_ID.\n REQUESTER_ID NUMBER, -- Employee who requested the goods or services. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n LEGAL_ENTITY_ID NUMBER, -- Legal entity the invoice belongs to.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number assigned to the invoice.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n ATTRIBUTE_CATEGORY VARCHAR2(30), -- Descriptive flexfield context (customer-defined extension fields).\n ATTRIBUTE1 VARCHAR2(150), -- Descriptive flexfield segment 1, customer-defined and normally unused.\n ATTRIBUTE2 VARCHAR2(150), -- Descriptive flexfield segment 2, customer-defined and normally unused.\n ATTRIBUTE3 VARCHAR2(150), -- Descriptive flexfield segment 3, customer-defined and normally unused.\n ATTRIBUTE4 VARCHAR2(150), -- Descriptive flexfield segment 4, customer-defined and normally unused.\n ATTRIBUTE5 VARCHAR2(150), -- Descriptive flexfield segment 5, customer-defined and normally unused.\n ATTRIBUTE6 VARCHAR2(150), -- Descriptive flexfield segment 6, customer-defined and normally unused.\n ATTRIBUTE7 VARCHAR2(150), -- Descriptive flexfield segment 7, customer-defined and normally unused.\n ATTRIBUTE8 VARCHAR2(150), -- Descriptive flexfield segment 8, customer-defined and normally unused.\n ATTRIBUTE9 VARCHAR2(150), -- Descriptive flexfield segment 9, customer-defined and normally unused.\n ATTRIBUTE10 VARCHAR2(150) -- Descriptive flexfield segment 10, customer-defined and normally unused.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n PARTY_ID NUMBER, -- Trading-community party behind the supplier. FK to HZ_PARTIES.PARTY_ID.\n VENDOR_NAME VARCHAR2(360), -- Supplier name.\n VENDOR_NAME_ALT VARCHAR2(320), -- Alternate or trading name of the supplier.\n SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\n VENDOR_TYPE_LOOKUP_CODE VARCHAR2(30), -- Supplier type. Values: VENDOR, CONTRACTOR, EMPLOYEE, TAX AUTHORITY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n START_DATE_ACTIVE DATE, -- Date the supplier becomes active.\n END_DATE_ACTIVE DATE, -- Date the supplier stops being active.\n SUMMARY_FLAG VARCHAR2(1), -- Y if the supplier is a summary (parent) record.\n ONE_TIME_FLAG VARCHAR2(1), -- Y if the supplier is a one-time supplier.\n SMALL_BUSINESS_FLAG VARCHAR2(1), -- Y if the supplier is a small business.\n WOMEN_OWNED_FLAG VARCHAR2(1), -- Y if the supplier is women-owned.\n MINORITY_GROUP_LOOKUP_CODE VARCHAR2(30), -- Minority ownership classification. Values: MBE, DBE.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Default payment method for the supplier. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Default pay group. Values: DOMESTIC, INTERNATIONAL.\n TERMS_ID NUMBER, -- Default payment terms. FK to AP_TERMS_B.TERM_ID.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Default invoice currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Default payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if all payments to the supplier are blocked.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n NUM_1099 VARCHAR2(30), -- US taxpayer identification number for 1099 reporting.\n TAX_REGISTRATION_NUMBER VARCHAR2(50), -- VAT or GST registration number.\n FEDERAL_REPORTABLE_FLAG VARCHAR2(1), -- Y if the supplier is reportable for federal income tax.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2), -- Maximum credit extended to the supplier.\n RISK_RATING VARCHAR2(25), -- Internal supplier risk rating. Values: LOW, MEDIUM, HIGH.\n CREATION_SOURCE VARCHAR2(30), -- Where the supplier record originated. Values: REGISTRATION, MANUAL, IMPORT.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ATTRIBUTE_CATEGORY VARCHAR2(30), -- Descriptive flexfield context (customer-defined extension fields).\n ATTRIBUTE1 VARCHAR2(150), -- Descriptive flexfield segment 1, customer-defined and normally unused.\n ATTRIBUTE2 VARCHAR2(150), -- Descriptive flexfield segment 2, customer-defined and normally unused.\n ATTRIBUTE3 VARCHAR2(150), -- Descriptive flexfield segment 3, customer-defined and normally unused.\n ATTRIBUTE4 VARCHAR2(150), -- Descriptive flexfield segment 4, customer-defined and normally unused.\n ATTRIBUTE5 VARCHAR2(150) -- Descriptive flexfield segment 5, customer-defined and normally unused.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- vendor spend / supplier spend => SUM(AP_INVOICES_ALL.INVOICE_AMOUNT) grouped by AP_INVOICES_ALL.VENDOR_ID (join POZ_SUPPLIERS for VENDOR_NAME)\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n"}, {"role": "user", "content": "Question: Show the 5 suppliers with the highest total invoice amount this quarter\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT s.VENDOR_NAME, SUM(i.INVOICE_AMOUNT) AS TOTAL_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN POZ_SUPPLIERS s ON s.VENDOR_ID = i.VENDOR_ID\nWHERE i.INVOICE_DATE >= TRUNC(NOW(), 'Q')\nGROUP BY s.VENDOR_NAME\nORDER BY TOTAL_INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\nError: ORA-00904: \"NOW\": invalid identifier\nDiagnosis: No table in your query has a column named NOW. The columns are — AP_INVOICES_ALL: INVOICE_ID, VENDOR_ID, VENDOR_SITE_ID, PARTY_ID, INVOICE_NUM, INVOICE_TYPE_LOOKUP_CODE, INVOICE_DATE, INVOICE_RECEIVED_DATE, GOODS_RECEIVED_DATE, GL_DATE, INVOICE_AMOUNT, AMOUNT_PAID, TOTAL_TAX_AMOUNT, BASE_AMOUNT, APPROVED_AMOUNT, AMOUNT_APPLICABLE_TO_DISCOUNT, DISCOUNT_AMOUNT_TAKEN, PREPAY_AMOUNT_REMAINING, SELF_ASSESSED_TAX_AMOUNT, INVOICE_CURRENCY_CODE, PAYMENT_CURRENCY_CODE, EXCHANGE_RATE, EXCHANGE_DATE, EXCHANGE_RATE_TYPE, TERMS_ID, TERMS_DATE, PAYMENT_METHOD_CODE, PAY_GROUP_LOOKUP_CODE, PAYMENT_STATUS_FLAG, DESCRIPTION, SOURCE, PO_HEADER_ID, BATCH_ID, VALIDATION_STATUS, WFAPPROVAL_STATUS, CANCELLED_DATE, CANCELLED_BY, ACCTS_PAY_CODE_COMBINATION_ID, LEDGER_ID, REQUESTER_ID, LEGAL_ENTITY_ID, DOC_SEQUENCE_VALUE, CREATION_DATE, CREATED_BY, LAST_UPDATE_DATE, LAST_UPDATED_BY, OBJECT_VERSION_NUMBER, ORG_ID, ATTRIBUTE_CATEGORY, ATTRIBUTE1, ATTRIBUTE2, ATTRIBUTE3, ATTRIBUTE4, ATTRIBUTE5, ATTRIBUTE6, ATTRIBUTE7, ATTRIBUTE8, ATTRIBUTE9, ATTRIBUTE10; POZ_SUPPLIERS: VENDOR_ID, PARTY_ID, VENDOR_NAME, VENDOR_NAME_ALT, SEGMENT1, VENDOR_TYPE_LOOKUP_CODE, ENABLED_FLAG, START_DATE_ACTIVE, END_DATE_ACTIVE, SUMMARY_FLAG, ONE_TIME_FLAG, SMALL_BUSINESS_FLAG, WOMEN_OWNED_FLAG, MINORITY_GROUP_LOOKUP_CODE, PAYMENT_METHOD_LOOKUP_CODE, PAY_GROUP_LOOKUP_CODE, TERMS_ID, INVOICE_CURRENCY_CODE, PAYMENT_CURRENCY_CODE, HOLD_ALL_PAYMENTS_FLAG, HOLD_REASON, FEDERAL_REPORTABLE_FLAG, CREDIT_LIMIT_AMOUNT, RISK_RATING, CREATION_SOURCE, CREATION_DATE, CREATED_BY, LAST_UPDATE_DATE, LAST_UPDATED_BY, OBJECT_VERSION_NUMBER, ATTRIBUTE_CATEGORY, ATTRIBUTE1, ATTRIBUTE2, ATTRIBUTE3, ATTRIBUTE4, ATTRIBUTE5.\nWrite a corrected query. It must differ from the failed one. Use ONLY the tables and columns in the schema above, spelled exactly as shown; if a column you wanted does not exist, choose the closest one that does."}, {"role": "assistant", "content": "```sql\nSELECT s.VENDOR_NAME, SUM(i.INVOICE_AMOUNT) AS TOTAL_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN POZ_SUPPLIERS s ON s.VENDOR_ID = i.VENDOR_ID\nWHERE i.INVOICE_DATE >= TRUNC(SYSDATE, 'Q')\nGROUP BY s.VENDOR_NAME\nORDER BY TOTAL_INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "r-00088", "tier": "T3", "family": "spec-inv", "kind": "repair-exec", "source": "S6-repair", "group": "65e327ed1ffc", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 0, "approx_prompt_tokens": 3466, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"NOW\": invalid identifier", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150) -- Message printed on the remittance advice.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Purchase order schedules: delivery schedules of a line with need-by date, quantity received and billed, and the matching option (two-, three- or four-way).\n-- (showing 15 of 22 columns: join keys + those relevant to the question)\nCREATE TABLE PO_LINE_LOCATIONS_ALL (\n LINE_LOCATION_ID NUMBER, -- Unique schedule identifier. Primary key.\n PO_HEADER_ID NUMBER, -- Order the schedule belongs to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n PO_LINE_ID NUMBER, -- Line the schedule belongs to. FK to PO_LINES_ALL.PO_LINE_ID.\n SHIPMENT_NUM NUMBER, -- Schedule number within the line.\n QUANTITY NUMBER, -- Quantity scheduled.\n QUANTITY_RECEIVED NUMBER, -- Quantity received so far.\n QUANTITY_BILLED NUMBER, -- Quantity invoiced so far.\n QUANTITY_CANCELLED NUMBER, -- Quantity cancelled.\n NEED_BY_DATE DATE, -- Date the goods are needed.\n PROMISED_DATE DATE, -- Date the supplier promised delivery.\n PRICE_OVERRIDE NUMBER(18,2), -- Price for this schedule if different from the line.\n INVOICE_MATCH_OPTION VARCHAR2(1), -- P match to order (two-way), R match to receipt (three-way). Values: R, P.\n RECEIPT_REQUIRED_FLAG VARCHAR2(1), -- Y if receipt is required before payment.\n TAXABLE_FLAG VARCHAR2(1), -- Y if the schedule is taxable.\n CLOSED_CODE VARCHAR2(25) -- Closure state of the schedule. Values: OPEN, CLOSED FOR RECEIVING, CLOSED.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment history: status changes and accounting events for each payment (created, cleared, voided, reconciled).\n-- (showing 12 of 17 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_HISTORY_ALL (\n PAYMENT_HISTORY_ID NUMBER, -- Unique payment history identifier. Primary key.\n CHECK_ID NUMBER, -- Payment the history row describes. FK to AP_CHECKS_ALL.CHECK_ID.\n TRANSACTION_TYPE VARCHAR2(25), -- Kind of event recorded. Values: PAYMENT CREATED, PAYMENT CLEARING, PAYMENT UNCLEARING, PAYMENT CANCELLED.\n TRANSACTION_DATE DATE, -- Date of the event.\n ACCOUNTING_DATE DATE, -- Accounting date of the event.\n TRX_BANK_AMOUNT NUMBER(18,2), -- Amount at the bank for the event.\n TRX_PMT_AMOUNT NUMBER(18,2), -- Amount in payment currency for the event.\n HISTORICAL_FLAG VARCHAR2(1), -- Y if the row is superseded by a later event.\n POSTED_FLAG VARCHAR2(1), -- Y if the event was accounted.\n REV_PMT_HIST_ID NUMBER, -- Payment history row this event reverses.\n BANK_CURRENCY_CODE VARCHAR2(15), -- Currency of the bank statement line. FK to FND_CURRENCIES.CURRENCY_CODE.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n DOC_SEQUENCE_VALUE NUMBER -- Document sequence number of the payment.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n CANCELLED_DATE DATE -- Date the invoice was cancelled; NULL if not cancelled.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n"}, {"role": "user", "content": "Question: What is the total scheduled installment amount for each payment term that were due last month?"}, {"role": "assistant", "content": "```sql\nSELECT t.NAME, SUM(ps.GROSS_AMOUNT) AS TOTAL_INSTALLMENT_AMOUNT\nFROM AP_PAYMENT_SCHEDULES_ALL ps\nJOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ps.INVOICE_ID\nJOIN AP_TERMS_B t ON t.TERM_ID = i.TERMS_ID\nWHERE ps.DUE_DATE >= ADD_MONTHS(TRUNC(SYSDATE, 'MM'), -1) AND ps.DUE_DATE < TRUNC(SYSDATE, 'MM')\nGROUP BY t.NAME\nORDER BY TOTAL_INSTALLMENT_AMOUNT DESC;\n```"}], "meta": {"id": "a-01049", "tier": "T3", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "916e7dd7ead4", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "AP_TERMS_B"], "result_rows": 9, "approx_prompt_tokens": 3125, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Purchase order schedules: delivery schedules of a line with need-by date, quantity received and billed, and the matching option (two-, three- or four-way).\n-- (showing 15 of 22 columns: join keys + those relevant to the question)\nCREATE TABLE PO_LINE_LOCATIONS_ALL (\n LINE_LOCATION_ID NUMBER, -- Unique schedule identifier. Primary key.\n PO_HEADER_ID NUMBER, -- Order the schedule belongs to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n PO_LINE_ID NUMBER, -- Line the schedule belongs to. FK to PO_LINES_ALL.PO_LINE_ID.\n SHIPMENT_NUM NUMBER, -- Schedule number within the line.\n QUANTITY NUMBER, -- Quantity scheduled.\n QUANTITY_RECEIVED NUMBER, -- Quantity received so far.\n QUANTITY_BILLED NUMBER, -- Quantity invoiced so far.\n QUANTITY_CANCELLED NUMBER, -- Quantity cancelled.\n NEED_BY_DATE DATE, -- Date the goods are needed.\n PROMISED_DATE DATE, -- Date the supplier promised delivery.\n PRICE_OVERRIDE NUMBER(18,2), -- Price for this schedule if different from the line.\n INVOICE_MATCH_OPTION VARCHAR2(1), -- P match to order (two-way), R match to receipt (three-way). Values: R, P.\n RECEIPT_REQUIRED_FLAG VARCHAR2(1), -- Y if receipt is required before payment.\n TAXABLE_FLAG VARCHAR2(1), -- Y if the schedule is taxable.\n CLOSED_CODE VARCHAR2(25) -- Closure state of the schedule. Values: OPEN, CLOSED FOR RECEIVING, CLOSED.\n);\n\n-- Payment history: status changes and accounting events for each payment (created, cleared, voided, reconciled).\n-- (showing 12 of 17 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_HISTORY_ALL (\n PAYMENT_HISTORY_ID NUMBER, -- Unique payment history identifier. Primary key.\n CHECK_ID NUMBER, -- Payment the history row describes. FK to AP_CHECKS_ALL.CHECK_ID.\n TRANSACTION_TYPE VARCHAR2(25), -- Kind of event recorded. Values: PAYMENT CREATED, PAYMENT CLEARING, PAYMENT UNCLEARING, PAYMENT CANCELLED.\n TRANSACTION_DATE DATE, -- Date of the event.\n ACCOUNTING_DATE DATE, -- Accounting date of the event.\n TRX_BANK_AMOUNT NUMBER(18,2), -- Amount at the bank for the event.\n TRX_PMT_AMOUNT NUMBER(18,2), -- Amount in payment currency for the event.\n HISTORICAL_FLAG VARCHAR2(1), -- Y if the row is superseded by a later event.\n POSTED_FLAG VARCHAR2(1), -- Y if the event was accounted.\n REV_PMT_HIST_ID NUMBER, -- Payment history row this event reverses.\n BANK_CURRENCY_CODE VARCHAR2(15), -- Currency of the bank statement line. FK to FND_CURRENCIES.CURRENCY_CODE.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 16 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n CANCELLED_DATE DATE -- Date the invoice was cancelled; NULL if not cancelled.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n CURRENCY_CODE VARCHAR2(15), -- Currency the payment was made in. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n DOC_SEQUENCE_VALUE NUMBER -- Document sequence number of the payment.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: Show the total scheduled installment amount per payment term due in the next 30 days"}, {"role": "assistant", "content": "```sql\nSELECT t.NAME, SUM(ps.GROSS_AMOUNT) AS TOTAL_INSTALLMENT_AMOUNT\nFROM AP_PAYMENT_SCHEDULES_ALL ps\nJOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ps.INVOICE_ID\nJOIN AP_TERMS_B t ON t.TERM_ID = i.TERMS_ID\nWHERE ps.DUE_DATE BETWEEN TRUNC(SYSDATE) AND TRUNC(SYSDATE) + 30\nGROUP BY t.NAME\nORDER BY TOTAL_INSTALLMENT_AMOUNT DESC;\n```"}], "meta": {"id": "a-01124", "tier": "T3", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "b698274e0cea", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "AP_TERMS_B"], "result_rows": 8, "approx_prompt_tokens": 3152, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n SOURCE VARCHAR2(80), -- How the invoice entered the system. Values: MANUAL, IMPORT, SUPPLIER PORTAL, EMAIL.\n LEGAL_ENTITY_ID NUMBER, -- Legal entity the invoice belongs to.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n DESCRIPTION VARCHAR2(240), -- Description of the goods or service on the line.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit billed.\n PO_HEADER_ID NUMBER, -- Purchase order this line is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n PO_LINE_ID NUMBER, -- Purchase order line this line is matched to. FK to PO_LINES_ALL.PO_LINE_ID.\n PO_LINE_LOCATION_ID NUMBER, -- Purchase order schedule this line is matched to. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n RCV_TRANSACTION_ID NUMBER, -- Receipt transaction this line is matched to. FK to RCV_TRANSACTIONS.TRANSACTION_ID.\n PRODUCT_CATEGORY VARCHAR2(80), -- Category of the product or service. Values: IT EQUIPMENT, OFFICE SUPPLIES, PROFESSIONAL SERVICES, LOGISTICS.\n REQUESTER_ID NUMBER, -- Employee who requested the line item. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n MATCH_TYPE VARCHAR2(25), -- How the line was matched. Values: ITEM_TO_PO, ITEM_TO_RECEIPT, NOT_MATCHED.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Receipt headers: goods receipts recorded against shipments, with supplier, receipt number and date.\nCREATE TABLE RCV_SHIPMENT_HEADERS (\n SHIPMENT_HEADER_ID NUMBER, -- Unique shipment or receipt identifier. Primary key.\n RECEIPT_NUM VARCHAR2(30), -- Receipt number.\n VENDOR_ID NUMBER, -- Supplier that shipped the goods. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site shipped from. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n SHIPPED_DATE DATE, -- Date the supplier shipped the goods.\n EXPECTED_RECEIPT_DATE DATE, -- Date the receipt was expected.\n RECEIPT_SOURCE_CODE VARCHAR2(25), -- Source of the receipt. Values: VENDOR, INTERNAL.\n SHIPMENT_NUM VARCHAR2(30), -- Supplier's shipment or packing slip number.\n WAYBILL_AIRBILL_NUM VARCHAR2(30), -- Carrier waybill number.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 15 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_CODE VARCHAR2(15), -- Short site code.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Default invoice currency at this site. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n ALWAYS_TAKE_DISC_FLAG VARCHAR2(1), -- Y if the early-payment discount is always taken.\n TOLERANCE_ID NUMBER, -- Matching tolerance applied at the site.\n BILL_TO_LOCATION_ID NUMBER, -- Default bill-to location.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\n-- (showing 15 of 38 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n VENDOR_NAME VARCHAR2(360), -- Supplier name.\n SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\n VENDOR_TYPE_LOOKUP_CODE VARCHAR2(30), -- Supplier type. Values: VENDOR, CONTRACTOR, EMPLOYEE, TAX AUTHORITY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n SUMMARY_FLAG VARCHAR2(1), -- Y if the supplier is a summary (parent) record.\n ONE_TIME_FLAG VARCHAR2(1), -- Y if the supplier is a one-time supplier.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Default payment method for the supplier. Values: CHECK, EFT, WIRE.\n TERMS_ID NUMBER, -- Default payment terms. FK to AP_TERMS_B.TERM_ID.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Default invoice currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if all payments to the supplier are blocked.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n FEDERAL_REPORTABLE_FLAG VARCHAR2(1), -- Y if the supplier is reportable for federal income tax.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2), -- Maximum credit extended to the supplier.\n CREATION_SOURCE VARCHAR2(30), -- Where the supplier record originated. Values: REGISTRATION, MANUAL, IMPORT.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- credit memo => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'CREDIT'\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\n"}, {"role": "user", "content": "Question: Suppliers with both an invoice and a credit memo"}, {"role": "assistant", "content": "```sql\nSELECT s.VENDOR_NAME\nFROM POZ_SUPPLIERS s\nWHERE s.VENDOR_ID IN (\n SELECT VENDOR_ID FROM AP_INVOICES_ALL\n INTERSECT\n SELECT VENDOR_ID FROM AP_INVOICES_ALL WHERE INVOICE_TYPE_LOOKUP_CODE = 'CREDIT'\n)\nORDER BY s.VENDOR_NAME;\n```"}], "meta": {"id": "b-00979", "tier": "T4", "family": "blocked-set", "kind": "ask", "source": "S2-templated", "group": "372043db4046", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 7, "approx_prompt_tokens": 3143, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n SELF_ASSESSED_TAX_AMOUNT NUMBER(18,2), -- Tax the buyer self-assesses instead of paying to the supplier.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n BATCH_ID NUMBER -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_NUMBER NUMBER, -- Sequence of the line within the invoice.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit billed.\n UNIT_MEAS_LOOKUP_CODE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\n ACCOUNTING_DATE DATE, -- Accounting date of the line.\n TAX_CLASSIFICATION_CODE VARCHAR2(30), -- Tax classification of the line. Values: STANDARD, REDUCED, EXEMPT.\n TAX_RATE NUMBER(12,6), -- Tax rate applied to the line.\n TAX_RATE_ID NUMBER, -- Tax rate record applied. FK to ZX_RATES_B.TAX_RATE_ID.\n DISCARDED_FLAG VARCHAR2(1), -- Y if the line was discarded during correction.\n MATCH_TYPE VARCHAR2(25) -- How the line was matched. Values: ITEM_TO_PO, ITEM_TO_RECEIPT, NOT_MATCHED.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice batches: groups of invoices entered together, with control totals and entry status.\nCREATE TABLE AP_BATCHES_ALL (\n BATCH_ID NUMBER, -- Unique invoice batch identifier. Primary key.\n BATCH_NAME VARCHAR2(50), -- Name of the batch.\n BATCH_DATE DATE, -- Date the batch was created.\n INVOICE_COUNT NUMBER, -- Number of invoices entered in the batch.\n INVOICE_AMOUNT NUMBER(18,2), -- Total amount of the invoices in the batch.\n CONTROL_INVOICE_COUNT NUMBER, -- Expected invoice count entered as a control total.\n CONTROL_INVOICE_AMOUNT NUMBER(18,2), -- Expected batch amount entered as a control total.\n BATCH_STATUS VARCHAR2(25), -- Status of the batch. Values: OPEN, CLOSED, POSTED.\n SOURCE VARCHAR2(80), -- Source of the batch. Values: MANUAL, IMPORT, SUPPLIER PORTAL.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Tax rates: rate percentage per tax and status, with recovery and accounting settings.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE ZX_RATES_B (\n TAX_RATE_ID NUMBER, -- Unique tax rate identifier. Primary key.\n TAX_ID NUMBER, -- Tax the rate belongs to. FK to ZX_TAXES_B.TAX_ID.\n TAX_RATE_CODE VARCHAR2(30), -- Tax rate code. Values: STANDARD, REDUCED, ZERO, EXEMPT.\n TAX_STATUS_CODE VARCHAR2(30), -- Tax status the rate applies under. Values: STANDARD, REDUCED, ZERO.\n PERCENTAGE_RATE NUMBER(12,6), -- Tax percentage.\n EFFECTIVE_FROM DATE, -- Date the rate becomes effective.\n EFFECTIVE_TO DATE, -- Date the rate stops applying.\n ACTIVE_FLAG VARCHAR2(1), -- Y if the rate is active.\n TAX_ACCOUNT_CCID NUMBER, -- Account tax is posted to. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n RECOVERY_TYPE_CODE VARCHAR2(30), -- Recovery treatment. Values: STANDARD, PARTIAL.\n DEFAULT_RECOVERY_RATE NUMBER(12,6) -- Default recoverable percentage.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- credit memo => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'CREDIT'\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: Total invoice tax amount by payment term excluding credit memos"}, {"role": "assistant", "content": "```sql\nSELECT t.NAME, SUM(i.TOTAL_TAX_AMOUNT) AS TOTAL_TAX_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN AP_TERMS_B t ON t.TERM_ID = i.TERMS_ID\nWHERE i.INVOICE_TYPE_LOOKUP_CODE <> 'CREDIT'\nGROUP BY t.NAME\nORDER BY TOTAL_TAX_AMOUNT DESC;\n```"}], "meta": {"id": "a-00752", "tier": "T2", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "d84f17880f06", "tables": ["AP_INVOICES_ALL", "AP_TERMS_B"], "result_rows": 10, "approx_prompt_tokens": 2963, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n PARTY_ID NUMBER, -- Trading-community party of the supplier. FK to HZ_PARTIES.PARTY_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n SELF_ASSESSED_TAX_AMOUNT NUMBER(18,2), -- Tax the buyer self-assesses instead of paying to the supplier.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice is denominated in. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice will be paid in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n EXCHANGE_RATE_TYPE VARCHAR2(30), -- Type of exchange rate used. Values: Corporate, Spot, User.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n SOURCE VARCHAR2(80), -- How the invoice entered the system. Values: MANUAL, IMPORT, SUPPLIER PORTAL, EMAIL.\n PO_HEADER_ID NUMBER, -- Purchase order the invoice is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n VALIDATION_STATUS VARCHAR2(25), -- Result of invoice validation. Values: VALIDATED, NEEDS REVALIDATION, NEVER VALIDATED.\n WFAPPROVAL_STATUS VARCHAR2(25), -- Approval workflow status of the invoice. Values: APPROVED, NOT REQUIRED, REJECTED, INITIATED.\n CANCELLED_DATE DATE, -- Date the invoice was cancelled; NULL if not cancelled.\n CANCELLED_BY VARCHAR2(64), -- User who cancelled the invoice.\n ACCTS_PAY_CODE_COMBINATION_ID NUMBER, -- Liability (accounts payable) account for the invoice. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n LEDGER_ID NUMBER, -- Ledger the invoice is accounted in. FK to GL_LEDGERS.LEDGER_ID.\n REQUESTER_ID NUMBER, -- Employee who requested the goods or services. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n LEGAL_ENTITY_ID NUMBER, -- Legal entity the invoice belongs to.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number assigned to the invoice.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n ATTRIBUTE_CATEGORY VARCHAR2(30), -- Descriptive flexfield context (customer-defined extension fields).\n ATTRIBUTE1 VARCHAR2(150), -- Descriptive flexfield segment 1, customer-defined and normally unused.\n ATTRIBUTE2 VARCHAR2(150), -- Descriptive flexfield segment 2, customer-defined and normally unused.\n ATTRIBUTE3 VARCHAR2(150), -- Descriptive flexfield segment 3, customer-defined and normally unused.\n ATTRIBUTE4 VARCHAR2(150), -- Descriptive flexfield segment 4, customer-defined and normally unused.\n ATTRIBUTE5 VARCHAR2(150), -- Descriptive flexfield segment 5, customer-defined and normally unused.\n ATTRIBUTE6 VARCHAR2(150), -- Descriptive flexfield segment 6, customer-defined and normally unused.\n ATTRIBUTE7 VARCHAR2(150), -- Descriptive flexfield segment 7, customer-defined and normally unused.\n ATTRIBUTE8 VARCHAR2(150), -- Descriptive flexfield segment 8, customer-defined and normally unused.\n ATTRIBUTE9 VARCHAR2(150), -- Descriptive flexfield segment 9, customer-defined and normally unused.\n ATTRIBUTE10 VARCHAR2(150) -- Descriptive flexfield segment 10, customer-defined and normally unused.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: Show the total scheduled installment amount per payment term due in the next 30 days\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT t.NAME, SUM(ps.GROSS_AMOUNT) AS TOTAL_INSTALLMENT_AMOUNT FROM AP_PAYMENT_SCHEDULES_ALL ps JOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ps.INVOICE_ID JOIN AP_TERMS_B t ON t.TERM_ID = i.TERMS_ID WHERE ps.DUE_DATE BETWEEN TRUNC(NOW(), 'DD') AND TRUNC(NOW(), 'DD') + 30 GROUP BY t.NAME ORDER BY TOTAL_INSTALLMENT_AMOUNT DESC FETCH FIRST 200 ROWS ONLY;\nError: ORA-00904: \"NOW\": invalid identifier\nDiagnosis: No table in your query has a column named NOW. The columns are — AP_PAYMENT_SCHEDULES_ALL: PAYMENT_SCHEDULE_ID, INVOICE_ID, PAYMENT_NUM, DUE_DATE, GROSS_AMOUNT, AMOUNT_REMAINING, DISCOUNT_DATE, DISCOUNT_AMOUNT_AVAILABLE, SECOND_DISCOUNT_DATE, HOLD_FLAG, PAYMENT_STATUS_FLAG, PAYMENT_PRIORITY, EXTERNAL_BANK_ACCOUNT_ID, CHECKRUN_ID, REMITTANCE_MESSAGE1, CREATION_DATE, CREATED_BY, LAST_UPDATE_DATE, LAST_UPDATED_BY, OBJECT_VERSION_NUMBER, ORG_ID; AP_INVOICES_ALL: INVOICE_ID, VENDOR_ID, VENDOR_SITE_ID, PARTY_ID, INVOICE_NUM, INVOICE_TYPE_LOOKUP_CODE, INVOICE_DATE, INVOICE_RECEIVED_DATE, GOODS_RECEIVED_DATE, GL_DATE, INVOICE_AMOUNT, AMOUNT_PAID, TOTAL_TAX_AMOUNT, BASE_AMOUNT, APPROVED_AMOUNT, AMOUNT_APPLICABLE_TO_DISCOUNT, DISCOUNT_AMOUNT_TAKEN, PREPAY_AMOUNT_REMAINING, SELF_ASSESSED_TAX_AMOUNT, INVOICE_CURRENCY_CODE, PAYMENT_CURRENCY_CODE, EXCHANGE_RATE, EXCHANGE_DATE, EXCHANGE_RATE_TYPE, TERMS_ID, TERMS_DATE, PAYMENT_METHOD_CODE, PAY_GROUP_LOOKUP_CODE, PAYMENT_STATUS_FLAG, DESCRIPTION, SOURCE, PO_HEADER_ID, BATCH_ID, VALIDATION_STATUS, WFAPPROVAL_STATUS, CANCELLED_DATE, CANCELLED_BY, ACCTS_PAY_CODE_COMBINATION_ID, LEDGER_ID, REQUESTER_ID, LEGAL_ENTITY_ID, DOC_SEQUENCE_VALUE, CREATION_DATE, CREATED_BY, LAST_UPDATE_DATE, LAST_UPDATED_BY, OBJECT_VERSION_NUMBER, ORG_ID, ATTRIBUTE_CATEGORY, ATTRIBUTE1, ATTRIBUTE2, ATTRIBUTE3, ATTRIBUTE4, ATTRIBUTE5, ATTRIBUTE6, ATTRIBUTE7, ATTRIBUTE8, ATTRIBUTE9, ATTRIBUTE10; AP_TERMS_B: TERM_ID, NAME, DESCRIPTION, ENABLED_FLAG, START_DATE_ACTIVE, END_DATE_ACTIVE, DUE_DAYS, DISCOUNT_PERCENT, DISCOUNT_DAYS, CUTOFF_DAY, CREATION_DATE, CREATED_BY, LAST_UPDATE_DATE, LAST_UPDATED_BY, OBJECT_VERSION_NUMBER.\nWrite a corrected query. It must differ from the failed one. Use ONLY the tables and columns in the schema above, spelled exactly as shown; if a column you wanted does not exist, choose the closest one that does."}, {"role": "assistant", "content": "```sql\nSELECT t.NAME, SUM(ps.GROSS_AMOUNT) AS TOTAL_INSTALLMENT_AMOUNT\nFROM AP_PAYMENT_SCHEDULES_ALL ps\nJOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ps.INVOICE_ID\nJOIN AP_TERMS_B t ON t.TERM_ID = i.TERMS_ID\nWHERE ps.DUE_DATE BETWEEN TRUNC(SYSDATE) AND TRUNC(SYSDATE) + 30\nGROUP BY t.NAME\nORDER BY TOTAL_INSTALLMENT_AMOUNT DESC;\n```"}], "meta": {"id": "r-00082", "tier": "T3", "family": "spec-inst", "kind": "repair-exec", "source": "S6-repair", "group": "b698274e0cea", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "AP_TERMS_B"], "result_rows": 0, "approx_prompt_tokens": 3560, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"NOW\": invalid identifier", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Purchase order schedules: delivery schedules of a line with need-by date, quantity received and billed, and the matching option (two-, three- or four-way).\n-- (showing 15 of 22 columns: join keys + those relevant to the question)\nCREATE TABLE PO_LINE_LOCATIONS_ALL (\n LINE_LOCATION_ID NUMBER, -- Unique schedule identifier. Primary key.\n PO_HEADER_ID NUMBER, -- Order the schedule belongs to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n PO_LINE_ID NUMBER, -- Line the schedule belongs to. FK to PO_LINES_ALL.PO_LINE_ID.\n SHIPMENT_NUM NUMBER, -- Schedule number within the line.\n QUANTITY NUMBER, -- Quantity scheduled.\n QUANTITY_RECEIVED NUMBER, -- Quantity received so far.\n QUANTITY_BILLED NUMBER, -- Quantity invoiced so far.\n QUANTITY_CANCELLED NUMBER, -- Quantity cancelled.\n NEED_BY_DATE DATE, -- Date the goods are needed.\n PROMISED_DATE DATE, -- Date the supplier promised delivery.\n PRICE_OVERRIDE NUMBER(18,2), -- Price for this schedule if different from the line.\n RECEIPT_REQUIRED_FLAG VARCHAR2(1), -- Y if receipt is required before payment.\n TAXABLE_FLAG VARCHAR2(1), -- Y if the schedule is taxable.\n SHIP_TO_LOCATION_ID NUMBER, -- Where the goods are delivered.\n CLOSED_CODE VARCHAR2(25) -- Closure state of the schedule. Values: OPEN, CLOSED FOR RECEIVING, CLOSED.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice holds: matching exceptions, duplicates and variances that block payment, with hold reason, date placed and release date. NULL RELEASE_DATE means the hold is still active.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_HOLDS_ALL (\n HOLD_ID NUMBER, -- Unique hold identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the hold is placed on. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_LOCATION_ID NUMBER, -- Purchase order schedule that caused the hold. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n HOLD_LOOKUP_CODE VARCHAR2(30), -- Hold reason. FK to AP_HOLD_CODES.HOLD_LOOKUP_CODE.\n HOLD_DATE DATE, -- Date the hold was placed.\n HELD_BY NUMBER, -- User who placed the hold. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n HOLD_REASON VARCHAR2(240), -- Explanation of why the hold was placed.\n RELEASE_LOOKUP_CODE VARCHAR2(30), -- Reason the hold was released. Values: VARIANCE ACCEPTED, CORRECTED, OVERRIDE.\n RELEASE_DATE DATE, -- Date the hold was released; NULL if still active.\n RELEASE_REASON VARCHAR2(240), -- Comments recorded when the hold was released.\n STATUS_FLAG VARCHAR2(1), -- Hold status: S system-placed, R released. Values: S, R.\n RESPONSIBILITY_ID NUMBER, -- Responsibility able to release the hold.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Purchase order distributions: charge accounts and quantities of a schedule, including amount ordered, delivered and billed.\n-- (showing 14 of 19 columns: join keys + those relevant to the question)\nCREATE TABLE PO_DISTRIBUTIONS_ALL (\n PO_DISTRIBUTION_ID NUMBER, -- Unique distribution identifier. Primary key.\n PO_HEADER_ID NUMBER, -- Order the distribution belongs to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n PO_LINE_ID NUMBER, -- Line the distribution belongs to. FK to PO_LINES_ALL.PO_LINE_ID.\n LINE_LOCATION_ID NUMBER, -- Schedule the distribution belongs to. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n DISTRIBUTION_NUM NUMBER, -- Distribution number within the schedule.\n CODE_COMBINATION_ID NUMBER, -- Expense account charged. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n QUANTITY_ORDERED NUMBER, -- Quantity ordered on the distribution.\n QUANTITY_DELIVERED NUMBER, -- Quantity delivered.\n QUANTITY_BILLED NUMBER, -- Quantity billed.\n AMOUNT_ORDERED NUMBER(18,2), -- Amount ordered.\n AMOUNT_BILLED NUMBER(18,2), -- Amount billed so far.\n DESTINATION_TYPE_CODE VARCHAR2(25), -- Where the goods go. Values: EXPENSE, INVENTORY.\n REQUESTER_ID NUMBER, -- Employee who requested the goods. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n PROJECT_ID NUMBER -- Project charged.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Purchase order headers: one row per purchase order with supplier, buyer, status, total and terms.\n-- (showing 15 of 28 columns: join keys + those relevant to the question)\nCREATE TABLE PO_HEADERS_ALL (\n PO_HEADER_ID NUMBER, -- Unique purchase order identifier. Primary key.\n SEGMENT1 VARCHAR2(30), -- Purchase order number.\n VENDOR_ID NUMBER, -- Supplier the order is placed with. FK to POZ_SUPPLIERS.VENDOR_ID.\n RATE NUMBER(12,6), -- Exchange rate on the order.\n TERMS_ID NUMBER, -- Payment terms on the order. FK to AP_TERMS_B.TERM_ID.\n DOCUMENT_STATUS VARCHAR2(25), -- Status of the order. Values: OPEN, CLOSED, CANCELLED, INCOMPLETE.\n APPROVED_DATE DATE, -- Date the order was approved.\n CREATION_DATE_ORDERED DATE, -- Date the order was placed.\n TOTAL_AMOUNT NUMBER(18,2), -- Total order amount.\n NOTE_TO_VENDOR VARCHAR2(480), -- Note printed for the supplier.\n SHIP_TO_LOCATION_ID NUMBER, -- Ship-to location.\n BILL_TO_LOCATION_ID NUMBER, -- Bill-to location.\n CANCEL_FLAG VARCHAR2(1), -- Y if the order was cancelled.\n CLOSED_DATE DATE, -- Date the order was closed.\n CLOSED_CODE VARCHAR2(25) -- Closure state of the order. Values: OPEN, CLOSED, FINALLY CLOSED.\n);\n\n-- Supplier addresses: physical and remit-to addresses of suppliers.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_ADDRESSES (\n ADDRESS_ID NUMBER, -- Unique address identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the address belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_NAME VARCHAR2(240), -- Name identifying the address.\n ADDRESS_LINE1 VARCHAR2(240), -- First address line.\n ADDRESS_LINE2 VARCHAR2(240), -- Second address line.\n CITY VARCHAR2(60), -- City.\n STATE VARCHAR2(60), -- State or province. Values: CA, NY, TX, WA, IL.\n POSTAL_CODE VARCHAR2(60), -- Postal or ZIP code.\n COUNTRY VARCHAR2(2), -- Country code.\n ADDRESS_PURPOSE VARCHAR2(30), -- What the address is used for. Values: REMIT_TO, PURCHASING, RFQ.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n LATITUDE NUMBER(12,6), -- Latitude of the address.\n LONGITUDE NUMBER(12,6) -- Longitude of the address.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PO_HEADER_ID NUMBER, -- Purchase order the invoice is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n ACCTS_PAY_CODE_COMBINATION_ID NUMBER -- Liability (accounts payable) account for the invoice. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- early payment discount => AP_PAYMENT_SCHEDULES_ALL.DISCOUNT_AMOUNT_AVAILABLE > 0\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: What is the number of open installments for each supplier city for installments on hold?"}, {"role": "assistant", "content": "```sql\nSELECT a.CITY, COUNT(*) AS OPEN_INSTALLMENTS\nFROM AP_PAYMENT_SCHEDULES_ALL ps\nJOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ps.INVOICE_ID\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = i.VENDOR_ID\nWHERE ps.AMOUNT_REMAINING > 0 AND ps.HOLD_FLAG = 'Y'\nGROUP BY a.CITY\nORDER BY OPEN_INSTALLMENTS DESC;\n```"}], "meta": {"id": "a-00727", "tier": "T2", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "fde9abfc532c", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 5, "approx_prompt_tokens": 2939, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Invoice holds: matching exceptions, duplicates and variances that block payment, with hold reason, date placed and release date. NULL RELEASE_DATE means the hold is still active.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_HOLDS_ALL (\n HOLD_ID NUMBER, -- Unique hold identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the hold is placed on. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_LOCATION_ID NUMBER, -- Purchase order schedule that caused the hold. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n HOLD_LOOKUP_CODE VARCHAR2(30), -- Hold reason. FK to AP_HOLD_CODES.HOLD_LOOKUP_CODE.\n HOLD_DATE DATE, -- Date the hold was placed.\n HELD_BY NUMBER, -- User who placed the hold. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n HOLD_REASON VARCHAR2(240), -- Explanation of why the hold was placed.\n RELEASE_LOOKUP_CODE VARCHAR2(30), -- Reason the hold was released. Values: VARIANCE ACCEPTED, CORRECTED, OVERRIDE.\n RELEASE_DATE DATE, -- Date the hold was released; NULL if still active.\n RELEASE_REASON VARCHAR2(240), -- Comments recorded when the hold was released.\n STATUS_FLAG VARCHAR2(1), -- Hold status: S system-placed, R released. Values: S, R.\n RESPONSIBILITY_ID NUMBER, -- Responsibility able to release the hold.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 16 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n CANCELLED_DATE DATE, -- Date the invoice was cancelled; NULL if not cancelled.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit billed.\n UNIT_MEAS_LOOKUP_CODE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\n PO_LINE_LOCATION_ID NUMBER, -- Purchase order schedule this line is matched to. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n RCV_TRANSACTION_ID NUMBER, -- Receipt transaction this line is matched to. FK to RCV_TRANSACTIONS.TRANSACTION_ID.\n ACCOUNTING_DATE DATE, -- Accounting date of the line.\n TAX_RATE NUMBER(12,6), -- Tax rate applied to the line.\n CANCELLED_FLAG VARCHAR2(1), -- Y if the line was cancelled.\n REQUESTER_ID NUMBER, -- Employee who requested the line item. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n PREPAY_INVOICE_ID NUMBER, -- Prepayment invoice applied on this line, if any.\n);\n\n-- Purchase order schedules: delivery schedules of a line with need-by date, quantity received and billed, and the matching option (two-, three- or four-way).\n-- (showing 15 of 22 columns: join keys + those relevant to the question)\nCREATE TABLE PO_LINE_LOCATIONS_ALL (\n LINE_LOCATION_ID NUMBER, -- Unique schedule identifier. Primary key.\n PO_HEADER_ID NUMBER, -- Order the schedule belongs to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n SHIPMENT_NUM NUMBER, -- Schedule number within the line.\n QUANTITY NUMBER, -- Quantity scheduled.\n QUANTITY_RECEIVED NUMBER, -- Quantity received so far.\n QUANTITY_BILLED NUMBER, -- Quantity invoiced so far.\n QUANTITY_CANCELLED NUMBER, -- Quantity cancelled.\n NEED_BY_DATE DATE, -- Date the goods are needed.\n PROMISED_DATE DATE, -- Date the supplier promised delivery.\n PRICE_OVERRIDE NUMBER(18,2), -- Price for this schedule if different from the line.\n INVOICE_MATCH_OPTION VARCHAR2(1), -- P match to order (two-way), R match to receipt (three-way). Values: R, P.\n RECEIPT_REQUIRED_FLAG VARCHAR2(1), -- Y if receipt is required before payment.\n TAXABLE_FLAG VARCHAR2(1), -- Y if the schedule is taxable.\n SHIP_TO_LOCATION_ID NUMBER, -- Where the goods are delivered.\n CLOSED_CODE VARCHAR2(25), -- Closure state of the schedule. Values: OPEN, CLOSED FOR RECEIVING, CLOSED.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- cancelled invoice => AP_INVOICES_ALL.CANCELLED_DATE IS NOT NULL\n"}, {"role": "user", "content": "Question: When is invoice INV-2026-5046 due and how much is still owed?"}, {"role": "assistant", "content": "```sql\nSELECT ps.PAYMENT_NUM, ps.DUE_DATE, ps.AMOUNT_REMAINING\nFROM AP_PAYMENT_SCHEDULES_ALL ps\nJOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ps.INVOICE_ID\nWHERE i.INVOICE_NUM = 'INV-2026-5046'\nORDER BY ps.PAYMENT_NUM;\n```"}], "meta": {"id": "a-00475", "tier": "T2", "family": "t2-invoice-lookup", "kind": "ask", "source": "S2-templated", "group": "765d04afe464", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL"], "result_rows": 1, "approx_prompt_tokens": 2724, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 16 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n VALIDATION_STATUS VARCHAR2(25), -- Result of invoice validation. Values: VALIDATED, NEEDS REVALIDATION, NEVER VALIDATED.\n CANCELLED_DATE DATE, -- Date the invoice was cancelled; NULL if not cancelled.\n CANCELLED_BY VARCHAR2(64), -- User who cancelled the invoice.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n);\n\n-- Invoice holds: matching exceptions, duplicates and variances that block payment, with hold reason, date placed and release date. NULL RELEASE_DATE means the hold is still active.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_HOLDS_ALL (\n HOLD_ID NUMBER, -- Unique hold identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the hold is placed on. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_LOCATION_ID NUMBER, -- Purchase order schedule that caused the hold. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n HOLD_LOOKUP_CODE VARCHAR2(30), -- Hold reason. FK to AP_HOLD_CODES.HOLD_LOOKUP_CODE.\n HOLD_DATE DATE, -- Date the hold was placed.\n HELD_BY NUMBER, -- User who placed the hold. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n HOLD_REASON VARCHAR2(240), -- Explanation of why the hold was placed.\n RELEASE_LOOKUP_CODE VARCHAR2(30), -- Reason the hold was released. Values: VARIANCE ACCEPTED, CORRECTED, OVERRIDE.\n RELEASE_DATE DATE, -- Date the hold was released; NULL if still active.\n RELEASE_REASON VARCHAR2(240), -- Comments recorded when the hold was released.\n STATUS_FLAG VARCHAR2(1), -- Hold status: S system-placed, R released. Values: S, R.\n RESPONSIBILITY_ID NUMBER, -- Responsibility able to release the hold.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice distributions: how each invoice line amount is split across general-ledger expense accounts, with accounting status. Use for spend-by-GL-account questions.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_DISTRIBUTIONS_ALL (\n INVOICE_DISTRIBUTION_ID NUMBER, -- Unique invoice distribution identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the distribution belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n INVOICE_LINE_ID NUMBER, -- Invoice line the distribution splits. FK to AP_INVOICE_LINES_ALL.INVOICE_LINE_ID.\n DISTRIBUTION_LINE_NUMBER NUMBER, -- Sequence of the distribution within the invoice.\n AMOUNT NUMBER(18,2), -- Distribution amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Distribution amount in ledger currency.\n ACCOUNTING_DATE DATE, -- Accounting date of the distribution.\n PERIOD_NAME VARCHAR2(15), -- Accounting period the distribution falls in.\n POSTED_FLAG VARCHAR2(1), -- Y if accounted and posted to the ledger, N if not yet accounted. Values: Y, N.\n ACCRUAL_POSTED_FLAG VARCHAR2(1), -- Y if accrual accounting entries were created.\n QUANTITY_INVOICED NUMBER, -- Quantity billed for the distribution.\n REVERSAL_FLAG VARCHAR2(1), -- Y if this distribution reverses another.\n TASK_ID NUMBER, -- Project task charged.\n INCOME_TAX_REGION VARCHAR2(10), -- Region used for income-tax reporting.\n DESCRIPTION VARCHAR2(240), -- Distribution description.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice batches: groups of invoices entered together, with control totals and entry status.\nCREATE TABLE AP_BATCHES_ALL (\n BATCH_ID NUMBER, -- Unique invoice batch identifier. Primary key.\n BATCH_NAME VARCHAR2(50), -- Name of the batch.\n BATCH_DATE DATE, -- Date the batch was created.\n INVOICE_COUNT NUMBER, -- Number of invoices entered in the batch.\n INVOICE_AMOUNT NUMBER(18,2), -- Total amount of the invoices in the batch.\n CONTROL_INVOICE_COUNT NUMBER, -- Expected invoice count entered as a control total.\n CONTROL_INVOICE_AMOUNT NUMBER(18,2), -- Expected batch amount entered as a control total.\n BATCH_STATUS VARCHAR2(25), -- Status of the batch. Values: OPEN, CLOSED, POSTED.\n SOURCE VARCHAR2(80), -- Source of the batch. Values: MANUAL, IMPORT, SUPPLIER PORTAL.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_NUMBER NUMBER, -- Sequence of the line within the invoice.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_MEAS_LOOKUP_CODE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\n ACCOUNTING_DATE DATE, -- Accounting date of the line.\n TAX_CLASSIFICATION_CODE VARCHAR2(30), -- Tax classification of the line. Values: STANDARD, REDUCED, EXEMPT.\n TAX_RATE NUMBER(12,6), -- Tax rate applied to the line.\n DISCARDED_FLAG VARCHAR2(1), -- Y if the line was discarded during correction.\n CANCELLED_FLAG VARCHAR2(1), -- Y if the line was cancelled.\n REQUESTER_ID NUMBER, -- Employee who requested the line item. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n MATCH_TYPE VARCHAR2(25), -- How the line was matched. Values: ITEM_TO_PO, ITEM_TO_RECEIPT, NOT_MATCHED.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- unvalidated invoice => AP_INVOICES_ALL.VALIDATION_STATUS <> 'VALIDATED'\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- cancelled invoice => AP_INVOICES_ALL.CANCELLED_DATE IS NOT NULL\n-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\n"}, {"role": "user", "content": "Question: How many unvalidated invoices were entered in the last 90 days?"}, {"role": "assistant", "content": "```sql\nSELECT COUNT(*)\nFROM AP_INVOICES_ALL i\nWHERE i.VALIDATION_STATUS <> 'VALIDATED'\nAND i.INVOICE_DATE >= TRUNC(SYSDATE) - 90;\n```"}], "meta": {"id": "a-01730", "tier": "T5", "family": "t5-glossary", "kind": "ask", "source": "S2-templated", "group": "111491c0ac77", "tables": ["AP_INVOICES_ALL"], "result_rows": 1, "approx_prompt_tokens": 3141, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n PARTY_ID NUMBER, -- Trading-community party of the supplier. FK to HZ_PARTIES.PARTY_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n SELF_ASSESSED_TAX_AMOUNT NUMBER(18,2), -- Tax the buyer self-assesses instead of paying to the supplier.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice is denominated in. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice will be paid in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n EXCHANGE_RATE_TYPE VARCHAR2(30), -- Type of exchange rate used. Values: Corporate, Spot, User.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n SOURCE VARCHAR2(80), -- How the invoice entered the system. Values: MANUAL, IMPORT, SUPPLIER PORTAL, EMAIL.\n PO_HEADER_ID NUMBER, -- Purchase order the invoice is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n VALIDATION_STATUS VARCHAR2(25), -- Result of invoice validation. Values: VALIDATED, NEEDS REVALIDATION, NEVER VALIDATED.\n WFAPPROVAL_STATUS VARCHAR2(25), -- Approval workflow status of the invoice. Values: APPROVED, NOT REQUIRED, REJECTED, INITIATED.\n CANCELLED_DATE DATE, -- Date the invoice was cancelled; NULL if not cancelled.\n CANCELLED_BY VARCHAR2(64), -- User who cancelled the invoice.\n ACCTS_PAY_CODE_COMBINATION_ID NUMBER, -- Liability (accounts payable) account for the invoice. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n LEDGER_ID NUMBER, -- Ledger the invoice is accounted in. FK to GL_LEDGERS.LEDGER_ID.\n REQUESTER_ID NUMBER, -- Employee who requested the goods or services. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n LEGAL_ENTITY_ID NUMBER, -- Legal entity the invoice belongs to.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number assigned to the invoice.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n ATTRIBUTE_CATEGORY VARCHAR2(30), -- Descriptive flexfield context (customer-defined extension fields).\n ATTRIBUTE1 VARCHAR2(150), -- Descriptive flexfield segment 1, customer-defined and normally unused.\n ATTRIBUTE2 VARCHAR2(150), -- Descriptive flexfield segment 2, customer-defined and normally unused.\n ATTRIBUTE3 VARCHAR2(150), -- Descriptive flexfield segment 3, customer-defined and normally unused.\n ATTRIBUTE4 VARCHAR2(150), -- Descriptive flexfield segment 4, customer-defined and normally unused.\n ATTRIBUTE5 VARCHAR2(150), -- Descriptive flexfield segment 5, customer-defined and normally unused.\n ATTRIBUTE6 VARCHAR2(150), -- Descriptive flexfield segment 6, customer-defined and normally unused.\n ATTRIBUTE7 VARCHAR2(150), -- Descriptive flexfield segment 7, customer-defined and normally unused.\n ATTRIBUTE8 VARCHAR2(150), -- Descriptive flexfield segment 8, customer-defined and normally unused.\n ATTRIBUTE9 VARCHAR2(150), -- Descriptive flexfield segment 9, customer-defined and normally unused.\n ATTRIBUTE10 VARCHAR2(150), -- Descriptive flexfield segment 10, customer-defined and normally unused.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice batches: groups of invoices entered together, with control totals and entry status.\nCREATE TABLE AP_BATCHES_ALL (\n BATCH_ID NUMBER, -- Unique invoice batch identifier. Primary key.\n BATCH_NAME VARCHAR2(50), -- Name of the batch.\n BATCH_DATE DATE, -- Date the batch was created.\n INVOICE_COUNT NUMBER, -- Number of invoices entered in the batch.\n INVOICE_AMOUNT NUMBER(18,2), -- Total amount of the invoices in the batch.\n CONTROL_INVOICE_COUNT NUMBER, -- Expected invoice count entered as a control total.\n CONTROL_INVOICE_AMOUNT NUMBER(18,2), -- Expected batch amount entered as a control total.\n BATCH_STATUS VARCHAR2(25), -- Status of the batch. Values: OPEN, CLOSED, POSTED.\n SOURCE VARCHAR2(80), -- Source of the batch. Values: MANUAL, IMPORT, SUPPLIER PORTAL.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_NUMBER NUMBER, -- Sequence of the line within the invoice.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n DESCRIPTION VARCHAR2(240), -- Description of the goods or service on the line.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit billed.\n UNIT_MEAS_LOOKUP_CODE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\n ACCOUNTING_DATE DATE, -- Accounting date of the line.\n DEFAULT_DIST_CCID NUMBER, -- Default account used to distribute the line. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n TAX_RATE NUMBER(12,6), -- Tax rate applied to the line.\n REQUESTER_ID NUMBER, -- Employee who requested the line item. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: Give me the 5 largest invoices\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT INVOICE_NUMBER, INVOICE_DATE, INVOICE_AMOUNT\nFROM AP_INVOICES_ALL\nORDER BY INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\nError: ORA-00904: \"INVOICE_NUMBER\": invalid identifier\nDiagnosis: No table in your query has a column named INVOICE_NUMBER. The columns are — AP_INVOICES_ALL: INVOICE_ID, VENDOR_ID, VENDOR_SITE_ID, PARTY_ID, INVOICE_NUM, INVOICE_TYPE_LOOKUP_CODE, INVOICE_DATE, INVOICE_RECEIVED_DATE, GOODS_RECEIVED_DATE, GL_DATE, INVOICE_AMOUNT, AMOUNT_PAID, TOTAL_TAX_AMOUNT, BASE_AMOUNT, APPROVED_AMOUNT, AMOUNT_APPLICABLE_TO_DISCOUNT, DISCOUNT_AMOUNT_TAKEN, PREPAY_AMOUNT_REMAINING, SELF_ASSESSED_TAX_AMOUNT, INVOICE_CURRENCY_CODE, PAYMENT_CURRENCY_CODE, EXCHANGE_RATE, EXCHANGE_DATE, EXCHANGE_RATE_TYPE, TERMS_ID, TERMS_DATE, PAYMENT_METHOD_CODE, PAY_GROUP_LOOKUP_CODE, PAYMENT_STATUS_FLAG, DESCRIPTION, SOURCE, PO_HEADER_ID, BATCH_ID, VALIDATION_STATUS, WFAPPROVAL_STATUS, CANCELLED_DATE, CANCELLED_BY, ACCTS_PAY_CODE_COMBINATION_ID, LEDGER_ID, REQUESTER_ID, LEGAL_ENTITY_ID, DOC_SEQUENCE_VALUE, CREATION_DATE, CREATED_BY, LAST_UPDATE_DATE, LAST_UPDATED_BY, OBJECT_VERSION_NUMBER, ORG_ID, ATTRIBUTE_CATEGORY, ATTRIBUTE1, ATTRIBUTE2, ATTRIBUTE3, ATTRIBUTE4, ATTRIBUTE5, ATTRIBUTE6, ATTRIBUTE7, ATTRIBUTE8, ATTRIBUTE9, ATTRIBUTE10.\nWrite a corrected query. It must differ from the failed one. Use ONLY the tables and columns in the schema above, spelled exactly as shown; if a column you wanted does not exist, choose the closest one that does."}, {"role": "assistant", "content": "```sql\nSELECT INVOICE_NUM, INVOICE_DATE, INVOICE_AMOUNT\nFROM AP_INVOICES_ALL\nORDER BY INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "r-00035", "tier": "T1", "family": "t1-topn", "kind": "repair-exec", "source": "S6-repair", "group": "9e8a0453211f", "tables": ["AP_INVOICES_ALL"], "result_rows": 0, "approx_prompt_tokens": 3405, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"INVOICE_NUMBER\": invalid identifier", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n CURRENCY_CODE VARCHAR2(15), -- Currency the payment was made in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting payment currency to ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account the payment was drawn on. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n);\n\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 15 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_CODE VARCHAR2(15), -- Short site code.\n ADDRESS_ID NUMBER, -- Address of the site. FK to POZ_SUPPLIER_ADDRESSES.ADDRESS_ID.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Payment method for this site. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Default payment currency at this site. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n SHIP_TO_LOCATION_ID NUMBER, -- Default ship-to location for purchase orders.\n BILL_TO_LOCATION_ID NUMBER, -- Default bill-to location.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Supplier bank accounts: external bank accounts that payments are sent to, with account holder, currency and validity dates.\n-- (showing 10 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXT_BANK_ACCOUNTS (\n EXT_BANK_ACCOUNT_ID NUMBER, -- Unique external bank account identifier. Primary key.\n BANK_PARTY_ID NUMBER, -- Bank holding the account. FK to CE_BANKS.BANK_PARTY_ID.\n ACCOUNT_OWNER_PARTY_ID NUMBER, -- Party that owns the account. FK to HZ_PARTIES.PARTY_ID.\n BANK_ACCOUNT_NAME VARCHAR2(80), -- Account holder name.\n CURRENCY_CODE VARCHAR2(15), -- Currency of the account. FK to FND_CURRENCIES.CURRENCY_CODE.\n COUNTRY_CODE VARCHAR2(2), -- Country of the account.\n START_DATE DATE, -- Date the account becomes valid.\n END_DATE DATE, -- Date the account stops being valid.\n ACCOUNT_SUFFIX VARCHAR2(30), -- Account suffix used by some banks.\n FOREIGN_PAYMENT_USE_FLAG VARCHAR2(1), -- Y if the account can receive foreign-currency payments.\n);\n\n-- Supplier addresses: physical and remit-to addresses of suppliers.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_ADDRESSES (\n ADDRESS_ID NUMBER, -- Unique address identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the address belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_NAME VARCHAR2(240), -- Name identifying the address.\n ADDRESS_LINE1 VARCHAR2(240), -- First address line.\n ADDRESS_LINE2 VARCHAR2(240), -- Second address line.\n CITY VARCHAR2(60), -- City.\n STATE VARCHAR2(60), -- State or province. Values: CA, NY, TX, WA, IL.\n POSTAL_CODE VARCHAR2(60), -- Postal or ZIP code.\n COUNTRY VARCHAR2(2), -- Country code.\n ADDRESS_PURPOSE VARCHAR2(30), -- What the address is used for. Values: REMIT_TO, PURCHASING, RFQ.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n LATITUDE NUMBER(12,6), -- Latitude of the address.\n LONGITUDE NUMBER(12,6), -- Longitude of the address.\n);\n\n-- Purchase order distributions: charge accounts and quantities of a schedule, including amount ordered, delivered and billed.\n-- (showing 14 of 19 columns: join keys + those relevant to the question)\nCREATE TABLE PO_DISTRIBUTIONS_ALL (\n PO_DISTRIBUTION_ID NUMBER, -- Unique distribution identifier. Primary key.\n PO_HEADER_ID NUMBER, -- Order the distribution belongs to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n PO_LINE_ID NUMBER, -- Line the distribution belongs to. FK to PO_LINES_ALL.PO_LINE_ID.\n LINE_LOCATION_ID NUMBER, -- Schedule the distribution belongs to. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n DISTRIBUTION_NUM NUMBER, -- Distribution number within the schedule.\n CODE_COMBINATION_ID NUMBER, -- Expense account charged. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n QUANTITY_ORDERED NUMBER, -- Quantity ordered on the distribution.\n QUANTITY_DELIVERED NUMBER, -- Quantity delivered.\n QUANTITY_BILLED NUMBER, -- Quantity billed.\n AMOUNT_ORDERED NUMBER(18,2), -- Amount ordered.\n AMOUNT_BILLED NUMBER(18,2), -- Amount billed so far.\n DESTINATION_TYPE_CODE VARCHAR2(25), -- Where the goods go. Values: EXPENSE, INVENTORY.\n REQUESTER_ID NUMBER, -- Employee who requested the goods. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n PROJECT_ID NUMBER, -- Project charged.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25), -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Purchase order schedules: delivery schedules of a line with need-by date, quantity received and billed, and the matching option (two-, three- or four-way).\n-- (showing 15 of 22 columns: join keys + those relevant to the question)\nCREATE TABLE PO_LINE_LOCATIONS_ALL (\n LINE_LOCATION_ID NUMBER, -- Unique schedule identifier. Primary key.\n PO_LINE_ID NUMBER, -- Line the schedule belongs to. FK to PO_LINES_ALL.PO_LINE_ID.\n SHIPMENT_NUM NUMBER, -- Schedule number within the line.\n QUANTITY NUMBER, -- Quantity scheduled.\n QUANTITY_RECEIVED NUMBER, -- Quantity received so far.\n QUANTITY_BILLED NUMBER, -- Quantity invoiced so far.\n QUANTITY_CANCELLED NUMBER, -- Quantity cancelled.\n NEED_BY_DATE DATE, -- Date the goods are needed.\n PROMISED_DATE DATE, -- Date the supplier promised delivery.\n PRICE_OVERRIDE NUMBER(18,2), -- Price for this schedule if different from the line.\n RECEIPT_REQUIRED_FLAG VARCHAR2(1), -- Y if receipt is required before payment.\n TAXABLE_FLAG VARCHAR2(1), -- Y if the schedule is taxable.\n SHIP_TO_LOCATION_ID NUMBER, -- Where the goods are delivered.\n CLOSED_CODE VARCHAR2(25), -- Closure state of the schedule. Values: OPEN, CLOSED FOR RECEIVING, CLOSED.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\n-- (showing 15 of 38 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n VENDOR_NAME VARCHAR2(360), -- Supplier name.\n SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\n VENDOR_TYPE_LOOKUP_CODE VARCHAR2(30), -- Supplier type. Values: VENDOR, CONTRACTOR, EMPLOYEE, TAX AUTHORITY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n SMALL_BUSINESS_FLAG VARCHAR2(1), -- Y if the supplier is a small business.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Default payment method for the supplier. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Default pay group. Values: DOMESTIC, INTERNATIONAL.\n TERMS_ID NUMBER, -- Default payment terms. FK to AP_TERMS_B.TERM_ID.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Default invoice currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Default payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if all payments to the supplier are blocked.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n FEDERAL_REPORTABLE_FLAG VARCHAR2(1), -- Y if the supplier is reportable for federal income tax.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2), -- Maximum credit extended to the supplier.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n\n"}, {"role": "user", "content": "Question: What is the total amount paid out for each supplier city for wire payments only?"}, {"role": "assistant", "content": "```sql\nSELECT a.CITY, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = c.VENDOR_ID\nWHERE c.PAYMENT_METHOD_CODE = 'WIRE'\nGROUP BY a.CITY\nORDER BY TOTAL_PAYMENT_AMOUNT DESC;\n```"}], "meta": {"id": "a-00725", "tier": "T2", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "408a02e93cb5", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 6, "approx_prompt_tokens": 2815, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n BATCH_ID NUMBER -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE, -- Date the payment was voided.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25) -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting payment currency to ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n CHECKRUN_ID NUMBER, -- Payment process request identifier.\n DOC_SEQUENCE_VALUE NUMBER -- Document sequence number of the payment.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n"}, {"role": "user", "content": "Question: Which 5 payment methods have the highest total paid against invoices for invoices over 10,000?"}, {"role": "assistant", "content": "```sql\nSELECT i.PAYMENT_METHOD_CODE, SUM(i.AMOUNT_PAID) AS TOTAL_AMOUNT_PAID\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_AMOUNT > 10000\nGROUP BY i.PAYMENT_METHOD_CODE\nORDER BY TOTAL_AMOUNT_PAID DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00109", "tier": "T1", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "9d74deac16c9", "tables": ["AP_INVOICES_ALL"], "result_rows": 3, "approx_prompt_tokens": 3111, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 15 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_ID NUMBER, -- Address of the site. FK to POZ_SUPPLIER_ADDRESSES.ADDRESS_ID.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Payment method for this site. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Default payment currency at this site. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n SHIP_TO_LOCATION_ID NUMBER, -- Default ship-to location for purchase orders.\n BILL_TO_LOCATION_ID NUMBER, -- Default bill-to location.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Supplier bank accounts: external bank accounts that payments are sent to, with account holder, currency and validity dates.\n-- (showing 10 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXT_BANK_ACCOUNTS (\n EXT_BANK_ACCOUNT_ID NUMBER, -- Unique external bank account identifier. Primary key.\n BANK_PARTY_ID NUMBER, -- Bank holding the account. FK to CE_BANKS.BANK_PARTY_ID.\n ACCOUNT_OWNER_PARTY_ID NUMBER, -- Party that owns the account. FK to HZ_PARTIES.PARTY_ID.\n BANK_ACCOUNT_NAME VARCHAR2(80), -- Account holder name.\n CURRENCY_CODE VARCHAR2(15), -- Currency of the account. FK to FND_CURRENCIES.CURRENCY_CODE.\n COUNTRY_CODE VARCHAR2(2), -- Country of the account.\n START_DATE DATE, -- Date the account becomes valid.\n END_DATE DATE, -- Date the account stops being valid.\n ACCOUNT_SUFFIX VARCHAR2(30), -- Account suffix used by some banks.\n FOREIGN_PAYMENT_USE_FLAG VARCHAR2(1), -- Y if the account can receive foreign-currency payments.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting payment currency to ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account the payment was drawn on. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n);\n\n-- Supplier addresses: physical and remit-to addresses of suppliers.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_ADDRESSES (\n ADDRESS_ID NUMBER, -- Unique address identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the address belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_NAME VARCHAR2(240), -- Name identifying the address.\n ADDRESS_LINE1 VARCHAR2(240), -- First address line.\n ADDRESS_LINE2 VARCHAR2(240), -- Second address line.\n CITY VARCHAR2(60), -- City.\n STATE VARCHAR2(60), -- State or province. Values: CA, NY, TX, WA, IL.\n POSTAL_CODE VARCHAR2(60), -- Postal or ZIP code.\n COUNTRY VARCHAR2(2), -- Country code.\n ADDRESS_PURPOSE VARCHAR2(30), -- What the address is used for. Values: REMIT_TO, PURCHASING, RFQ.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n LATITUDE NUMBER(12,6), -- Latitude of the address.\n LONGITUDE NUMBER(12,6), -- Longitude of the address.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\n-- (showing 15 of 38 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n VENDOR_NAME VARCHAR2(360), -- Supplier name.\n SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\n VENDOR_TYPE_LOOKUP_CODE VARCHAR2(30), -- Supplier type. Values: VENDOR, CONTRACTOR, EMPLOYEE, TAX AUTHORITY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n SMALL_BUSINESS_FLAG VARCHAR2(1), -- Y if the supplier is a small business.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Default payment method for the supplier. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Default pay group. Values: DOMESTIC, INTERNATIONAL.\n TERMS_ID NUMBER, -- Default payment terms. FK to AP_TERMS_B.TERM_ID.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Default invoice currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Default payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if all payments to the supplier are blocked.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2), -- Maximum credit extended to the supplier.\n CREATION_SOURCE VARCHAR2(30), -- Where the supplier record originated. Values: REGISTRATION, MANUAL, IMPORT.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n INT_BANK_ACCOUNT_ID NUMBER, -- Company bank account used. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXT_BANK_ACCOUNT_ID NUMBER, -- Payee bank account credited. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payees: the payment-engine record linking a supplier or site to its payment defaults (method, delivery channel, bank instructions).\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXTERNAL_PAYEES_ALL (\n EXT_PAYEE_ID NUMBER, -- Unique payee identifier. Primary key.\n PAYEE_PARTY_ID NUMBER, -- Party being paid. FK to HZ_PARTIES.PARTY_ID.\n SUPPLIER_SITE_ID NUMBER, -- Supplier site the payee record represents. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n PAYMENT_FUNCTION VARCHAR2(30), -- Payment function the payee is used for. Values: PAYABLES_DISB, EMPLOYEE_EXP.\n DEFAULT_PAYMENT_METHOD_CODE VARCHAR2(30), -- Default payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_FORMAT_CODE VARCHAR2(30), -- Format used for payment files. Values: NACHA, SEPA, POSITIVE PAY.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Default bank delivery channel. Values: ACH, CHAPS, SEPA.\n BANK_INSTRUCTION1_CODE VARCHAR2(30), -- First bank instruction code.\n REMIT_ADVICE_DELIVERY_METHOD VARCHAR2(30), -- How remittance advice is delivered. Values: EMAIL, PRINT.\n REMIT_ADVICE_EMAIL VARCHAR2(255), -- Email address remittance advice is sent to.\n INACTIVE_DATE DATE, -- Date the payee record stops being valid.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25), -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n-- supplier state / vendor state / by state => POZ_SUPPLIER_ADDRESSES.STATE (join on VENDOR_ID)\n"}, {"role": "user", "content": "Question: Top 5 supplier cities by biggest payment for payments over 10,000"}, {"role": "assistant", "content": "```sql\nSELECT a.CITY, MAX(c.AMOUNT) AS MAX_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = c.VENDOR_ID\nWHERE c.AMOUNT > 10000\nGROUP BY a.CITY\nORDER BY MAX_PAYMENT_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00441", "tier": "T2", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "1552ab7811f7", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 5, "approx_prompt_tokens": 2933, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n SOURCE VARCHAR2(80), -- How the invoice entered the system. Values: MANUAL, IMPORT, SUPPLIER PORTAL, EMAIL.\n PO_HEADER_ID NUMBER, -- Purchase order the invoice is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account the payment was drawn on. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n DOC_SEQUENCE_VALUE NUMBER -- Document sequence number of the payment.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Purchase order headers: one row per purchase order with supplier, buyer, status, total and terms.\n-- (showing 15 of 28 columns: join keys + those relevant to the question)\nCREATE TABLE PO_HEADERS_ALL (\n PO_HEADER_ID NUMBER, -- Unique purchase order identifier. Primary key.\n SEGMENT1 VARCHAR2(30), -- Purchase order number.\n TYPE_LOOKUP_CODE VARCHAR2(25), -- Order type. Values: STANDARD, BLANKET, CONTRACT.\n VENDOR_ID NUMBER, -- Supplier the order is placed with. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the order is placed with. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n AGENT_ID NUMBER, -- Buyer who created the order. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n CURRENCY_CODE VARCHAR2(15), -- Order currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n RATE NUMBER(12,6), -- Exchange rate on the order.\n TERMS_ID NUMBER, -- Payment terms on the order. FK to AP_TERMS_B.TERM_ID.\n DOCUMENT_STATUS VARCHAR2(25), -- Status of the order. Values: OPEN, CLOSED, CANCELLED, INCOMPLETE.\n APPROVED_FLAG VARCHAR2(1), -- Y if approved. Values: Y, N.\n TOTAL_AMOUNT NUMBER(18,2), -- Total order amount.\n NOTE_TO_VENDOR VARCHAR2(480), -- Note printed for the supplier.\n FREIGHT_TERMS_LOOKUP_CODE VARCHAR2(25), -- Who pays freight. Values: PAID, DUE.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25) -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 15 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_CODE VARCHAR2(15), -- Short site code.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Payment method for this site. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n TOLERANCE_ID NUMBER, -- Matching tolerance applied at the site.\n BILL_TO_LOCATION_ID NUMBER, -- Default bill-to location.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\n-- (showing 15 of 38 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n VENDOR_NAME VARCHAR2(360), -- Supplier name.\n SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\n VENDOR_TYPE_LOOKUP_CODE VARCHAR2(30), -- Supplier type. Values: VENDOR, CONTRACTOR, EMPLOYEE, TAX AUTHORITY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n SUMMARY_FLAG VARCHAR2(1), -- Y if the supplier is a summary (parent) record.\n ONE_TIME_FLAG VARCHAR2(1), -- Y if the supplier is a one-time supplier.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Default payment method for the supplier. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Default pay group. Values: DOMESTIC, INTERNATIONAL.\n TERMS_ID NUMBER, -- Default payment terms. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Default payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if all payments to the supplier are blocked.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n FEDERAL_REPORTABLE_FLAG VARCHAR2(1), -- Y if the supplier is reportable for federal income tax.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2) -- Maximum credit extended to the supplier.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- vendor spend / supplier spend => SUM(AP_INVOICES_ALL.INVOICE_AMOUNT) grouped by AP_INVOICES_ALL.VENDOR_ID (join POZ_SUPPLIERS for VENDOR_NAME)\n-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n"}, {"role": "user", "content": "Question: Show every supplier with a comma-separated list of the payment statuses of their payments\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT VENDOR_NAME, GROUP_CONCAT(STATUS_LOOKUP_CODE SEPARATOR ', ') AS VALUES_LIST\nFROM (\n SELECT DISTINCT s.VENDOR_NAME, c.STATUS_LOOKUP_CODE\n FROM AP_CHECKS_ALL c\n JOIN POZ_SUPPLIERS s ON s.VENDOR_ID = c.VENDOR_ID\n)\nGROUP BY VENDOR_NAME\nORDER BY VENDOR_NAME;\nError: Generated SQL failed to parse: Expecting ). Line 1, Col: 61.\nDiagnosis: That is not valid Oracle SQL. Write Oracle SQL, not MySQL or PostgreSQL: LISTAGG(col, ', ') WITHIN GROUP (ORDER BY col) instead of GROUP_CONCAT or STRING_AGG, FETCH FIRST n ROWS ONLY instead of LIMIT, NVL instead of IFNULL, SYSDATE instead of NOW(), and TRUNC/TO_CHAR for date parts.\nWrite a corrected query. It must differ from the failed one. Use ONLY the tables and columns in the schema above, spelled exactly as shown; if a column you wanted does not exist, choose the closest one that does."}, {"role": "assistant", "content": "```sql\nSELECT VENDOR_NAME, LISTAGG(STATUS_LOOKUP_CODE, ', ') WITHIN GROUP (ORDER BY STATUS_LOOKUP_CODE) AS VALUES_LIST\nFROM (\n SELECT DISTINCT s.VENDOR_NAME, c.STATUS_LOOKUP_CODE\n FROM AP_CHECKS_ALL c\n JOIN POZ_SUPPLIERS s ON s.VENDOR_ID = c.VENDOR_ID\n)\nGROUP BY VENDOR_NAME\nORDER BY VENDOR_NAME;\n```"}], "meta": {"id": "r-00060", "tier": "T3", "family": "t3-listagg", "kind": "repair-parse", "source": "S6-repair", "group": "0874243a92d7", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIERS"], "result_rows": 0, "approx_prompt_tokens": 3374, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "Generated SQL failed to parse: Expecting ). Line 1, Col: 61.", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n CURRENCY_CODE VARCHAR2(15), -- Currency the payment was made in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting payment currency to ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account the payment was drawn on. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n CHECKRUN_ID NUMBER, -- Payment process request identifier.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n ATTRIBUTE_CATEGORY VARCHAR2(30), -- Descriptive flexfield context (customer-defined extension fields).\n ATTRIBUTE1 VARCHAR2(150), -- Descriptive flexfield segment 1, customer-defined and normally unused.\n ATTRIBUTE2 VARCHAR2(150), -- Descriptive flexfield segment 2, customer-defined and normally unused.\n ATTRIBUTE3 VARCHAR2(150), -- Descriptive flexfield segment 3, customer-defined and normally unused.\n ATTRIBUTE4 VARCHAR2(150), -- Descriptive flexfield segment 4, customer-defined and normally unused.\n ATTRIBUTE5 VARCHAR2(150) -- Descriptive flexfield segment 5, customer-defined and normally unused.\n);\n\n-- Supplier addresses: physical and remit-to addresses of suppliers.\nCREATE TABLE POZ_SUPPLIER_ADDRESSES (\n ADDRESS_ID NUMBER, -- Unique address identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the address belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_NAME VARCHAR2(240), -- Name identifying the address.\n ADDRESS_LINE1 VARCHAR2(240), -- First address line.\n ADDRESS_LINE2 VARCHAR2(240), -- Second address line.\n CITY VARCHAR2(60), -- City.\n STATE VARCHAR2(60), -- State or province. Values: CA, NY, TX, WA, IL.\n POSTAL_CODE VARCHAR2(60), -- Postal or ZIP code.\n COUNTRY VARCHAR2(2), -- Country code.\n ADDRESS_PURPOSE VARCHAR2(30), -- What the address is used for. Values: REMIT_TO, PURCHASING, RFQ.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n LATITUDE NUMBER(12,6), -- Latitude of the address.\n LONGITUDE NUMBER(12,6), -- Longitude of the address.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 16 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_ID NUMBER, -- Address of the site. FK to POZ_SUPPLIER_ADDRESSES.ADDRESS_ID.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Payment method for this site. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Default payment currency at this site. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n INACTIVE_DATE DATE, -- Date the site becomes inactive.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n SHIP_TO_LOCATION_ID NUMBER, -- Default ship-to location for purchase orders.\n BILL_TO_LOCATION_ID NUMBER -- Default bill-to location.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n INT_BANK_ACCOUNT_ID NUMBER, -- Company bank account used. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXT_BANK_ACCOUNT_ID NUMBER, -- Payee bank account credited. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE, -- Date the payment was voided.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment history: status changes and accounting events for each payment (created, cleared, voided, reconciled).\n-- (showing 12 of 17 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_HISTORY_ALL (\n PAYMENT_HISTORY_ID NUMBER, -- Unique payment history identifier. Primary key.\n CHECK_ID NUMBER, -- Payment the history row describes. FK to AP_CHECKS_ALL.CHECK_ID.\n TRANSACTION_TYPE VARCHAR2(25), -- Kind of event recorded. Values: PAYMENT CREATED, PAYMENT CLEARING, PAYMENT UNCLEARING, PAYMENT CANCELLED.\n TRANSACTION_DATE DATE, -- Date of the event.\n ACCOUNTING_DATE DATE, -- Accounting date of the event.\n TRX_BANK_AMOUNT NUMBER(18,2), -- Amount at the bank for the event.\n TRX_PMT_AMOUNT NUMBER(18,2), -- Amount in payment currency for the event.\n HISTORICAL_FLAG VARCHAR2(1), -- Y if the row is superseded by a later event.\n POSTED_FLAG VARCHAR2(1), -- Y if the event was accounted.\n REV_PMT_HIST_ID NUMBER, -- Payment history row this event reverses.\n BANK_CURRENCY_CODE VARCHAR2(15), -- Currency of the bank statement line. FK to FND_CURRENCIES.CURRENCY_CODE.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Supplier bank accounts: external bank accounts that payments are sent to, with account holder, currency and validity dates.\n-- (showing 10 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXT_BANK_ACCOUNTS (\n EXT_BANK_ACCOUNT_ID NUMBER, -- Unique external bank account identifier. Primary key.\n BANK_PARTY_ID NUMBER, -- Bank holding the account. FK to CE_BANKS.BANK_PARTY_ID.\n ACCOUNT_OWNER_PARTY_ID NUMBER, -- Party that owns the account. FK to HZ_PARTIES.PARTY_ID.\n BANK_ACCOUNT_NAME VARCHAR2(80), -- Account holder name.\n CURRENCY_CODE VARCHAR2(15), -- Currency of the account. FK to FND_CURRENCIES.CURRENCY_CODE.\n COUNTRY_CODE VARCHAR2(2), -- Country of the account.\n START_DATE DATE, -- Date the account becomes valid.\n END_DATE DATE, -- Date the account stops being valid.\n ACCOUNT_SUFFIX VARCHAR2(30), -- Account suffix used by some banks.\n FOREIGN_PAYMENT_USE_FLAG VARCHAR2(1) -- Y if the account can receive foreign-currency payments.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- vendor spend / supplier spend => SUM(AP_INVOICES_ALL.INVOICE_AMOUNT) grouped by AP_INVOICES_ALL.VENDOR_ID (join POZ_SUPPLIERS for VENDOR_NAME)\n"}, {"role": "user", "content": "Question: Show the 5 supplier cities with the highest total payment amount over the last year\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT a.CITY, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = c.VENDOR_ID\nWHERE c.PAYMENT_DATE >= ADD_MONTHS(TRUNC(SYSDATE), -12)\nGROUP BY a.CITY\nORDER BY TOTAL_PAYMENT_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\nError: ORA-00904: \"C\".\"PAYMENT_DATE\": invalid identifier\nDiagnosis: C is AP_CHECKS_ALL, which has NO column named PAYMENT_DATE. Its columns are: CHECK_ID, CHECK_NUMBER, VENDOR_ID, VENDOR_SITE_ID, VENDOR_NAME, CHECK_DATE, AMOUNT, BASE_AMOUNT, CURRENCY_CODE, EXCHANGE_RATE, PAYMENT_METHOD_CODE, PAYMENT_TYPE_FLAG, STATUS_LOOKUP_CODE, BANK_ACCOUNT_ID, EXTERNAL_BANK_ACCOUNT_ID, PAYMENT_ID, CLEARED_DATE, CLEARED_AMOUNT, VOID_DATE, VOID_REASON, STOPPED_DATE, FUTURE_PAY_DUE_DATE, CHECKRUN_NAME, CHECKRUN_ID, DOC_SEQUENCE_VALUE, CREATION_DATE, CREATED_BY, LAST_UPDATE_DATE, LAST_UPDATED_BY, OBJECT_VERSION_NUMBER, ORG_ID, ATTRIBUTE_CATEGORY, ATTRIBUTE1, ATTRIBUTE2, ATTRIBUTE3, ATTRIBUTE4, ATTRIBUTE5. Closest names: PAYMENT_ID, PAYMENT_TYPE_FLAG, PAYMENT_METHOD_CODE.\nWrite a corrected query. It must differ from the failed one. Use ONLY the tables and columns in the schema above, spelled exactly as shown; if a column you wanted does not exist, choose the closest one that does."}, {"role": "assistant", "content": "```sql\nSELECT a.CITY, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = c.VENDOR_ID\nWHERE c.CHECK_DATE >= ADD_MONTHS(TRUNC(SYSDATE), -12)\nGROUP BY a.CITY\nORDER BY TOTAL_PAYMENT_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "r-00016", "tier": "T3", "family": "spec-pay", "kind": "repair-exec", "source": "S6-repair", "group": "d464a57ab45e", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 0, "approx_prompt_tokens": 3331, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"C\".\"PAYMENT_DATE\": invalid identifier", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 15 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_ID NUMBER, -- Address of the site. FK to POZ_SUPPLIER_ADDRESSES.ADDRESS_ID.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Payment method for this site. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Default payment currency at this site. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n SHIP_TO_LOCATION_ID NUMBER, -- Default ship-to location for purchase orders.\n BILL_TO_LOCATION_ID NUMBER -- Default bill-to location.\n);\n\n-- Supplier addresses: physical and remit-to addresses of suppliers.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_ADDRESSES (\n ADDRESS_ID NUMBER, -- Unique address identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the address belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_NAME VARCHAR2(240), -- Name identifying the address.\n ADDRESS_LINE1 VARCHAR2(240), -- First address line.\n ADDRESS_LINE2 VARCHAR2(240), -- Second address line.\n CITY VARCHAR2(60), -- City.\n STATE VARCHAR2(60), -- State or province. Values: CA, NY, TX, WA, IL.\n POSTAL_CODE VARCHAR2(60), -- Postal or ZIP code.\n COUNTRY VARCHAR2(2), -- Country code.\n ADDRESS_PURPOSE VARCHAR2(30), -- What the address is used for. Values: REMIT_TO, PURCHASING, RFQ.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n LATITUDE NUMBER(12,6), -- Latitude of the address.\n LONGITUDE NUMBER(12,6) -- Longitude of the address.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\n-- (showing 15 of 38 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n VENDOR_NAME VARCHAR2(360), -- Supplier name.\n SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\n VENDOR_TYPE_LOOKUP_CODE VARCHAR2(30), -- Supplier type. Values: VENDOR, CONTRACTOR, EMPLOYEE, TAX AUTHORITY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n SMALL_BUSINESS_FLAG VARCHAR2(1), -- Y if the supplier is a small business.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Default payment method for the supplier. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Default pay group. Values: DOMESTIC, INTERNATIONAL.\n TERMS_ID NUMBER, -- Default payment terms. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Default payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if all payments to the supplier are blocked.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n FEDERAL_REPORTABLE_FLAG VARCHAR2(1), -- Y if the supplier is reportable for federal income tax.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2), -- Maximum credit extended to the supplier.\n RISK_RATING VARCHAR2(25) -- Internal supplier risk rating. Values: LOW, MEDIUM, HIGH.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n CURRENCY_CODE VARCHAR2(15), -- Currency the payment was made in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting payment currency to ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n CHECKRUN_NAME VARCHAR2(255) -- Payment process request that created the payment.\n);\n\n-- Supplier bank accounts: external bank accounts that payments are sent to, with account holder, currency and validity dates.\n-- (showing 10 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXT_BANK_ACCOUNTS (\n EXT_BANK_ACCOUNT_ID NUMBER, -- Unique external bank account identifier. Primary key.\n BANK_PARTY_ID NUMBER, -- Bank holding the account. FK to CE_BANKS.BANK_PARTY_ID.\n ACCOUNT_OWNER_PARTY_ID NUMBER, -- Party that owns the account. FK to HZ_PARTIES.PARTY_ID.\n BANK_ACCOUNT_NAME VARCHAR2(80), -- Account holder name.\n CURRENCY_CODE VARCHAR2(15), -- Currency of the account. FK to FND_CURRENCIES.CURRENCY_CODE.\n COUNTRY_CODE VARCHAR2(2), -- Country of the account.\n START_DATE DATE, -- Date the account becomes valid.\n END_DATE DATE, -- Date the account stops being valid.\n ACCOUNT_SUFFIX VARCHAR2(30), -- Account suffix used by some banks.\n FOREIGN_PAYMENT_USE_FLAG VARCHAR2(1) -- Y if the account can receive foreign-currency payments.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n PARTY_ID NUMBER, -- Trading-community party of the supplier. FK to HZ_PARTIES.PARTY_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice will be paid in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n EXCHANGE_RATE_TYPE VARCHAR2(30), -- Type of exchange rate used. Values: Corporate, Spot, User.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n PO_HEADER_ID NUMBER -- Purchase order the invoice is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n EXT_BANK_ACCOUNT_ID NUMBER, -- Payee bank account credited. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Purchase order headers: one row per purchase order with supplier, buyer, status, total and terms.\n-- (showing 15 of 28 columns: join keys + those relevant to the question)\nCREATE TABLE PO_HEADERS_ALL (\n PO_HEADER_ID NUMBER, -- Unique purchase order identifier. Primary key.\n SEGMENT1 VARCHAR2(30), -- Purchase order number.\n TYPE_LOOKUP_CODE VARCHAR2(25), -- Order type. Values: STANDARD, BLANKET, CONTRACT.\n VENDOR_ID NUMBER, -- Supplier the order is placed with. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the order is placed with. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n AGENT_ID NUMBER, -- Buyer who created the order. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n CURRENCY_CODE VARCHAR2(15), -- Order currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n RATE NUMBER(12,6), -- Exchange rate on the order.\n TERMS_ID NUMBER, -- Payment terms on the order. FK to AP_TERMS_B.TERM_ID.\n TOTAL_AMOUNT NUMBER(18,2), -- Total order amount.\n NOTE_TO_VENDOR VARCHAR2(480), -- Note printed for the supplier.\n SHIP_TO_LOCATION_ID NUMBER, -- Ship-to location.\n BILL_TO_LOCATION_ID NUMBER, -- Bill-to location.\n FOB_LOOKUP_CODE VARCHAR2(25), -- Freight-on-board terms. Values: ORIGIN, DESTINATION.\n FREIGHT_TERMS_LOOKUP_CODE VARCHAR2(25) -- Who pays freight. Values: PAID, DUE.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- supplier state / vendor state / by state => POZ_SUPPLIER_ADDRESSES.STATE (join on VENDOR_ID)\n-- vendor spend / supplier spend => SUM(AP_INVOICES_ALL.INVOICE_AMOUNT) grouped by AP_INVOICES_ALL.VENDOR_ID (join POZ_SUPPLIERS for VENDOR_NAME)\n-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n"}, {"role": "user", "content": "Question: Top 5 supplier states by biggest payment"}, {"role": "assistant", "content": "```sql\nSELECT a.STATE, MAX(c.AMOUNT) AS MAX_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = c.VENDOR_ID\nGROUP BY a.STATE\nORDER BY MAX_PAYMENT_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00502", "tier": "T2", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "1a7950e34e0d", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 3, "approx_prompt_tokens": 3126, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 16 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n SELF_ASSESSED_TAX_AMOUNT NUMBER(18,2), -- Tax the buyer self-assesses instead of paying to the supplier.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account the payment was drawn on. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_NUMBER NUMBER, -- Sequence of the line within the invoice.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit billed.\n UNIT_MEAS_LOOKUP_CODE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\n PO_HEADER_ID NUMBER, -- Purchase order this line is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n ACCOUNTING_DATE DATE, -- Accounting date of the line.\n TAX_CLASSIFICATION_CODE VARCHAR2(30), -- Tax classification of the line. Values: STANDARD, REDUCED, EXEMPT.\n TAX_RATE NUMBER(12,6), -- Tax rate applied to the line.\n MATCH_TYPE VARCHAR2(25), -- How the line was matched. Values: ITEM_TO_PO, ITEM_TO_RECEIPT, NOT_MATCHED.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice batches: groups of invoices entered together, with control totals and entry status.\nCREATE TABLE AP_BATCHES_ALL (\n BATCH_ID NUMBER, -- Unique invoice batch identifier. Primary key.\n BATCH_NAME VARCHAR2(50), -- Name of the batch.\n BATCH_DATE DATE, -- Date the batch was created.\n INVOICE_COUNT NUMBER, -- Number of invoices entered in the batch.\n INVOICE_AMOUNT NUMBER(18,2), -- Total amount of the invoices in the batch.\n CONTROL_INVOICE_COUNT NUMBER, -- Expected invoice count entered as a control total.\n CONTROL_INVOICE_AMOUNT NUMBER(18,2), -- Expected batch amount entered as a control total.\n BATCH_STATUS VARCHAR2(25), -- Status of the batch. Values: OPEN, CLOSED, POSTED.\n SOURCE VARCHAR2(80), -- Source of the batch. Values: MANUAL, IMPORT, SUPPLIER PORTAL.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\n-- (showing 15 of 38 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\n VENDOR_TYPE_LOOKUP_CODE VARCHAR2(30), -- Supplier type. Values: VENDOR, CONTRACTOR, EMPLOYEE, TAX AUTHORITY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n START_DATE_ACTIVE DATE, -- Date the supplier becomes active.\n END_DATE_ACTIVE DATE, -- Date the supplier stops being active.\n SUMMARY_FLAG VARCHAR2(1), -- Y if the supplier is a summary (parent) record.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Default pay group. Values: DOMESTIC, INTERNATIONAL.\n TERMS_ID NUMBER, -- Default payment terms. FK to AP_TERMS_B.TERM_ID.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Default invoice currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if all payments to the supplier are blocked.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n FEDERAL_REPORTABLE_FLAG VARCHAR2(1), -- Y if the supplier is reportable for federal income tax.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2), -- Maximum credit extended to the supplier.\n CREATION_SOURCE VARCHAR2(30), -- Where the supplier record originated. Values: REGISTRATION, MANUAL, IMPORT.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- vendor spend / supplier spend => SUM(AP_INVOICES_ALL.INVOICE_AMOUNT) grouped by AP_INVOICES_ALL.VENDOR_ID (join POZ_SUPPLIERS for VENDOR_NAME)\n-- days to pay => AP_CHECKS_ALL.CHECK_DATE - AP_INVOICES_ALL.INVOICE_DATE (join AP_INVOICE_PAYMENTS_ALL on INVOICE_ID and CHECK_ID)\n"}, {"role": "user", "content": "Question: Total paid against invoices by supplier year to date"}, {"role": "assistant", "content": "```sql\nSELECT s.VENDOR_NAME, SUM(i.AMOUNT_PAID) AS TOTAL_AMOUNT_PAID\nFROM AP_INVOICES_ALL i\nJOIN POZ_SUPPLIERS s ON s.VENDOR_ID = i.VENDOR_ID\nWHERE i.INVOICE_DATE >= TRUNC(SYSDATE, 'YYYY')\nGROUP BY s.VENDOR_NAME\nORDER BY TOTAL_AMOUNT_PAID DESC;\n```"}], "meta": {"id": "a-00944", "tier": "T3", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "16f9add2938d", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 9, "approx_prompt_tokens": 3072, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n CURRENCY_CODE VARCHAR2(15), -- Currency the payment was made in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting payment currency to ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account the payment was drawn on. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n CHECKRUN_ID NUMBER, -- Payment process request identifier.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n ATTRIBUTE_CATEGORY VARCHAR2(30), -- Descriptive flexfield context (customer-defined extension fields).\n ATTRIBUTE1 VARCHAR2(150), -- Descriptive flexfield segment 1, customer-defined and normally unused.\n ATTRIBUTE2 VARCHAR2(150), -- Descriptive flexfield segment 2, customer-defined and normally unused.\n ATTRIBUTE3 VARCHAR2(150), -- Descriptive flexfield segment 3, customer-defined and normally unused.\n ATTRIBUTE4 VARCHAR2(150), -- Descriptive flexfield segment 4, customer-defined and normally unused.\n ATTRIBUTE5 VARCHAR2(150) -- Descriptive flexfield segment 5, customer-defined and normally unused.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n PARTY_ID NUMBER, -- Trading-community party behind the supplier. FK to HZ_PARTIES.PARTY_ID.\n VENDOR_NAME VARCHAR2(360), -- Supplier name.\n VENDOR_NAME_ALT VARCHAR2(320), -- Alternate or trading name of the supplier.\n SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\n VENDOR_TYPE_LOOKUP_CODE VARCHAR2(30), -- Supplier type. Values: VENDOR, CONTRACTOR, EMPLOYEE, TAX AUTHORITY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n START_DATE_ACTIVE DATE, -- Date the supplier becomes active.\n END_DATE_ACTIVE DATE, -- Date the supplier stops being active.\n SUMMARY_FLAG VARCHAR2(1), -- Y if the supplier is a summary (parent) record.\n ONE_TIME_FLAG VARCHAR2(1), -- Y if the supplier is a one-time supplier.\n SMALL_BUSINESS_FLAG VARCHAR2(1), -- Y if the supplier is a small business.\n WOMEN_OWNED_FLAG VARCHAR2(1), -- Y if the supplier is women-owned.\n MINORITY_GROUP_LOOKUP_CODE VARCHAR2(30), -- Minority ownership classification. Values: MBE, DBE.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Default payment method for the supplier. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Default pay group. Values: DOMESTIC, INTERNATIONAL.\n TERMS_ID NUMBER, -- Default payment terms. FK to AP_TERMS_B.TERM_ID.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Default invoice currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Default payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if all payments to the supplier are blocked.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n NUM_1099 VARCHAR2(30), -- US taxpayer identification number for 1099 reporting.\n TAX_REGISTRATION_NUMBER VARCHAR2(50), -- VAT or GST registration number.\n FEDERAL_REPORTABLE_FLAG VARCHAR2(1), -- Y if the supplier is reportable for federal income tax.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2), -- Maximum credit extended to the supplier.\n RISK_RATING VARCHAR2(25), -- Internal supplier risk rating. Values: LOW, MEDIUM, HIGH.\n CREATION_SOURCE VARCHAR2(30), -- Where the supplier record originated. Values: REGISTRATION, MANUAL, IMPORT.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ATTRIBUTE_CATEGORY VARCHAR2(30), -- Descriptive flexfield context (customer-defined extension fields).\n ATTRIBUTE1 VARCHAR2(150), -- Descriptive flexfield segment 1, customer-defined and normally unused.\n ATTRIBUTE2 VARCHAR2(150), -- Descriptive flexfield segment 2, customer-defined and normally unused.\n ATTRIBUTE3 VARCHAR2(150), -- Descriptive flexfield segment 3, customer-defined and normally unused.\n ATTRIBUTE4 VARCHAR2(150), -- Descriptive flexfield segment 4, customer-defined and normally unused.\n ATTRIBUTE5 VARCHAR2(150) -- Descriptive flexfield segment 5, customer-defined and normally unused.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n SOURCE VARCHAR2(80), -- How the invoice entered the system. Values: MANUAL, IMPORT, SUPPLIER PORTAL, EMAIL.\n PO_HEADER_ID NUMBER, -- Purchase order the invoice is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Purchase order headers: one row per purchase order with supplier, buyer, status, total and terms.\n-- (showing 15 of 28 columns: join keys + those relevant to the question)\nCREATE TABLE PO_HEADERS_ALL (\n PO_HEADER_ID NUMBER, -- Unique purchase order identifier. Primary key.\n SEGMENT1 VARCHAR2(30), -- Purchase order number.\n TYPE_LOOKUP_CODE VARCHAR2(25), -- Order type. Values: STANDARD, BLANKET, CONTRACT.\n VENDOR_ID NUMBER, -- Supplier the order is placed with. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the order is placed with. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n AGENT_ID NUMBER, -- Buyer who created the order. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n CURRENCY_CODE VARCHAR2(15), -- Order currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n RATE NUMBER(12,6), -- Exchange rate on the order.\n TERMS_ID NUMBER, -- Payment terms on the order. FK to AP_TERMS_B.TERM_ID.\n DOCUMENT_STATUS VARCHAR2(25), -- Status of the order. Values: OPEN, CLOSED, CANCELLED, INCOMPLETE.\n APPROVED_FLAG VARCHAR2(1), -- Y if approved. Values: Y, N.\n TOTAL_AMOUNT NUMBER(18,2), -- Total order amount.\n NOTE_TO_VENDOR VARCHAR2(480), -- Note printed for the supplier.\n FREIGHT_TERMS_LOOKUP_CODE VARCHAR2(25), -- Who pays freight. Values: PAID, DUE.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- vendor spend / supplier spend => SUM(AP_INVOICES_ALL.INVOICE_AMOUNT) grouped by AP_INVOICES_ALL.VENDOR_ID (join POZ_SUPPLIERS for VENDOR_NAME)\n-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n"}, {"role": "user", "content": "Question: Show every supplier with a comma-separated list of the payment statuses of their payments\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT SUPPLIER_NAME, LISTAGG(STATUS_LOOKUP_CODE, ', ') WITHIN GROUP (ORDER BY STATUS_LOOKUP_CODE) AS VALUES_LIST FROM (SELECT DISTINCT s.SUPPLIER_NAME, c.STATUS_LOOKUP_CODE FROM AP_CHECKS_ALL c JOIN POZ_SUPPLIERS s ON s.VENDOR_ID = c.VENDOR_ID) GROUP BY SUPPLIER_NAME ORDER BY SUPPLIER_NAME FETCH FIRST 200 ROWS ONLY;\nError: ORA-00904: \"S\".\"SUPPLIER_NAME\": invalid identifier\nDiagnosis: S is POZ_SUPPLIERS, which has NO column named SUPPLIER_NAME. Its columns are: VENDOR_ID, PARTY_ID, VENDOR_NAME, VENDOR_NAME_ALT, SEGMENT1, VENDOR_TYPE_LOOKUP_CODE, ENABLED_FLAG, START_DATE_ACTIVE, END_DATE_ACTIVE, SUMMARY_FLAG, ONE_TIME_FLAG, SMALL_BUSINESS_FLAG, WOMEN_OWNED_FLAG, MINORITY_GROUP_LOOKUP_CODE, PAYMENT_METHOD_LOOKUP_CODE, PAY_GROUP_LOOKUP_CODE, TERMS_ID, INVOICE_CURRENCY_CODE, PAYMENT_CURRENCY_CODE, HOLD_ALL_PAYMENTS_FLAG, HOLD_REASON, FEDERAL_REPORTABLE_FLAG, CREDIT_LIMIT_AMOUNT, RISK_RATING, CREATION_SOURCE, CREATION_DATE, CREATED_BY, LAST_UPDATE_DATE, LAST_UPDATED_BY, OBJECT_VERSION_NUMBER, ATTRIBUTE_CATEGORY, ATTRIBUTE1, ATTRIBUTE2, ATTRIBUTE3, ATTRIBUTE4, ATTRIBUTE5. Closest names: VENDOR_NAME, VENDOR_NAME_ALT.\nWrite a corrected query. It must differ from the failed one. Use ONLY the tables and columns in the schema above, spelled exactly as shown; if a column you wanted does not exist, choose the closest one that does."}, {"role": "assistant", "content": "```sql\nSELECT VENDOR_NAME, LISTAGG(STATUS_LOOKUP_CODE, ', ') WITHIN GROUP (ORDER BY STATUS_LOOKUP_CODE) AS VALUES_LIST\nFROM (\n SELECT DISTINCT s.VENDOR_NAME, c.STATUS_LOOKUP_CODE\n FROM AP_CHECKS_ALL c\n JOIN POZ_SUPPLIERS s ON s.VENDOR_ID = c.VENDOR_ID\n)\nGROUP BY VENDOR_NAME\nORDER BY VENDOR_NAME;\n```"}], "meta": {"id": "r-00018", "tier": "T3", "family": "t3-listagg", "kind": "repair-exec", "source": "S6-repair", "group": "0874243a92d7", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIERS"], "result_rows": 0, "approx_prompt_tokens": 3417, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"S\".\"SUPPLIER_NAME\": invalid identifier", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice holds: matching exceptions, duplicates and variances that block payment, with hold reason, date placed and release date. NULL RELEASE_DATE means the hold is still active.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_HOLDS_ALL (\n HOLD_ID NUMBER, -- Unique hold identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the hold is placed on. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_LOCATION_ID NUMBER, -- Purchase order schedule that caused the hold. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n HOLD_LOOKUP_CODE VARCHAR2(30), -- Hold reason. FK to AP_HOLD_CODES.HOLD_LOOKUP_CODE.\n HOLD_DATE DATE, -- Date the hold was placed.\n HELD_BY NUMBER, -- User who placed the hold. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n HOLD_REASON VARCHAR2(240), -- Explanation of why the hold was placed.\n RELEASE_LOOKUP_CODE VARCHAR2(30), -- Reason the hold was released. Values: VARIANCE ACCEPTED, CORRECTED, OVERRIDE.\n RELEASE_DATE DATE, -- Date the hold was released; NULL if still active.\n RELEASE_REASON VARCHAR2(240), -- Comments recorded when the hold was released.\n STATUS_FLAG VARCHAR2(1), -- Hold status: S system-placed, R released. Values: S, R.\n RESPONSIBILITY_ID NUMBER, -- Responsibility able to release the hold.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Hold and release reason codes: definitions of the hold types that can be placed on invoices.\nCREATE TABLE AP_HOLD_CODES (\n HOLD_LOOKUP_CODE VARCHAR2(30), -- Hold or release reason code. Values: MATCHING, DUPLICATE INVOICE, TAX VARIANCE, PRICE VARIANCE, QTY VARIANCE, MISSING RECEIPT, AMOUNT LIMIT, UNAPPROVED, CURRENCY MISMATCH, TERMS MISMATCH. Primary key.\n HOLD_TYPE VARCHAR2(25), -- Whether the code is a hold or a release reason. Values: HOLD, RELEASE.\n DESCRIPTION VARCHAR2(240), -- Meaning of the hold code.\n USER_RELEASEABLE_FLAG VARCHAR2(1), -- Y if users may release this hold manually.\n USER_ALLOWED_FLAG VARCHAR2(1), -- Y if users may place this hold manually.\n POSTABLE_FLAG VARCHAR2(1), -- Y if invoices with this hold can still be accounted.\n INACTIVE_DATE DATE, -- Date the code stops being valid.\n HOLD_INSTRUCTION VARCHAR2(240), -- Guidance to the analyst on resolving the hold.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment history: status changes and accounting events for each payment (created, cleared, voided, reconciled).\n-- (showing 12 of 17 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_HISTORY_ALL (\n PAYMENT_HISTORY_ID NUMBER, -- Unique payment history identifier. Primary key.\n CHECK_ID NUMBER, -- Payment the history row describes. FK to AP_CHECKS_ALL.CHECK_ID.\n TRANSACTION_TYPE VARCHAR2(25), -- Kind of event recorded. Values: PAYMENT CREATED, PAYMENT CLEARING, PAYMENT UNCLEARING, PAYMENT CANCELLED.\n TRANSACTION_DATE DATE, -- Date of the event.\n ACCOUNTING_DATE DATE, -- Accounting date of the event.\n TRX_BANK_AMOUNT NUMBER(18,2), -- Amount at the bank for the event.\n TRX_PMT_AMOUNT NUMBER(18,2), -- Amount in payment currency for the event.\n HISTORICAL_FLAG VARCHAR2(1), -- Y if the row is superseded by a later event.\n POSTED_FLAG VARCHAR2(1), -- Y if the event was accounted.\n REV_PMT_HIST_ID NUMBER, -- Payment history row this event reverses.\n BANK_CURRENCY_CODE VARCHAR2(15), -- Currency of the bank statement line. FK to FND_CURRENCIES.CURRENCY_CODE.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Subledger accounting entry lines: debit and credit lines of each accounting entry with account, amounts and the source transaction.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE XLA_AE_LINES (\n AE_LINE_ID NUMBER, -- Unique accounting line identifier. Primary key.\n AE_HEADER_ID NUMBER, -- Entry the line belongs to. FK to XLA_AE_HEADERS.AE_HEADER_ID.\n AE_LINE_NUM NUMBER, -- Line number within the entry.\n CODE_COMBINATION_ID NUMBER, -- Account of the line. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n ENTERED_DR NUMBER(18,2), -- Debit in entered currency.\n ENTERED_CR NUMBER(18,2), -- Credit in entered currency.\n ACCOUNTED_DR NUMBER(18,2), -- Debit in ledger currency.\n ACCOUNTED_CR NUMBER(18,2), -- Credit in ledger currency.\n CURRENCY_CODE VARCHAR2(15), -- Entered currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n CURRENCY_CONVERSION_RATE NUMBER(12,6), -- Rate used to convert to ledger currency.\n DESCRIPTION VARCHAR2(240), -- Line description.\n SOURCE_TABLE VARCHAR2(30), -- Source table of the transaction. Values: AP_INVOICES_ALL, AP_INVOICE_PAYMENTS_ALL.\n SOURCE_ID NUMBER, -- Identifier of the source transaction.\n PARTY_ID NUMBER, -- Supplier party of the line. FK to HZ_PARTIES.PARTY_ID.\n GL_SL_LINK_ID NUMBER, -- Link to the general-ledger journal line.\n);\n\n-- Journal entry lines: debit and credit amounts per account for each journal.\n-- (showing 14 of 19 columns: join keys + those relevant to the question)\nCREATE TABLE GL_JE_LINES (\n JE_LINE_ID NUMBER, -- Unique journal line identifier. Primary key.\n JE_HEADER_ID NUMBER, -- Journal the line belongs to. FK to GL_JE_HEADERS.JE_HEADER_ID.\n JE_LINE_NUM NUMBER, -- Line number within the journal.\n LEDGER_ID NUMBER, -- Ledger of the line. FK to GL_LEDGERS.LEDGER_ID.\n CODE_COMBINATION_ID NUMBER, -- Account the line posts to. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the line.\n EFFECTIVE_DATE DATE, -- Accounting date of the line.\n ENTERED_DR NUMBER(18,2), -- Debit in entered currency.\n ENTERED_CR NUMBER(18,2), -- Credit in entered currency.\n ACCOUNTED_DR NUMBER(18,2), -- Debit in ledger currency.\n ACCOUNTED_CR NUMBER(18,2), -- Credit in ledger currency.\n DESCRIPTION VARCHAR2(240), -- Line description.\n STATUS VARCHAR2(1), -- P posted, U unposted. Values: P, U.\n REFERENCE_1 VARCHAR2(240), -- Reference such as an invoice number.\n);\n\n-- Chart of accounts: every valid account code combination (company, cost center, natural account) with type and enabled flag. Joined from invoice distributions to name the expense account.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE GL_CODE_COMBINATIONS (\n CODE_COMBINATION_ID NUMBER, -- Unique account combination identifier. Primary key.\n CHART_OF_ACCOUNTS_ID NUMBER, -- Chart of accounts the combination belongs to.\n CONCATENATED_SEGMENTS VARCHAR2(240), -- Full account string, for example 01-520-7110-0000.\n SEGMENT1 VARCHAR2(25), -- Company segment.\n SEGMENT2 VARCHAR2(25), -- Cost center segment.\n SEGMENT3 VARCHAR2(25), -- Natural account segment.\n SEGMENT4 VARCHAR2(25), -- Sub-account segment.\n SEGMENT5 VARCHAR2(25), -- Product segment.\n SEGMENT6 VARCHAR2(25), -- Intercompany segment.\n ENABLED_FLAG VARCHAR2(1), -- Y if the combination can be used.\n SUMMARY_FLAG VARCHAR2(1), -- Y if the combination is a summary account.\n DETAIL_POSTING_ALLOWED_FLAG VARCHAR2(1), -- Y if posting is allowed to the account.\n START_DATE_ACTIVE DATE, -- Date the combination becomes active.\n END_DATE_ACTIVE DATE, -- Date the combination stops being active.\n LEDGER_ID NUMBER, -- Ledger the combination belongs to. FK to GL_LEDGERS.LEDGER_ID.\n);\n\n-- Ledgers: primary and secondary ledgers with currency, chart of accounts, calendar and period status.\n-- (showing 15 of 20 columns: join keys + those relevant to the question)\nCREATE TABLE GL_LEDGERS (\n LEDGER_ID NUMBER, -- Unique ledger identifier. Primary key.\n NAME VARCHAR2(30), -- Ledger name.\n SHORT_NAME VARCHAR2(20), -- Short ledger name.\n DESCRIPTION VARCHAR2(240), -- Ledger description.\n LEDGER_CATEGORY_CODE VARCHAR2(30), -- Whether the ledger is primary, secondary or reporting. Values: PRIMARY, SECONDARY.\n CURRENCY_CODE VARCHAR2(15), -- Functional (ledger) currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n CHART_OF_ACCOUNTS_ID NUMBER, -- Chart of accounts used by the ledger.\n PERIOD_SET_NAME VARCHAR2(15), -- Accounting calendar used by the ledger. Values: FISCAL MONTH, CALENDAR MONTH.\n ACCOUNTED_PERIOD_TYPE VARCHAR2(15), -- Period type of the calendar.\n ENABLE_BUDGETARY_CONTROL_FLAG VARCHAR2(1), -- Y if budgetary control is enabled.\n LATEST_OPENED_PERIOD_NAME VARCHAR2(15), -- Most recent period that was opened.\n FIRST_LEDGER_PERIOD_NAME VARCHAR2(15), -- First period defined for the ledger.\n RET_EARN_CODE_COMBINATION_ID NUMBER, -- Retained earnings account.\n CUM_TRANS_CODE_COMBINATION_ID NUMBER, -- Cumulative translation adjustment account.\n NET_INCOME_CODE_COMBINATION_ID NUMBER, -- Net income account.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- three-way match failure => AP_HOLDS_ALL.HOLD_LOOKUP_CODE IN ('QTY VARIANCE', 'PRICE VARIANCE', 'MISSING RECEIPT')\n-- on hold => AP_HOLDS_ALL.RELEASE_DATE IS NULL (active hold; the reason is AP_HOLDS_ALL.HOLD_LOOKUP_CODE)\n-- duplicate invoice => AP_HOLDS_ALL.HOLD_LOOKUP_CODE = 'DUPLICATE INVOICE'\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: Show the 2 most recent holds for each hold reason"}, {"role": "assistant", "content": "```sql\nSELECT HOLD_LOOKUP_CODE, INVOICE_ID, HOLD_DATE\nFROM (\n SELECT h.HOLD_LOOKUP_CODE, h.INVOICE_ID, h.HOLD_DATE,\n ROW_NUMBER() OVER (PARTITION BY h.HOLD_LOOKUP_CODE ORDER BY h.HOLD_DATE DESC) AS RN\n FROM AP_HOLDS_ALL h\n)\nWHERE RN <= 2\nORDER BY HOLD_LOOKUP_CODE, RN;\n```"}], "meta": {"id": "a-01418", "tier": "T4", "family": "t4-topk", "kind": "ask", "source": "S2-templated", "group": "b24a296263d6", "tables": ["AP_HOLDS_ALL"], "result_rows": 15, "approx_prompt_tokens": 2951, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n WFAPPROVAL_STATUS VARCHAR2(25), -- Approval workflow status of the invoice. Values: APPROVED, NOT REQUIRED, REJECTED, INITIATED.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number assigned to the invoice.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice batches: groups of invoices entered together, with control totals and entry status.\nCREATE TABLE AP_BATCHES_ALL (\n BATCH_ID NUMBER, -- Unique invoice batch identifier. Primary key.\n BATCH_NAME VARCHAR2(50), -- Name of the batch.\n BATCH_DATE DATE, -- Date the batch was created.\n INVOICE_COUNT NUMBER, -- Number of invoices entered in the batch.\n INVOICE_AMOUNT NUMBER(18,2), -- Total amount of the invoices in the batch.\n CONTROL_INVOICE_COUNT NUMBER, -- Expected invoice count entered as a control total.\n CONTROL_INVOICE_AMOUNT NUMBER(18,2), -- Expected batch amount entered as a control total.\n BATCH_STATUS VARCHAR2(25), -- Status of the batch. Values: OPEN, CLOSED, POSTED.\n SOURCE VARCHAR2(80), -- Source of the batch. Values: MANUAL, IMPORT, SUPPLIER PORTAL.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n CHECKRUN_ID NUMBER, -- Payment process request identifier.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n-- days to pay => AP_CHECKS_ALL.CHECK_DATE - AP_INVOICES_ALL.INVOICE_DATE (join AP_INVOICE_PAYMENTS_ALL on INVOICE_ID and CHECK_ID)\n"}, {"role": "user", "content": "Question: Count the approved invoices"}, {"role": "assistant", "content": "```sql\nSELECT COUNT(*)\nFROM AP_INVOICES_ALL i\nWHERE i.WFAPPROVAL_STATUS = 'APPROVED';\n```"}], "meta": {"id": "a-01704", "tier": "T5", "family": "t5-glossary", "kind": "ask", "source": "S2-templated", "group": "8c750a2a764c", "tables": ["AP_INVOICES_ALL"], "result_rows": 1, "approx_prompt_tokens": 2781, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting payment currency to ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25), -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE, -- Date the payment was voided.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 17 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- early payment discount => AP_PAYMENT_SCHEDULES_ALL.DISCOUNT_AMOUNT_AVAILABLE > 0\n"}, {"role": "user", "content": "Question: Give me the average payment this month."}, {"role": "assistant", "content": "```sql\nSELECT AVG(c.AMOUNT) AS AVG_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nWHERE c.CHECK_DATE >= TRUNC(SYSDATE, 'MM');\n```"}], "meta": {"id": "a-00873", "tier": "T3", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "265d7248ece1", "tables": ["AP_CHECKS_ALL"], "result_rows": 1, "approx_prompt_tokens": 2867, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n PARTY_ID NUMBER, -- Trading-community party of the supplier. FK to HZ_PARTIES.PARTY_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n SELF_ASSESSED_TAX_AMOUNT NUMBER(18,2), -- Tax the buyer self-assesses instead of paying to the supplier.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice is denominated in. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency the invoice will be paid in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting invoice currency to ledger currency.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n EXCHANGE_RATE_TYPE VARCHAR2(30), -- Type of exchange rate used. Values: Corporate, Spot, User.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n SOURCE VARCHAR2(80), -- How the invoice entered the system. Values: MANUAL, IMPORT, SUPPLIER PORTAL, EMAIL.\n PO_HEADER_ID NUMBER, -- Purchase order the invoice is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n VALIDATION_STATUS VARCHAR2(25), -- Result of invoice validation. Values: VALIDATED, NEEDS REVALIDATION, NEVER VALIDATED.\n WFAPPROVAL_STATUS VARCHAR2(25), -- Approval workflow status of the invoice. Values: APPROVED, NOT REQUIRED, REJECTED, INITIATED.\n CANCELLED_DATE DATE, -- Date the invoice was cancelled; NULL if not cancelled.\n CANCELLED_BY VARCHAR2(64), -- User who cancelled the invoice.\n ACCTS_PAY_CODE_COMBINATION_ID NUMBER, -- Liability (accounts payable) account for the invoice. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n LEDGER_ID NUMBER, -- Ledger the invoice is accounted in. FK to GL_LEDGERS.LEDGER_ID.\n REQUESTER_ID NUMBER, -- Employee who requested the goods or services. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n LEGAL_ENTITY_ID NUMBER, -- Legal entity the invoice belongs to.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number assigned to the invoice.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n ATTRIBUTE_CATEGORY VARCHAR2(30), -- Descriptive flexfield context (customer-defined extension fields).\n ATTRIBUTE1 VARCHAR2(150), -- Descriptive flexfield segment 1, customer-defined and normally unused.\n ATTRIBUTE2 VARCHAR2(150), -- Descriptive flexfield segment 2, customer-defined and normally unused.\n ATTRIBUTE3 VARCHAR2(150), -- Descriptive flexfield segment 3, customer-defined and normally unused.\n ATTRIBUTE4 VARCHAR2(150), -- Descriptive flexfield segment 4, customer-defined and normally unused.\n ATTRIBUTE5 VARCHAR2(150), -- Descriptive flexfield segment 5, customer-defined and normally unused.\n ATTRIBUTE6 VARCHAR2(150), -- Descriptive flexfield segment 6, customer-defined and normally unused.\n ATTRIBUTE7 VARCHAR2(150), -- Descriptive flexfield segment 7, customer-defined and normally unused.\n ATTRIBUTE8 VARCHAR2(150), -- Descriptive flexfield segment 8, customer-defined and normally unused.\n ATTRIBUTE9 VARCHAR2(150), -- Descriptive flexfield segment 9, customer-defined and normally unused.\n ATTRIBUTE10 VARCHAR2(150), -- Descriptive flexfield segment 10, customer-defined and normally unused.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n);\n\n-- Invoice holds: matching exceptions, duplicates and variances that block payment, with hold reason, date placed and release date. NULL RELEASE_DATE means the hold is still active.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_HOLDS_ALL (\n HOLD_ID NUMBER, -- Unique hold identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the hold is placed on. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_LOCATION_ID NUMBER, -- Purchase order schedule that caused the hold. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n HOLD_LOOKUP_CODE VARCHAR2(30), -- Hold reason. FK to AP_HOLD_CODES.HOLD_LOOKUP_CODE.\n HOLD_DATE DATE, -- Date the hold was placed.\n HELD_BY NUMBER, -- User who placed the hold. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n HOLD_REASON VARCHAR2(240), -- Explanation of why the hold was placed.\n RELEASE_LOOKUP_CODE VARCHAR2(30), -- Reason the hold was released. Values: VARIANCE ACCEPTED, CORRECTED, OVERRIDE.\n RELEASE_DATE DATE, -- Date the hold was released; NULL if still active.\n RELEASE_REASON VARCHAR2(240), -- Comments recorded when the hold was released.\n STATUS_FLAG VARCHAR2(1), -- Hold status: S system-placed, R released. Values: S, R.\n RESPONSIBILITY_ID NUMBER, -- Responsibility able to release the hold.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice distributions: how each invoice line amount is split across general-ledger expense accounts, with accounting status. Use for spend-by-GL-account questions.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_DISTRIBUTIONS_ALL (\n INVOICE_DISTRIBUTION_ID NUMBER, -- Unique invoice distribution identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the distribution belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n INVOICE_LINE_ID NUMBER, -- Invoice line the distribution splits. FK to AP_INVOICE_LINES_ALL.INVOICE_LINE_ID.\n DISTRIBUTION_LINE_NUMBER NUMBER, -- Sequence of the distribution within the invoice.\n AMOUNT NUMBER(18,2), -- Distribution amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Distribution amount in ledger currency.\n ACCOUNTING_DATE DATE, -- Accounting date of the distribution.\n PERIOD_NAME VARCHAR2(15), -- Accounting period the distribution falls in.\n POSTED_FLAG VARCHAR2(1), -- Y if accounted and posted to the ledger, N if not yet accounted. Values: Y, N.\n ACCRUAL_POSTED_FLAG VARCHAR2(1), -- Y if accrual accounting entries were created.\n QUANTITY_INVOICED NUMBER, -- Quantity billed for the distribution.\n REVERSAL_FLAG VARCHAR2(1), -- Y if this distribution reverses another.\n TASK_ID NUMBER, -- Project task charged.\n INCOME_TAX_REGION VARCHAR2(10), -- Region used for income-tax reporting.\n DESCRIPTION VARCHAR2(240), -- Distribution description.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- unvalidated invoice => AP_INVOICES_ALL.VALIDATION_STATUS <> 'VALIDATED'\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- cancelled invoice => AP_INVOICES_ALL.CANCELLED_DATE IS NOT NULL\n-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\n"}, {"role": "user", "content": "Question: How many unvalidated invoices were entered in the last 90 days?\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT COUNT(*) FROM AP_INVOICES_ALL i WHERE i.VALIDATION_STATUS <> 'VALIDATED' AND i.INVOICE_DATE >= TRUNC(NOW(), 'DD') - 90 FETCH FIRST 200 ROWS ONLY;\nError: ORA-00904: \"NOW\": invalid identifier\nDiagnosis: No table in your query has a column named NOW. The columns are — AP_INVOICES_ALL: INVOICE_ID, VENDOR_ID, VENDOR_SITE_ID, PARTY_ID, INVOICE_NUM, INVOICE_TYPE_LOOKUP_CODE, INVOICE_DATE, INVOICE_RECEIVED_DATE, GOODS_RECEIVED_DATE, GL_DATE, INVOICE_AMOUNT, AMOUNT_PAID, TOTAL_TAX_AMOUNT, BASE_AMOUNT, APPROVED_AMOUNT, AMOUNT_APPLICABLE_TO_DISCOUNT, DISCOUNT_AMOUNT_TAKEN, PREPAY_AMOUNT_REMAINING, SELF_ASSESSED_TAX_AMOUNT, INVOICE_CURRENCY_CODE, PAYMENT_CURRENCY_CODE, EXCHANGE_RATE, EXCHANGE_DATE, EXCHANGE_RATE_TYPE, TERMS_ID, TERMS_DATE, PAYMENT_METHOD_CODE, PAY_GROUP_LOOKUP_CODE, PAYMENT_STATUS_FLAG, DESCRIPTION, SOURCE, PO_HEADER_ID, BATCH_ID, VALIDATION_STATUS, WFAPPROVAL_STATUS, CANCELLED_DATE, CANCELLED_BY, ACCTS_PAY_CODE_COMBINATION_ID, LEDGER_ID, REQUESTER_ID, LEGAL_ENTITY_ID, DOC_SEQUENCE_VALUE, CREATION_DATE, CREATED_BY, LAST_UPDATE_DATE, LAST_UPDATED_BY, OBJECT_VERSION_NUMBER, ORG_ID, ATTRIBUTE_CATEGORY, ATTRIBUTE1, ATTRIBUTE2, ATTRIBUTE3, ATTRIBUTE4, ATTRIBUTE5, ATTRIBUTE6, ATTRIBUTE7, ATTRIBUTE8, ATTRIBUTE9, ATTRIBUTE10.\nWrite a corrected query. It must differ from the failed one. Use ONLY the tables and columns in the schema above, spelled exactly as shown; if a column you wanted does not exist, choose the closest one that does."}, {"role": "assistant", "content": "```sql\nSELECT COUNT(*)\nFROM AP_INVOICES_ALL i\nWHERE i.VALIDATION_STATUS <> 'VALIDATED'\nAND i.INVOICE_DATE >= TRUNC(SYSDATE) - 90;\n```"}], "meta": {"id": "r-00082", "tier": "T5", "family": "t5-glossary", "kind": "repair-exec", "source": "S6-repair", "group": "111491c0ac77", "tables": ["AP_INVOICES_ALL"], "result_rows": 0, "approx_prompt_tokens": 3531, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"NOW\": invalid identifier", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 15 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n VALIDATION_STATUS VARCHAR2(25), -- Result of invoice validation. Values: VALIDATED, NEEDS REVALIDATION, NEVER VALIDATED.\n CANCELLED_DATE DATE, -- Date the invoice was cancelled; NULL if not cancelled.\n);\n\n-- Invoice holds: matching exceptions, duplicates and variances that block payment, with hold reason, date placed and release date. NULL RELEASE_DATE means the hold is still active.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_HOLDS_ALL (\n HOLD_ID NUMBER, -- Unique hold identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the hold is placed on. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_LOCATION_ID NUMBER, -- Purchase order schedule that caused the hold. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n HOLD_LOOKUP_CODE VARCHAR2(30), -- Hold reason. FK to AP_HOLD_CODES.HOLD_LOOKUP_CODE.\n HOLD_DATE DATE, -- Date the hold was placed.\n HELD_BY NUMBER, -- User who placed the hold. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n HOLD_REASON VARCHAR2(240), -- Explanation of why the hold was placed.\n RELEASE_LOOKUP_CODE VARCHAR2(30), -- Reason the hold was released. Values: VARIANCE ACCEPTED, CORRECTED, OVERRIDE.\n RELEASE_DATE DATE, -- Date the hold was released; NULL if still active.\n RELEASE_REASON VARCHAR2(240), -- Comments recorded when the hold was released.\n STATUS_FLAG VARCHAR2(1), -- Hold status: S system-placed, R released. Values: S, R.\n RESPONSIBILITY_ID NUMBER, -- Responsibility able to release the hold.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_NUMBER NUMBER, -- Sequence of the line within the invoice.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit billed.\n UNIT_MEAS_LOOKUP_CODE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\n PO_LINE_LOCATION_ID NUMBER, -- Purchase order schedule this line is matched to. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n ACCOUNTING_DATE DATE, -- Accounting date of the line.\n TAX_RATE NUMBER(12,6), -- Tax rate applied to the line.\n CANCELLED_FLAG VARCHAR2(1), -- Y if the line was cancelled.\n MATCH_TYPE VARCHAR2(25), -- How the line was matched. Values: ITEM_TO_PO, ITEM_TO_RECEIPT, NOT_MATCHED.\n PREPAY_INVOICE_ID NUMBER, -- Prepayment invoice applied on this line, if any.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Invoice batches: groups of invoices entered together, with control totals and entry status.\nCREATE TABLE AP_BATCHES_ALL (\n BATCH_ID NUMBER, -- Unique invoice batch identifier. Primary key.\n BATCH_NAME VARCHAR2(50), -- Name of the batch.\n BATCH_DATE DATE, -- Date the batch was created.\n INVOICE_COUNT NUMBER, -- Number of invoices entered in the batch.\n INVOICE_AMOUNT NUMBER(18,2), -- Total amount of the invoices in the batch.\n CONTROL_INVOICE_COUNT NUMBER, -- Expected invoice count entered as a control total.\n CONTROL_INVOICE_AMOUNT NUMBER(18,2), -- Expected batch amount entered as a control total.\n BATCH_STATUS VARCHAR2(25), -- Status of the batch. Values: OPEN, CLOSED, POSTED.\n SOURCE VARCHAR2(80), -- Source of the batch. Values: MANUAL, IMPORT, SUPPLIER PORTAL.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Purchase order schedules: delivery schedules of a line with need-by date, quantity received and billed, and the matching option (two-, three- or four-way).\n-- (showing 15 of 22 columns: join keys + those relevant to the question)\nCREATE TABLE PO_LINE_LOCATIONS_ALL (\n LINE_LOCATION_ID NUMBER, -- Unique schedule identifier. Primary key.\n PO_HEADER_ID NUMBER, -- Order the schedule belongs to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n SHIPMENT_NUM NUMBER, -- Schedule number within the line.\n QUANTITY NUMBER, -- Quantity scheduled.\n QUANTITY_RECEIVED NUMBER, -- Quantity received so far.\n QUANTITY_BILLED NUMBER, -- Quantity invoiced so far.\n QUANTITY_CANCELLED NUMBER, -- Quantity cancelled.\n NEED_BY_DATE DATE, -- Date the goods are needed.\n PROMISED_DATE DATE, -- Date the supplier promised delivery.\n PRICE_OVERRIDE NUMBER(18,2), -- Price for this schedule if different from the line.\n INVOICE_MATCH_OPTION VARCHAR2(1), -- P match to order (two-way), R match to receipt (three-way). Values: R, P.\n RECEIPT_REQUIRED_FLAG VARCHAR2(1), -- Y if receipt is required before payment.\n TAXABLE_FLAG VARCHAR2(1), -- Y if the schedule is taxable.\n SHIP_TO_LOCATION_ID NUMBER, -- Where the goods are delivered.\n CLOSED_CODE VARCHAR2(25), -- Closure state of the schedule. Values: OPEN, CLOSED FOR RECEIVING, CLOSED.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- cancelled invoice => AP_INVOICES_ALL.CANCELLED_DATE IS NOT NULL\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: What is the latest invoice date on any invoice?"}, {"role": "assistant", "content": "```sql\nSELECT MAX(INVOICE_DATE)\nFROM AP_INVOICES_ALL;\n```"}], "meta": {"id": "a-00004", "tier": "T1", "family": "t1-date", "kind": "ask", "source": "S2-templated", "group": "3a30e522fb4d", "tables": ["AP_INVOICES_ALL"], "result_rows": 1, "approx_prompt_tokens": 2694, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 17 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that issued the invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Invoice type: STANDARD, CREDIT (credit memo), PREPAYMENT or DEBIT. Values: STANDARD, CREDIT, PREPAYMENT, DEBIT.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n SOURCE VARCHAR2(80), -- How the invoice entered the system. Values: MANUAL, IMPORT, SUPPLIER PORTAL, EMAIL.\n BATCH_ID NUMBER, -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n REQUESTER_ID NUMBER, -- Employee who requested the goods or services. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n);\n\n-- Invoices selected for a payment run: the payment process request's shortlist with proposed amount and pay-through date.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE AP_SELECTED_INVOICES_ALL (\n SELECTED_INVOICE_ID NUMBER, -- Unique selected-invoice identifier. Primary key.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request name.\n INVOICE_ID NUMBER, -- Invoice selected for payment. FK to AP_INVOICES_ALL.INVOICE_ID.\n VENDOR_ID NUMBER, -- Supplier of the selected invoice. FK to POZ_SUPPLIERS.VENDOR_ID.\n PAYMENT_NUM NUMBER, -- Installment selected.\n PAYMENT_AMOUNT NUMBER(18,2), -- Proposed payment amount.\n DISCOUNT_AMOUNT NUMBER(18,2), -- Discount to be taken if paid.\n PAY_THRU_DATE DATE, -- Latest due date included in the run.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Method the payment will use. Values: CHECK, EFT, WIRE.\n OK_TO_PAY_FLAG VARCHAR2(1), -- Y if the invoice passed selection checks.\n DONT_PAY_REASON_CODE VARCHAR2(25), -- Reason the invoice was excluded from payment. Values: ON HOLD, BANK DETAILS MISSING, CREDIT BALANCE.\n PROPOSED_PAYMENT_DATE DATE, -- Date the payment is planned for.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Invoice lines: item, tax, freight and miscellaneous charge lines of an invoice, with quantity, unit price, PO match and tax classification.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_LINES_ALL (\n INVOICE_LINE_ID NUMBER, -- Unique invoice line identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the line belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n LINE_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\n DESCRIPTION VARCHAR2(240), -- Description of the goods or service on the line.\n AMOUNT NUMBER(18,2), -- Line amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Line amount in ledger currency.\n QUANTITY_INVOICED NUMBER, -- Quantity billed on the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit billed.\n PO_HEADER_ID NUMBER, -- Purchase order this line is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n PO_LINE_ID NUMBER, -- Purchase order line this line is matched to. FK to PO_LINES_ALL.PO_LINE_ID.\n PO_LINE_LOCATION_ID NUMBER, -- Purchase order schedule this line is matched to. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n ACCOUNTING_DATE DATE, -- Accounting date of the line.\n PRODUCT_CATEGORY VARCHAR2(80), -- Category of the product or service. Values: IT EQUIPMENT, OFFICE SUPPLIES, PROFESSIONAL SERVICES, LOGISTICS.\n REQUESTER_ID NUMBER, -- Employee who requested the line item. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n MATCH_TYPE VARCHAR2(25), -- How the line was matched. Values: ITEM_TO_PO, ITEM_TO_RECEIPT, NOT_MATCHED.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Supplier contacts: people at a supplier with role, phone and email.\n-- (showing 12 of 17 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_CONTACTS (\n CONTACT_ID NUMBER, -- Unique contact identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the contact works for. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Site the contact is associated with. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n FIRST_NAME VARCHAR2(150), -- Contact first name.\n LAST_NAME VARCHAR2(150), -- Contact last name.\n JOB_TITLE VARCHAR2(100), -- Contact job title. Values: ACCOUNTS RECEIVABLE, SALES MANAGER, CFO, CREDIT CONTROLLER.\n EMAIL_ADDRESS VARCHAR2(320), -- Contact email address.\n PHONE_NUMBER VARCHAR2(40), -- Contact phone number.\n PRIMARY_FLAG VARCHAR2(1), -- Y if this is the primary contact.\n INACTIVE_DATE DATE, -- Date the contact is no longer active.\n DEPARTMENT VARCHAR2(80), -- Contact department. Values: FINANCE, SALES, OPERATIONS.\n PREFERRED_CONTACT_METHOD VARCHAR2(25), -- How the contact prefers to be reached. Values: EMAIL, PHONE.\n);\n\n-- Invoice import staging: invoices loaded from external sources awaiting import, with import status and rejection reason.\nCREATE TABLE AP_INVOICES_INTERFACE (\n INVOICE_INTERFACE_ID NUMBER, -- Unique interface row identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Invoice number from the source system.\n VENDOR_NUM VARCHAR2(30), -- Supplier number from the source system.\n INVOICE_AMOUNT NUMBER(18,2), -- Invoice total from the source system.\n INVOICE_DATE DATE, -- Invoice date from the source system.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Currency from the source system. FK to FND_CURRENCIES.CURRENCY_CODE.\n SOURCE VARCHAR2(80), -- Source system that supplied the row. Values: SUPPLIER PORTAL, EDI, EMAIL, OCR.\n STATUS VARCHAR2(25), -- Import status. Values: PROCESSED, REJECTED, PENDING.\n REJECT_REASON VARCHAR2(240), -- Why the row was rejected during import.\n GROUP_ID VARCHAR2(80), -- Load group identifier.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\n-- (showing 15 of 38 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n VENDOR_NAME VARCHAR2(360), -- Supplier name.\n SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\n VENDOR_TYPE_LOOKUP_CODE VARCHAR2(30), -- Supplier type. Values: VENDOR, CONTRACTOR, EMPLOYEE, TAX AUTHORITY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n START_DATE_ACTIVE DATE, -- Date the supplier becomes active.\n END_DATE_ACTIVE DATE, -- Date the supplier stops being active.\n SUMMARY_FLAG VARCHAR2(1), -- Y if the supplier is a summary (parent) record.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Default payment method for the supplier. Values: CHECK, EFT, WIRE.\n TERMS_ID NUMBER, -- Default payment terms. FK to AP_TERMS_B.TERM_ID.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if all payments to the supplier are blocked.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2), -- Maximum credit extended to the supplier.\n RISK_RATING VARCHAR2(25), -- Internal supplier risk rating. Values: LOW, MEDIUM, HIGH.\n CREATION_SOURCE VARCHAR2(30), -- Where the supplier record originated. Values: REGISTRATION, MANUAL, IMPORT.\n);\n\n-- Invoice batches: groups of invoices entered together, with control totals and entry status.\nCREATE TABLE AP_BATCHES_ALL (\n BATCH_ID NUMBER, -- Unique invoice batch identifier. Primary key.\n BATCH_NAME VARCHAR2(50), -- Name of the batch.\n BATCH_DATE DATE, -- Date the batch was created.\n INVOICE_COUNT NUMBER, -- Number of invoices entered in the batch.\n INVOICE_AMOUNT NUMBER(18,2), -- Total amount of the invoices in the batch.\n CONTROL_INVOICE_COUNT NUMBER, -- Expected invoice count entered as a control total.\n CONTROL_INVOICE_AMOUNT NUMBER(18,2), -- Expected batch amount entered as a control total.\n BATCH_STATUS VARCHAR2(25), -- Status of the batch. Values: OPEN, CLOSED, POSTED.\n SOURCE VARCHAR2(80), -- Source of the batch. Values: MANUAL, IMPORT, SUPPLIER PORTAL.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- vendor spend / supplier spend => SUM(AP_INVOICES_ALL.INVOICE_AMOUNT) grouped by AP_INVOICES_ALL.VENDOR_ID (join POZ_SUPPLIERS for VENDOR_NAME)\n-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: For every supplier, list the top 2 most recent invoices"}, {"role": "assistant", "content": "```sql\nSELECT VENDOR_NAME, INVOICE_NUM, INVOICE_DATE, INVOICE_AMOUNT\nFROM (\n SELECT s.VENDOR_NAME, i.INVOICE_NUM, i.INVOICE_DATE, i.INVOICE_AMOUNT,\n ROW_NUMBER() OVER (PARTITION BY s.VENDOR_NAME ORDER BY i.INVOICE_DATE DESC) AS RN\n FROM AP_INVOICES_ALL i\n JOIN POZ_SUPPLIERS s ON s.VENDOR_ID = i.VENDOR_ID\n)\nWHERE RN <= 2\nORDER BY VENDOR_NAME, RN;\n```"}], "meta": {"id": "a-01334", "tier": "T4", "family": "t4-topk", "kind": "ask", "source": "S2-templated", "group": "775cf7fd3991", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 18, "approx_prompt_tokens": 3084, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n CURRENCY_CODE VARCHAR2(15), -- Currency the payment was made in. FK to FND_CURRENCIES.CURRENCY_CODE.\n EXCHANGE_RATE NUMBER(12,6), -- Rate converting payment currency to ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account the payment was drawn on. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n CHECKRUN_ID NUMBER, -- Payment process request identifier.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n ATTRIBUTE_CATEGORY VARCHAR2(30), -- Descriptive flexfield context (customer-defined extension fields).\n ATTRIBUTE1 VARCHAR2(150), -- Descriptive flexfield segment 1, customer-defined and normally unused.\n ATTRIBUTE2 VARCHAR2(150), -- Descriptive flexfield segment 2, customer-defined and normally unused.\n ATTRIBUTE3 VARCHAR2(150), -- Descriptive flexfield segment 3, customer-defined and normally unused.\n ATTRIBUTE4 VARCHAR2(150), -- Descriptive flexfield segment 4, customer-defined and normally unused.\n ATTRIBUTE5 VARCHAR2(150), -- Descriptive flexfield segment 5, customer-defined and normally unused.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n PARTY_ID NUMBER, -- Trading-community party behind the supplier. FK to HZ_PARTIES.PARTY_ID.\n VENDOR_NAME VARCHAR2(360), -- Supplier name.\n VENDOR_NAME_ALT VARCHAR2(320), -- Alternate or trading name of the supplier.\n SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\n VENDOR_TYPE_LOOKUP_CODE VARCHAR2(30), -- Supplier type. Values: VENDOR, CONTRACTOR, EMPLOYEE, TAX AUTHORITY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n START_DATE_ACTIVE DATE, -- Date the supplier becomes active.\n END_DATE_ACTIVE DATE, -- Date the supplier stops being active.\n SUMMARY_FLAG VARCHAR2(1), -- Y if the supplier is a summary (parent) record.\n ONE_TIME_FLAG VARCHAR2(1), -- Y if the supplier is a one-time supplier.\n SMALL_BUSINESS_FLAG VARCHAR2(1), -- Y if the supplier is a small business.\n WOMEN_OWNED_FLAG VARCHAR2(1), -- Y if the supplier is women-owned.\n MINORITY_GROUP_LOOKUP_CODE VARCHAR2(30), -- Minority ownership classification. Values: MBE, DBE.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Default payment method for the supplier. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Default pay group. Values: DOMESTIC, INTERNATIONAL.\n TERMS_ID NUMBER, -- Default payment terms. FK to AP_TERMS_B.TERM_ID.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Default invoice currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Default payment currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if all payments to the supplier are blocked.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n NUM_1099 VARCHAR2(30), -- US taxpayer identification number for 1099 reporting.\n TAX_REGISTRATION_NUMBER VARCHAR2(50), -- VAT or GST registration number.\n FEDERAL_REPORTABLE_FLAG VARCHAR2(1), -- Y if the supplier is reportable for federal income tax.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2), -- Maximum credit extended to the supplier.\n RISK_RATING VARCHAR2(25), -- Internal supplier risk rating. Values: LOW, MEDIUM, HIGH.\n CREATION_SOURCE VARCHAR2(30), -- Where the supplier record originated. Values: REGISTRATION, MANUAL, IMPORT.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ATTRIBUTE_CATEGORY VARCHAR2(30), -- Descriptive flexfield context (customer-defined extension fields).\n ATTRIBUTE1 VARCHAR2(150), -- Descriptive flexfield segment 1, customer-defined and normally unused.\n ATTRIBUTE2 VARCHAR2(150), -- Descriptive flexfield segment 2, customer-defined and normally unused.\n ATTRIBUTE3 VARCHAR2(150), -- Descriptive flexfield segment 3, customer-defined and normally unused.\n ATTRIBUTE4 VARCHAR2(150), -- Descriptive flexfield segment 4, customer-defined and normally unused.\n ATTRIBUTE5 VARCHAR2(150), -- Descriptive flexfield segment 5, customer-defined and normally unused.\n);\n\n-- Supplier bank accounts: external bank accounts that payments are sent to, with account holder, currency and validity dates.\n-- (showing 10 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXT_BANK_ACCOUNTS (\n EXT_BANK_ACCOUNT_ID NUMBER, -- Unique external bank account identifier. Primary key.\n BANK_PARTY_ID NUMBER, -- Bank holding the account. FK to CE_BANKS.BANK_PARTY_ID.\n ACCOUNT_OWNER_PARTY_ID NUMBER, -- Party that owns the account. FK to HZ_PARTIES.PARTY_ID.\n BANK_ACCOUNT_NAME VARCHAR2(80), -- Account holder name.\n CURRENCY_CODE VARCHAR2(15), -- Currency of the account. FK to FND_CURRENCIES.CURRENCY_CODE.\n COUNTRY_CODE VARCHAR2(2), -- Country of the account.\n START_DATE DATE, -- Date the account becomes valid.\n END_DATE DATE, -- Date the account stops being valid.\n ACCOUNT_SUFFIX VARCHAR2(30), -- Account suffix used by some banks.\n FOREIGN_PAYMENT_USE_FLAG VARCHAR2(1), -- Y if the account can receive foreign-currency payments.\n);\n\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 15 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_CODE VARCHAR2(15), -- Short site code.\n ADDRESS_ID NUMBER, -- Address of the site. FK to POZ_SUPPLIER_ADDRESSES.ADDRESS_ID.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Payment method for this site. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n TOLERANCE_ID NUMBER, -- Matching tolerance applied at the site.\n BILL_TO_LOCATION_ID NUMBER, -- Default bill-to location.\n);\n\n-- Supplier contacts: people at a supplier with role, phone and email.\n-- (showing 12 of 17 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_CONTACTS (\n CONTACT_ID NUMBER, -- Unique contact identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the contact works for. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Site the contact is associated with. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n FIRST_NAME VARCHAR2(150), -- Contact first name.\n LAST_NAME VARCHAR2(150), -- Contact last name.\n JOB_TITLE VARCHAR2(100), -- Contact job title. Values: ACCOUNTS RECEIVABLE, SALES MANAGER, CFO, CREDIT CONTROLLER.\n EMAIL_ADDRESS VARCHAR2(320), -- Contact email address.\n PHONE_NUMBER VARCHAR2(40), -- Contact phone number.\n PRIMARY_FLAG VARCHAR2(1), -- Y if this is the primary contact.\n INACTIVE_DATE DATE, -- Date the contact is no longer active.\n DEPARTMENT VARCHAR2(80), -- Contact department. Values: FINANCE, SALES, OPERATIONS.\n PREFERRED_CONTACT_METHOD VARCHAR2(25), -- How the contact prefers to be reached. Values: EMAIL, PHONE.\n);\n\n-- Supplier addresses: physical and remit-to addresses of suppliers.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_ADDRESSES (\n ADDRESS_ID NUMBER, -- Unique address identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the address belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_NAME VARCHAR2(240), -- Name identifying the address.\n ADDRESS_LINE1 VARCHAR2(240), -- First address line.\n ADDRESS_LINE2 VARCHAR2(240), -- Second address line.\n CITY VARCHAR2(60), -- City.\n STATE VARCHAR2(60), -- State or province. Values: CA, NY, TX, WA, IL.\n POSTAL_CODE VARCHAR2(60), -- Postal or ZIP code.\n COUNTRY VARCHAR2(2), -- Country code.\n ADDRESS_PURPOSE VARCHAR2(30), -- What the address is used for. Values: REMIT_TO, PURCHASING, RFQ.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n LATITUDE NUMBER(12,6), -- Latitude of the address.\n LONGITUDE NUMBER(12,6), -- Longitude of the address.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n\n"}, {"role": "user", "content": "Question: Suppliers whose total payments is below average\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT s.VENDOR_NAME, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT FROM AP_CHECKS_ALL c JOIN POZ_SUPPLIERS s ON s.VENDOR_ID = c.VENDOR_ID HAVING SUM(c.AMOUNT) < (SELECT AVG(t.TOTAL_PAYMENT_AMOUNT) FROM (SELECT s.VENDOR_NAME, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT FROM AP_CHECKS_ALL c JOIN POZ_SUPPLIERS s ON s.VENDOR_ID = c.VENDOR_ID GROUP BY s.VENDOR_NAME) t) ORDER BY TOTAL_PAYMENT_AMOUNT DESC FETCH FIRST 200 ROWS ONLY;\nError: ORA-00937: not a single-group group function\nWrite a corrected query. It must differ from the failed one. Use ONLY the tables and columns in the schema above, spelled exactly as shown; if a column you wanted does not exist, choose the closest one that does."}, {"role": "assistant", "content": "```sql\nSELECT s.VENDOR_NAME, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nJOIN POZ_SUPPLIERS s ON s.VENDOR_ID = c.VENDOR_ID\nGROUP BY s.VENDOR_NAME\nHAVING SUM(c.AMOUNT) < (\n SELECT AVG(t.TOTAL_PAYMENT_AMOUNT)\n FROM (\n SELECT s.VENDOR_NAME, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT\n FROM AP_CHECKS_ALL c\n JOIN POZ_SUPPLIERS s ON s.VENDOR_ID = c.VENDOR_ID\n GROUP BY s.VENDOR_NAME\n ) t\n)\nORDER BY TOTAL_PAYMENT_AMOUNT DESC;\n```"}], "meta": {"id": "r-00046", "tier": "T4", "family": "t4-average", "kind": "repair-exec", "source": "S6-repair", "group": "77683da129a4", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIERS"], "result_rows": 0, "approx_prompt_tokens": 3222, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00937: not a single-group group function", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier that was paid. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site paid. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n VENDOR_NAME VARCHAR2(240), -- Name of the supplier at the time of payment.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n CURRENCY_CODE VARCHAR2(15), -- Currency the payment was made in. FK to FND_CURRENCIES.CURRENCY_CODE.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n);\n\n-- Supplier bank accounts: external bank accounts that payments are sent to, with account holder, currency and validity dates.\n-- (showing 10 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_EXT_BANK_ACCOUNTS (\n EXT_BANK_ACCOUNT_ID NUMBER, -- Unique external bank account identifier. Primary key.\n BANK_PARTY_ID NUMBER, -- Bank holding the account. FK to CE_BANKS.BANK_PARTY_ID.\n ACCOUNT_OWNER_PARTY_ID NUMBER, -- Party that owns the account. FK to HZ_PARTIES.PARTY_ID.\n BANK_ACCOUNT_NAME VARCHAR2(80), -- Account holder name.\n CURRENCY_CODE VARCHAR2(15), -- Currency of the account. FK to FND_CURRENCIES.CURRENCY_CODE.\n COUNTRY_CODE VARCHAR2(2), -- Country of the account.\n START_DATE DATE, -- Date the account becomes valid.\n END_DATE DATE, -- Date the account stops being valid.\n ACCOUNT_SUFFIX VARCHAR2(30), -- Account suffix used by some banks.\n FOREIGN_PAYMENT_USE_FLAG VARCHAR2(1), -- Y if the account can receive foreign-currency payments.\n);\n\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 15 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_CODE VARCHAR2(15), -- Short site code.\n ADDRESS_ID NUMBER, -- Address of the site. FK to POZ_SUPPLIER_ADDRESSES.ADDRESS_ID.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n TERMS_ID NUMBER, -- Payment terms for invoices at this site. FK to AP_TERMS_B.TERM_ID.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Payment method for this site. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n TOLERANCE_ID NUMBER, -- Matching tolerance applied at the site.\n BILL_TO_LOCATION_ID NUMBER, -- Default bill-to location.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\n-- (showing 15 of 38 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n VENDOR_NAME VARCHAR2(360), -- Supplier name.\n VENDOR_NAME_ALT VARCHAR2(320), -- Alternate or trading name of the supplier.\n SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\n VENDOR_TYPE_LOOKUP_CODE VARCHAR2(30), -- Supplier type. Values: VENDOR, CONTRACTOR, EMPLOYEE, TAX AUTHORITY.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n SUMMARY_FLAG VARCHAR2(1), -- Y if the supplier is a summary (parent) record.\n SMALL_BUSINESS_FLAG VARCHAR2(1), -- Y if the supplier is a small business.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Default payment method for the supplier. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Default pay group. Values: DOMESTIC, INTERNATIONAL.\n TERMS_ID NUMBER, -- Default payment terms. FK to AP_TERMS_B.TERM_ID.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if all payments to the supplier are blocked.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2), -- Maximum credit extended to the supplier.\n RISK_RATING VARCHAR2(25), -- Internal supplier risk rating. Values: LOW, MEDIUM, HIGH.\n);\n\n-- Supplier contacts: people at a supplier with role, phone and email.\n-- (showing 12 of 17 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_CONTACTS (\n CONTACT_ID NUMBER, -- Unique contact identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the contact works for. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Site the contact is associated with. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n FIRST_NAME VARCHAR2(150), -- Contact first name.\n LAST_NAME VARCHAR2(150), -- Contact last name.\n JOB_TITLE VARCHAR2(100), -- Contact job title. Values: ACCOUNTS RECEIVABLE, SALES MANAGER, CFO, CREDIT CONTROLLER.\n EMAIL_ADDRESS VARCHAR2(320), -- Contact email address.\n PHONE_NUMBER VARCHAR2(40), -- Contact phone number.\n PRIMARY_FLAG VARCHAR2(1), -- Y if this is the primary contact.\n INACTIVE_DATE DATE, -- Date the contact is no longer active.\n DEPARTMENT VARCHAR2(80), -- Contact department. Values: FINANCE, SALES, OPERATIONS.\n PREFERRED_CONTACT_METHOD VARCHAR2(25), -- How the contact prefers to be reached. Values: EMAIL, PHONE.\n);\n\n-- Supplier addresses: physical and remit-to addresses of suppliers.\n-- (showing 13 of 18 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_ADDRESSES (\n ADDRESS_ID NUMBER, -- Unique address identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the address belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n ADDRESS_NAME VARCHAR2(240), -- Name identifying the address.\n ADDRESS_LINE1 VARCHAR2(240), -- First address line.\n ADDRESS_LINE2 VARCHAR2(240), -- Second address line.\n CITY VARCHAR2(60), -- City.\n STATE VARCHAR2(60), -- State or province. Values: CA, NY, TX, WA, IL.\n POSTAL_CODE VARCHAR2(60), -- Postal or ZIP code.\n COUNTRY VARCHAR2(2), -- Country code.\n ADDRESS_PURPOSE VARCHAR2(30), -- What the address is used for. Values: REMIT_TO, PURCHASING, RFQ.\n STATUS VARCHAR2(1), -- A active, I inactive. Values: A, I.\n LATITUDE NUMBER(12,6), -- Latitude of the address.\n LONGITUDE NUMBER(12,6), -- Longitude of the address.\n);\n\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n EXT_BANK_ACCOUNT_ID NUMBER, -- Payee bank account credited. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_REASON_CODE VARCHAR2(30), -- Regulatory reason code for the payment. Values: GOODS, SERVICES, UTILITIES.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE, -- Date the payment was voided.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n\n"}, {"role": "user", "content": "Question: Suppliers whose total payments is below average"}, {"role": "assistant", "content": "```sql\nSELECT s.VENDOR_NAME, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nJOIN POZ_SUPPLIERS s ON s.VENDOR_ID = c.VENDOR_ID\nGROUP BY s.VENDOR_NAME\nHAVING SUM(c.AMOUNT) < (\n SELECT AVG(t.TOTAL_PAYMENT_AMOUNT)\n FROM (\n SELECT s.VENDOR_NAME, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT\n FROM AP_CHECKS_ALL c\n JOIN POZ_SUPPLIERS s ON s.VENDOR_ID = c.VENDOR_ID\n GROUP BY s.VENDOR_NAME\n ) t\n)\nORDER BY TOTAL_PAYMENT_AMOUNT DESC;\n```"}], "meta": {"id": "a-01349", "tier": "T4", "family": "t4-average", "kind": "ask", "source": "S2-templated", "group": "77683da129a4", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIERS"], "result_rows": 6, "approx_prompt_tokens": 2471, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAYMENTS_ALL (\n PAYMENT_ID NUMBER, -- Unique payment identifier in the payments engine. Primary key.\n PAYMENT_INSTRUCTION_ID NUMBER, -- Instruction the payment was sent in. FK to IBY_PAY_INSTRUCTIONS_ALL.PAYMENT_INSTRUCTION_ID.\n PAYEE_ID NUMBER, -- Supplier payee that receives the payment. FK to IBY_EXTERNAL_PAYEES_ALL.EXT_PAYEE_ID.\n PAYMENT_REFERENCE_NUMBER NUMBER, -- Reference number of the payment.\n PAYMENT_AMOUNT NUMBER(18,2), -- Payment amount.\n PAYMENT_DATE DATE, -- Date the payment is made.\n PAYMENT_STATUS VARCHAR2(30), -- Status of the payment. Values: ISSUED, PAID, FAILED, VOID.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Payment method. Values: CHECK, EFT, WIRE.\n PAYMENT_PROCESS_REQUEST_NAME VARCHAR2(255), -- Name of the process request.\n PAYEE_NAME VARCHAR2(240), -- Name of the payee.\n EXT_BANK_ACCOUNT_ID NUMBER, -- Payee bank account credited. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE, -- Date the payment was voided.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the installment is paid to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n);\n\n-- Payment history: status changes and accounting events for each payment (created, cleared, voided, reconciled).\n-- (showing 12 of 17 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_HISTORY_ALL (\n PAYMENT_HISTORY_ID NUMBER, -- Unique payment history identifier. Primary key.\n CHECK_ID NUMBER, -- Payment the history row describes. FK to AP_CHECKS_ALL.CHECK_ID.\n TRANSACTION_TYPE VARCHAR2(25), -- Kind of event recorded. Values: PAYMENT CREATED, PAYMENT CLEARING, PAYMENT UNCLEARING, PAYMENT CANCELLED.\n TRANSACTION_DATE DATE, -- Date of the event.\n ACCOUNTING_DATE DATE, -- Accounting date of the event.\n TRX_BANK_AMOUNT NUMBER(18,2), -- Amount at the bank for the event.\n TRX_PMT_AMOUNT NUMBER(18,2), -- Amount in payment currency for the event.\n HISTORICAL_FLAG VARCHAR2(1), -- Y if the row is superseded by a later event.\n POSTED_FLAG VARCHAR2(1), -- Y if the event was accounted.\n REV_PMT_HIST_ID NUMBER, -- Payment history row this event reverses.\n BANK_CURRENCY_CODE VARCHAR2(15), -- Currency of the bank statement line. FK to FND_CURRENCIES.CURRENCY_CODE.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\n EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\n PAYMENT_ID NUMBER, -- Payment record in the payments engine. FK to IBY_PAYMENTS_ALL.PAYMENT_ID.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\n);\n\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment instructions: files or batches of payments sent to the bank for processing, with totals and transmission status.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE IBY_PAY_INSTRUCTIONS_ALL (\n PAYMENT_INSTRUCTION_ID NUMBER, -- Unique payment instruction identifier. Primary key.\n PAYMENT_INSTRUCTION_STATUS VARCHAR2(30), -- Processing status of the instruction. Values: CREATED, FORMATTED, TRANSMITTED, TERMINATED.\n PAYMENT_PROFILE_ID NUMBER, -- Payment process profile that formatted the file.\n PAYMENT_COUNT NUMBER, -- Number of payments in the instruction.\n PAYMENT_AMOUNT NUMBER(18,2), -- Total amount of the instruction.\n PAYMENT_CURRENCY_CODE VARCHAR2(15), -- Currency of the instruction. FK to FND_CURRENCIES.CURRENCY_CODE.\n CREATION_ON DATE, -- Date the instruction was created.\n TRANSMITTED_DATE DATE, -- Date the file was transmitted to the bank.\n BANK_ACCOUNT_ID NUMBER, -- Company bank account debited. FK to CE_BANK_ACCOUNTS.BANK_ACCOUNT_ID.\n FILE_REFERENCE VARCHAR2(80), -- Bank file reference number.\n ACKNOWLEDGEMENT_STATUS VARCHAR2(25), -- Whether the bank acknowledged the file. Values: ACKNOWLEDGED, PENDING, REJECTED.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 19 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n AMOUNT_APPLICABLE_TO_DISCOUNT NUMBER(18,2), -- Portion of the invoice eligible for early-payment discount.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- Preferred payment method for the invoice. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group used to select invoices into the same payment run. Values: DOMESTIC, INTERNATIONAL, EMPLOYEE.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n-- days to pay => AP_CHECKS_ALL.CHECK_DATE - AP_INVOICES_ALL.INVOICE_DATE (join AP_INVOICE_PAYMENTS_ALL on INVOICE_ID and CHECK_ID)\n"}, {"role": "user", "content": "Question: Which 5 payment statuses have the highest total amount paid out last year?"}, {"role": "assistant", "content": "```sql\nSELECT c.STATUS_LOOKUP_CODE, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nWHERE c.CHECK_DATE >= ADD_MONTHS(TRUNC(SYSDATE, 'YYYY'), -12) AND c.CHECK_DATE < TRUNC(SYSDATE, 'YYYY')\nGROUP BY c.STATUS_LOOKUP_CODE\nORDER BY TOTAL_PAYMENT_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-01131", "tier": "T3", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "32248545a763", "tables": ["AP_CHECKS_ALL"], "result_rows": 3, "approx_prompt_tokens": 2936, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Links invoices to the payments that paid them: one row per invoice installment paid by a payment, with amount, discount taken and accounting status. A payment can cover many invoices.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_PAYMENTS_ALL (\n INVOICE_PAYMENT_ID NUMBER, -- Unique invoice payment identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice that was paid. FK to AP_INVOICES_ALL.INVOICE_ID.\n CHECK_ID NUMBER, -- Payment that paid the invoice. FK to AP_CHECKS_ALL.CHECK_ID.\n PAYMENT_NUM NUMBER, -- Installment number that was paid.\n AMOUNT NUMBER(18,2), -- Amount of the payment applied to the invoice.\n PAYMENT_BASE_AMOUNT NUMBER(18,2), -- Applied amount in ledger currency.\n DISCOUNT_TAKEN NUMBER(18,2), -- Early-payment discount taken on this payment.\n DISCOUNT_LOST NUMBER(18,2), -- Early-payment discount forfeited.\n ACCOUNTING_DATE DATE, -- Accounting date of the payment application.\n PERIOD_NAME VARCHAR2(15), -- Accounting period of the payment.\n POSTED_FLAG VARCHAR2(1), -- Y if the payment was accounted.\n REVERSAL_FLAG VARCHAR2(1), -- Y if the payment application was reversed.\n INVOICE_PAYMENT_TYPE VARCHAR2(25), -- Kind of payment application. Values: PAYMENT, PREPAYMENT, REFUND.\n EXCHANGE_RATE NUMBER(12,6), -- Rate used for the payment application.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment terms: net days, discount percentages and installment rules that determine invoice due dates.\nCREATE TABLE AP_TERMS_B (\n TERM_ID NUMBER, -- Unique payment terms identifier. Primary key.\n NAME VARCHAR2(50), -- Payment terms name, for example NET30 or 2/10 NET 30. Values: NET15, NET30, NET45, NET60, NET90, 2-10 NET30, IMMEDIATE, EOM, NET20.\n DESCRIPTION VARCHAR2(240), -- Meaning of the payment terms.\n ENABLED_FLAG VARCHAR2(1), -- Y if the terms can be used.\n START_DATE_ACTIVE DATE, -- First date the terms can be used.\n END_DATE_ACTIVE DATE, -- Last date the terms can be used.\n DUE_DAYS NUMBER, -- Days after the terms date that payment is due.\n DISCOUNT_PERCENT NUMBER(12,6), -- Early-payment discount percentage.\n DISCOUNT_DAYS NUMBER, -- Days within which the discount applies.\n CUTOFF_DAY NUMBER, -- Day of month after which due dates roll to the next month.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Invoice distributions: how each invoice line amount is split across general-ledger expense accounts, with accounting status. Use for spend-by-GL-account questions.\n-- (showing 15 of 42 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICE_DISTRIBUTIONS_ALL (\n INVOICE_DISTRIBUTION_ID NUMBER, -- Unique invoice distribution identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the distribution belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n INVOICE_LINE_ID NUMBER, -- Invoice line the distribution splits. FK to AP_INVOICE_LINES_ALL.INVOICE_LINE_ID.\n AMOUNT NUMBER(18,2), -- Distribution amount in invoice currency.\n BASE_AMOUNT NUMBER(18,2), -- Distribution amount in ledger currency.\n ACCOUNTING_DATE DATE, -- Accounting date of the distribution.\n PERIOD_NAME VARCHAR2(15), -- Accounting period the distribution falls in.\n POSTED_FLAG VARCHAR2(1), -- Y if accounted and posted to the ledger, N if not yet accounted. Values: Y, N.\n ACCRUAL_POSTED_FLAG VARCHAR2(1), -- Y if accrual accounting entries were created.\n QUANTITY_INVOICED NUMBER, -- Quantity billed for the distribution.\n UNIT_PRICE NUMBER(18,2), -- Unit price on the distribution.\n PO_DISTRIBUTION_ID NUMBER, -- Purchase order distribution matched to. FK to PO_DISTRIBUTIONS_ALL.PO_DISTRIBUTION_ID.\n TASK_ID NUMBER, -- Project task charged.\n INCOME_TAX_REGION VARCHAR2(10), -- Region used for income-tax reporting.\n DESCRIPTION VARCHAR2(240) -- Distribution description.\n);\n\n-- Invoice headers: one row per supplier invoice, credit memo, prepayment or debit memo, with amounts, currency, payment terms, approval and validation status. The central AP transaction table.\n-- (showing 18 of 59 columns: join keys + those relevant to the question)\nCREATE TABLE AP_INVOICES_ALL (\n INVOICE_ID NUMBER, -- Unique invoice identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\n INVOICE_DATE DATE, -- Date printed on the supplier invoice.\n INVOICE_RECEIVED_DATE DATE, -- Date the invoice was received by the company.\n GOODS_RECEIVED_DATE DATE, -- Date the goods or services were received.\n GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\n INVOICE_AMOUNT NUMBER(18,2), -- Total invoice amount in invoice currency; negative for credit memos.\n AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\n TOTAL_TAX_AMOUNT NUMBER(18,2), -- Total tax charged on the invoice.\n BASE_AMOUNT NUMBER(18,2), -- Invoice amount converted to the ledger currency.\n APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\n DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\n PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\n EXCHANGE_DATE DATE, -- Date the exchange rate applies to.\n TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n TERMS_DATE DATE, -- Date from which payment terms are counted.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Payment status: Y fully paid, N unpaid, P partially paid. Values: Y, N, P.\n BATCH_ID NUMBER -- Invoice batch the invoice was entered in. FK to AP_BATCHES_ALL.BATCH_ID.\n);\n\n-- Invoice batches: groups of invoices entered together, with control totals and entry status.\nCREATE TABLE AP_BATCHES_ALL (\n BATCH_ID NUMBER, -- Unique invoice batch identifier. Primary key.\n BATCH_NAME VARCHAR2(50), -- Name of the batch.\n BATCH_DATE DATE, -- Date the batch was created.\n INVOICE_COUNT NUMBER, -- Number of invoices entered in the batch.\n INVOICE_AMOUNT NUMBER(18,2), -- Total amount of the invoices in the batch.\n CONTROL_INVOICE_COUNT NUMBER, -- Expected invoice count entered as a control total.\n CONTROL_INVOICE_AMOUNT NUMBER(18,2), -- Expected batch amount entered as a control total.\n BATCH_STATUS VARCHAR2(25), -- Status of the batch. Values: OPEN, CLOSED, POSTED.\n SOURCE VARCHAR2(80), -- Source of the batch. Values: MANUAL, IMPORT, SUPPLIER PORTAL.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER, -- Optimistic-locking version number, incremented on each update.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payment schedules: due date, amount remaining, discount and hold status for each invoice installment. Use for aging, overdue, outstanding balance and cash-forecast questions.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE AP_PAYMENT_SCHEDULES_ALL (\n PAYMENT_SCHEDULE_ID NUMBER, -- Unique payment schedule identifier. Primary key.\n INVOICE_ID NUMBER, -- Invoice the installment belongs to. FK to AP_INVOICES_ALL.INVOICE_ID.\n PAYMENT_NUM NUMBER, -- Installment number within the invoice.\n DUE_DATE DATE, -- Date this installment is due for payment.\n GROSS_AMOUNT NUMBER(18,2), -- Gross amount of the installment.\n AMOUNT_REMAINING NUMBER(18,2), -- Unpaid amount remaining; 0 when fully paid.\n DISCOUNT_DATE DATE, -- Last date the early-payment discount is available.\n DISCOUNT_AMOUNT_AVAILABLE NUMBER(18,2), -- Early-payment discount available if paid by the discount date.\n SECOND_DISCOUNT_DATE DATE, -- Second (reduced) early-payment discount date.\n HOLD_FLAG VARCHAR2(1), -- Y if an active hold currently blocks payment of the installment.\n PAYMENT_STATUS_FLAG VARCHAR2(1), -- Y paid, N unpaid, P partially paid. Values: Y, N, P.\n PAYMENT_PRIORITY NUMBER, -- Priority 1-99 used when selecting invoices for payment.\n CHECKRUN_ID NUMBER, -- Payment run that selected the installment, if any.\n REMITTANCE_MESSAGE1 VARCHAR2(150), -- Message printed on the remittance advice.\n ORG_ID NUMBER -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Payments issued to suppliers (check, EFT or wire): one row per payment, with amount, date, method, bank account and status. Use for payments made, payment method and voided payment questions.\n-- (showing 15 of 37 columns: join keys + those relevant to the question)\nCREATE TABLE AP_CHECKS_ALL (\n CHECK_ID NUMBER, -- Unique payment identifier. Primary key.\n CHECK_NUMBER NUMBER, -- Check or payment document number.\n CHECK_DATE DATE, -- Date the payment was issued.\n AMOUNT NUMBER(18,2), -- Payment amount in payment currency.\n BASE_AMOUNT NUMBER(18,2), -- Payment amount in ledger currency.\n PAYMENT_METHOD_CODE VARCHAR2(30), -- How the payment was made. Values: CHECK, EFT, WIRE.\n PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\n CLEARED_DATE DATE, -- Date the payment cleared the bank.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\n VOID_DATE DATE, -- Date the payment was voided.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n STOPPED_DATE DATE, -- Date a stop-payment was issued.\n FUTURE_PAY_DUE_DATE DATE, -- Maturity date for future-dated payments.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created the payment.\n DOC_SEQUENCE_VALUE NUMBER -- Document sequence number of the payment.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- payments due / amount due / due in the next N days, months or year / upcoming payments => SUM(AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING) WHERE AP_PAYMENT_SCHEDULES_ALL.DUE_DATE BETWEEN SYSDATE AND SYSDATE + AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0 (join AP_INVOICES_ALL on INVOICE_ID for the vendor). Do not use AP_CHECKS_ALL: it holds payments already made, so it has no future dates\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: Total amount paid on invoices per month over the past 6 months"}, {"role": "assistant", "content": "```sql\nSELECT TRUNC(i.INVOICE_DATE, 'MM') AS MONTH_START, SUM(i.AMOUNT_PAID) AS TOTAL_AMOUNT_PAID\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_DATE >= ADD_MONTHS(TRUNC(SYSDATE), -6)\nGROUP BY TRUNC(i.INVOICE_DATE, 'MM')\nORDER BY MONTH_START;\n```"}], "meta": {"id": "a-01140", "tier": "T3", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "a767c1739c71", "tables": ["AP_INVOICES_ALL"], "result_rows": 7, "approx_prompt_tokens": 2862, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}} {"messages": [{"role": "system", "content": "You are a precise Oracle SQL generator for an Accounts Payable analytics assistant.\n\nRules:\n- Output ONLY a single read-only Oracle SQL SELECT statement that answers the user's question.\n- Respond with the SQL in a single ```sql code block and nothing else — no prose, no explanation.\n- Only reference tables/columns from the schema below. Never invent tables or columns.\n- Use Oracle's `FETCH FIRST N ROWS ONLY` for row limits, not `LIMIT`.\n- Apply the business glossary below when the question uses those phrases.\n\n### Database Schema (Oracle dialect)\n-- Invoice import staging: invoices loaded from external sources awaiting import, with import status and rejection reason.\nCREATE TABLE AP_INVOICES_INTERFACE (\n INVOICE_INTERFACE_ID NUMBER, -- Unique interface row identifier. Primary key.\n INVOICE_NUM VARCHAR2(50), -- Invoice number from the source system.\n VENDOR_NUM VARCHAR2(30), -- Supplier number from the source system.\n INVOICE_AMOUNT NUMBER(18,2), -- Invoice total from the source system.\n INVOICE_DATE DATE, -- Invoice date from the source system.\n INVOICE_CURRENCY_CODE VARCHAR2(15), -- Currency from the source system. FK to FND_CURRENCIES.CURRENCY_CODE.\n SOURCE VARCHAR2(80), -- Source system that supplied the row. Values: SUPPLIER PORTAL, EDI, EMAIL, OCR.\n STATUS VARCHAR2(25), -- Import status. Values: PROCESSED, REJECTED, PENDING.\n REJECT_REASON VARCHAR2(240), -- Why the row was rejected during import.\n GROUP_ID VARCHAR2(80), -- Load group identifier.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Supplier master: one row per supplier with name, number, type, status, tax details, payment defaults and classification. Use for any question about vendors or suppliers.\n-- (showing 15 of 38 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIERS (\n VENDOR_ID NUMBER, -- Unique supplier identifier. Primary key.\n PARTY_ID NUMBER, -- Trading-community party behind the supplier. FK to HZ_PARTIES.PARTY_ID.\n VENDOR_NAME VARCHAR2(360), -- Supplier name.\n VENDOR_NAME_ALT VARCHAR2(320), -- Alternate or trading name of the supplier.\n SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\n ENABLED_FLAG VARCHAR2(1), -- Y if the supplier can be used on new transactions.\n END_DATE_ACTIVE DATE, -- Date the supplier stops being active.\n SUMMARY_FLAG VARCHAR2(1), -- Y if the supplier is a summary (parent) record.\n ONE_TIME_FLAG VARCHAR2(1), -- Y if the supplier is a one-time supplier.\n SMALL_BUSINESS_FLAG VARCHAR2(1), -- Y if the supplier is a small business.\n WOMEN_OWNED_FLAG VARCHAR2(1), -- Y if the supplier is women-owned.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if all payments to the supplier are blocked.\n HOLD_REASON VARCHAR2(240), -- Why payments to the supplier are blocked.\n CREDIT_LIMIT_AMOUNT NUMBER(18,2), -- Maximum credit extended to the supplier.\n CREATION_SOURCE VARCHAR2(30) -- Where the supplier record originated. Values: REGISTRATION, MANUAL, IMPORT.\n);\n\n-- Purchase order lines: items or services ordered, with quantity, price and category.\n-- (showing 15 of 21 columns: join keys + those relevant to the question)\nCREATE TABLE PO_LINES_ALL (\n PO_LINE_ID NUMBER, -- Unique purchase order line identifier. Primary key.\n PO_HEADER_ID NUMBER, -- Order the line belongs to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n LINE_NUM NUMBER, -- Line number on the order.\n LINE_TYPE_ID NUMBER, -- Line type such as goods or services.\n ITEM_DESCRIPTION VARCHAR2(240), -- Description of the item or service ordered.\n CATEGORY_ID NUMBER, -- Purchasing category of the line.\n UNIT_PRICE NUMBER(18,2), -- Price per unit ordered.\n QUANTITY NUMBER, -- Quantity ordered.\n AMOUNT NUMBER(18,2), -- Line amount for service lines.\n ORDER_TYPE_LOOKUP_CODE VARCHAR2(25), -- Whether the line is quantity or amount based. Values: QUANTITY, AMOUNT.\n CANCEL_FLAG VARCHAR2(1), -- Y if the line was cancelled.\n CLOSED_CODE VARCHAR2(25), -- Closure state of the line. Values: OPEN, CLOSED.\n ITEM_ID NUMBER, -- Inventory item ordered.\n VENDOR_PRODUCT_NUM VARCHAR2(30), -- Supplier's part number.\n TAXABLE_FLAG VARCHAR2(1) -- Y if the line is taxable.\n);\n\n-- Receipt lines: quantities received per purchase order schedule, with item and unit of measure.\n-- (showing 11 of 16 columns: join keys + those relevant to the question)\nCREATE TABLE RCV_SHIPMENT_LINES (\n SHIPMENT_LINE_ID NUMBER, -- Unique receipt line identifier. Primary key.\n SHIPMENT_HEADER_ID NUMBER, -- Receipt the line belongs to. FK to RCV_SHIPMENT_HEADERS.SHIPMENT_HEADER_ID.\n LINE_NUM NUMBER, -- Line number on the receipt.\n PO_HEADER_ID NUMBER, -- Order the receipt line is against. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n PO_LINE_ID NUMBER, -- Order line received against. FK to PO_LINES_ALL.PO_LINE_ID.\n PO_LINE_LOCATION_ID NUMBER, -- Order schedule received against. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n QUANTITY_SHIPPED NUMBER, -- Quantity the supplier shipped.\n QUANTITY_RECEIVED NUMBER, -- Quantity actually received.\n UNIT_OF_MEASURE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\n ITEM_DESCRIPTION VARCHAR2(240), -- Description of the received item.\n SHIPMENT_LINE_STATUS_CODE VARCHAR2(25) -- Status of the receipt line. Values: FULLY RECEIVED, PARTIALLY RECEIVED, EXPECTED.\n);\n\n-- Supplier contacts: people at a supplier with role, phone and email.\n-- (showing 12 of 17 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_CONTACTS (\n CONTACT_ID NUMBER, -- Unique contact identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the contact works for. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Site the contact is associated with. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n FIRST_NAME VARCHAR2(150), -- Contact first name.\n LAST_NAME VARCHAR2(150), -- Contact last name.\n JOB_TITLE VARCHAR2(100), -- Contact job title. Values: ACCOUNTS RECEIVABLE, SALES MANAGER, CFO, CREDIT CONTROLLER.\n EMAIL_ADDRESS VARCHAR2(320), -- Contact email address.\n PHONE_NUMBER VARCHAR2(40), -- Contact phone number.\n PRIMARY_FLAG VARCHAR2(1), -- Y if this is the primary contact.\n INACTIVE_DATE DATE, -- Date the contact is no longer active.\n DEPARTMENT VARCHAR2(80), -- Contact department. Values: FINANCE, SALES, OPERATIONS.\n PREFERRED_CONTACT_METHOD VARCHAR2(25) -- How the contact prefers to be reached. Values: EMAIL, PHONE.\n);\n\n-- Purchase order headers: one row per purchase order with supplier, buyer, status, total and terms.\n-- (showing 15 of 28 columns: join keys + those relevant to the question)\nCREATE TABLE PO_HEADERS_ALL (\n PO_HEADER_ID NUMBER, -- Unique purchase order identifier. Primary key.\n SEGMENT1 VARCHAR2(30), -- Purchase order number.\n VENDOR_ID NUMBER, -- Supplier the order is placed with. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site the order is placed with. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n AGENT_ID NUMBER, -- Buyer who created the order. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n CURRENCY_CODE VARCHAR2(15), -- Order currency. FK to FND_CURRENCIES.CURRENCY_CODE.\n RATE NUMBER(12,6), -- Exchange rate on the order.\n APPROVED_FLAG VARCHAR2(1), -- Y if approved. Values: Y, N.\n APPROVED_DATE DATE, -- Date the order was approved.\n NOTE_TO_VENDOR VARCHAR2(480), -- Note printed for the supplier.\n SHIP_TO_LOCATION_ID NUMBER, -- Ship-to location.\n BILL_TO_LOCATION_ID NUMBER, -- Bill-to location.\n FOB_LOOKUP_CODE VARCHAR2(25), -- Freight-on-board terms. Values: ORIGIN, DESTINATION.\n FREIGHT_TERMS_LOOKUP_CODE VARCHAR2(25), -- Who pays freight. Values: PAID, DUE.\n CANCEL_FLAG VARCHAR2(1) -- Y if the order was cancelled.\n);\n\n-- Purchase order schedules: delivery schedules of a line with need-by date, quantity received and billed, and the matching option (two-, three- or four-way).\n-- (showing 15 of 22 columns: join keys + those relevant to the question)\nCREATE TABLE PO_LINE_LOCATIONS_ALL (\n LINE_LOCATION_ID NUMBER, -- Unique schedule identifier. Primary key.\n PO_HEADER_ID NUMBER, -- Order the schedule belongs to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n PO_LINE_ID NUMBER, -- Line the schedule belongs to. FK to PO_LINES_ALL.PO_LINE_ID.\n SHIPMENT_NUM NUMBER, -- Schedule number within the line.\n QUANTITY NUMBER, -- Quantity scheduled.\n QUANTITY_RECEIVED NUMBER, -- Quantity received so far.\n QUANTITY_BILLED NUMBER, -- Quantity invoiced so far.\n QUANTITY_CANCELLED NUMBER, -- Quantity cancelled.\n NEED_BY_DATE DATE, -- Date the goods are needed.\n PROMISED_DATE DATE, -- Date the supplier promised delivery.\n PRICE_OVERRIDE NUMBER(18,2), -- Price for this schedule if different from the line.\n INVOICE_MATCH_OPTION VARCHAR2(1), -- P match to order (two-way), R match to receipt (three-way). Values: R, P.\n RECEIPT_REQUIRED_FLAG VARCHAR2(1), -- Y if receipt is required before payment.\n TAXABLE_FLAG VARCHAR2(1), -- Y if the schedule is taxable.\n SHIP_TO_LOCATION_ID NUMBER -- Where the goods are delivered.\n);\n\n-- Supplier sites: purchasing and pay locations of a supplier per business unit, with site code, payment terms, payment method, bank details and hold status.\n-- (showing 15 of 34 columns: join keys + those relevant to the question)\nCREATE TABLE POZ_SUPPLIER_SITES_ALL_M (\n VENDOR_SITE_ID NUMBER, -- Unique supplier site identifier. Primary key.\n VENDOR_ID NUMBER, -- Supplier the site belongs to. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_CODE VARCHAR2(15), -- Short site code.\n PURCHASING_SITE_FLAG VARCHAR2(1), -- Y if the site can receive purchase orders.\n PAY_SITE_FLAG VARCHAR2(1), -- Y if invoices can be paid at this site.\n PRIMARY_PAY_SITE_FLAG VARCHAR2(1), -- Y if this is the supplier's primary pay site.\n PAYMENT_METHOD_LOOKUP_CODE VARCHAR2(30), -- Payment method for this site. Values: CHECK, EFT, WIRE.\n PAY_GROUP_LOOKUP_CODE VARCHAR2(25), -- Pay group for this site. Values: DOMESTIC, INTERNATIONAL.\n HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\n HOLD_FUTURE_PAYMENTS_FLAG VARCHAR2(1), -- Y if future invoices at this site are held on entry.\n MATCH_OPTION VARCHAR2(25), -- Whether invoices match to purchase order or receipt. Values: P, R.\n ALWAYS_TAKE_DISC_FLAG VARCHAR2(1), -- Y if the early-payment discount is always taken.\n TOLERANCE_ID NUMBER, -- Matching tolerance applied at the site.\n SHIP_TO_LOCATION_ID NUMBER, -- Default ship-to location for purchase orders.\n BILL_TO_LOCATION_ID NUMBER -- Default bill-to location.\n);\n\n-- Receipt headers: goods receipts recorded against shipments, with supplier, receipt number and date.\nCREATE TABLE RCV_SHIPMENT_HEADERS (\n SHIPMENT_HEADER_ID NUMBER, -- Unique shipment or receipt identifier. Primary key.\n RECEIPT_NUM VARCHAR2(30), -- Receipt number.\n VENDOR_ID NUMBER, -- Supplier that shipped the goods. FK to POZ_SUPPLIERS.VENDOR_ID.\n VENDOR_SITE_ID NUMBER, -- Supplier site shipped from. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\n SHIPPED_DATE DATE, -- Date the supplier shipped the goods.\n EXPECTED_RECEIPT_DATE DATE, -- Date the receipt was expected.\n RECEIPT_SOURCE_CODE VARCHAR2(25), -- Source of the receipt. Values: VENDOR, INTERNAL.\n SHIPMENT_NUM VARCHAR2(30), -- Supplier's shipment or packing slip number.\n WAYBILL_AIRBILL_NUM VARCHAR2(30), -- Carrier waybill number.\n CREATION_DATE DATE, -- Date and time the row was created.\n CREATED_BY VARCHAR2(64), -- User who created the row.\n LAST_UPDATE_DATE DATE, -- Date and time the row was last updated.\n LAST_UPDATED_BY VARCHAR2(64), -- User who last updated the row.\n OBJECT_VERSION_NUMBER NUMBER -- Optimistic-locking version number, incremented on each update.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n"}, {"role": "user", "content": "Recent conversation (for follow-up questions like 'now filter to APAC'):\nQ: Show the total payment amount per payment status\nSQL: SELECT c.STATUS_LOOKUP_CODE, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT FROM AP_CHECKS_ALL c GROUP BY c.STATUS_LOOKUP_CODE ORDER BY TOTAL_PAYMENT_AMOUNT DESC FETCH FIRST 200 ROWS ONLY;\n\nQuestion: Now just for Vandelay Imports"}, {"role": "assistant", "content": "```sql\nSELECT c.STATUS_LOOKUP_CODE, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nJOIN POZ_SUPPLIERS s ON s.VENDOR_ID = c.VENDOR_ID\nWHERE s.VENDOR_NAME = 'Vandelay Imports'\nGROUP BY c.STATUS_LOOKUP_CODE\nORDER BY TOTAL_PAYMENT_AMOUNT DESC;\n```"}], "meta": {"id": "a-01558", "tier": "T2", "family": "followup", "kind": "followup", "source": "S2-templated", "group": "ffe2cbc1f9fe", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIERS"], "result_rows": 4, "approx_prompt_tokens": 3158, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "val"}}