{"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-- 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 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-- 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_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 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 CHECKRUN_ID NUMBER, -- Payment process request identifier.\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-- 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_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 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_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-- voided payment => AP_CHECKS_ALL.STATUS_LOOKUP_CODE = 'VOIDED'\n"}, {"role": "user", "content": "Question: Which 5 payment statuses have the highest biggest payment last year?"}, {"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, 'YYYY'), -12) AND c.CHECK_DATE < TRUNC(SYSDATE, 'YYYY')\nGROUP BY c.STATUS_LOOKUP_CODE\nORDER BY MAX_PAYMENT_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-01014", "tier": "T3", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "66f240535674", "tables": ["AP_CHECKS_ALL"], "result_rows": 3, "approx_prompt_tokens": 3089, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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 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-- 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_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_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);\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-- 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 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_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 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 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 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);\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-- 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-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: Show the early-payment discount on offer per supplier city due this quarter"}, {"role": "assistant", "content": "```sql\nSELECT a.CITY, 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 POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = i.VENDOR_ID\nWHERE ps.DISCOUNT_AMOUNT_AVAILABLE > 0 AND ps.DUE_DATE >= TRUNC(SYSDATE, 'Q')\nGROUP BY a.CITY\nORDER BY TOTAL_DISCOUNT_AVAILABLE DESC;\n```"}], "meta": {"id": "a-01060", "tier": "T3", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "776a6025959f", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 5, "approx_prompt_tokens": 3149, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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 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 DISCARDED_FLAG VARCHAR2(1), -- Y if the line was discarded during correction.\n CANCELLED_FLAG VARCHAR2(1) -- Y if the line was cancelled.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n\n"}, {"role": "user", "content": "Question: Show me the invoice total for Umbrella Chemicals this quarter.\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT SUM(i.INVOICE_AMOUNT) AS TOTAL_INVOICE_AMOUNT FROM AP_INVOICES_ALL i JOIN POZ_SUPPLIERS s ON s.VENDOR_ID = i.VENDOR_ID WHERE s.VENDOR_NAME = 'Umbrella Chemicals' AND i.INVOICE_DATE >= TRUNC(NOW(), 'QUARTER') 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; 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 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 s.VENDOR_NAME = 'Umbrella Chemicals' AND i.INVOICE_DATE >= TRUNC(SYSDATE, 'Q');\n```"}], "meta": {"id": "r-00095", "tier": "T3", "family": "spec-supplier", "kind": "repair-exec", "source": "S6-repair", "group": "ab848e15c674", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 0, "approx_prompt_tokens": 3425, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"NOW\": invalid identifier", "split": "test"}} {"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-- 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 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 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 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_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 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 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 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_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-- 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: Payment count by payment method 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;\n```"}], "meta": {"id": "a-00120", "tier": "T1", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "58ff8fdbb14d", "tables": ["AP_CHECKS_ALL"], "result_rows": 3, "approx_prompt_tokens": 2822, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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_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 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 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-- 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 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 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 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 PREPAY_INVOICE_ID NUMBER -- Prepayment invoice applied on this line, if any.\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 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-- 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-- 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 total tax on invoices over the past 6 months"}, {"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.INVOICE_DATE >= ADD_MONTHS(TRUNC(SYSDATE), -6)\nGROUP BY i.PAYMENT_METHOD_CODE\nORDER BY TOTAL_TAX_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00866", "tier": "T3", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "1b21ffc18aa2", "tables": ["AP_INVOICES_ALL"], "result_rows": 3, "approx_prompt_tokens": 2911, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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_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 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 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-- 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-- 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-5016 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-5016'\nORDER BY ps.PAYMENT_NUM;\n```"}], "meta": {"id": "a-00559", "tier": "T2", "family": "t2-invoice-lookup", "kind": "ask", "source": "S2-templated", "group": "8b49388af325", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL"], "result_rows": 1, "approx_prompt_tokens": 2666, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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_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 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 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 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 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 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 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_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-- unpaid / outstanding => 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-- 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: Give me the biggest payment over the past 30 days."}, {"role": "assistant", "content": "```sql\nSELECT MAX(c.AMOUNT) AS MAX_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nWHERE c.CHECK_DATE >= TRUNC(SYSDATE) - 30;\n```"}], "meta": {"id": "a-00982", "tier": "T3", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "66c74a2e0702", "tables": ["AP_CHECKS_ALL"], "result_rows": 1, "approx_prompt_tokens": 3101, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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-- 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 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 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-- 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-- 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_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 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);\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-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\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: Count the prepayment invoices."}, {"role": "assistant", "content": "```sql\nSELECT COUNT(*)\nFROM AP_INVOICES_ALL\nWHERE INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT';\n```"}], "meta": {"id": "a-00059", "tier": "T1", "family": "t1-count", "kind": "ask", "source": "S2-templated", "group": "cf0add5e9e3b", "tables": ["AP_INVOICES_ALL"], "result_rows": 1, "approx_prompt_tokens": 3040, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 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 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 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 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);\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-- 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-- 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 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 TOLERANCE_ID NUMBER, -- Matching tolerance applied at the site.\n BILL_TO_LOCATION_ID NUMBER, -- Default bill-to location.\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-- 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-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n"}, {"role": "user", "content": "Question: Overdue amount by supplier state"}, {"role": "assistant", "content": "```sql\nSELECT a.STATE, SUM(ps.AMOUNT_REMAINING) AS TOTAL_OVERDUE\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.DUE_DATE < TRUNC(SYSDATE) AND ps.AMOUNT_REMAINING > 0\nGROUP BY a.STATE\nORDER BY TOTAL_OVERDUE DESC;\n```"}], "meta": {"id": "a-00993", "tier": "T3", "family": "t3-overdue", "kind": "ask", "source": "S2-templated", "group": "c54d918235d0", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 3, "approx_prompt_tokens": 2945, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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_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 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_DATE DATE, -- Date from which payment terms are counted.\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 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 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 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 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 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 MATCHED_UOM_LOOKUP_CODE VARCHAR2(25), -- Unit of measure of the matched quantity. Values: EA, HR, KG, BOX.\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 RCV_TRANSACTION_ID NUMBER, -- Receipt transaction matched to. FK to RCV_TRANSACTIONS.TRANSACTION_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-- 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-- Receiving transactions: receive, deliver, return and correct events for goods, with quantity and date. Used to match invoices to receipts.\n-- (showing 14 of 19 columns: join keys + those relevant to the question)\nCREATE TABLE RCV_TRANSACTIONS (\n TRANSACTION_ID NUMBER, -- Unique receiving transaction identifier. Primary key.\n SHIPMENT_HEADER_ID NUMBER, -- Receipt the transaction belongs to. FK to RCV_SHIPMENT_HEADERS.SHIPMENT_HEADER_ID.\n SHIPMENT_LINE_ID NUMBER, -- Receipt line the transaction belongs to. FK to RCV_SHIPMENT_LINES.SHIPMENT_LINE_ID.\n PO_HEADER_ID NUMBER, -- Order the transaction is against. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n PO_LINE_LOCATION_ID NUMBER, -- Order schedule the transaction is against. FK to PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID.\n PO_DISTRIBUTION_ID NUMBER, -- Order distribution charged. FK to PO_DISTRIBUTIONS_ALL.PO_DISTRIBUTION_ID.\n TRANSACTION_TYPE VARCHAR2(25), -- Type of receiving event. Values: RECEIVE, DELIVER, RETURN TO VENDOR, CORRECT.\n TRANSACTION_DATE DATE, -- Date of the event.\n QUANTITY NUMBER, -- Quantity in the transaction.\n UNIT_OF_MEASURE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\n PO_UNIT_PRICE NUMBER(18,2), -- Order unit price at the time.\n CURRENCY_CODE VARCHAR2(15), -- Currency of the transaction. FK to FND_CURRENCIES.CURRENCY_CODE.\n SOURCE_DOCUMENT_CODE VARCHAR2(25), -- Type of document the event came from. Values: PO, RMA.\n DESTINATION_TYPE_CODE VARCHAR2(25) -- Where goods were delivered. Values: RECEIVING, EXPENSE, INVENTORY.\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: What is the largest invoice amount of imported invoices?"}, {"role": "assistant", "content": "```sql\nSELECT MAX(INVOICE_AMOUNT)\nFROM AP_INVOICES_ALL\nWHERE SOURCE = 'IMPORT';\n```"}], "meta": {"id": "a-00106", "tier": "T1", "family": "t1-agg", "kind": "ask", "source": "S2-templated", "group": "c54ad5c9fee4", "tables": ["AP_INVOICES_ALL"], "result_rows": 1, "approx_prompt_tokens": 3093, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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-- 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-- 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-- 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 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 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-- 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-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: How many holds are still active, by hold reason?"}, {"role": "assistant", "content": "```sql\nSELECT HOLD_LOOKUP_CODE, COUNT(*) FROM AP_HOLDS_ALL WHERE RELEASE_DATE IS NULL GROUP BY HOLD_LOOKUP_CODE;\n```"}], "meta": {"id": "p-002", "tier": "T1", "family": "pilot-gold", "kind": "ask", "source": "S1-golden", "group": "ebd9ce1abb33", "tables": ["AP_HOLDS_ALL"], "result_rows": 7, "approx_prompt_tokens": 2629, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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_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 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 PO_HEADER_ID NUMBER, -- Purchase order the invoice is matched to. FK to PO_HEADERS_ALL.PO_HEADER_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 DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number assigned to the invoice.\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-- 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-- 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-- duplicate invoice => AP_HOLDS_ALL.HOLD_LOOKUP_CODE = 'DUPLICATE INVOICE'\n-- cancelled invoice => AP_INVOICES_ALL.CANCELLED_DATE IS NOT NULL\n-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\n-- unvalidated invoice => AP_INVOICES_ALL.VALIDATION_STATUS <> 'VALIDATED'\n"}, {"role": "user", "content": "Question: Why is invoice INV-2025-5040 on hold?"}, {"role": "assistant", "content": "```sql\nSELECT h.HOLD_LOOKUP_CODE, h.HOLD_DATE, h.HOLD_REASON, h.RELEASE_DATE\nFROM AP_HOLDS_ALL h\nJOIN AP_INVOICES_ALL i ON i.INVOICE_ID = h.INVOICE_ID\nWHERE i.INVOICE_NUM = 'INV-2025-5040';\n```"}], "meta": {"id": "a-00612", "tier": "T2", "family": "t2-invoice-lookup", "kind": "ask", "source": "S2-templated", "group": "567a0cce87f4", "tables": ["AP_HOLDS_ALL", "AP_INVOICES_ALL"], "result_rows": 1, "approx_prompt_tokens": 3077, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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-- Employees and contingent workers: person master with name, number, hire date, job, department, manager and business unit.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE PER_ALL_PEOPLE_F (\n PERSON_ID NUMBER, -- Unique person identifier. Primary key.\n PERSON_NUMBER VARCHAR2(30), -- Employee number.\n FIRST_NAME VARCHAR2(150), -- First name.\n LAST_NAME VARCHAR2(150), -- Last name.\n FULL_NAME VARCHAR2(240), -- Full display name.\n EMAIL_ADDRESS VARCHAR2(240), -- Work email address.\n HIRE_DATE DATE, -- Date the person was hired.\n EFFECTIVE_START_DATE DATE, -- Start of the effective-dated row.\n EFFECTIVE_END_DATE DATE, -- End of the effective-dated row.\n JOB_TITLE VARCHAR2(100), -- Job title. Values: AP CLERK, AP MANAGER, BUYER, CONTROLLER, ANALYST.\n DEPARTMENT_NAME VARCHAR2(100), -- Department. Values: FINANCE, PROCUREMENT, OPERATIONS.\n MANAGER_ID NUMBER, -- Person's manager. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n BUSINESS_UNIT_ID NUMBER, -- Business unit the person works in. FK to FUN_BUSINESS_UNITS.BU_ID.\n ASSIGNMENT_STATUS VARCHAR2(25), -- Employment status. Values: ACTIVE, INACTIVE.\n LOCATION VARCHAR2(80) -- Work 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-- 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-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: Give me the 20 oldest holds"}, {"role": "assistant", "content": "```sql\nSELECT INVOICE_ID, HOLD_LOOKUP_CODE, HOLD_DATE, RELEASE_DATE\nFROM AP_HOLDS_ALL\nORDER BY HOLD_DATE ASC\nFETCH FIRST 20 ROWS ONLY;\n```"}], "meta": {"id": "a-00093", "tier": "T1", "family": "t1-topn", "kind": "ask", "source": "S2-templated", "group": "bbb43778c195", "tables": ["AP_HOLDS_ALL"], "result_rows": 20, "approx_prompt_tokens": 2507, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\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 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);\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-- 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-- 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-- 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 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 EXCHANGE_RATE_TYPE VARCHAR2(30), -- Type of exchange rate used. Values: Corporate, Spot, User.\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-- 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-- early payment discount => AP_PAYMENT_SCHEDULES_ALL.DISCOUNT_AMOUNT_AVAILABLE > 0\n"}, {"role": "user", "content": "Question: Show me the average payment amount for EFT payments only."}, {"role": "assistant", "content": "```sql\nSELECT AVG(c.AMOUNT) AS AVG_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nWHERE c.PAYMENT_METHOD_CODE = 'EFT';\n```"}], "meta": {"id": "a-00069", "tier": "T1", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "85da6e277708", "tables": ["AP_CHECKS_ALL"], "result_rows": 1, "approx_prompt_tokens": 3066, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 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 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 MATCHED_UOM_LOOKUP_CODE VARCHAR2(25), -- Unit of measure of the matched quantity. Values: EA, HR, KG, BOX.\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 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 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 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 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 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-- 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 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-- Business glossary (how analysts phrase common conditions):\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: What is the average invoice amount for each business unit?"}, {"role": "assistant", "content": "```sql\nSELECT bu.BU_NAME, AVG(i.INVOICE_AMOUNT) AS AVG_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN FUN_BUSINESS_UNITS bu ON bu.BU_ID = i.ORG_ID\nGROUP BY bu.BU_NAME\nORDER BY AVG_INVOICE_AMOUNT DESC;\n```"}], "meta": {"id": "a-00720", "tier": "T2", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "85d7589dab65", "tables": ["AP_INVOICES_ALL", "FUN_BUSINESS_UNITS"], "result_rows": 10, "approx_prompt_tokens": 3006, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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-- 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-- 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-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: Show the early-payment discount on offer per supplier city due this quarter\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT a.CITY, SUM(ps.DISCOUNT_AMOUNT_AVAILABLE) AS TOTAL_DISCOUNT_AVAILABLE FROM AP_PAYMENT_SCHEDULES_ALL ps JOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ps.INVOICE_ID JOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = i.VENDOR_ID WHERE ps.DISCOUNT_AMOUNT_AVAILABLE > 0 AND ps.DUE_DATE >= TRUNC(NOW(), 'QUARTER') GROUP BY a.CITY ORDER BY TOTAL_DISCOUNT_AVAILABLE 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; 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(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 POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = i.VENDOR_ID\nWHERE ps.DISCOUNT_AMOUNT_AVAILABLE > 0 AND ps.DUE_DATE >= TRUNC(SYSDATE, 'Q')\nGROUP BY a.CITY\nORDER BY TOTAL_DISCOUNT_AVAILABLE DESC;\n```"}], "meta": {"id": "r-00095", "tier": "T3", "family": "spec-inst", "kind": "repair-exec", "source": "S6-repair", "group": "776a6025959f", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 0, "approx_prompt_tokens": 3537, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"NOW\": invalid identifier", "split": "test"}} {"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-- 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 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 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 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 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 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 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 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_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 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);\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-- voided payment => AP_CHECKS_ALL.STATUS_LOOKUP_CODE = 'VOIDED'\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- unpaid / outstanding => 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: How many payments were voided?"}, {"role": "assistant", "content": "```sql\nSELECT COUNT(*) FROM AP_CHECKS_ALL WHERE STATUS_LOOKUP_CODE = 'VOIDED';\n```"}], "meta": {"id": "p-000", "tier": "T1", "family": "pilot-gold", "kind": "ask", "source": "S1-golden", "group": "5f79d0121fab", "tables": ["AP_CHECKS_ALL"], "result_rows": 1, "approx_prompt_tokens": 3129, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 PRODUCT_CATEGORY VARCHAR2(80), -- Category of the product or service. Values: IT EQUIPMENT, OFFICE SUPPLIES, PROFESSIONAL SERVICES, LOGISTICS.\n CANCELLED_FLAG VARCHAR2(1), -- Y if the line was cancelled.\n ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\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-- 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 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 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 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 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 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-- 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-- 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-- cancelled invoice => AP_INVOICES_ALL.CANCELLED_DATE IS NOT NULL\n-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\n-- unvalidated invoice => AP_INVOICES_ALL.VALIDATION_STATUS <> 'VALIDATED'\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: Which 5 business units have the highest total tax on invoices excluding cancelled invoices?"}, {"role": "assistant", "content": "```sql\nSELECT bu.BU_NAME, SUM(i.TOTAL_TAX_AMOUNT) AS TOTAL_TAX_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN FUN_BUSINESS_UNITS bu ON bu.BU_ID = i.ORG_ID\nWHERE i.CANCELLED_DATE IS NULL\nGROUP BY bu.BU_NAME\nORDER BY TOTAL_TAX_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00740", "tier": "T2", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "59e1ed5b18aa", "tables": ["AP_INVOICES_ALL", "FUN_BUSINESS_UNITS"], "result_rows": 5, "approx_prompt_tokens": 2783, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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_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-- 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_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 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-- 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 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 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 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-- 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-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n"}, {"role": "user", "content": "Question: Show me the average payment year to date."}, {"role": "assistant", "content": "```sql\nSELECT AVG(c.AMOUNT) AS AVG_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nWHERE c.CHECK_DATE >= TRUNC(SYSDATE, 'YYYY');\n```"}], "meta": {"id": "a-01070", "tier": "T3", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "15134267ee20", "tables": ["AP_CHECKS_ALL"], "result_rows": 1, "approx_prompt_tokens": 3129, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\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 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 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 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 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 SOURCE VARCHAR2(80), -- How the invoice entered the system. Values: MANUAL, IMPORT, SUPPLIER PORTAL, EMAIL.\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 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 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 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);\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 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 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-- 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-- 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-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: Top 5 supplier cities by average invoice amount for invoices paid by wire"}, {"role": "assistant", "content": "```sql\nSELECT a.CITY, AVG(i.INVOICE_AMOUNT) AS AVG_INVOICE_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 AVG_INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00744", "tier": "T2", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "88a19e3075c3", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 5, "approx_prompt_tokens": 3113, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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 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-- 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 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-- 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-- 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-- 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-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: Show the 10 payment terms with the highest largest invoice amount"}, {"role": "assistant", "content": "```sql\nSELECT t.NAME, MAX(i.INVOICE_AMOUNT) AS MAX_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN AP_TERMS_B t ON t.TERM_ID = i.TERMS_ID\nGROUP BY t.NAME\nORDER BY MAX_INVOICE_AMOUNT DESC\nFETCH FIRST 10 ROWS ONLY;\n```"}], "meta": {"id": "a-00330", "tier": "T2", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "0137bab4c0bd", "tables": ["AP_INVOICES_ALL", "AP_TERMS_B"], "result_rows": 10, "approx_prompt_tokens": 3150, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 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);\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 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 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 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 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 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 INVOICE_CURRENCY_CODE VARCHAR2(15), -- Default invoice currency at this site. FK to FND_CURRENCIES.CURRENCY_CODE.\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 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 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 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);\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-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\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: Suppliers that have both an invoice in a foreign currency and a wire payment"}, {"role": "assistant", "content": "```sql\nSELECT DISTINCT s.VENDOR_NAME\nFROM POZ_SUPPLIERS s\nWHERE EXISTS (SELECT 1 FROM AP_INVOICES_ALL i WHERE i.VENDOR_ID = s.VENDOR_ID AND i.INVOICE_CURRENCY_CODE <> 'USD')\nAND EXISTS (SELECT 1 FROM AP_CHECKS_ALL c WHERE c.VENDOR_ID = s.VENDOR_ID AND c.PAYMENT_METHOD_CODE = 'WIRE')\nORDER BY s.VENDOR_NAME;\n```"}], "meta": {"id": "a-01455", "tier": "T4", "family": "t4-logic", "kind": "ask", "source": "S2-templated", "group": "2c5659afefa2", "tables": ["AP_CHECKS_ALL", "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": "test"}} {"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 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-- 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 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-- 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 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-- 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_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-- Business glossary (how analysts phrase common conditions):\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-- 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"}, {"role": "user", "content": "Question: When was the oldest payment payment date?"}, {"role": "assistant", "content": "```sql\nSELECT MIN(CHECK_DATE)\nFROM AP_CHECKS_ALL;\n```"}], "meta": {"id": "a-00046", "tier": "T1", "family": "t1-date", "kind": "ask", "source": "S2-templated", "group": "edce717c025d", "tables": ["AP_CHECKS_ALL"], "result_rows": 1, "approx_prompt_tokens": 3066, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 TOLERANCE_ID NUMBER, -- Matching tolerance applied at the site.\n BILL_TO_LOCATION_ID NUMBER -- Default bill-to location.\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 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 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 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-- 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 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 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 WOMEN_OWNED_FLAG VARCHAR2(1), -- Y if the supplier is women-owned.\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 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 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-- 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 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-- 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_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 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 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 CANCELLED_BY VARCHAR2(64) -- User who cancelled the invoice.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\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-- 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 with more than 40,000 still unpaid"}, {"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\nGROUP BY s.VENDOR_NAME\nHAVING SUM(ps.AMOUNT_REMAINING) > 40000\nORDER BY TOTAL_UNPAID_AMOUNT DESC;\n```"}], "meta": {"id": "a-00352", "tier": "T2", "family": "t2-having", "kind": "ask", "source": "S2-templated", "group": "d6bd8579d32e", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "POZ_SUPPLIERS"], "result_rows": 3, "approx_prompt_tokens": 2982, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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 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 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-- 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_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_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 PREPAY_INVOICE_ID NUMBER, -- Prepayment invoice applied on this line, if any.\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 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 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-- 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-- credit memo => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'CREDIT'\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n"}, {"role": "user", "content": "Question: Average invoice amount by payment term excluding credit memos"}, {"role": "assistant", "content": "```sql\nSELECT t.NAME, AVG(i.INVOICE_AMOUNT) AS AVG_INVOICE_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 AVG_INVOICE_AMOUNT DESC;\n```"}], "meta": {"id": "a-00478", "tier": "T2", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "07d6b981007a", "tables": ["AP_INVOICES_ALL", "AP_TERMS_B"], "result_rows": 10, "approx_prompt_tokens": 2860, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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-- 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-- Currencies: ISO currency codes with names, symbols and decimal precision.\nCREATE TABLE FND_CURRENCIES (\n CURRENCY_CODE VARCHAR2(15), -- ISO 4217 currency code. Values: USD, EUR, GBP, JPY, CAD, AUD, CHF, INR, SGD, CNY. Primary key.\n NAME VARCHAR2(80), -- Currency name. Values: US Dollar, Euro, Pound Sterling, Yen, Canadian Dollar, Australian Dollar, Swiss Franc, Indian Rupee, Singapore Dollar, Yuan Renminbi.\n ISSUING_TERRITORY_CODE VARCHAR2(2), -- Country that issues the currency. Values: US, DE, GB, JP, CA, AU, CH, IN, SG, CN.\n PRECISION NUMBER, -- Number of decimal places the currency uses.\n SYMBOL VARCHAR2(4), -- Currency symbol.\n ENABLED_FLAG VARCHAR2(1), -- Y if the currency is enabled for transactions.\n START_DATE_ACTIVE DATE, -- Date the currency becomes active.\n END_DATE_ACTIVE DATE, -- Date the currency stops being active.\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 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_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 PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\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_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 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-- 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"}, {"role": "user", "content": "Question: What is the total amount more than 60 days overdue?"}, {"role": "assistant", "content": "```sql\nSELECT SUM(ps.AMOUNT_REMAINING) AS TOTAL_OVERDUE\nFROM AP_PAYMENT_SCHEDULES_ALL ps\nWHERE ps.AMOUNT_REMAINING > 0\nAND TRUNC(SYSDATE) - ps.DUE_DATE > 60;\n```"}], "meta": {"id": "a-00952", "tier": "T3", "family": "t3-overdue-days", "kind": "ask", "source": "S2-templated", "group": "69bdd16c2c5f", "tables": ["AP_PAYMENT_SCHEDULES_ALL"], "result_rows": 1, "approx_prompt_tokens": 3103, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 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 DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\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 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 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-- 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"}, {"role": "user", "content": "Question: Overdue amount by aging bucket: 1-30, 31-60, 61-90 and over 90 days"}, {"role": "assistant", "content": "```sql\nSELECT CASE WHEN TRUNC(SYSDATE) - DUE_DATE <= 30 THEN '1-30' WHEN TRUNC(SYSDATE) - DUE_DATE <= 60 THEN '31-60' WHEN TRUNC(SYSDATE) - DUE_DATE <= 90 THEN '61-90' ELSE 'over 90' END, SUM(AMOUNT_REMAINING) FROM AP_PAYMENT_SCHEDULES_ALL WHERE DUE_DATE < TRUNC(SYSDATE) AND AMOUNT_REMAINING > 0 GROUP BY CASE WHEN TRUNC(SYSDATE) - DUE_DATE <= 30 THEN '1-30' WHEN TRUNC(SYSDATE) - DUE_DATE <= 60 THEN '31-60' WHEN TRUNC(SYSDATE) - DUE_DATE <= 90 THEN '61-90' ELSE 'over 90' END;\n```"}], "meta": {"id": "p-006", "tier": "T3", "family": "pilot-gold", "kind": "ask", "source": "S1-golden", "group": "398d476036ae", "tables": ["AP_PAYMENT_SCHEDULES_ALL"], "result_rows": 4, "approx_prompt_tokens": 2260, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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_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 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-- 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 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 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-- 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-- Employees and contingent workers: person master with name, number, hire date, job, department, manager and business unit.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE PER_ALL_PEOPLE_F (\n PERSON_ID NUMBER, -- Unique person identifier. Primary key.\n PERSON_NUMBER VARCHAR2(30), -- Employee number.\n FIRST_NAME VARCHAR2(150), -- First name.\n LAST_NAME VARCHAR2(150), -- Last name.\n FULL_NAME VARCHAR2(240), -- Full display name.\n EMAIL_ADDRESS VARCHAR2(240), -- Work email address.\n HIRE_DATE DATE, -- Date the person was hired.\n EFFECTIVE_START_DATE DATE, -- Start of the effective-dated row.\n EFFECTIVE_END_DATE DATE, -- End of the effective-dated row.\n JOB_TITLE VARCHAR2(100), -- Job title. Values: AP CLERK, AP MANAGER, BUYER, CONTROLLER, ANALYST.\n DEPARTMENT_NAME VARCHAR2(100), -- Department. Values: FINANCE, PROCUREMENT, OPERATIONS.\n MANAGER_ID NUMBER, -- Person's manager. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n BUSINESS_UNIT_ID NUMBER, -- Business unit the person works in. FK to FUN_BUSINESS_UNITS.BU_ID.\n ASSIGNMENT_STATUS VARCHAR2(25), -- Employment status. Values: ACTIVE, INACTIVE.\n LOCATION VARCHAR2(80), -- Work location.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n\n"}, {"role": "user", "content": "Question: Which 5 business units have the highest total amount paid out in the last 6 months?"}, {"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 >= ADD_MONTHS(TRUNC(SYSDATE), -6)\nGROUP BY bu.BU_NAME\nORDER BY TOTAL_PAYMENT_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00899", "tier": "T3", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "38c754386a93", "tables": ["AP_CHECKS_ALL", "FUN_BUSINESS_UNITS"], "result_rows": 5, "approx_prompt_tokens": 2505, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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-- 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 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-- 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 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 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 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 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-- 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-- 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-- 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: Give me the 5 most recent payments"}, {"role": "assistant", "content": "```sql\nSELECT CHECK_NUMBER, CHECK_DATE, AMOUNT, VENDOR_NAME\nFROM AP_CHECKS_ALL\nORDER BY CHECK_DATE DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00147", "tier": "T1", "family": "t1-topn", "kind": "ask", "source": "S2-templated", "group": "412b3ad4845c", "tables": ["AP_CHECKS_ALL"], "result_rows": 5, "approx_prompt_tokens": 3153, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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_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-- 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-- 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-- 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-- 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 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-- 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 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 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-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: Which 5 supplier cities have the highest total invoice amount?"}, {"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 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00529", "tier": "T2", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "ec47940cbe08", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 5, "approx_prompt_tokens": 3070, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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 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 CASH_POSTED_FLAG VARCHAR2(1), -- Y if cash-basis 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 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-- 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-- 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-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: Give me the total amount paid on invoices last year.\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT SUM(i.AMOUNT_PAID) AS TOTAL_AMOUNT_PAID FROM AP_INVOICES_ALL i WHERE i.INVOICE_DATE >= ADD_MONTHS(TRUNC(NOW(), 'YYYY'), -12) AND i.INVOICE_DATE < TRUNC(NOW(), 'YYYY') 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 SUM(i.AMOUNT_PAID) AS TOTAL_AMOUNT_PAID\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_DATE >= ADD_MONTHS(TRUNC(SYSDATE, 'YYYY'), -12) AND i.INVOICE_DATE < TRUNC(SYSDATE, 'YYYY');\n```"}], "meta": {"id": "r-00073", "tier": "T3", "family": "spec-inv", "kind": "repair-exec", "source": "S6-repair", "group": "b1a5b826d425", "tables": ["AP_INVOICES_ALL"], "result_rows": 0, "approx_prompt_tokens": 3541, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"NOW\": invalid identifier", "split": "test"}} {"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 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 DOC_SEQUENCE_VALUE NUMBER -- Document sequence number assigned to the invoice.\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 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 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-- 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 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-- Business glossary (how analysts phrase common conditions):\n\n"}, {"role": "user", "content": "Question: What is the total invoice amount of invoices over 20,000?"}, {"role": "assistant", "content": "```sql\nSELECT SUM(INVOICE_AMOUNT)\nFROM AP_INVOICES_ALL\nWHERE INVOICE_AMOUNT > 20000;\n```"}], "meta": {"id": "a-00050", "tier": "T1", "family": "t1-agg", "kind": "ask", "source": "S2-templated", "group": "5fc5e7e30744", "tables": ["AP_INVOICES_ALL"], "result_rows": 1, "approx_prompt_tokens": 2978, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 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 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 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-- 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_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-- 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 average payment amount for each supplier for wire payments only?"}, {"role": "assistant", "content": "```sql\nSELECT s.VENDOR_NAME, AVG(c.AMOUNT) AS AVG_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nJOIN POZ_SUPPLIERS s ON s.VENDOR_ID = c.VENDOR_ID\nWHERE c.PAYMENT_METHOD_CODE = 'WIRE'\nGROUP BY s.VENDOR_NAME\nORDER BY AVG_PAYMENT_AMOUNT DESC;\n```"}], "meta": {"id": "a-00567", "tier": "T2", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "544dc02b409b", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIERS"], "result_rows": 7, "approx_prompt_tokens": 2553, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n SOURCE VARCHAR2(80), -- How the invoice entered the system. Values: MANUAL, IMPORT, SUPPLIER PORTAL, EMAIL.\n DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number assigned to the invoice.\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 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 EXTERNAL_BANK_ACCOUNT_ID NUMBER, -- Supplier bank account the payment was sent to. FK to IBY_EXT_BANK_ACCOUNTS.EXT_BANK_ACCOUNT_ID.\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-- 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 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 TERMS_ID NUMBER, -- Default payment terms. FK to AP_TERMS_B.TERM_ID.\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 CREATION_SOURCE VARCHAR2(30), -- Where the supplier record originated. Values: REGISTRATION, MANUAL, IMPORT.\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-- 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 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 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 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 CASH_POSTED_FLAG VARCHAR2(1), -- Y if cash-basis 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 RCV_TRANSACTION_ID NUMBER, -- Receipt transaction matched to. FK to RCV_TRANSACTIONS.TRANSACTION_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-- 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 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-- 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-- credit memo => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'CREDIT'\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: How many credit memos per supplier?"}, {"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_TYPE_LOOKUP_CODE = 'CREDIT'\nGROUP BY s.VENDOR_NAME\nORDER BY INVOICE_COUNT DESC;\n```"}], "meta": {"id": "a-01711", "tier": "T5", "family": "t5-glossary", "kind": "ask", "source": "S2-templated", "group": "69feb42a37c7", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 7, "approx_prompt_tokens": 3135, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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-- 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 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 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 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 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 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 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-- 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 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 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);\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-- Business glossary (how analysts phrase common conditions):\n-- credit memo => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'CREDIT'\n-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n-- voided payment => AP_CHECKS_ALL.STATUS_LOOKUP_CODE = 'VOIDED'\n"}, {"role": "user", "content": "Question: Suppliers that have both a wire payment and a credit memo"}, {"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.PAYMENT_METHOD_CODE = 'WIRE')\nAND EXISTS (SELECT 1 FROM AP_INVOICES_ALL i WHERE i.VENDOR_ID = s.VENDOR_ID AND i.INVOICE_TYPE_LOOKUP_CODE = 'CREDIT')\nORDER BY s.VENDOR_NAME;\n```"}], "meta": {"id": "a-01619", "tier": "T4", "family": "t4-logic", "kind": "ask", "source": "S2-templated", "group": "6a0224454dbf", "tables": ["AP_CHECKS_ALL", "AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 6, "approx_prompt_tokens": 3051, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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-- 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 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-- 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-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND 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-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n"}, {"role": "user", "content": "Question: List the most recent 3 payments"}, {"role": "assistant", "content": "```sql\nSELECT CHECK_NUMBER, CHECK_DATE, AMOUNT, VENDOR_NAME\nFROM AP_CHECKS_ALL\nORDER BY CHECK_DATE DESC\nFETCH FIRST 3 ROWS ONLY;\n```"}], "meta": {"id": "a-00015", "tier": "T1", "family": "t1-topn", "kind": "ask", "source": "S2-templated", "group": "8641dff817a8", "tables": ["AP_CHECKS_ALL"], "result_rows": 3, "approx_prompt_tokens": 2763, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 UNIT_MEAS_LOOKUP_CODE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\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 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 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 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 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-- 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 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 DIST_CODE_COMBINATION_ID NUMBER, -- General-ledger account charged by the distribution. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\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-- 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_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 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_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-- 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-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\n-- credit memo => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'CREDIT'\n"}, {"role": "user", "content": "Question: Which 5 invoice sources have the highest invoice count for invoices paid by wire?"}, {"role": "assistant", "content": "```sql\nSELECT i.SOURCE, COUNT(*) AS INVOICE_COUNT\nFROM AP_INVOICES_ALL i\nWHERE i.PAYMENT_METHOD_CODE = 'WIRE'\nGROUP BY i.SOURCE\nORDER BY INVOICE_COUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00114", "tier": "T1", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "8a8ca344dc8d", "tables": ["AP_INVOICES_ALL"], "result_rows": 4, "approx_prompt_tokens": 3138, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE -- Date funds settled.\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-- 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 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 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-- 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 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-- 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-- 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: Which 10 payment methods have the highest number of payments?"}, {"role": "assistant", "content": "```sql\nSELECT c.PAYMENT_METHOD_CODE, COUNT(*) AS PAYMENT_COUNT\nFROM AP_CHECKS_ALL c\nGROUP BY c.PAYMENT_METHOD_CODE\nORDER BY PAYMENT_COUNT DESC\nFETCH FIRST 10 ROWS ONLY;\n```"}], "meta": {"id": "a-00047", "tier": "T1", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "5ce2a9fc326b", "tables": ["AP_CHECKS_ALL"], "result_rows": 3, "approx_prompt_tokens": 3051, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 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 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 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 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 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 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 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 TASK_ID NUMBER, -- Project task charged.\n EXPENDITURE_TYPE VARCHAR2(80), -- Project expenditure type. Values: TRAVEL, MATERIALS, LABOR.\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-- 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-- 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-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n-- credit memo => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'CREDIT'\n"}, {"role": "user", "content": "Question: Top 10 invoice types by total tax on invoices"}, {"role": "assistant", "content": "```sql\nSELECT i.INVOICE_TYPE_LOOKUP_CODE, SUM(i.TOTAL_TAX_AMOUNT) AS TOTAL_TAX_AMOUNT\nFROM AP_INVOICES_ALL i\nGROUP BY i.INVOICE_TYPE_LOOKUP_CODE\nORDER BY TOTAL_TAX_AMOUNT DESC\nFETCH FIRST 10 ROWS ONLY;\n```"}], "meta": {"id": "a-00143", "tier": "T1", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "c0d85d489330", "tables": ["AP_INVOICES_ALL"], "result_rows": 4, "approx_prompt_tokens": 2641, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 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 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-- 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-- 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-- 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-- 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 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 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_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 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-- Business glossary (how analysts phrase common conditions):\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: What is the payment count for each supplier city last year?"}, {"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.CHECK_DATE >= ADD_MONTHS(TRUNC(SYSDATE, 'YYYY'), -12) AND c.CHECK_DATE < TRUNC(SYSDATE, 'YYYY')\nGROUP BY a.CITY\nORDER BY PAYMENT_COUNT DESC;\n```"}], "meta": {"id": "a-00945", "tier": "T3", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "5e3669eb73ef", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 7, "approx_prompt_tokens": 3026, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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);\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-- 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-- 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 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 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 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-- Business glossary (how analysts phrase common conditions):\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-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: For every currency, list the top 2 most recent invoices"}, {"role": "assistant", "content": "```sql\nSELECT INVOICE_CURRENCY_CODE, INVOICE_NUM, INVOICE_DATE, INVOICE_AMOUNT\nFROM (\n SELECT i.INVOICE_CURRENCY_CODE, i.INVOICE_NUM, i.INVOICE_DATE, i.INVOICE_AMOUNT,\n ROW_NUMBER() OVER (PARTITION BY i.INVOICE_CURRENCY_CODE ORDER BY i.INVOICE_DATE DESC) AS RN\n FROM AP_INVOICES_ALL i\n)\nWHERE RN <= 2\nORDER BY INVOICE_CURRENCY_CODE, RN;\n```"}], "meta": {"id": "a-01423", "tier": "T4", "family": "t4-topk", "kind": "ask", "source": "S2-templated", "group": "a3744de27076", "tables": ["AP_INVOICES_ALL"], "result_rows": 18, "approx_prompt_tokens": 2860, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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);\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 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 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 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 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 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 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 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 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-- 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 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-- supplier state / vendor state / by state => POZ_SUPPLIER_ADDRESSES.STATE (join on VENDOR_ID)\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: For every supplier state, list the top 2 largest invoices"}, {"role": "assistant", "content": "```sql\nSELECT STATE, INVOICE_NUM, INVOICE_DATE, INVOICE_AMOUNT\nFROM (\n SELECT a.STATE, i.INVOICE_NUM, i.INVOICE_DATE, i.INVOICE_AMOUNT,\n ROW_NUMBER() OVER (PARTITION BY a.STATE ORDER BY i.INVOICE_AMOUNT DESC) AS RN\n FROM AP_INVOICES_ALL i\n JOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = i.VENDOR_ID\n)\nWHERE RN <= 2\nORDER BY STATE, RN;\n```"}], "meta": {"id": "a-01446", "tier": "T4", "family": "t4-topk", "kind": "ask", "source": "S2-templated", "group": "3a0cfef42a79", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 6, "approx_prompt_tokens": 2764, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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-- Business glossary (how analysts phrase common conditions):\n-- unvalidated invoice => AP_INVOICES_ALL.VALIDATION_STATUS <> 'VALIDATED'\n-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\n-- credit memo => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'CREDIT'\n"}, {"role": "user", "content": "Question: Top 5 validation statuses by biggest invoice amount last month\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT i.VALIDATION_STATUS, MAX(i.INVOICE_AMOUNT) AS MAX_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_DATE >= ADD_MONTHS(TRUNC(NOW(), 'MM'), -1) AND i.INVOICE_DATE < TRUNC(NOW(), 'MM')\nGROUP BY i.VALIDATION_STATUS\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.\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.VALIDATION_STATUS, MAX(i.INVOICE_AMOUNT) AS MAX_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_DATE >= ADD_MONTHS(TRUNC(SYSDATE, 'MM'), -1) AND i.INVOICE_DATE < TRUNC(SYSDATE, 'MM')\nGROUP BY i.VALIDATION_STATUS\nORDER BY MAX_INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "r-00085", "tier": "T3", "family": "spec-inv", "kind": "repair-exec", "source": "S6-repair", "group": "09672c3b3758", "tables": ["AP_INVOICES_ALL"], "result_rows": 0, "approx_prompt_tokens": 3415, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"NOW\": invalid identifier", "split": "test"}} {"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 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 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-- 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 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 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_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-- 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_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 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);\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 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 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-- 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-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\n"}, {"role": "user", "content": "Question: Which 5 suppliers have the highest total value of invoices over the past 30 days?"}, {"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) - 30\nGROUP BY s.VENDOR_NAME\nORDER BY TOTAL_INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-01046", "tier": "T3", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "a89487ff6617", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 5, "approx_prompt_tokens": 3074, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\n CANCELLED_BY VARCHAR2(64) -- User who cancelled the invoice.\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 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 RISK_RATING VARCHAR2(25) -- Internal supplier risk rating. Values: LOW, MEDIUM, HIGH.\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 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 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_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-- 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 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-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n"}, {"role": "user", "content": "Question: 5 suppliers with the lowest total invoiced"}, {"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\nGROUP BY s.VENDOR_NAME\nORDER BY TOTAL_INVOICE_AMOUNT ASC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00711", "tier": "T2", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "b2bc28af8fb5", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 5, "approx_prompt_tokens": 3032, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- Journal entry lines: debit and credit amounts per account for each journal.\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 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-- 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-- 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-- 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-- 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: Show the 5 payment statuses with the highest average payment for payments that have cleared\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT c.STATUS, AVG(c.AMOUNT) AS AVG_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nWHERE c.STATUS IN ('CLEARED', 'RECONCILED')\nGROUP BY c.STATUS\nORDER BY AVG_PAYMENT_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\nError: ORA-00904: \"C\".\"STATUS\": invalid identifier\nDiagnosis: None of your query's tables has a column meaning 'STATUS', but the schema has: GL_JE_LINES.STATUS (P posted, U unposted. Values: P, U.) AP_HOLDS_ALL.STATUS_FLAG (Hold status: S system-placed, R released. Values: S, R.) Add that table to your query. 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 c.STATUS_LOOKUP_CODE, AVG(c.AMOUNT) AS AVG_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nWHERE c.STATUS_LOOKUP_CODE IN ('CLEARED', 'RECONCILED')\nGROUP BY c.STATUS_LOOKUP_CODE\nORDER BY AVG_PAYMENT_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "r-00026", "tier": "T1", "family": "spec-pay", "kind": "repair-exec", "source": "S6-repair", "group": "58802d4559ed", "tables": ["AP_CHECKS_ALL"], "result_rows": 0, "approx_prompt_tokens": 3378, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"C\".\"STATUS\": invalid identifier", "split": "test"}} {"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-- 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-- 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-- 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"}, {"role": "user", "content": "Question: How many payments are there for Stark Components?\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT COUNT(*) AS PAYMENT_COUNT FROM AP_CHECKS_ALL c JOIN POZ_SUPPLIERS s ON s.VENDOR_ID = c.VENDOR_ID WHERE s.SUPPLIER_NAME = 'Stark Components' 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 COUNT(*) AS PAYMENT_COUNT\nFROM AP_CHECKS_ALL c\nJOIN POZ_SUPPLIERS s ON s.VENDOR_ID = c.VENDOR_ID\nWHERE s.VENDOR_NAME = 'Stark Components';\n```"}], "meta": {"id": "r-00009", "tier": "T2", "family": "spec-supplier", "kind": "repair-exec", "source": "S6-repair", "group": "cdf04b2d1023", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIERS"], "result_rows": 0, "approx_prompt_tokens": 3444, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"S\".\"SUPPLIER_NAME\": invalid identifier", "split": "test"}} {"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-- 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 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_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-- 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-- 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_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_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);\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-- unpaid / outstanding => 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-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n"}, {"role": "user", "content": "Question: What is the largest unpaid installment for each supplier state due in the next 30 days?"}, {"role": "assistant", "content": "```sql\nSELECT a.STATE, MAX(ps.AMOUNT_REMAINING) AS MAX_UNPAID_AMOUNT\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.DUE_DATE BETWEEN TRUNC(SYSDATE) AND TRUNC(SYSDATE) + 30\nGROUP BY a.STATE\nORDER BY MAX_UNPAID_AMOUNT DESC;\n```"}], "meta": {"id": "a-01037", "tier": "T3", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "4075efbe3281", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 3, "approx_prompt_tokens": 2635, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number assigned to the invoice.\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-- 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-- 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-- 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-- credit memo => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'CREDIT'\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: Count the credit memos"}, {"role": "assistant", "content": "```sql\nSELECT COUNT(*)\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_TYPE_LOOKUP_CODE = 'CREDIT';\n```"}], "meta": {"id": "a-01634", "tier": "T5", "family": "t5-glossary", "kind": "ask", "source": "S2-templated", "group": "73e61cfa9a98", "tables": ["AP_INVOICES_ALL"], "result_rows": 1, "approx_prompt_tokens": 2591, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 PERIOD_NAME VARCHAR2(15), -- Accounting period the distribution falls in.\n ACCRUAL_POSTED_FLAG VARCHAR2(1), -- Y if accrual accounting entries were created.\n MATCHED_UOM_LOOKUP_CODE VARCHAR2(25), -- Unit of measure of the matched quantity. Values: EA, HR, KG, BOX.\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 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-- 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 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 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 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 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 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 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 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\n"}, {"role": "user", "content": "Question: 5 business units with the lowest total amount paid on invoices"}, {"role": "assistant", "content": "```sql\nSELECT bu.BU_NAME, SUM(i.AMOUNT_PAID) AS TOTAL_AMOUNT_PAID\nFROM AP_INVOICES_ALL i\nJOIN FUN_BUSINESS_UNITS bu ON bu.BU_ID = i.ORG_ID\nGROUP BY bu.BU_NAME\nORDER BY TOTAL_AMOUNT_PAID ASC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00575", "tier": "T2", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "644fd6660632", "tables": ["AP_INVOICES_ALL", "FUN_BUSINESS_UNITS"], "result_rows": 5, "approx_prompt_tokens": 3018, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 DESCRIPTION VARCHAR2(240) -- Free-text invoice 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 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 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 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 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-- 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 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 DOC_SEQUENCE_VALUE NUMBER -- Document sequence number of the payment.\n);\n\n-- Daily currency exchange rates between currency pairs by conversion type.\nCREATE TABLE GL_DAILY_RATES (\n RATE_ID NUMBER, -- Unique rate identifier. Primary key.\n FROM_CURRENCY VARCHAR2(15), -- Currency converted from. FK to FND_CURRENCIES.CURRENCY_CODE.\n TO_CURRENCY VARCHAR2(15), -- Currency converted to. FK to FND_CURRENCIES.CURRENCY_CODE.\n CONVERSION_DATE DATE, -- Date the rate applies to.\n CONVERSION_TYPE VARCHAR2(30), -- Rate type such as Corporate or Spot. Values: Corporate, Spot, User.\n CONVERSION_RATE NUMBER(12,6), -- Units of the to-currency per unit of the from-currency.\n STATUS_CODE VARCHAR2(1), -- Rate status: C confirmed.\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-- Currencies: ISO currency codes with names, symbols and decimal precision.\nCREATE TABLE FND_CURRENCIES (\n CURRENCY_CODE VARCHAR2(15), -- ISO 4217 currency code. Values: USD, EUR, GBP, JPY, CAD, AUD, CHF, INR, SGD, CNY. Primary key.\n NAME VARCHAR2(80), -- Currency name. Values: US Dollar, Euro, Pound Sterling, Yen, Canadian Dollar, Australian Dollar, Swiss Franc, Indian Rupee, Singapore Dollar, Yuan Renminbi.\n ISSUING_TERRITORY_CODE VARCHAR2(2), -- Country that issues the currency. Values: US, DE, GB, JP, CA, AU, CH, IN, SG, CN.\n PRECISION NUMBER, -- Number of decimal places the currency uses.\n SYMBOL VARCHAR2(4), -- Currency symbol.\n ENABLED_FLAG VARCHAR2(1), -- Y if the currency is enabled for transactions.\n START_DATE_ACTIVE DATE, -- Date the currency becomes active.\n END_DATE_ACTIVE DATE, -- Date the currency stops being active.\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\n"}, {"role": "user", "content": "Question: Average invoice amount by currency counting only USD invoices"}, {"role": "assistant", "content": "```sql\nSELECT i.INVOICE_CURRENCY_CODE, AVG(i.INVOICE_AMOUNT) AS AVG_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_CURRENCY_CODE = 'USD'\nGROUP BY i.INVOICE_CURRENCY_CODE\nORDER BY AVG_INVOICE_AMOUNT DESC;\n```"}], "meta": {"id": "a-00100", "tier": "T1", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "e5dc3f19d37b", "tables": ["AP_INVOICES_ALL"], "result_rows": 1, "approx_prompt_tokens": 2557, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 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);\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 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-- 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-- 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-- 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 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-- duplicate invoice => AP_HOLDS_ALL.HOLD_LOOKUP_CODE = 'DUPLICATE INVOICE'\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\n"}, {"role": "user", "content": "Question: What is the largest of the invoices on hold?"}, {"role": "assistant", "content": "```sql\nSELECT MAX(i.INVOICE_AMOUNT)\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_ID IN (SELECT h.INVOICE_ID FROM AP_HOLDS_ALL h WHERE h.RELEASE_DATE IS NULL);\n```"}], "meta": {"id": "a-01684", "tier": "T5", "family": "t5-glossary", "kind": "ask", "source": "S2-templated", "group": "701f4a52b20d", "tables": ["AP_HOLDS_ALL", "AP_INVOICES_ALL"], "result_rows": 1, "approx_prompt_tokens": 3022, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\n CHECKRUN_NAME VARCHAR2(255), -- Payment process request that created 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-- 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 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 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-- 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_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-- 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-- 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-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n"}, {"role": "user", "content": "Question: Biggest payment by business unit for wire payments only"}, {"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.PAYMENT_METHOD_CODE = 'WIRE'\nGROUP BY bu.BU_NAME\nORDER BY MAX_PAYMENT_AMOUNT DESC;\n```"}], "meta": {"id": "a-00479", "tier": "T2", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "6d34fa4d0f8b", "tables": ["AP_CHECKS_ALL", "FUN_BUSINESS_UNITS"], "result_rows": 8, "approx_prompt_tokens": 2951, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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_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 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 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-- 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 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 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-- unpaid / outstanding => 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-- 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"}, {"role": "user", "content": "Question: Largest unpaid installment by payment term due for the rest of this month"}, {"role": "assistant", "content": "```sql\nSELECT t.NAME, MAX(ps.AMOUNT_REMAINING) AS MAX_UNPAID_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.AMOUNT_REMAINING > 0 AND ps.DUE_DATE BETWEEN TRUNC(SYSDATE) AND LAST_DAY(TRUNC(SYSDATE))\nGROUP BY t.NAME\nORDER BY MAX_UNPAID_AMOUNT DESC;\n```"}], "meta": {"id": "a-01110", "tier": "T3", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "a1f64440a26b", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "AP_TERMS_B"], "result_rows": 5, "approx_prompt_tokens": 3079, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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 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 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 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 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-- Business glossary (how analysts phrase common conditions):\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-- 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 outstanding balance for each payment term for installments on hold?"}, {"role": "assistant", "content": "```sql\nSELECT t.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 AP_TERMS_B t ON t.TERM_ID = i.TERMS_ID\nWHERE ps.AMOUNT_REMAINING > 0 AND ps.HOLD_FLAG = 'Y'\nGROUP BY t.NAME\nORDER BY TOTAL_UNPAID_AMOUNT DESC;\n```"}], "meta": {"id": "a-00768", "tier": "T2", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "a047889d9dc5", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "AP_TERMS_B"], "result_rows": 6, "approx_prompt_tokens": 2815, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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_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-- 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_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-- 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-- 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_NUM VARCHAR2(50), -- Supplier's invoice number as printed on the document.\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 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 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-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n"}, {"role": "user", "content": "Question: Show the total unpaid amount per business unit"}, {"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\nGROUP BY bu.BU_NAME\nORDER BY TOTAL_UNPAID_AMOUNT DESC;\n```"}], "meta": {"id": "a-00820", "tier": "T2", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "9bc4f7af7918", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "FUN_BUSINESS_UNITS"], "result_rows": 10, "approx_prompt_tokens": 3011, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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 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 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-- 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 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 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 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-- 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-- 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: Give me the total installment amount that were due last month."}, {"role": "assistant", "content": "```sql\nSELECT 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\nWHERE ps.DUE_DATE >= ADD_MONTHS(TRUNC(SYSDATE, 'MM'), -1) AND ps.DUE_DATE < TRUNC(SYSDATE, 'MM');\n```"}], "meta": {"id": "a-01158", "tier": "T3", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "2d009ba7cae1", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL"], "result_rows": 1, "approx_prompt_tokens": 3156, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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-- 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 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 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_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-- 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-- 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-- 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: How many installments with an early-payment discount available are there?"}, {"role": "assistant", "content": "```sql\nSELECT COUNT(*)\nFROM AP_PAYMENT_SCHEDULES_ALL\nWHERE DISCOUNT_AMOUNT_AVAILABLE > 0;\n```"}], "meta": {"id": "a-00118", "tier": "T1", "family": "t1-count", "kind": "ask", "source": "S2-templated", "group": "490e5915f559", "tables": ["AP_PAYMENT_SCHEDULES_ALL"], "result_rows": 1, "approx_prompt_tokens": 3140, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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.\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 BANK_ACCOUNT_NUM VARCHAR2(30), -- Bank account number the payment was drawn on.\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-- 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-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: Average days to pay for payments made this year\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT ROUND(AVG(c.CHECK_DATE - i.INVOICE_CREATION_DATE), 1) AS AVG_DAYS_TO_PAY FROM AP_INVOICE_PAYMENTS_ALL ip JOIN AP_CHECKS_ALL c ON c.CHECK_ID = ip.CHECK_ID JOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ip.INVOICE_ID WHERE c.STATUS_LOOKUP_CODE <> 'VOIDED' AND c.CHECK_DATE >= TRUNC(SYSDATE, 'YYYY') 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 ROUND(AVG(c.CHECK_DATE - i.INVOICE_DATE), 1) AS AVG_DAYS_TO_PAY\nFROM AP_INVOICE_PAYMENTS_ALL ip\nJOIN AP_CHECKS_ALL c ON c.CHECK_ID = ip.CHECK_ID\nJOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ip.INVOICE_ID\nWHERE c.STATUS_LOOKUP_CODE <> 'VOIDED'\nAND c.CHECK_DATE >= TRUNC(SYSDATE, 'YYYY');\n```"}], "meta": {"id": "r-00031", "tier": "T3", "family": "t3-days-to-pay", "kind": "repair-exec", "source": "S6-repair", "group": "c729a454ac69", "tables": ["AP_CHECKS_ALL", "AP_INVOICES_ALL", "AP_INVOICE_PAYMENTS_ALL"], "result_rows": 0, "approx_prompt_tokens": 3531, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"I\".\"INVOICE_CREATION_DATE\": invalid identifier", "split": "test"}} {"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 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 AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\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 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-- 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-- 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-- 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 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-- 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-- 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-- credit memo => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'CREDIT'\n"}, {"role": "user", "content": "Question: Show the 3 oldest invoices"}, {"role": "assistant", "content": "```sql\nSELECT INVOICE_NUM, INVOICE_DATE, INVOICE_AMOUNT\nFROM AP_INVOICES_ALL\nORDER BY INVOICE_DATE ASC\nFETCH FIRST 3 ROWS ONLY;\n```"}], "meta": {"id": "a-00026", "tier": "T1", "family": "t1-topn", "kind": "ask", "source": "S2-templated", "group": "c7aff8ba8931", "tables": ["AP_INVOICES_ALL"], "result_rows": 3, "approx_prompt_tokens": 2985, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 CHECKRUN_ID NUMBER, -- Payment process request identifier.\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 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);\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-- 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_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);\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-- 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-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n"}, {"role": "user", "content": "Question: Top 5 suppliers by average payment amount for EFT payments only"}, {"role": "assistant", "content": "```sql\nSELECT s.VENDOR_NAME, AVG(c.AMOUNT) AS AVG_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nJOIN POZ_SUPPLIERS s ON s.VENDOR_ID = c.VENDOR_ID\nWHERE c.PAYMENT_METHOD_CODE = 'EFT'\nGROUP BY s.VENDOR_NAME\nORDER BY AVG_PAYMENT_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00342", "tier": "T2", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "a22a6b807704", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIERS"], "result_rows": 5, "approx_prompt_tokens": 2924, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\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 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);\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 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-- 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-- Business glossary (how analysts phrase common conditions):\n-- unvalidated invoice => AP_INVOICES_ALL.VALIDATION_STATUS <> 'VALIDATED'\n-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\n-- credit memo => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'CREDIT'\n"}, {"role": "user", "content": "Question: Top 5 validation statuses by biggest invoice amount last month"}, {"role": "assistant", "content": "```sql\nSELECT i.VALIDATION_STATUS, MAX(i.INVOICE_AMOUNT) AS MAX_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_DATE >= ADD_MONTHS(TRUNC(SYSDATE, 'MM'), -1) AND i.INVOICE_DATE < TRUNC(SYSDATE, 'MM')\nGROUP BY i.VALIDATION_STATUS\nORDER BY MAX_INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-01150", "tier": "T3", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "09672c3b3758", "tables": ["AP_INVOICES_ALL"], "result_rows": 2, "approx_prompt_tokens": 2342, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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 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 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 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-- 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-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND 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 business units have the highest payment count in the last 90 days?"}, {"role": "assistant", "content": "```sql\nSELECT bu.BU_NAME, COUNT(*) AS PAYMENT_COUNT\nFROM AP_CHECKS_ALL c\nJOIN FUN_BUSINESS_UNITS bu ON bu.BU_ID = c.ORG_ID\nWHERE c.CHECK_DATE >= TRUNC(SYSDATE) - 90\nGROUP BY bu.BU_NAME\nORDER BY PAYMENT_COUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-01019", "tier": "T3", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "2e6c536cca2b", "tables": ["AP_CHECKS_ALL", "FUN_BUSINESS_UNITS"], "result_rows": 5, "approx_prompt_tokens": 2785, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 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);\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-- 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 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 ACCOUNTING_DATE DATE, -- Accounting date of the line.\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-- 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 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_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 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 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_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 FREIGHT_TERMS_LOOKUP_CODE VARCHAR2(25), -- Who pays freight. Values: PAID, DUE.\n CLOSED_DATE DATE, -- Date the order was closed.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\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 earliest invoice per supplier"}, {"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 ASC) AS RN\n FROM AP_INVOICES_ALL i\n JOIN POZ_SUPPLIERS s ON s.VENDOR_ID = i.VENDOR_ID\n)\nWHERE RN <= 1\nORDER BY VENDOR_NAME, RN;\n```"}], "meta": {"id": "a-01368", "tier": "T4", "family": "t4-topk", "kind": "ask", "source": "S2-templated", "group": "9d84d0932e41", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 9, "approx_prompt_tokens": 2711, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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-- 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 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 CASH_POSTED_FLAG VARCHAR2(1), -- Y if cash-basis 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 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-- 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_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 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 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-- 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-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: Total invoice amount across prepayment invoices"}, {"role": "assistant", "content": "```sql\nSELECT SUM(INVOICE_AMOUNT)\nFROM AP_INVOICES_ALL\nWHERE INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT';\n```"}], "meta": {"id": "a-00066", "tier": "T1", "family": "t1-agg", "kind": "ask", "source": "S2-templated", "group": "82a5e7d4a0d1", "tables": ["AP_INVOICES_ALL"], "result_rows": 1, "approx_prompt_tokens": 2965, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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_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-- 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 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 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 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);\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_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 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-- 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-- 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 total invoice amount"}, {"role": "assistant", "content": "```sql\nSELECT s.VENDOR_NAME, SUM(i.INVOICE_AMOUNT) FROM AP_INVOICES_ALL i JOIN POZ_SUPPLIERS s ON s.VENDOR_ID = i.VENDOR_ID GROUP BY s.VENDOR_NAME ORDER BY 2 DESC FETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "p-003", "tier": "T2", "family": "pilot-gold", "kind": "ask", "source": "S1-golden", "group": "47f0aef37e23", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 5, "approx_prompt_tokens": 2790, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\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 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);\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 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 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-- 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 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 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 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-- 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 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 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_DATE DATE, -- Date the order was approved.\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-- 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-- 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"}, {"role": "user", "content": "Question: For each supplier, show their single largest invoice"}, {"role": "assistant", "content": "```sql\nSELECT VENDOR_NAME, INVOICE_NUM, INVOICE_AMOUNT FROM (SELECT s.VENDOR_NAME, i.INVOICE_NUM, i.INVOICE_AMOUNT, ROW_NUMBER() OVER (PARTITION BY i.VENDOR_ID ORDER BY i.INVOICE_AMOUNT DESC) rn FROM AP_INVOICES_ALL i JOIN POZ_SUPPLIERS s ON s.VENDOR_ID = i.VENDOR_ID) WHERE rn = 1;\n```"}], "meta": {"id": "p-008", "tier": "T4", "family": "pilot-gold", "kind": "ask", "source": "S1-golden", "group": "241a33811707", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 10, "approx_prompt_tokens": 3103, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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);\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 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-- 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-- 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 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 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-- 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-- 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: Show the 5 supplier states with the highest average payment for wire payments only"}, {"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.PAYMENT_METHOD_CODE = 'WIRE'\nGROUP BY a.STATE\nORDER BY AVG_PAYMENT_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00819", "tier": "T2", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "cc89e776816b", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 3, "approx_prompt_tokens": 2924, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 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);\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 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 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-- 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"}, {"role": "user", "content": "Question: Overdue amount by aging bucket: 1-30, 31-60, 61-120 and over 120 days"}, {"role": "assistant", "content": "```sql\nSELECT CASE WHEN TRUNC(SYSDATE) - ps.DUE_DATE <= 30 THEN '1-30' WHEN TRUNC(SYSDATE) - ps.DUE_DATE <= 60 THEN '31-60' WHEN TRUNC(SYSDATE) - ps.DUE_DATE <= 120 THEN '61-120' ELSE 'Over 120' END AS AGING_BUCKET, SUM(ps.AMOUNT_REMAINING) AS TOTAL_OVERDUE\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 <= 30 THEN '1-30' WHEN TRUNC(SYSDATE) - ps.DUE_DATE <= 60 THEN '31-60' WHEN TRUNC(SYSDATE) - ps.DUE_DATE <= 120 THEN '61-120' ELSE 'Over 120' END\nORDER BY MAX(ps.DUE_DATE) DESC;\n```"}], "meta": {"id": "a-00958", "tier": "T3", "family": "t3-aging", "kind": "ask", "source": "S2-templated", "group": "1aa46adcef39", "tables": ["AP_PAYMENT_SCHEDULES_ALL"], "result_rows": 4, "approx_prompt_tokens": 2223, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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 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 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 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 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);\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-- 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-- credit memo => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'CREDIT'\n-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\n"}, {"role": "user", "content": "Question: Show the 5 payment terms with the highest total invoice tax amount 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\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00716", "tier": "T2", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "616a0cf33221", "tables": ["AP_INVOICES_ALL", "AP_TERMS_B"], "result_rows": 5, "approx_prompt_tokens": 2969, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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_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 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 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 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-- 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 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 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-- Business glossary (how analysts phrase common conditions):\n\n"}, {"role": "user", "content": "Question: Show the 10 business units with the highest largest payment amount"}, {"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\nGROUP BY bu.BU_NAME\nORDER BY MAX_PAYMENT_AMOUNT DESC\nFETCH FIRST 10 ROWS ONLY;\n```"}], "meta": {"id": "a-00507", "tier": "T2", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "2aa4eea093e2", "tables": ["AP_CHECKS_ALL", "FUN_BUSINESS_UNITS"], "result_rows": 10, "approx_prompt_tokens": 2959, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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 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 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 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);\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-- 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-- 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-- cancelled invoice => AP_INVOICES_ALL.CANCELLED_DATE IS NOT NULL\n"}, {"role": "user", "content": "Recent conversation (for follow-up questions like 'now filter to APAC'):\nQ: What is the outstanding balance for each payment term?\nSQL: SELECT t.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 AP_TERMS_B t ON t.TERM_ID = i.TERMS_ID WHERE ps.AMOUNT_REMAINING > 0 GROUP BY t.NAME ORDER BY TOTAL_UNPAID_AMOUNT DESC FETCH FIRST 200 ROWS ONLY;\n\nQuestion: Now do the same for installments that were due last month"}, {"role": "assistant", "content": "```sql\nSELECT t.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 AP_TERMS_B t ON t.TERM_ID = i.TERMS_ID\nWHERE ps.AMOUNT_REMAINING > 0 AND ps.DUE_DATE >= ADD_MONTHS(TRUNC(SYSDATE, 'MM'), -1) AND ps.DUE_DATE < TRUNC(SYSDATE, 'MM')\nGROUP BY t.NAME\nORDER BY TOTAL_UNPAID_AMOUNT DESC;\n```"}], "meta": {"id": "a-01554", "tier": "T3", "family": "followup", "kind": "followup", "source": "S2-templated", "group": "a21a05c8a473", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "AP_TERMS_B"], "result_rows": 5, "approx_prompt_tokens": 3237, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 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 DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number assigned to the invoice.\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-- 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_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_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 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 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-- 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: Total invoice amount by payment term year to date"}, {"role": "assistant", "content": "```sql\nSELECT t.NAME, SUM(i.INVOICE_AMOUNT) AS TOTAL_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN AP_TERMS_B t ON t.TERM_ID = i.TERMS_ID\nWHERE i.INVOICE_DATE >= TRUNC(SYSDATE, 'YYYY')\nGROUP BY t.NAME\nORDER BY TOTAL_INVOICE_AMOUNT DESC;\n```"}], "meta": {"id": "a-01144", "tier": "T3", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "c5b2c01cd35b", "tables": ["AP_INVOICES_ALL", "AP_TERMS_B"], "result_rows": 10, "approx_prompt_tokens": 3137, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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_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 ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\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-- 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 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_MEAS_LOOKUP_CODE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\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-- 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 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 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 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_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 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 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 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 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 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 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 SELF_ASSESSED_TAX_AMOUNT NUMBER(18,2), -- Tax the buyer self-assesses instead of paying to the supplier.\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 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-- 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-- supplier state / vendor state / by state => POZ_SUPPLIER_ADDRESSES.STATE (join on VENDOR_ID)\n"}, {"role": "user", "content": "Question: Miscellaneous line amount per supplier"}, {"role": "assistant", "content": "```sql\nSELECT s.VENDOR_NAME, SUM(l.AMOUNT) AS TOTAL_MISCELLANEOUS_AMOUNT\nFROM AP_INVOICE_LINES_ALL l\nJOIN AP_INVOICES_ALL i ON i.INVOICE_ID = l.INVOICE_ID\nJOIN POZ_SUPPLIERS s ON s.VENDOR_ID = i.VENDOR_ID\nWHERE l.LINE_TYPE_LOOKUP_CODE = 'MISCELLANEOUS'\nGROUP BY s.VENDOR_NAME\nORDER BY TOTAL_MISCELLANEOUS_AMOUNT DESC;\n```"}], "meta": {"id": "a-00338", "tier": "T2", "family": "t2-lines", "kind": "ask", "source": "S2-templated", "group": "654c7ef3122c", "tables": ["AP_INVOICES_ALL", "AP_INVOICE_LINES_ALL", "POZ_SUPPLIERS"], "result_rows": 3, "approx_prompt_tokens": 2658, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 CHECKRUN_ID NUMBER, -- Payment process request identifier.\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 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 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 SOURCE VARCHAR2(80), -- How the invoice entered the system. Values: MANUAL, IMPORT, SUPPLIER PORTAL, EMAIL.\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 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 ALWAYS_TAKE_DISC_FLAG VARCHAR2(1), -- Y if the early-payment discount is always taken.\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-- 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_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-- 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 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 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 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-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n-- voided payment => AP_CHECKS_ALL.STATUS_LOOKUP_CODE = 'VOIDED'\n-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n"}, {"role": "user", "content": "Question: Which suppliers have a credit memo as well as a wire payment?"}, {"role": "assistant", "content": "```sql\nSELECT DISTINCT s.VENDOR_NAME\nFROM POZ_SUPPLIERS s\nWHERE EXISTS (SELECT 1 FROM AP_INVOICES_ALL i WHERE i.VENDOR_ID = s.VENDOR_ID AND i.INVOICE_TYPE_LOOKUP_CODE = 'CREDIT')\nAND EXISTS (SELECT 1 FROM AP_CHECKS_ALL c WHERE c.VENDOR_ID = s.VENDOR_ID AND c.PAYMENT_METHOD_CODE = 'WIRE')\nORDER BY s.VENDOR_NAME;\n```"}], "meta": {"id": "a-01517", "tier": "T4", "family": "t4-logic", "kind": "ask", "source": "S2-templated", "group": "2363c68859e3", "tables": ["AP_CHECKS_ALL", "AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 6, "approx_prompt_tokens": 3041, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 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-- 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 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-- 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 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 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-- 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-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: Average days to pay for payments made this year"}, {"role": "assistant", "content": "```sql\nSELECT ROUND(AVG(c.CHECK_DATE - i.INVOICE_DATE), 1) AS AVG_DAYS_TO_PAY\nFROM AP_INVOICE_PAYMENTS_ALL ip\nJOIN AP_CHECKS_ALL c ON c.CHECK_ID = ip.CHECK_ID\nJOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ip.INVOICE_ID\nWHERE c.STATUS_LOOKUP_CODE <> 'VOIDED'\nAND c.CHECK_DATE >= TRUNC(SYSDATE, 'YYYY');\n```"}], "meta": {"id": "a-00864", "tier": "T3", "family": "t3-days-to-pay", "kind": "ask", "source": "S2-templated", "group": "c729a454ac69", "tables": ["AP_CHECKS_ALL", "AP_INVOICES_ALL", "AP_INVOICE_PAYMENTS_ALL"], "result_rows": 1, "approx_prompt_tokens": 3139, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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 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-- 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 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 CANCELLED_BY VARCHAR2(64) -- User who cancelled the invoice.\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-- 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 PAYMENT_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\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 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_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-- 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-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n"}, {"role": "user", "content": "Question: What is the count of unpaid installments for each supplier city that came due in the last 90 days?"}, {"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.DUE_DATE >= TRUNC(SYSDATE) - 90\nGROUP BY a.CITY\nORDER BY OPEN_INSTALLMENTS DESC;\n```"}], "meta": {"id": "a-01189", "tier": "T3", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "1c0beefe4314", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 7, "approx_prompt_tokens": 3044, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 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-- 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 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 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 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-- 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 CASH_POSTED_FLAG VARCHAR2(1), -- Y if cash-basis accounting entries were created.\n MATCHED_UOM_LOOKUP_CODE VARCHAR2(25), -- Unit of measure of the matched quantity. Values: EA, HR, KG, BOX.\n QUANTITY_INVOICED NUMBER, -- Quantity billed for the distribution.\n UNIT_PRICE NUMBER(18,2), -- Unit price on the distribution.\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 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-- Currencies: ISO currency codes with names, symbols and decimal precision.\nCREATE TABLE FND_CURRENCIES (\n CURRENCY_CODE VARCHAR2(15), -- ISO 4217 currency code. Values: USD, EUR, GBP, JPY, CAD, AUD, CHF, INR, SGD, CNY. Primary key.\n NAME VARCHAR2(80), -- Currency name. Values: US Dollar, Euro, Pound Sterling, Yen, Canadian Dollar, Australian Dollar, Swiss Franc, Indian Rupee, Singapore Dollar, Yuan Renminbi.\n ISSUING_TERRITORY_CODE VARCHAR2(2), -- Country that issues the currency. Values: US, DE, GB, JP, CA, AU, CH, IN, SG, CN.\n PRECISION NUMBER, -- Number of decimal places the currency uses.\n SYMBOL VARCHAR2(4), -- Currency symbol.\n ENABLED_FLAG VARCHAR2(1), -- Y if the currency is enabled for transactions.\n START_DATE_ACTIVE DATE, -- Date the currency becomes active.\n END_DATE_ACTIVE DATE, -- Date the currency stops being active.\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-- Business glossary (how analysts phrase common conditions):\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: Show the invoice total per currency"}, {"role": "assistant", "content": "```sql\nSELECT i.INVOICE_CURRENCY_CODE, SUM(i.INVOICE_AMOUNT) AS TOTAL_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nGROUP BY i.INVOICE_CURRENCY_CODE\nORDER BY TOTAL_INVOICE_AMOUNT DESC;\n```"}], "meta": {"id": "a-00074", "tier": "T1", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "bff28ea90c79", "tables": ["AP_INVOICES_ALL"], "result_rows": 10, "approx_prompt_tokens": 2982, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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-- 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 CASH_POSTED_FLAG VARCHAR2(1), -- Y if cash-basis 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 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 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 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 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-- 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 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-- 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-- 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: Running total of invoiced amount by month for this year"}, {"role": "assistant", "content": "```sql\nSELECT m, amt, SUM(amt) OVER (ORDER BY m) FROM (SELECT TRUNC(INVOICE_DATE, 'MM') m, SUM(INVOICE_AMOUNT) amt FROM AP_INVOICES_ALL WHERE INVOICE_DATE >= TRUNC(SYSDATE, 'YYYY') GROUP BY TRUNC(INVOICE_DATE, 'MM'));\n```"}], "meta": {"id": "p-010", "tier": "T4", "family": "pilot-gold", "kind": "ask", "source": "S1-golden", "group": "b0b368ddfb8f", "tables": ["AP_INVOICES_ALL"], "result_rows": 9, "approx_prompt_tokens": 2967, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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 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_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 CHECKRUN_ID NUMBER, -- Payment process request identifier.\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-- 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 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 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-- 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-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND 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: Suppliers that have both an active hold and an overdue installment"}, {"role": "assistant", "content": "```sql\nSELECT s.VENDOR_NAME FROM POZ_SUPPLIERS s WHERE s.VENDOR_ID IN (SELECT i.VENDOR_ID FROM AP_HOLDS_ALL h JOIN AP_INVOICES_ALL i ON i.INVOICE_ID = h.INVOICE_ID WHERE h.RELEASE_DATE IS NULL) AND s.VENDOR_ID IN (SELECT i.VENDOR_ID FROM AP_PAYMENT_SCHEDULES_ALL ps JOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ps.INVOICE_ID WHERE ps.DUE_DATE < TRUNC(SYSDATE) AND ps.AMOUNT_REMAINING > 0);\n```"}], "meta": {"id": "p-011", "tier": "T4", "family": "pilot-gold", "kind": "ask", "source": "S1-golden", "group": "4a6d7571e6d3", "tables": ["AP_HOLDS_ALL", "AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "POZ_SUPPLIERS"], "result_rows": 8, "approx_prompt_tokens": 3122, "context_complete": false, "missing_tables": ["POZ_SUPPLIERS"], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 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 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 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 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 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 ALWAYS_TAKE_DISC_FLAG VARCHAR2(1), -- Y if the early-payment discount is always taken.\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-- 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 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-- 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_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 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 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 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-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n-- voided payment => AP_CHECKS_ALL.STATUS_LOOKUP_CODE = 'VOIDED'\n-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n"}, {"role": "user", "content": "Question: Which suppliers have a credit memo but not a wire payment?"}, {"role": "assistant", "content": "```sql\nSELECT DISTINCT s.VENDOR_NAME\nFROM POZ_SUPPLIERS s\nWHERE EXISTS (SELECT 1 FROM AP_INVOICES_ALL i WHERE i.VENDOR_ID = s.VENDOR_ID AND i.INVOICE_TYPE_LOOKUP_CODE = 'CREDIT')\nAND NOT EXISTS (SELECT 1 FROM AP_CHECKS_ALL c WHERE c.VENDOR_ID = s.VENDOR_ID AND c.PAYMENT_METHOD_CODE = 'WIRE')\nORDER BY s.VENDOR_NAME;\n```"}], "meta": {"id": "a-01470", "tier": "T4", "family": "t4-logic", "kind": "ask", "source": "S2-templated", "group": "b57a5ff332d6", "tables": ["AP_CHECKS_ALL", "AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 1, "approx_prompt_tokens": 3032, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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 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-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n"}, {"role": "user", "content": "Question: What is the remaining balance and due date of invoice INV-2025-5022?"}, {"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-2025-5022'\nORDER BY ps.PAYMENT_NUM;\n```"}], "meta": {"id": "a-00576", "tier": "T2", "family": "t2-invoice-lookup", "kind": "ask", "source": "S2-templated", "group": "ef1efb14cdbc", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL"], "result_rows": 1, "approx_prompt_tokens": 2712, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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 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 PO_HEADER_ID NUMBER, -- Purchase order the invoice is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\n VALIDATION_STATUS VARCHAR2(25), -- Result of invoice validation. Values: VALIDATED, NEEDS REVALIDATION, NEVER VALIDATED.\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);\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 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 DEFAULT_DIST_CCID NUMBER, -- Default account used to distribute the line. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_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 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_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 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-- 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 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-- 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 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 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 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-- three-way match failure => AP_HOLDS_ALL.HOLD_LOOKUP_CODE IN ('QTY VARIANCE', 'PRICE VARIANCE', 'MISSING RECEIPT')\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-- duplicate invoice => AP_HOLDS_ALL.HOLD_LOOKUP_CODE = 'DUPLICATE INVOICE'\n-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n"}, {"role": "user", "content": "Question: List the suppliers with invoices failing three-way match"}, {"role": "assistant", "content": "```sql\nSELECT DISTINCT s.VENDOR_NAME\nFROM AP_INVOICES_ALL i\nJOIN POZ_SUPPLIERS s ON s.VENDOR_ID = i.VENDOR_ID\nWHERE i.INVOICE_ID IN (SELECT h.INVOICE_ID FROM AP_HOLDS_ALL h WHERE h.HOLD_LOOKUP_CODE IN ('QTY VARIANCE', 'PRICE VARIANCE', 'MISSING RECEIPT'))\nORDER BY s.VENDOR_NAME;\n```"}], "meta": {"id": "a-01680", "tier": "T5", "family": "t5-glossary", "kind": "ask", "source": "S2-templated", "group": "db34f4875d99", "tables": ["AP_HOLDS_ALL", "AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 6, "approx_prompt_tokens": 2879, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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_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 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 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_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-- 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 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 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-- 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_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 AMOUNT_PAID NUMBER(18,2), -- Amount of the invoice already paid.\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 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 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: Show the 5 business units with the highest average payment amount 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\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00528", "tier": "T2", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "58075b6e0eb6", "tables": ["AP_CHECKS_ALL", "FUN_BUSINESS_UNITS"], "result_rows": 5, "approx_prompt_tokens": 3085, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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 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 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 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-- 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_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 PO_LINE_ID NUMBER, -- Purchase order line this line is matched to. FK to PO_LINES_ALL.PO_LINE_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 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-- 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 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_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-- 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 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 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-- 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"}, {"role": "user", "content": "Question: How many invoices from Vandelay Imports are over 5,000?"}, {"role": "assistant", "content": "```sql\nSELECT COUNT(*)\nFROM AP_INVOICES_ALL i\nJOIN POZ_SUPPLIERS s ON s.VENDOR_ID = i.VENDOR_ID\nWHERE s.VENDOR_NAME = 'Vandelay Imports'\nAND i.INVOICE_AMOUNT > 5000;\n```"}], "meta": {"id": "a-00706", "tier": "T2", "family": "t2-supplier-list", "kind": "ask", "source": "S2-templated", "group": "1027885e176d", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 1, "approx_prompt_tokens": 3126, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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 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-- 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 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 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);\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-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: Count the cancelled invoices"}, {"role": "assistant", "content": "```sql\nSELECT COUNT(*)\nFROM AP_INVOICES_ALL i\nWHERE i.CANCELLED_DATE IS NOT NULL;\n```"}], "meta": {"id": "a-01654", "tier": "T5", "family": "t5-glossary", "kind": "ask", "source": "S2-templated", "group": "36a916454ce2", "tables": ["AP_INVOICES_ALL"], "result_rows": 1, "approx_prompt_tokens": 2343, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- Currencies: ISO currency codes with names, symbols and decimal precision.\nCREATE TABLE FND_CURRENCIES (\n CURRENCY_CODE VARCHAR2(15), -- ISO 4217 currency code. Values: USD, EUR, GBP, JPY, CAD, AUD, CHF, INR, SGD, CNY. Primary key.\n NAME VARCHAR2(80), -- Currency name. Values: US Dollar, Euro, Pound Sterling, Yen, Canadian Dollar, Australian Dollar, Swiss Franc, Indian Rupee, Singapore Dollar, Yuan Renminbi.\n ISSUING_TERRITORY_CODE VARCHAR2(2), -- Country that issues the currency. Values: US, DE, GB, JP, CA, AU, CH, IN, SG, CN.\n PRECISION NUMBER, -- Number of decimal places the currency uses.\n SYMBOL VARCHAR2(4), -- Currency symbol.\n ENABLED_FLAG VARCHAR2(1), -- Y if the currency is enabled for transactions.\n START_DATE_ACTIVE DATE, -- Date the currency becomes active.\n END_DATE_ACTIVE DATE, -- Date the currency stops being active.\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-- 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 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 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 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 MATCH_TYPE VARCHAR2(25) -- How the line was matched. Values: ITEM_TO_PO, ITEM_TO_RECEIPT, NOT_MATCHED.\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-- Business glossary (how analysts phrase common conditions):\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: What is the total tax on invoices for each currency for standard invoices only?\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT i.CURRENCY_CODE, SUM(i.TOTAL_TAX_AMOUNT) AS TOTAL_TAX_AMOUNT FROM AP_INVOICES_ALL i WHERE i.INVOICE_TYPE_LOOKUP_CODE = 'STANDARD' GROUP BY i.CURRENCY_CODE ORDER BY TOTAL_TAX_AMOUNT DESC FETCH FIRST 200 ROWS ONLY;\nError: ORA-00904: \"I\".\"CURRENCY_CODE\": invalid identifier\nDiagnosis: None of your query's tables has a column meaning 'CURRENCY_CODE', but the schema has: FND_CURRENCIES.CURRENCY_CODE (ISO 4217 currency code. Values: USD, EUR, GBP, JPY, CAD, AUD, CHF, INR, SGD, CNY. Primary key.) Add that table to your query. I is AP_INVOICES_ALL, which has NO column named CURRENCY_CODE. 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: PAYMENT_CURRENCY_CODE, INVOICE_CURRENCY_CODE, CREATION_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.INVOICE_CURRENCY_CODE, SUM(i.TOTAL_TAX_AMOUNT) AS TOTAL_TAX_AMOUNT\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_TYPE_LOOKUP_CODE = 'STANDARD'\nGROUP BY i.INVOICE_CURRENCY_CODE\nORDER BY TOTAL_TAX_AMOUNT DESC;\n```"}], "meta": {"id": "r-00014", "tier": "T1", "family": "spec-inv", "kind": "repair-exec", "source": "S6-repair", "group": "728b453c9a18", "tables": ["AP_INVOICES_ALL"], "result_rows": 0, "approx_prompt_tokens": 3461, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"I\".\"CURRENCY_CODE\": invalid identifier", "split": "test"}} {"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-- 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-- 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-- 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-- 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_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_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-- 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 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_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 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-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND 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-- 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: How much is over 90 days past due?"}, {"role": "assistant", "content": "```sql\nSELECT SUM(ps.AMOUNT_REMAINING) AS TOTAL_OVERDUE\nFROM AP_PAYMENT_SCHEDULES_ALL ps\nWHERE ps.AMOUNT_REMAINING > 0\nAND TRUNC(SYSDATE) - ps.DUE_DATE > 90;\n```"}], "meta": {"id": "a-00962", "tier": "T3", "family": "t3-overdue-days", "kind": "ask", "source": "S2-templated", "group": "0880fa717465", "tables": ["AP_PAYMENT_SCHEDULES_ALL"], "result_rows": 1, "approx_prompt_tokens": 3124, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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 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 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-- 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-- Employees and contingent workers: person master with name, number, hire date, job, department, manager and business unit.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE PER_ALL_PEOPLE_F (\n PERSON_ID NUMBER, -- Unique person identifier. Primary key.\n PERSON_NUMBER VARCHAR2(30), -- Employee number.\n FIRST_NAME VARCHAR2(150), -- First name.\n LAST_NAME VARCHAR2(150), -- Last name.\n FULL_NAME VARCHAR2(240), -- Full display name.\n EMAIL_ADDRESS VARCHAR2(240), -- Work email address.\n HIRE_DATE DATE, -- Date the person was hired.\n EFFECTIVE_START_DATE DATE, -- Start of the effective-dated row.\n EFFECTIVE_END_DATE DATE, -- End of the effective-dated row.\n JOB_TITLE VARCHAR2(100), -- Job title. Values: AP CLERK, AP MANAGER, BUYER, CONTROLLER, ANALYST.\n DEPARTMENT_NAME VARCHAR2(100), -- Department. Values: FINANCE, PROCUREMENT, OPERATIONS.\n MANAGER_ID NUMBER, -- Person's manager. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n BUSINESS_UNIT_ID NUMBER, -- Business unit the person works in. FK to FUN_BUSINESS_UNITS.BU_ID.\n ASSIGNMENT_STATUS VARCHAR2(25), -- Employment status. Values: ACTIVE, INACTIVE.\n LOCATION VARCHAR2(80), -- Work location.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n\n"}, {"role": "user", "content": "Question: Which 5 business units have the highest total amount paid out in the last 6 months?\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT 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 >= ADD_MONTHS(CURDATE(), -6)\nGROUP BY bu.BU_NAME\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; 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, 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 >= ADD_MONTHS(TRUNC(SYSDATE), -6)\nGROUP BY bu.BU_NAME\nORDER BY TOTAL_PAYMENT_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "r-00088", "tier": "T3", "family": "spec-pay", "kind": "repair-exec", "source": "S6-repair", "group": "38c754386a93", "tables": ["AP_CHECKS_ALL", "FUN_BUSINESS_UNITS"], "result_rows": 0, "approx_prompt_tokens": 3303, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"CURDATE\": invalid identifier", "split": "test"}} {"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 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 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 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 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 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 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 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-- 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 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 RCV_TRANSACTION_ID NUMBER, -- Receipt transaction matched to. FK to RCV_TRANSACTIONS.TRANSACTION_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 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 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 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_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-- 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 credit memos with supplier name and invoice amount"}, {"role": "assistant", "content": "```sql\nSELECT i.INVOICE_NUM, s.VENDOR_NAME, i.INVOICE_DATE, i.INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN POZ_SUPPLIERS s ON s.VENDOR_ID = i.VENDOR_ID\nWHERE i.INVOICE_TYPE_LOOKUP_CODE = 'CREDIT'\nORDER BY i.INVOICE_AMOUNT DESC;\n```"}], "meta": {"id": "a-01706", "tier": "T5", "family": "t5-glossary", "kind": "ask", "source": "S2-templated", "group": "0e9656e29cdf", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 7, "approx_prompt_tokens": 3130, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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 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 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 CANCELLED_DATE DATE, -- Date the invoice was cancelled; NULL if not cancelled.\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_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 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 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-- 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-- unpaid / outstanding => 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-- 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"}, {"role": "user", "content": "Question: Which 5 business units have the highest amount still owed due this quarter?"}, {"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, 'Q')\nGROUP BY bu.BU_NAME\nORDER BY TOTAL_UNPAID_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-01183", "tier": "T3", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "688e7b61c993", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "FUN_BUSINESS_UNITS"], "result_rows": 5, "approx_prompt_tokens": 2958, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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_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);\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 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-- 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 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 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-- 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 SEGMENT1 VARCHAR2(30), -- Supplier number, the business-facing identifier.\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 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 CREATION_SOURCE VARCHAR2(30), -- Where the supplier record originated. Values: REGISTRATION, MANUAL, IMPORT.\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_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 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-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\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-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: Total unpaid amount by supplier state"}, {"role": "assistant", "content": "```sql\nSELECT a.STATE, SUM(ps.AMOUNT_REMAINING) FROM AP_PAYMENT_SCHEDULES_ALL ps JOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ps.INVOICE_ID JOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = i.VENDOR_ID WHERE ps.AMOUNT_REMAINING > 0 GROUP BY a.STATE;\n```"}], "meta": {"id": "p-004", "tier": "T2", "family": "pilot-gold", "kind": "ask", "source": "S1-golden", "group": "53043b7ee723", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 3, "approx_prompt_tokens": 3025, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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 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-- 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_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 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_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-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND 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-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: Top 5 payment methods by total installment amount that were due last month"}, {"role": "assistant", "content": "```sql\nSELECT i.PAYMENT_METHOD_CODE, 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\nWHERE ps.DUE_DATE >= ADD_MONTHS(TRUNC(SYSDATE, 'MM'), -1) AND ps.DUE_DATE < TRUNC(SYSDATE, 'MM')\nGROUP BY i.PAYMENT_METHOD_CODE\nORDER BY TOTAL_INSTALLMENT_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00884", "tier": "T3", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "699396cea256", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL"], "result_rows": 3, "approx_prompt_tokens": 2933, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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-- cancelled invoice => AP_INVOICES_ALL.CANCELLED_DATE IS NOT NULL\n-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\n"}, {"role": "user", "content": "Question: Which suppliers have a rejected invoice as well as an overdue installment?\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT DISTINCT s.VENDOR_NAME FROM POZ_SUPPLIERS s WHERE EXISTS(SELECT 1 FROM AP_INVOICES_ALL i WHERE i.VENDOR_ID = s.VENDOR_ID AND i.WFAPPROVAL_STATUS = 'REJECTED') AND EXISTS(SELECT 1 FROM AP_PAYMENT_SCHEDULES_ALL ps JOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ps.INVOICE_ID WHERE i.VENDOR_ID = s.VENDOR_ID AND ps.PAYMENT_DUE_DATE < TRUNC(SYSDATE, 'DD') AND ps.AMOUNT_REMAINING > 0) ORDER BY s.VENDOR_NAME FETCH FIRST 200 ROWS ONLY;\nError: ORA-00904: \"PS\".\"PAYMENT_DUE_DATE\": invalid identifier\nDiagnosis: PS is AP_PAYMENT_SCHEDULES_ALL, which has NO column named PAYMENT_DUE_DATE. Its columns are: 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. Closest names: PAYMENT_SCHEDULE_ID, PAYMENT_NUM, DUE_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 DISTINCT s.VENDOR_NAME\nFROM POZ_SUPPLIERS s\nWHERE EXISTS (SELECT 1 FROM AP_INVOICES_ALL i WHERE i.VENDOR_ID = s.VENDOR_ID AND i.WFAPPROVAL_STATUS = 'REJECTED')\nAND EXISTS (SELECT 1 FROM AP_PAYMENT_SCHEDULES_ALL ps JOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ps.INVOICE_ID WHERE i.VENDOR_ID = s.VENDOR_ID AND ps.DUE_DATE < TRUNC(SYSDATE) AND ps.AMOUNT_REMAINING > 0)\nORDER BY s.VENDOR_NAME;\n```"}], "meta": {"id": "r-00041", "tier": "T4", "family": "t4-logic", "kind": "repair-exec", "source": "S6-repair", "group": "4805eb6a16ed", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "POZ_SUPPLIERS"], "result_rows": 0, "approx_prompt_tokens": 3406, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"PS\".\"PAYMENT_DUE_DATE\": invalid identifier", "split": "test"}} {"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 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);\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 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);\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 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-- 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 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 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-- 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-- Business glossary (how analysts phrase common conditions):\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-- 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 states with the highest number of payments for EFT payments only"}, {"role": "assistant", "content": "```sql\nSELECT a.STATE, 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.STATE\nORDER BY PAYMENT_COUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00770", "tier": "T2", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "c295f8168c89", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 3, "approx_prompt_tokens": 2976, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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_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 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-- 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 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-- 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_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_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_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_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);\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-- 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"}, {"role": "user", "content": "Question: How many reconciled payments are there?"}, {"role": "assistant", "content": "```sql\nSELECT COUNT(*)\nFROM AP_CHECKS_ALL\nWHERE STATUS_LOOKUP_CODE = 'RECONCILED';\n```"}], "meta": {"id": "a-00141", "tier": "T1", "family": "t1-count", "kind": "ask", "source": "S2-templated", "group": "c8e04a008d18", "tables": ["AP_CHECKS_ALL"], "result_rows": 1, "approx_prompt_tokens": 3140, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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-- 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-- 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 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 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-- 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-- 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: Top 5 payment methods by total payments 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\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00087", "tier": "T1", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "174a8c39f2ed", "tables": ["AP_CHECKS_ALL"], "result_rows": 3, "approx_prompt_tokens": 2870, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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_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-- 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 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 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 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-- 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-- early payment discount => AP_PAYMENT_SCHEDULES_ALL.DISCOUNT_AMOUNT_AVAILABLE > 0\n"}, {"role": "user", "content": "Question: Total scheduled installment amount by payment method for USD invoices only"}, {"role": "assistant", "content": "```sql\nSELECT i.PAYMENT_METHOD_CODE, 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\nWHERE i.INVOICE_CURRENCY_CODE = 'USD'\nGROUP BY i.PAYMENT_METHOD_CODE\nORDER BY TOTAL_INSTALLMENT_AMOUNT DESC;\n```"}], "meta": {"id": "a-00753", "tier": "T2", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "c71185fd984b", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL"], "result_rows": 3, "approx_prompt_tokens": 2813, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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 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 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 INT_BANK_ACCOUNT_ID NUMBER, -- Company bank account used. FK to CE_BANK_ACCOUNTS.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-- 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-- 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-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: Give me the average payment over the last year."}, {"role": "assistant", "content": "```sql\nSELECT AVG(c.AMOUNT) AS AVG_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nWHERE c.CHECK_DATE >= ADD_MONTHS(TRUNC(SYSDATE), -12);\n```"}], "meta": {"id": "a-01090", "tier": "T3", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "49cdd292b1b0", "tables": ["AP_CHECKS_ALL"], "result_rows": 1, "approx_prompt_tokens": 3054, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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 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 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-- 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-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: Give me the average payment over the last year.\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT AVG(c.AMOUNT) AS AVG_PAYMENT_AMOUNT FROM AP_CHECKS_ALL c WHERE c.CHECK_DATE >= ADD_MONTHS(TRUNC(NOW(), 'DD'), -12) 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_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.\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 AVG(c.AMOUNT) AS AVG_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nWHERE c.CHECK_DATE >= ADD_MONTHS(TRUNC(SYSDATE), -12);\n```"}], "meta": {"id": "r-00091", "tier": "T3", "family": "spec-pay", "kind": "repair-exec", "source": "S6-repair", "group": "49cdd292b1b0", "tables": ["AP_CHECKS_ALL"], "result_rows": 0, "approx_prompt_tokens": 3184, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"NOW\": invalid identifier", "split": "test"}} {"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 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 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 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-- 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 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-- 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 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 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 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-- 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 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 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);\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 payments over 10,000"}, {"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.AMOUNT > 10000\nGROUP BY a.STATE\nORDER BY TOTAL_PAYMENT_AMOUNT DESC;\n```"}], "meta": {"id": "a-00761", "tier": "T2", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "d5f74fd331d8", "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": "test"}} {"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-- 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 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 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 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-- 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 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 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-- 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 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 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 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 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: Show the total payments per business unit"}, {"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\nGROUP BY bu.BU_NAME\nORDER BY TOTAL_PAYMENT_AMOUNT DESC;\n```"}], "meta": {"id": "a-00717", "tier": "T2", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "51fab9e701d0", "tables": ["AP_CHECKS_ALL", "FUN_BUSINESS_UNITS"], "result_rows": 10, "approx_prompt_tokens": 2611, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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_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_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 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-- 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 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 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 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-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: Show the total invoice amount per payment method for invoices over 10,000"}, {"role": "assistant", "content": "```sql\nSELECT i.PAYMENT_METHOD_CODE, SUM(i.INVOICE_AMOUNT) AS TOTAL_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_AMOUNT > 10000\nGROUP BY i.PAYMENT_METHOD_CODE\nORDER BY TOTAL_INVOICE_AMOUNT DESC;\n```"}], "meta": {"id": "a-00080", "tier": "T1", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "158b31494c72", "tables": ["AP_INVOICES_ALL"], "result_rows": 3, "approx_prompt_tokens": 3156, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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_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 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);\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 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_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 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 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 CANCELLED_DATE DATE -- Date the invoice was cancelled; NULL if not 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 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-- 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-- 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"}, {"role": "user", "content": "Question: Which 5 supplier states have the highest total early-payment discount available due in the next 90 days?"}, {"role": "assistant", "content": "```sql\nSELECT a.STATE, 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 POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = i.VENDOR_ID\nWHERE ps.DISCOUNT_AMOUNT_AVAILABLE > 0 AND ps.DUE_DATE BETWEEN TRUNC(SYSDATE) AND TRUNC(SYSDATE) + 90\nGROUP BY a.STATE\nORDER BY TOTAL_DISCOUNT_AVAILABLE DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-01053", "tier": "T3", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "34753b4d381a", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 2, "approx_prompt_tokens": 2951, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 CANCELLED_DATE DATE -- Date the invoice was cancelled; NULL if not cancelled.\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-- 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 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 MATCH_TYPE VARCHAR2(25) -- How the line was matched. Values: ITEM_TO_PO, ITEM_TO_RECEIPT, NOT_MATCHED.\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_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 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);\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 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 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 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-- 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"}, {"role": "user", "content": "Question: Show the total paid against invoices per supplier excluding cancelled invoices"}, {"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.CANCELLED_DATE IS NULL\nGROUP BY s.VENDOR_NAME\nORDER BY TOTAL_AMOUNT_PAID DESC;\n```"}], "meta": {"id": "a-00716", "tier": "T2", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "d35e9a072aac", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 9, "approx_prompt_tokens": 2771, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 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 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 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 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 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 MATCHED_UOM_LOOKUP_CODE VARCHAR2(25), -- Unit of measure of the matched quantity. Values: EA, HR, KG, BOX.\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 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 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-- 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 STATUS_LOOKUP_CODE VARCHAR2(25), -- Payment status. Values: NEGOTIABLE, RECONCILED, VOIDED, CLEARED.\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 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-- Business glossary (how analysts phrase common conditions):\n\n"}, {"role": "user", "content": "Question: What is the total invoice amount by currency?"}, {"role": "assistant", "content": "```sql\nSELECT INVOICE_CURRENCY_CODE, SUM(INVOICE_AMOUNT) FROM AP_INVOICES_ALL GROUP BY INVOICE_CURRENCY_CODE;\n```"}], "meta": {"id": "p-001", "tier": "T1", "family": "pilot-gold", "kind": "ask", "source": "S1-golden", "group": "27a4da3993ce", "tables": ["AP_INVOICES_ALL"], "result_rows": 10, "approx_prompt_tokens": 2997, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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_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_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\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);\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 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 SETTLEMENT_DATE DATE, -- Date funds settled.\n VOID_DATE DATE, -- Date the payment was voided.\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-- 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: How did payments change from one month to the next this year?"}, {"role": "assistant", "content": "```sql\nSELECT MONTH_START, TOTAL_PAYMENT_AMOUNT, TOTAL_PAYMENT_AMOUNT - LAG(TOTAL_PAYMENT_AMOUNT) OVER (ORDER BY MONTH_START) AS CHANGE_FROM_PREVIOUS_MONTH\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 >= TRUNC(SYSDATE, 'YYYY')\n GROUP BY TRUNC(c.CHECK_DATE, 'MM')\n)\nORDER BY MONTH_START;\n```"}], "meta": {"id": "a-01365", "tier": "T4", "family": "t4-mom", "kind": "ask", "source": "S2-templated", "group": "4c1dfc44127a", "tables": ["AP_CHECKS_ALL"], "result_rows": 9, "approx_prompt_tokens": 2907, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number of the payment.\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 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 CREDIT_LIMIT_AMOUNT NUMBER(18,2), -- Maximum credit extended to the supplier.\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 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 TOLERANCE_ID NUMBER, -- Matching tolerance applied at the site.\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 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 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 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-- 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 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 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 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_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-- 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-- 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: For each supplier, show the largest payment"}, {"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.AMOUNT DESC) AS RN\n FROM AP_CHECKS_ALL c\n JOIN POZ_SUPPLIERS s ON s.VENDOR_ID = c.VENDOR_ID\n)\nWHERE RN <= 1\nORDER BY VENDOR_NAME, RN;\n```"}], "meta": {"id": "a-01421", "tier": "T4", "family": "t4-topk", "kind": "ask", "source": "S2-templated", "group": "10bb5de6c13f", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIERS"], "result_rows": 9, "approx_prompt_tokens": 3146, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 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-- 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 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);\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-- 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 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 RISK_RATING VARCHAR2(25) -- Internal supplier risk rating. Values: LOW, MEDIUM, HIGH.\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 supplier cities have the highest average payment amount for EFT payments only?"}, {"role": "assistant", "content": "```sql\nSELECT a.CITY, 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.PAYMENT_METHOD_CODE = 'EFT'\nGROUP BY a.CITY\nORDER BY AVG_PAYMENT_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00795", "tier": "T2", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "342722b01113", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 5, "approx_prompt_tokens": 2911, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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);\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 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 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_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 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-- 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 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 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-- 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 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_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-- 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: Invoice count by supplier for invoices in a foreign currency"}, {"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;\n```"}], "meta": {"id": "a-00824", "tier": "T2", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "90625efef453", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 9, "approx_prompt_tokens": 3110, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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-- 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"}, {"role": "user", "content": "Question: What is the largest invoice amount for each supplier city for standard invoices only?\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT a.CITY, MAX(i.TOTAL_AMOUNT) AS MAX_INVOICE_AMOUNT FROM AP_INVOICES_ALL i JOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = i.VENDOR_ID WHERE i.INVOICE_TYPE_LOOKUP_CODE = 'STANDARD' GROUP BY a.CITY ORDER BY MAX_INVOICE_AMOUNT DESC FETCH FIRST 200 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 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_TYPE_LOOKUP_CODE = 'STANDARD'\nGROUP BY a.CITY\nORDER BY MAX_INVOICE_AMOUNT DESC;\n```"}], "meta": {"id": "r-00005", "tier": "T2", "family": "spec-inv", "kind": "repair-exec", "source": "S6-repair", "group": "59aee88be61e", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 0, "approx_prompt_tokens": 3497, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"I\".\"TOTAL_AMOUNT\": invalid identifier", "split": "test"}} {"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-- 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-- 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: Top 3 suppliers by number of overdue invoices\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT 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_ID IN (SELECT ps.INVOICE_ID FROM AP_PAYMENT_SCHEDULES_ALL ps WHERE ps.DUE_DATE < TRUNC(SYSDATE) AND ps.AMOUNT_DUE > 0)\nGROUP BY s.VENDOR_NAME\nORDER BY INVOICE_COUNT DESC\nFETCH FIRST 3 ROWS ONLY;\nError: ORA-00904: \"PS\".\"AMOUNT_DUE\": invalid identifier\nDiagnosis: PS is AP_PAYMENT_SCHEDULES_ALL, which has NO column named AMOUNT_DUE. Its columns are: 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. Closest names: AMOUNT_REMAINING, DISCOUNT_DATE, PAYMENT_NUM.\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, COUNT(*) AS INVOICE_COUNT\nFROM AP_INVOICES_ALL i\nJOIN POZ_SUPPLIERS s ON s.VENDOR_ID = i.VENDOR_ID\nWHERE i.INVOICE_ID IN (SELECT ps.INVOICE_ID FROM AP_PAYMENT_SCHEDULES_ALL ps WHERE ps.DUE_DATE < TRUNC(SYSDATE) AND ps.AMOUNT_REMAINING > 0)\nGROUP BY s.VENDOR_NAME\nORDER BY INVOICE_COUNT DESC\nFETCH FIRST 3 ROWS ONLY;\n```"}], "meta": {"id": "r-00031", "tier": "T5", "family": "t5-glossary", "kind": "repair-exec", "source": "S6-repair", "group": "49249275c21c", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "POZ_SUPPLIERS"], "result_rows": 0, "approx_prompt_tokens": 3336, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"PS\".\"AMOUNT_DUE\": invalid identifier", "split": "test"}} {"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 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 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 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 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-- 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 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 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 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 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 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-- 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: Which suppliers have been paid more than 10,000 in total?"}, {"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) > 10000\nORDER BY TOTAL_PAYMENT_AMOUNT DESC;\n```"}], "meta": {"id": "a-00452", "tier": "T2", "family": "t2-having", "kind": "ask", "source": "S2-templated", "group": "a2db37210676", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIERS"], "result_rows": 9, "approx_prompt_tokens": 2499, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 SOURCE VARCHAR2(80), -- How the invoice entered the system. Values: MANUAL, IMPORT, SUPPLIER PORTAL, EMAIL.\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 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-- 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 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_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 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-- 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 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 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-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: Suppliers with over 3 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\nGROUP BY s.VENDOR_NAME\nHAVING COUNT(*) > 3\nORDER BY INVOICE_COUNT DESC;\n```"}], "meta": {"id": "a-00468", "tier": "T2", "family": "t2-having", "kind": "ask", "source": "S2-templated", "group": "9b58246624bd", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 9, "approx_prompt_tokens": 2881, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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-- 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 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 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 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_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 PO_HEADER_ID NUMBER -- Purchase order the invoice is matched to. FK to PO_HEADERS_ALL.PO_HEADER_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-- 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-- 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-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: Average payment amount by payment status this month"}, {"role": "assistant", "content": "```sql\nSELECT c.STATUS_LOOKUP_CODE, AVG(c.AMOUNT) AS AVG_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nWHERE c.CHECK_DATE >= TRUNC(SYSDATE, 'MM')\nGROUP BY c.STATUS_LOOKUP_CODE\nORDER BY AVG_PAYMENT_AMOUNT DESC;\n```"}], "meta": {"id": "a-01066", "tier": "T3", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "b9e2e0a6f5cc", "tables": ["AP_CHECKS_ALL"], "result_rows": 3, "approx_prompt_tokens": 3150, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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 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_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);\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-- 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_MEAS_LOOKUP_CODE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\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 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-- 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_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 CANCEL_FLAG VARCHAR2(1), -- Y if the tax line was cancelled.\n TAX_STATUS_CODE VARCHAR2(30), -- Tax status applied. Values: STANDARD, REDUCED, ZERO.\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 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 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 APPROVED_DATE DATE, -- Date the order was approved.\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-- 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 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 SELF_ASSESSED_TAX_AMOUNT NUMBER(18,2), -- Tax the buyer self-assesses instead of paying to the supplier.\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 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);\n\n-- Business glossary (how analysts phrase common conditions):\n\n"}, {"role": "user", "content": "Question: Total freight line amount"}, {"role": "assistant", "content": "```sql\nSELECT SUM(l.AMOUNT)\nFROM AP_INVOICE_LINES_ALL l\nWHERE l.LINE_TYPE_LOOKUP_CODE = 'FREIGHT';\n```"}], "meta": {"id": "a-00397", "tier": "T2", "family": "t2-lines", "kind": "ask", "source": "S2-templated", "group": "ed8a198af974", "tables": ["AP_INVOICE_LINES_ALL"], "result_rows": 1, "approx_prompt_tokens": 2863, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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 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-- 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 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 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 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-- 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-- 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: top 10 states with highest payment amounts due in next 1 yr"}, {"role": "assistant", "content": "```sql\nSELECT a.STATE, SUM(ps.AMOUNT_REMAINING) FROM AP_PAYMENT_SCHEDULES_ALL ps JOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ps.INVOICE_ID JOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = i.VENDOR_ID WHERE ps.DUE_DATE BETWEEN SYSDATE AND SYSDATE + INTERVAL '1' YEAR AND ps.AMOUNT_REMAINING > 0 GROUP BY a.STATE ORDER BY 2 DESC FETCH FIRST 10 ROWS ONLY;\n```"}], "meta": {"id": "p-005", "tier": "T2", "family": "pilot-gold", "kind": "ask", "source": "S1-golden", "group": "2f328649b4de", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 3, "approx_prompt_tokens": 3012, "context_complete": false, "missing_tables": ["AP_INVOICES_ALL"], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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 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 CLEARED_DATE DATE, -- Date the payment cleared the bank.\n CLEARED_AMOUNT NUMBER(18,2), -- Amount that cleared the bank.\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_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 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_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-- 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-- 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-- early payment discount => AP_PAYMENT_SCHEDULES_ALL.DISCOUNT_AMOUNT_AVAILABLE > 0\n"}, {"role": "user", "content": "Question: Show the 5 payment statuses with the highest average payment amount"}, {"role": "assistant", "content": "```sql\nSELECT c.STATUS_LOOKUP_CODE, AVG(c.AMOUNT) AS AVG_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nGROUP BY c.STATUS_LOOKUP_CODE\nORDER BY AVG_PAYMENT_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00057", "tier": "T1", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "1f554c74a61f", "tables": ["AP_CHECKS_ALL"], "result_rows": 4, "approx_prompt_tokens": 3112, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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-- 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-- 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 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 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 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 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);\n\n-- Business glossary (how analysts phrase common conditions):\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n-- early payment discount => AP_PAYMENT_SCHEDULES_ALL.DISCOUNT_AMOUNT_AVAILABLE > 0\n"}, {"role": "user", "content": "Question: Which 5 payment methods have the highest largest unpaid installment?"}, {"role": "assistant", "content": "```sql\nSELECT i.PAYMENT_METHOD_CODE, MAX(ps.AMOUNT_REMAINING) AS MAX_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\nGROUP BY i.PAYMENT_METHOD_CODE\nORDER BY MAX_UNPAID_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00630", "tier": "T2", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "5859b2b37ad3", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL"], "result_rows": 3, "approx_prompt_tokens": 3146, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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_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 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 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 DOC_SEQUENCE_VALUE NUMBER, -- Document sequence number assigned to the invoice.\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 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 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 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 INCOME_TAX_REGION VARCHAR2(10), -- Region used for income-tax reporting.\n DESCRIPTION VARCHAR2(240), -- Distribution description.\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-- 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-- Business glossary (how analysts phrase common conditions):\n-- unvalidated invoice => AP_INVOICES_ALL.VALIDATION_STATUS <> 'VALIDATED'\n"}, {"role": "user", "content": "Question: Count the distinct invoice sources"}, {"role": "assistant", "content": "```sql\nSELECT COUNT(DISTINCT SOURCE)\nFROM AP_INVOICES_ALL;\n```"}], "meta": {"id": "a-00019", "tier": "T1", "family": "t1-distinct", "kind": "ask", "source": "S2-templated", "group": "ba89240a8b1b", "tables": ["AP_INVOICES_ALL"], "result_rows": 1, "approx_prompt_tokens": 2985, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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-- 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 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 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-- 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 VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\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 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 ACCTS_PAY_CODE_COMBINATION_ID NUMBER -- Liability (accounts payable) account for the invoice. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_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-- 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-- 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-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: Largest payment amount across payments that are still negotiable"}, {"role": "assistant", "content": "```sql\nSELECT MAX(AMOUNT)\nFROM AP_CHECKS_ALL\nWHERE STATUS_LOOKUP_CODE = 'NEGOTIABLE';\n```"}], "meta": {"id": "a-00117", "tier": "T1", "family": "t1-agg", "kind": "ask", "source": "S2-templated", "group": "9f1f4fa102cb", "tables": ["AP_CHECKS_ALL"], "result_rows": 1, "approx_prompt_tokens": 3122, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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 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 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);\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 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 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 DOC_SEQUENCE_VALUE NUMBER -- Document sequence number assigned to the invoice.\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 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_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 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\n"}, {"role": "user", "content": "Question: Count the imported invoices."}, {"role": "assistant", "content": "```sql\nSELECT COUNT(*)\nFROM AP_INVOICES_ALL\nWHERE SOURCE = 'IMPORT';\n```"}], "meta": {"id": "a-00032", "tier": "T1", "family": "t1-count", "kind": "ask", "source": "S2-templated", "group": "aa759eae1eda", "tables": ["AP_INVOICES_ALL"], "result_rows": 1, "approx_prompt_tokens": 2930, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- Payments engine records: each payment with payee, amount, status, method and the instruction that carried it.\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 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 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 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-- 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 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-- 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-- 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 10 payment methods have the highest number of payments?\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT c.PAYMENT_METHOD, COUNT(*) AS PAYMENT_COUNT\nFROM AP_CHECKS_ALL c\nGROUP BY c.PAYMENT_METHOD\nORDER BY PAYMENT_COUNT DESC\nFETCH FIRST 10 ROWS ONLY;\nError: ORA-00904: \"C\".\"PAYMENT_METHOD\": invalid identifier\nDiagnosis: None of your query's tables has a column meaning 'PAYMENT_METHOD', but the schema has: IBY_PAYMENTS_ALL.PAYMENT_METHOD_CODE (Payment method. Values: CHECK, EFT, WIRE.) Join it to your query on PAYMENT_ID. IBY_PAYMENTS_ALL.PAYMENT_AMOUNT (Payment amount.) Join it to your query on PAYMENT_ID. Add that table to your query. C is AP_CHECKS_ALL, which has NO column named PAYMENT_METHOD. 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_METHOD_CODE, PAYMENT_ID, PAYMENT_TYPE_FLAG.\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 c.PAYMENT_METHOD_CODE, COUNT(*) AS PAYMENT_COUNT\nFROM AP_CHECKS_ALL c\nGROUP BY c.PAYMENT_METHOD_CODE\nORDER BY PAYMENT_COUNT DESC\nFETCH FIRST 10 ROWS ONLY;\n```"}], "meta": {"id": "r-00038", "tier": "T1", "family": "spec-pay", "kind": "repair-exec", "source": "S6-repair", "group": "5ce2a9fc326b", "tables": ["AP_CHECKS_ALL"], "result_rows": 0, "approx_prompt_tokens": 3433, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"C\".\"PAYMENT_METHOD\": invalid identifier", "split": "test"}} {"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-- 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-- 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 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-- 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_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\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 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 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_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_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 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-- 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: What is the total early-payment discount available for each business unit due this year?"}, {"role": "assistant", "content": "```sql\nSELECT bu.BU_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 FUN_BUSINESS_UNITS bu ON bu.BU_ID = i.ORG_ID\nWHERE ps.DISCOUNT_AMOUNT_AVAILABLE > 0 AND ps.DUE_DATE >= TRUNC(SYSDATE, 'YYYY')\nGROUP BY bu.BU_NAME\nORDER BY TOTAL_DISCOUNT_AVAILABLE DESC;\n```"}], "meta": {"id": "a-01180", "tier": "T3", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "101beba2f2c1", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "FUN_BUSINESS_UNITS"], "result_rows": 6, "approx_prompt_tokens": 2819, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 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 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-- 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 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_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\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 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_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 ACCTS_PAY_CODE_COMBINATION_ID NUMBER, -- Liability (accounts payable) account for the invoice. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_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-- 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-- 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 number of payments that are still negotiable?"}, {"role": "assistant", "content": "```sql\nSELECT COUNT(*)\nFROM AP_CHECKS_ALL\nWHERE STATUS_LOOKUP_CODE = 'NEGOTIABLE';\n```"}], "meta": {"id": "a-00038", "tier": "T1", "family": "t1-count", "kind": "ask", "source": "S2-templated", "group": "8677d22bbd52", "tables": ["AP_CHECKS_ALL"], "result_rows": 1, "approx_prompt_tokens": 3161, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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 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-- 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-- 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_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_TYPE_FLAG VARCHAR2(1), -- Q quick payment, M manual payment, R payment batch. Values: R, M, Q.\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 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 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_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 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 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-- 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-- 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 installment amount for each supplier city for installments on hold?"}, {"role": "assistant", "content": "```sql\nSELECT a.CITY, 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 POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = i.VENDOR_ID\nWHERE ps.HOLD_FLAG = 'Y'\nGROUP BY a.CITY\nORDER BY TOTAL_INSTALLMENT_AMOUNT DESC;\n```"}], "meta": {"id": "a-00506", "tier": "T2", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "0c392f7befe1", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 5, "approx_prompt_tokens": 3009, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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_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 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-- 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-- 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 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_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 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 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 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-- 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\n"}, {"role": "user", "content": "Question: Number of payments by supplier city over the last year"}, {"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.CHECK_DATE >= ADD_MONTHS(TRUNC(SYSDATE), -12)\nGROUP BY a.CITY\nORDER BY PAYMENT_COUNT DESC;\n```"}], "meta": {"id": "a-00975", "tier": "T3", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "16ec1e0eaade", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 7, "approx_prompt_tokens": 2815, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 VALIDATION_STATUS VARCHAR2(25), -- Result of invoice validation. Values: VALIDATED, NEEDS REVALIDATION, NEVER VALIDATED.\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-- 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 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 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 16 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 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-- unvalidated invoice => AP_INVOICES_ALL.VALIDATION_STATUS <> 'VALIDATED'\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\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"}, {"role": "user", "content": "Question: Total amount paid on invoices by validation status this quarter"}, {"role": "assistant", "content": "```sql\nSELECT i.VALIDATION_STATUS, SUM(i.AMOUNT_PAID) AS TOTAL_AMOUNT_PAID\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_DATE >= TRUNC(SYSDATE, 'Q')\nGROUP BY i.VALIDATION_STATUS\nORDER BY TOTAL_AMOUNT_PAID DESC;\n```"}], "meta": {"id": "a-01008", "tier": "T3", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "791dc1354369", "tables": ["AP_INVOICES_ALL"], "result_rows": 3, "approx_prompt_tokens": 2924, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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);\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 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 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 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-- 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-- 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-- 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_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\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 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 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-- 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-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n-- early payment discount => AP_PAYMENT_SCHEDULES_ALL.DISCOUNT_AMOUNT_AVAILABLE > 0\n-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n"}, {"role": "user", "content": "Question: 5 payment methods with the lowest average payment amount"}, {"role": "assistant", "content": "```sql\nSELECT c.PAYMENT_METHOD_CODE, AVG(c.AMOUNT) AS AVG_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nGROUP BY c.PAYMENT_METHOD_CODE\nORDER BY AVG_PAYMENT_AMOUNT ASC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00008", "tier": "T1", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "675c2dd5595c", "tables": ["AP_CHECKS_ALL"], "result_rows": 3, "approx_prompt_tokens": 3110, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 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-- 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 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 VENDOR_SITE_ID NUMBER, -- Supplier site the invoice is payable to. FK to POZ_SUPPLIER_SITES_ALL_M.VENDOR_SITE_ID.\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_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-- 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-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n-- voided payment => AP_CHECKS_ALL.STATUS_LOOKUP_CODE = 'VOIDED'\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 total payment amount for each payment method excluding voided payments?"}, {"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 <> 'VOIDED'\nGROUP BY c.PAYMENT_METHOD_CODE\nORDER BY TOTAL_PAYMENT_AMOUNT DESC;\n```"}], "meta": {"id": "a-00148", "tier": "T1", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "a892a7b4a243", "tables": ["AP_CHECKS_ALL"], "result_rows": 3, "approx_prompt_tokens": 3164, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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-- 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-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: Which 5 payment terms have the highest invoice total for invoices in a foreign currency?\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT t.NAME, SUM(i.INVOICE_AMOUNT) AS TOTAL_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN AP_TERMS_B t ON t.TERM_ID = i.TERMS_ID\nWHERE i.INVOICE_CURRENCY_CODE <> 'USD'\nORDER BY TOTAL_INVOICE_AMOUNT DESC\nFETCH FIRST 5 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 t.NAME, SUM(i.INVOICE_AMOUNT) AS TOTAL_INVOICE_AMOUNT\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 TOTAL_INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "r-00056", "tier": "T2", "family": "spec-inv", "kind": "repair-exec", "source": "S6-repair", "group": "eb07b4dfe678", "tables": ["AP_INVOICES_ALL", "AP_TERMS_B"], "result_rows": 0, "approx_prompt_tokens": 3204, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00937: not a single-group group function", "split": "test"}} {"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_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 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 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 CANCELLED_DATE DATE -- Date the invoice was cancelled; NULL if not cancelled.\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-- 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 last year?"}, {"role": "assistant", "content": "```sql\nSELECT i.PAYMENT_METHOD_CODE, COUNT(*) AS INVOICE_COUNT\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_DATE >= ADD_MONTHS(TRUNC(SYSDATE, 'YYYY'), -12) AND i.INVOICE_DATE < TRUNC(SYSDATE, 'YYYY')\nGROUP BY i.PAYMENT_METHOD_CODE\nORDER BY INVOICE_COUNT DESC;\n```"}], "meta": {"id": "a-01038", "tier": "T3", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "f76d4fa29325", "tables": ["AP_INVOICES_ALL"], "result_rows": 3, "approx_prompt_tokens": 2852, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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 QUANTITY_INVOICED NUMBER, -- Quantity billed for the distribution.\n UNIT_PRICE NUMBER(18,2), -- Unit price on the distribution.\n REVERSAL_FLAG VARCHAR2(1), -- Y if this distribution reverses another.\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-- 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 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 PREPAY_INVOICE_ID NUMBER, -- Prepayment invoice applied on this line, if any.\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 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 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 CANCELLED_DATE DATE, -- Date the invoice was cancelled; NULL if not cancelled.\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-- 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-- 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: Percentage change in invoiced amount versus the previous month"}, {"role": "assistant", "content": "```sql\nSELECT MONTH_START, TOTAL_INVOICE_AMOUNT, ROUND(100 * (TOTAL_INVOICE_AMOUNT - LAG(TOTAL_INVOICE_AMOUNT) OVER (ORDER BY MONTH_START)) / NULLIF(LAG(TOTAL_INVOICE_AMOUNT) OVER (ORDER BY MONTH_START), 0), 1) AS PCT_CHANGE\nFROM (\n SELECT TRUNC(i.INVOICE_DATE, 'MM') AS MONTH_START, SUM(i.INVOICE_AMOUNT) AS TOTAL_INVOICE_AMOUNT\n FROM AP_INVOICES_ALL i\n GROUP BY TRUNC(i.INVOICE_DATE, 'MM')\n)\nORDER BY MONTH_START;\n```"}], "meta": {"id": "a-01351", "tier": "T4", "family": "t4-mom", "kind": "ask", "source": "S2-templated", "group": "3847ac9149ab", "tables": ["AP_INVOICES_ALL"], "result_rows": 14, "approx_prompt_tokens": 3018, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- Accounting calendar periods: period name, year, number, start and end dates and quarter.\nCREATE TABLE GL_PERIODS (\n PERIOD_ID NUMBER, -- Unique period identifier. Primary key.\n PERIOD_SET_NAME VARCHAR2(15), -- Calendar the period belongs to.\n PERIOD_NAME VARCHAR2(15), -- Period name such as JAN-26.\n PERIOD_YEAR NUMBER, -- Fiscal year of the period.\n PERIOD_NUM NUMBER, -- Period number within the year.\n QUARTER_NUM NUMBER, -- Fiscal quarter of the period.\n START_DATE DATE, -- First day of the period.\n END_DATE DATE, -- Last day of the period.\n PERIOD_TYPE VARCHAR2(15), -- Type of period.\n ADJUSTMENT_PERIOD_FLAG VARCHAR2(1), -- Y if the period is an adjusting period.\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 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 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 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);\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 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 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 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);\n\n-- Currencies: ISO currency codes with names, symbols and decimal precision.\nCREATE TABLE FND_CURRENCIES (\n CURRENCY_CODE VARCHAR2(15), -- ISO 4217 currency code. Values: USD, EUR, GBP, JPY, CAD, AUD, CHF, INR, SGD, CNY. Primary key.\n NAME VARCHAR2(80), -- Currency name. Values: US Dollar, Euro, Pound Sterling, Yen, Canadian Dollar, Australian Dollar, Swiss Franc, Indian Rupee, Singapore Dollar, Yuan Renminbi.\n ISSUING_TERRITORY_CODE VARCHAR2(2), -- Country that issues the currency. Values: US, DE, GB, JP, CA, AU, CH, IN, SG, CN.\n PRECISION NUMBER, -- Number of decimal places the currency uses.\n SYMBOL VARCHAR2(4), -- Currency symbol.\n ENABLED_FLAG VARCHAR2(1), -- Y if the currency is enabled for transactions.\n START_DATE_ACTIVE DATE, -- Date the currency becomes active.\n END_DATE_ACTIVE DATE, -- Date the currency stops being active.\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-- 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 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 LEDGER_ID NUMBER -- Ledger the combination belongs to. FK to GL_LEDGERS.LEDGER_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"}, {"role": "user", "content": "Recent conversation (for follow-up questions like 'now filter to APAC'):\nQ: Total invoiced by currency\nSQL: SELECT i.INVOICE_CURRENCY_CODE, SUM(i.INVOICE_AMOUNT) AS TOTAL_INVOICE_AMOUNT FROM AP_INVOICES_ALL i GROUP BY i.INVOICE_CURRENCY_CODE ORDER BY TOTAL_INVOICE_AMOUNT DESC FETCH FIRST 200 ROWS ONLY;\n\nQuestion: Now do the same this quarter"}, {"role": "assistant", "content": "```sql\nSELECT i.INVOICE_CURRENCY_CODE, SUM(i.INVOICE_AMOUNT) AS TOTAL_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_DATE >= TRUNC(SYSDATE, 'Q')\nGROUP BY i.INVOICE_CURRENCY_CODE\nORDER BY TOTAL_INVOICE_AMOUNT DESC;\n```"}], "meta": {"id": "a-01559", "tier": "T3", "family": "followup", "kind": "followup", "source": "S2-templated", "group": "e305ec535867", "tables": ["AP_INVOICES_ALL"], "result_rows": 6, "approx_prompt_tokens": 3100, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 VOID_DATE DATE, -- Date the payment was voided.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\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 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 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-- 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 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_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 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-- 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-- 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: Suppliers that have both a voided payment and a wire 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 AND c.PAYMENT_METHOD_CODE = 'WIRE')\nORDER BY s.VENDOR_NAME;\n```"}], "meta": {"id": "a-01556", "tier": "T4", "family": "t4-logic", "kind": "ask", "source": "S2-templated", "group": "671c3e72851f", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIERS"], "result_rows": 5, "approx_prompt_tokens": 2619, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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);\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 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-- 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-- 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 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 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 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 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-- 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-- cancelled invoice => AP_INVOICES_ALL.CANCELLED_DATE IS NOT NULL\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: Average invoice value by currency year to date"}, {"role": "assistant", "content": "```sql\nSELECT i.INVOICE_CURRENCY_CODE, AVG(i.INVOICE_AMOUNT) AS AVG_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_DATE >= TRUNC(SYSDATE, 'YYYY')\nGROUP BY i.INVOICE_CURRENCY_CODE\nORDER BY AVG_INVOICE_AMOUNT DESC;\n```"}], "meta": {"id": "a-01121", "tier": "T3", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "c2eeedb5715f", "tables": ["AP_INVOICES_ALL"], "result_rows": 10, "approx_prompt_tokens": 2848, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 SELF_ASSESSED_TAX_AMOUNT NUMBER(18,2), -- Tax the buyer self-assesses instead of paying to the supplier.\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 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 LEGAL_ENTITY_ID NUMBER, -- Legal entity the invoice belongs to.\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 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 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 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-- 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 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-- 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-- 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 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-- 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 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 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 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 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-- voided payment => AP_CHECKS_ALL.STATUS_LOOKUP_CODE = 'VOIDED'\n-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\n"}, {"role": "user", "content": "Question: Suppliers with a credit memo but not a voided payment"}, {"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 WHERE INVOICE_TYPE_LOOKUP_CODE = 'CREDIT'\n MINUS\n SELECT VENDOR_ID FROM AP_CHECKS_ALL WHERE STATUS_LOOKUP_CODE = 'VOIDED'\n)\nORDER BY s.VENDOR_NAME;\n```"}], "meta": {"id": "b-00976", "tier": "T4", "family": "blocked-set", "kind": "ask", "source": "S2-templated", "group": "2054ac043030", "tables": ["AP_CHECKS_ALL", "AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 2, "approx_prompt_tokens": 3016, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 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_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 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-- 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-- 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 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-- 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 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-- 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: Top 3 business units by number of payments"}, {"role": "assistant", "content": "```sql\nSELECT bu.BU_NAME, COUNT(*) AS PAYMENT_COUNT\nFROM AP_CHECKS_ALL c\nJOIN FUN_BUSINESS_UNITS bu ON bu.BU_ID = c.ORG_ID\nGROUP BY bu.BU_NAME\nORDER BY PAYMENT_COUNT DESC\nFETCH FIRST 3 ROWS ONLY;\n```"}], "meta": {"id": "a-00686", "tier": "T2", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "0f8edf525e4b", "tables": ["AP_CHECKS_ALL", "FUN_BUSINESS_UNITS"], "result_rows": 3, "approx_prompt_tokens": 2921, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: Cumulative invoiced amount per month for Massive Dynamic\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT MONTH_START, TOTAL_INVOICE_AMOUNT, SUM(TOTAL_INVOICE_AMOUNT) OVER (ORDER BY MONTH_START) AS RUNNING_TOTAL FROM (SELECT TRUNC(i.INVOICE_CREATION_DATE, 'MM') AS MONTH_START, SUM(i.INVOICE_AMOUNT) AS TOTAL_INVOICE_AMOUNT FROM AP_INVOICES_ALL i JOIN POZ_SUPPLIERS s ON s.VENDOR_ID = i.VENDOR_ID WHERE s.VENDOR_NAME = 'Massive Dynamic' GROUP BY TRUNC(i.INVOICE_CREATION_DATE, 'MM')) ORDER BY MONTH_START 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 MONTH_START, TOTAL_INVOICE_AMOUNT, SUM(TOTAL_INVOICE_AMOUNT) OVER (ORDER BY MONTH_START) AS RUNNING_TOTAL\nFROM (\n SELECT TRUNC(i.INVOICE_DATE, 'MM') AS MONTH_START, SUM(i.INVOICE_AMOUNT) AS TOTAL_INVOICE_AMOUNT\n FROM AP_INVOICES_ALL i\n JOIN POZ_SUPPLIERS s ON s.VENDOR_ID = i.VENDOR_ID\n WHERE s.VENDOR_NAME = 'Massive Dynamic'\n GROUP BY TRUNC(i.INVOICE_DATE, 'MM')\n)\nORDER BY MONTH_START;\n```"}], "meta": {"id": "r-00001", "tier": "T4", "family": "t4-running", "kind": "repair-exec", "source": "S6-repair", "group": "db6d80765a2c", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 0, "approx_prompt_tokens": 3375, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"I\".\"INVOICE_CREATION_DATE\": invalid identifier", "split": "test"}} {"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_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 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 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 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-- 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 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-- 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_ID NUMBER, -- Purchase order line this line is matched to. FK to PO_LINES_ALL.PO_LINE_ID.\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-- 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-- 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-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: Show the 5 suppliers with the highest largest invoice amount year to date"}, {"role": "assistant", "content": "```sql\nSELECT s.VENDOR_NAME, MAX(i.INVOICE_AMOUNT) AS MAX_INVOICE_AMOUNT\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 MAX_INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-01193", "tier": "T3", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "b220538b211e", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 5, "approx_prompt_tokens": 2774, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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_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 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 CANCELLED_DATE DATE -- Date the invoice was cancelled; NULL if not 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 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-- 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-- 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: How much early-payment discount expires in the next 7 days?"}, {"role": "assistant", "content": "```sql\nSELECT SUM(ps.DISCOUNT_AMOUNT_AVAILABLE) AS DISCOUNT_EXPIRING\nFROM AP_PAYMENT_SCHEDULES_ALL ps\nWHERE ps.AMOUNT_REMAINING > 0 AND ps.DISCOUNT_AMOUNT_AVAILABLE > 0 AND ps.DISCOUNT_DATE BETWEEN TRUNC(SYSDATE) AND TRUNC(SYSDATE) + 7;\n```"}], "meta": {"id": "a-00911", "tier": "T3", "family": "t3-discount", "kind": "ask", "source": "S2-templated", "group": "1f73dbfc9c93", "tables": ["AP_PAYMENT_SCHEDULES_ALL"], "result_rows": 1, "approx_prompt_tokens": 3138, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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 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 VOID_DATE DATE -- Date the payment was voided.\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_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 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_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 PO_HEADER_ID NUMBER -- Purchase order the invoice is matched to. FK to PO_HEADERS_ALL.PO_HEADER_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 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 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 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-- 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-- 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: Show the 5 payment statuses with the highest payment count this quarter"}, {"role": "assistant", "content": "```sql\nSELECT c.STATUS_LOOKUP_CODE, COUNT(*) AS PAYMENT_COUNT\nFROM AP_CHECKS_ALL c\nWHERE c.CHECK_DATE >= TRUNC(SYSDATE, 'Q')\nGROUP BY c.STATUS_LOOKUP_CODE\nORDER BY PAYMENT_COUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-01177", "tier": "T3", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "b06384cb1ccc", "tables": ["AP_CHECKS_ALL"], "result_rows": 3, "approx_prompt_tokens": 2926, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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-- 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 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 19 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 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 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-- 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 16 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 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_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 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 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 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-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: Show the 5 business units with the highest largest payment amount over the last year"}, {"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.CHECK_DATE >= ADD_MONTHS(TRUNC(SYSDATE), -12)\nGROUP BY bu.BU_NAME\nORDER BY MAX_PAYMENT_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-01182", "tier": "T3", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "75b72efac234", "tables": ["AP_CHECKS_ALL", "FUN_BUSINESS_UNITS"], "result_rows": 5, "approx_prompt_tokens": 3017, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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-- 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-- 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 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 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 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 CANCELLED_DATE DATE, -- Date the invoice was cancelled; NULL if not cancelled.\n CANCELLED_BY VARCHAR2(64), -- User who cancelled the invoice.\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-- unpaid / outstanding => 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-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n"}, {"role": "user", "content": "Question: Which 5 business units have the highest total early-payment discount available for installments on hold?"}, {"role": "assistant", "content": "```sql\nSELECT bu.BU_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 FUN_BUSINESS_UNITS bu ON bu.BU_ID = i.ORG_ID\nWHERE ps.DISCOUNT_AMOUNT_AVAILABLE > 0 AND ps.HOLD_FLAG = 'Y'\nGROUP BY bu.BU_NAME\nORDER BY TOTAL_DISCOUNT_AVAILABLE DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00664", "tier": "T2", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "1045e3a72a6c", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "FUN_BUSINESS_UNITS"], "result_rows": 1, "approx_prompt_tokens": 3085, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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 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 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 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 MATCH_TYPE VARCHAR2(25) -- How the line was matched. Values: ITEM_TO_PO, ITEM_TO_RECEIPT, NOT_MATCHED.\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-- Currencies: ISO currency codes with names, symbols and decimal precision.\nCREATE TABLE FND_CURRENCIES (\n CURRENCY_CODE VARCHAR2(15), -- ISO 4217 currency code. Values: USD, EUR, GBP, JPY, CAD, AUD, CHF, INR, SGD, CNY. Primary key.\n NAME VARCHAR2(80), -- Currency name. Values: US Dollar, Euro, Pound Sterling, Yen, Canadian Dollar, Australian Dollar, Swiss Franc, Indian Rupee, Singapore Dollar, Yuan Renminbi.\n ISSUING_TERRITORY_CODE VARCHAR2(2), -- Country that issues the currency. Values: US, DE, GB, JP, CA, AU, CH, IN, SG, CN.\n PRECISION NUMBER, -- Number of decimal places the currency uses.\n SYMBOL VARCHAR2(4), -- Currency symbol.\n ENABLED_FLAG VARCHAR2(1), -- Y if the currency is enabled for transactions.\n START_DATE_ACTIVE DATE, -- Date the currency becomes active.\n END_DATE_ACTIVE DATE, -- Date the currency stops being active.\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-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: What is the total tax on invoices for each currency for standard invoices only?\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT i.INVOICE_CURRENCY_CODE, SUM(i.TOTAL_TAX_AMOUNT) AS TOTAL_TAX_AMOUNT FROM AP_INVOICES_ALL i WHERE i.INVOICE_TYPE_LOOKUP_CODE = 'STANDARD' ORDER BY TOTAL_TAX_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 i.INVOICE_CURRENCY_CODE, SUM(i.TOTAL_TAX_AMOUNT) AS TOTAL_TAX_AMOUNT\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_TYPE_LOOKUP_CODE = 'STANDARD'\nGROUP BY i.INVOICE_CURRENCY_CODE\nORDER BY TOTAL_TAX_AMOUNT DESC;\n```"}], "meta": {"id": "r-00049", "tier": "T1", "family": "spec-inv", "kind": "repair-exec", "source": "S6-repair", "group": "728b453c9a18", "tables": ["AP_INVOICES_ALL"], "result_rows": 0, "approx_prompt_tokens": 3113, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00937: not a single-group group function", "split": "test"}} {"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 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 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 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 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-- 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-- 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 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 CREATION_SOURCE VARCHAR2(30) -- Where the supplier record originated. Values: REGISTRATION, MANUAL, IMPORT.\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"}, {"role": "user", "content": "Question: Average payment amount by supplier city for payments over 10,000"}, {"role": "assistant", "content": "```sql\nSELECT a.CITY, 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.AMOUNT > 10000\nGROUP BY a.CITY\nORDER BY AVG_PAYMENT_AMOUNT DESC;\n```"}], "meta": {"id": "a-00597", "tier": "T2", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "4d7b7e74b884", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 7, "approx_prompt_tokens": 2880, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 DISCOUNT_AMOUNT_TAKEN NUMBER(18,2), -- Early-payment discount actually taken.\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 CANCELLED_DATE DATE, -- Date the invoice was cancelled; NULL if not cancelled.\n LEGAL_ENTITY_ID NUMBER -- Legal entity the invoice belongs to.\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 16 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 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-- 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-- 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-- 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_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 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 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-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: Which 5 supplier cities have the highest invoice count over the last year?"}, {"role": "assistant", "content": "```sql\nSELECT a.CITY, COUNT(*) AS INVOICE_COUNT\nFROM AP_INVOICES_ALL i\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = i.VENDOR_ID\nWHERE i.INVOICE_DATE >= ADD_MONTHS(TRUNC(SYSDATE), -12)\nGROUP BY a.CITY\nORDER BY INVOICE_COUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-01158", "tier": "T3", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "73a54a17df11", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 5, "approx_prompt_tokens": 3077, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 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 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_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 CREATION_SOURCE VARCHAR2(30), -- Where the supplier record originated. Values: REGISTRATION, MANUAL, IMPORT.\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 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 HOLD_ALL_PAYMENTS_FLAG VARCHAR2(1), -- Y if payments to this site are blocked.\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 ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\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_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_MEAS_LOOKUP_CODE VARCHAR2(25), -- Unit of measure. Values: EA, HR, KG, BOX.\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-- 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-- 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 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 FREIGHT_TERMS_LOOKUP_CODE VARCHAR2(25), -- Who pays freight. Values: PAID, DUE.\n CANCEL_FLAG VARCHAR2(1), -- Y if the order was cancelled.\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-- 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": "Recent conversation (for follow-up questions like 'now filter to APAC'):\nQ: Amount still owed by payment term\nSQL: SELECT t.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 AP_TERMS_B t ON t.TERM_ID = i.TERMS_ID WHERE ps.AMOUNT_REMAINING > 0 GROUP BY t.NAME ORDER BY TOTAL_UNPAID_AMOUNT DESC FETCH FIRST 200 ROWS ONLY;\n\nQuestion: Break that down by supplier state instead"}, {"role": "assistant", "content": "```sql\nSELECT a.STATE, 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_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = i.VENDOR_ID\nWHERE ps.AMOUNT_REMAINING > 0\nGROUP BY a.STATE\nORDER BY TOTAL_UNPAID_AMOUNT DESC;\n```"}], "meta": {"id": "a-01811", "tier": "T2", "family": "followup", "kind": "followup", "source": "S2-templated", "group": "da2fa49333bc", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 3, "approx_prompt_tokens": 2489, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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-- 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-- 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_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 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 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 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 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-- early payment discount => AP_PAYMENT_SCHEDULES_ALL.DISCOUNT_AMOUNT_AVAILABLE > 0\n-- unpaid / outstanding => 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-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n"}, {"role": "user", "content": "Question: What is the average unpaid amount of installments with an early-payment discount available?"}, {"role": "assistant", "content": "```sql\nSELECT AVG(AMOUNT_REMAINING)\nFROM AP_PAYMENT_SCHEDULES_ALL\nWHERE DISCOUNT_AMOUNT_AVAILABLE > 0;\n```"}], "meta": {"id": "a-00037", "tier": "T1", "family": "t1-agg", "kind": "ask", "source": "S2-templated", "group": "c88c47cec94a", "tables": ["AP_PAYMENT_SCHEDULES_ALL"], "result_rows": 1, "approx_prompt_tokens": 3041, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 VOID_DATE DATE, -- Date the payment was voided.\n VOID_REASON VARCHAR2(240), -- Reason the payment was voided.\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 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 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-- 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 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_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-- voided payment => AP_CHECKS_ALL.STATUS_LOOKUP_CODE = 'VOIDED'\n-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\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: Suppliers that have either a voided payment or a wire 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')\nOR EXISTS (SELECT 1 FROM AP_CHECKS_ALL c WHERE c.VENDOR_ID = s.VENDOR_ID AND c.PAYMENT_METHOD_CODE = 'WIRE')\nORDER BY s.VENDOR_NAME;\n```"}], "meta": {"id": "a-01538", "tier": "T4", "family": "t4-logic", "kind": "ask", "source": "S2-templated", "group": "68849d29e48d", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIERS"], "result_rows": 8, "approx_prompt_tokens": 2607, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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 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 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 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-- 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-- Currencies: ISO currency codes with names, symbols and decimal precision.\nCREATE TABLE FND_CURRENCIES (\n CURRENCY_CODE VARCHAR2(15), -- ISO 4217 currency code. Values: USD, EUR, GBP, JPY, CAD, AUD, CHF, INR, SGD, CNY. Primary key.\n NAME VARCHAR2(80), -- Currency name. Values: US Dollar, Euro, Pound Sterling, Yen, Canadian Dollar, Australian Dollar, Swiss Franc, Indian Rupee, Singapore Dollar, Yuan Renminbi.\n ISSUING_TERRITORY_CODE VARCHAR2(2), -- Country that issues the currency. Values: US, DE, GB, JP, CA, AU, CH, IN, SG, CN.\n PRECISION NUMBER, -- Number of decimal places the currency uses.\n SYMBOL VARCHAR2(4), -- Currency symbol.\n ENABLED_FLAG VARCHAR2(1), -- Y if the currency is enabled for transactions.\n START_DATE_ACTIVE DATE, -- Date the currency becomes active.\n END_DATE_ACTIVE DATE, -- Date the currency stops being active.\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 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-- 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-- 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: Which 5 payment terms have the highest outstanding balance for USD invoices only?"}, {"role": "assistant", "content": "```sql\nSELECT t.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 AP_TERMS_B t ON t.TERM_ID = i.TERMS_ID\nWHERE ps.AMOUNT_REMAINING > 0 AND i.INVOICE_CURRENCY_CODE = 'USD'\nGROUP BY t.NAME\nORDER BY TOTAL_UNPAID_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00699", "tier": "T2", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "b0e89eeb75ea", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "AP_TERMS_B"], "result_rows": 5, "approx_prompt_tokens": 3079, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 LEGAL_ENTITY_ID NUMBER, -- Legal entity the invoice belongs to.\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-- 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_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 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 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 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_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-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: What is the number of invoices over 10,000?"}, {"role": "assistant", "content": "```sql\nSELECT COUNT(*)\nFROM AP_INVOICES_ALL\nWHERE INVOICE_AMOUNT > 10000;\n```"}], "meta": {"id": "a-00077", "tier": "T1", "family": "t1-count", "kind": "ask", "source": "S2-templated", "group": "afd2569c733d", "tables": ["AP_INVOICES_ALL"], "result_rows": 1, "approx_prompt_tokens": 2624, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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 last year?\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT i.PAYMENT_METHOD_CODE, COUNT(*) AS INVOICE_COUNT FROM AP_INVOICES_ALL i WHERE i.INVOICE_DATE >= ADD_MONTHS(TRUNC(NOW(), 'YYYY'), -12) AND i.INVOICE_DATE < TRUNC(NOW(), 'YYYY') GROUP BY i.PAYMENT_METHOD_CODE ORDER BY INVOICE_COUNT 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_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.PAYMENT_METHOD_CODE, COUNT(*) AS INVOICE_COUNT\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_DATE >= ADD_MONTHS(TRUNC(SYSDATE, 'YYYY'), -12) AND i.INVOICE_DATE < TRUNC(SYSDATE, 'YYYY')\nGROUP BY i.PAYMENT_METHOD_CODE\nORDER BY INVOICE_COUNT DESC;\n```"}], "meta": {"id": "r-00079", "tier": "T3", "family": "spec-inv", "kind": "repair-exec", "source": "S6-repair", "group": "f76d4fa29325", "tables": ["AP_INVOICES_ALL"], "result_rows": 0, "approx_prompt_tokens": 3296, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"NOW\": invalid identifier", "split": "test"}} {"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-- 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-- 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-- 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-- 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 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 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 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 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 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-- 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-- 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"}, {"role": "user", "content": "Question: What is the early-payment discount on offer for each payment term that came due in the last 6 months?"}, {"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 ps.DUE_DATE >= ADD_MONTHS(TRUNC(SYSDATE), -6)\nGROUP BY t.NAME\nORDER BY TOTAL_DISCOUNT_AVAILABLE DESC;\n```"}], "meta": {"id": "a-01096", "tier": "T3", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "311e3ee9b4ee", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "AP_TERMS_B"], "result_rows": 6, "approx_prompt_tokens": 3123, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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 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 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-- 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 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 DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\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: Show the 5 payment terms with the highest total scheduled installment amount that were due last year"}, {"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, 'YYYY'), -12) AND ps.DUE_DATE < TRUNC(SYSDATE, 'YYYY')\nGROUP BY t.NAME\nORDER BY TOTAL_INSTALLMENT_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-01186", "tier": "T3", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "60879af2127d", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "AP_TERMS_B"], "result_rows": 5, "approx_prompt_tokens": 3121, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\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 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 PO_HEADER_ID NUMBER, -- Purchase order the invoice is matched to. FK to PO_HEADERS_ALL.PO_HEADER_ID.\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-- 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_TYPE_LOOKUP_CODE VARCHAR2(25), -- Line type: ITEM, TAX, FREIGHT or MISCELLANEOUS. Values: ITEM, TAX, FREIGHT, MISCELLANEOUS.\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 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 PREPAY_INVOICE_ID NUMBER, -- Prepayment invoice applied on this line, if any.\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 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 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-- 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 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-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\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: Approved invoices by supplier state"}, {"role": "assistant", "content": "```sql\nSELECT a.STATE, COUNT(*) AS INVOICE_COUNT\nFROM AP_INVOICES_ALL i\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = i.VENDOR_ID\nWHERE i.WFAPPROVAL_STATUS = 'APPROVED'\nGROUP BY a.STATE\nORDER BY INVOICE_COUNT DESC;\n```"}], "meta": {"id": "a-01672", "tier": "T5", "family": "t5-glossary", "kind": "ask", "source": "S2-templated", "group": "8d9e032775da", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 3, "approx_prompt_tokens": 2692, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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 LEDGER_ID NUMBER, -- Ledger the combination belongs to. FK to GL_LEDGERS.LEDGER_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 LEDGER_ID NUMBER, -- Ledger of the entry. FK to GL_LEDGERS.LEDGER_ID.\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 PRODUCT_RULE_CODE VARCHAR2(30), -- Accounting rule applied.\n FUNDS_STATUS_CODE VARCHAR2(1), -- Funds check status.\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-- 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 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 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 CASH_POSTED_FLAG VARCHAR2(1), -- Y if cash-basis accounting entries were created.\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 RCV_TRANSACTION_ID NUMBER, -- Receipt transaction matched to. FK to RCV_TRANSACTIONS.TRANSACTION_ID.\n TASK_ID NUMBER, -- Project task charged.\n INCOME_TAX_REGION VARCHAR2(10), -- Region used for income-tax reporting.\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-- 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-- 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_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 GL_DATE DATE, -- Accounting date used to post the invoice to the general ledger.\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 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 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 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 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-- spend by GL account => SUM(AP_INVOICE_DISTRIBUTIONS_ALL.AMOUNT) grouped by DIST_CODE_COMBINATION_ID (join GL_CODE_COMBINATIONS for CONCATENATED_SEGMENTS)\n"}, {"role": "user", "content": "Question: Top 10 GL accounts by spend"}, {"role": "assistant", "content": "```sql\nSELECT g.CONCATENATED_SEGMENTS, SUM(d.AMOUNT) AS TOTAL_AMOUNT\nFROM AP_INVOICE_DISTRIBUTIONS_ALL d\nJOIN GL_CODE_COMBINATIONS g ON g.CODE_COMBINATION_ID = d.DIST_CODE_COMBINATION_ID\nGROUP BY g.CONCATENATED_SEGMENTS\nORDER BY TOTAL_AMOUNT DESC\nFETCH FIRST 10 ROWS ONLY;\n```"}], "meta": {"id": "a-00344", "tier": "T2", "family": "t2-gl", "kind": "ask", "source": "S2-templated", "group": "586d6be49ac4", "tables": ["AP_INVOICE_DISTRIBUTIONS_ALL", "GL_CODE_COMBINATIONS"], "result_rows": 10, "approx_prompt_tokens": 2633, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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 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 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 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-- 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 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_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 MATCH_TYPE VARCHAR2(25) -- How the line was matched. Values: ITEM_TO_PO, ITEM_TO_RECEIPT, NOT_MATCHED.\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 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 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);\n\n-- Business glossary (how analysts phrase common conditions):\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-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: Top 3 payment terms by average invoice value"}, {"role": "assistant", "content": "```sql\nSELECT t.NAME, AVG(i.INVOICE_AMOUNT) AS AVG_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN AP_TERMS_B t ON t.TERM_ID = i.TERMS_ID\nGROUP BY t.NAME\nORDER BY AVG_INVOICE_AMOUNT DESC\nFETCH FIRST 3 ROWS ONLY;\n```"}], "meta": {"id": "a-00652", "tier": "T2", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "226ea6272a16", "tables": ["AP_INVOICES_ALL", "AP_TERMS_B"], "result_rows": 3, "approx_prompt_tokens": 2906, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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_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 WFAPPROVAL_STATUS VARCHAR2(25) -- Approval workflow status of the invoice. Values: APPROVED, NOT REQUIRED, REJECTED, INITIATED.\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 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_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 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-- 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-- 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-- 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-- 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-- unvalidated invoice => AP_INVOICES_ALL.VALIDATION_STATUS <> 'VALIDATED'\n"}, {"role": "user", "content": "Question: Which 5 supplier cities have the highest average invoice value counting only approved invoices?"}, {"role": "assistant", "content": "```sql\nSELECT a.CITY, AVG(i.INVOICE_AMOUNT) AS AVG_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = i.VENDOR_ID\nWHERE i.WFAPPROVAL_STATUS = 'APPROVED'\nGROUP BY a.CITY\nORDER BY AVG_INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00702", "tier": "T2", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "42ef05cfba4e", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 5, "approx_prompt_tokens": 3048, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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 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 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 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 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 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 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 CASH_POSTED_FLAG VARCHAR2(1), -- Y if cash-basis 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 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-- 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-- 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: How many installments are due in the next 90 days?"}, {"role": "assistant", "content": "```sql\nSELECT COUNT(*) AS INSTALLMENTS_DUE\nFROM AP_PAYMENT_SCHEDULES_ALL ps\nWHERE ps.AMOUNT_REMAINING > 0 AND ps.DUE_DATE BETWEEN TRUNC(SYSDATE) AND TRUNC(SYSDATE) + 90;\n```"}], "meta": {"id": "a-00883", "tier": "T3", "family": "t3-upcoming", "kind": "ask", "source": "S2-templated", "group": "816203e3cce4", "tables": ["AP_PAYMENT_SCHEDULES_ALL"], "result_rows": 1, "approx_prompt_tokens": 3155, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 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-- 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 ALWAYS_TAKE_DISC_FLAG VARCHAR2(1), -- Y if the early-payment discount is always taken.\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 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_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 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 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 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-- 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 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 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-- payment method => AP_CHECKS_ALL.PAYMENT_METHOD_CODE (CHECK, EFT or WIRE)\n-- credit memo => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'CREDIT'\n-- voided payment => AP_CHECKS_ALL.STATUS_LOOKUP_CODE = 'VOIDED'\n-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n"}, {"role": "user", "content": "Question: Which suppliers have a wire payment but not a credit memo?"}, {"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.PAYMENT_METHOD_CODE = 'WIRE')\nAND NOT EXISTS (SELECT 1 FROM AP_INVOICES_ALL i WHERE i.VENDOR_ID = s.VENDOR_ID AND i.INVOICE_TYPE_LOOKUP_CODE = 'CREDIT')\nORDER BY s.VENDOR_NAME;\n```"}], "meta": {"id": "a-01328", "tier": "T4", "family": "t4-logic", "kind": "ask", "source": "S2-templated", "group": "3b27d37095c2", "tables": ["AP_CHECKS_ALL", "AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 2, "approx_prompt_tokens": 3090, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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_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 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 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-- 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 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-- 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: Show the average invoice value per payment term over the past 6 months"}, {"role": "assistant", "content": "```sql\nSELECT t.NAME, AVG(i.INVOICE_AMOUNT) AS AVG_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN AP_TERMS_B t ON t.TERM_ID = i.TERMS_ID\nWHERE i.INVOICE_DATE >= ADD_MONTHS(TRUNC(SYSDATE), -6)\nGROUP BY t.NAME\nORDER BY AVG_INVOICE_AMOUNT DESC;\n```"}], "meta": {"id": "a-00872", "tier": "T3", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "ae60c9ed29ab", "tables": ["AP_INVOICES_ALL", "AP_TERMS_B"], "result_rows": 10, "approx_prompt_tokens": 2860, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 PREPAY_AMOUNT_REMAINING NUMBER(18,2), -- Unapplied balance remaining on a prepayment invoice.\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 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 DESCRIPTION VARCHAR2(240), -- Free-text invoice description.\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 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-- 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 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-- 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-- 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 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 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 RISK_RATING VARCHAR2(25), -- Internal supplier risk rating. Values: LOW, MEDIUM, HIGH.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- unpaid / outstanding => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\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-- 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: Top 5 supplier cities by largest unpaid installment for USD invoices only"}, {"role": "assistant", "content": "```sql\nSELECT a.CITY, MAX(ps.AMOUNT_REMAINING) AS MAX_UNPAID_AMOUNT\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 i.INVOICE_CURRENCY_CODE = 'USD'\nGROUP BY a.CITY\nORDER BY MAX_UNPAID_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00647", "tier": "T2", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "91c248e7ffe9", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 5, "approx_prompt_tokens": 3078, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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-- 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 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 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_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 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 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 PRODUCT_CATEGORY VARCHAR2(80), -- Category of the product or service. Values: IT EQUIPMENT, OFFICE SUPPLIES, PROFESSIONAL SERVICES, LOGISTICS.\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 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 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 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 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\n"}, {"role": "user", "content": "Question: Total invoiced per month over the past 12 months"}, {"role": "assistant", "content": "```sql\nSELECT TRUNC(INVOICE_DATE, 'MM'), SUM(INVOICE_AMOUNT) FROM AP_INVOICES_ALL WHERE INVOICE_DATE >= ADD_MONTHS(TRUNC(SYSDATE), -12) GROUP BY TRUNC(INVOICE_DATE, 'MM');\n```"}], "meta": {"id": "p-007", "tier": "T3", "family": "pilot-gold", "kind": "ask", "source": "S1-golden", "group": "0f89419114ee", "tables": ["AP_INVOICES_ALL"], "result_rows": 13, "approx_prompt_tokens": 2990, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 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-- 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 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 CREATION_SOURCE VARCHAR2(30) -- Where the supplier record originated. Values: REGISTRATION, MANUAL, IMPORT.\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-- 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 DELIVERY_CHANNEL_CODE VARCHAR2(30), -- Bank delivery channel. Values: ACH, CHAPS, SEPA.\n SETTLEMENT_DATE DATE -- Date funds settled.\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"}, {"role": "user", "content": "Question: Which 3 suppliers have the highest average payment amount?"}, {"role": "assistant", "content": "```sql\nSELECT s.VENDOR_NAME, AVG(c.AMOUNT) AS AVG_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 AVG_PAYMENT_AMOUNT DESC\nFETCH FIRST 3 ROWS ONLY;\n```"}], "meta": {"id": "a-00615", "tier": "T2", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "44c963886f55", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIERS"], "result_rows": 3, "approx_prompt_tokens": 2902, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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_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-- 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-- 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 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 PRODUCT_CATEGORY VARCHAR2(80), -- Category of the product or service. Values: IT EQUIPMENT, OFFICE SUPPLIES, PROFESSIONAL SERVICES, LOGISTICS.\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);\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-- 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: Total invoiced per month in the last 6 months"}, {"role": "assistant", "content": "```sql\nSELECT TRUNC(i.INVOICE_DATE, 'MM') AS MONTH_START, SUM(i.INVOICE_AMOUNT) AS TOTAL_INVOICE_AMOUNT\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-01053", "tier": "T3", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "4c37047517be", "tables": ["AP_INVOICES_ALL"], "result_rows": 7, "approx_prompt_tokens": 3099, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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 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 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 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 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 ACCTS_PAY_CODE_COMBINATION_ID NUMBER, -- Liability (accounts payable) account for the invoice. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\n LEGAL_ENTITY_ID NUMBER, -- Legal entity the invoice belongs to.\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 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_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 RCV_TRANSACTION_ID NUMBER, -- Receipt transaction this line is matched to. FK to RCV_TRANSACTIONS.TRANSACTION_ID.\n DEFAULT_DIST_CCID NUMBER, -- Default account used to distribute the line. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_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 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 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 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_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-- 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 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-- 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-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n-- unvalidated invoice => AP_INVOICES_ALL.VALIDATION_STATUS <> 'VALIDATED'\n"}, {"role": "user", "content": "Question: Invoices failing three-way match by supplier state"}, {"role": "assistant", "content": "```sql\nSELECT a.STATE, COUNT(*) AS INVOICE_COUNT\nFROM AP_INVOICES_ALL i\nJOIN POZ_SUPPLIER_ADDRESSES a ON a.VENDOR_ID = i.VENDOR_ID\nWHERE i.INVOICE_ID IN (SELECT h.INVOICE_ID FROM AP_HOLDS_ALL h WHERE h.HOLD_LOOKUP_CODE IN ('QTY VARIANCE', 'PRICE VARIANCE', 'MISSING RECEIPT'))\nGROUP BY a.STATE\nORDER BY INVOICE_COUNT DESC;\n```"}], "meta": {"id": "a-01649", "tier": "T5", "family": "t5-glossary", "kind": "ask", "source": "S2-templated", "group": "42fe3d8e342a", "tables": ["AP_HOLDS_ALL", "AP_INVOICES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 3, "approx_prompt_tokens": 3129, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 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 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 ACCTS_PAY_CODE_COMBINATION_ID NUMBER, -- Liability (accounts payable) account for the invoice. FK to GL_CODE_COMBINATIONS.CODE_COMBINATION_ID.\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-- 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-- 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_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 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 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-- 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 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 LEDGER_ID NUMBER, -- Ledger the combination belongs to. FK to GL_LEDGERS.LEDGER_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\n-- unvalidated invoice => AP_INVOICES_ALL.VALIDATION_STATUS <> 'VALIDATED'\n-- credit memo => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'CREDIT'\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: Which 5 validation statuses have the highest biggest invoice amount for standard invoices only?"}, {"role": "assistant", "content": "```sql\nSELECT i.VALIDATION_STATUS, MAX(i.INVOICE_AMOUNT) AS MAX_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_TYPE_LOOKUP_CODE = 'STANDARD'\nGROUP BY i.VALIDATION_STATUS\nORDER BY MAX_INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00130", "tier": "T1", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "8eddc918b68f", "tables": ["AP_INVOICES_ALL"], "result_rows": 3, "approx_prompt_tokens": 3121, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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-- 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 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 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-- 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-- 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-- 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 number of payments in the last 6 months?"}, {"role": "assistant", "content": "```sql\nSELECT COUNT(*) AS PAYMENT_COUNT\nFROM AP_CHECKS_ALL c\nWHERE c.CHECK_DATE >= ADD_MONTHS(TRUNC(SYSDATE), -6);\n```"}], "meta": {"id": "a-01047", "tier": "T3", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "c15656aad6ce", "tables": ["AP_CHECKS_ALL"], "result_rows": 1, "approx_prompt_tokens": 2725, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 TERMS_ID NUMBER, -- Payment terms applied to the invoice. FK to AP_TERMS_B.TERM_ID.\n PO_HEADER_ID NUMBER -- Purchase order the invoice is matched to. FK to PO_HEADERS_ALL.PO_HEADER_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_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 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-- 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 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 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 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-- 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 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 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 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-- 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 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 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 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-- 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-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: Show the total invoice tax amount per supplier for approved invoices only"}, {"role": "assistant", "content": "```sql\nSELECT s.VENDOR_NAME, SUM(i.TOTAL_TAX_AMOUNT) AS TOTAL_TAX_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN POZ_SUPPLIERS s ON s.VENDOR_ID = i.VENDOR_ID\nWHERE i.WFAPPROVAL_STATUS = 'APPROVED'\nGROUP BY s.VENDOR_NAME\nORDER BY TOTAL_TAX_AMOUNT DESC;\n```"}], "meta": {"id": "a-00578", "tier": "T2", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "25c2de0f07ce", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIERS"], "result_rows": 9, "approx_prompt_tokens": 3155, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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-- 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 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 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-- 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-- 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-- 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-- 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-- fully paid => AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING = 0\n"}, {"role": "user", "content": "Question: Which 5 payment methods have the highest average payment amount over the past 30 days?"}, {"role": "assistant", "content": "```sql\nSELECT c.PAYMENT_METHOD_CODE, AVG(c.AMOUNT) AS AVG_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nWHERE c.CHECK_DATE >= TRUNC(SYSDATE) - 30\nGROUP BY c.PAYMENT_METHOD_CODE\nORDER BY AVG_PAYMENT_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-01115", "tier": "T3", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "ead58c307606", "tables": ["AP_CHECKS_ALL"], "result_rows": 2, "approx_prompt_tokens": 2972, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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-- 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 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-- 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 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 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-- 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-- 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-- supplier name / vendor name => POZ_SUPPLIERS.VENDOR_NAME\n"}, {"role": "user", "content": "Question: Which 5 supplier cities have the lowest number of payments?"}, {"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 ASC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00713", "tier": "T2", "family": "spec-pay", "kind": "ask", "source": "S2-templated", "group": "7501f220d2e6", "tables": ["AP_CHECKS_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 5, "approx_prompt_tokens": 2561, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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.\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 BANK_ACCOUNT_NUM VARCHAR2(30), -- Bank account number the payment was drawn on.\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-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\n-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: How was invoice INV-2026-5016 paid?\n\nYour previous attempt was rejected by Oracle:\nSQL: SELECT c.CHECK_NUMBER, c.PAYMENT_DATE, ip.AMOUNT, c.PAYMENT_METHOD_CODE FROM AP_INVOICE_PAYMENTS_ALL ip JOIN AP_CHECKS_ALL c ON c.CHECK_ID = ip.CHECK_ID JOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ip.INVOICE_ID WHERE i.INVOICE_NUM = 'INV-2026-5016' FETCH FIRST 200 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 c.CHECK_NUMBER, c.CHECK_DATE, ip.AMOUNT, c.PAYMENT_METHOD_CODE\nFROM AP_INVOICE_PAYMENTS_ALL ip\nJOIN AP_CHECKS_ALL c ON c.CHECK_ID = ip.CHECK_ID\nJOIN AP_INVOICES_ALL i ON i.INVOICE_ID = ip.INVOICE_ID\nWHERE i.INVOICE_NUM = 'INV-2026-5016';\n```"}], "meta": {"id": "r-00011", "tier": "T2", "family": "t2-invoice-lookup", "kind": "repair-exec", "source": "S6-repair", "group": "ca6274456fda", "tables": ["AP_CHECKS_ALL", "AP_INVOICES_ALL", "AP_INVOICE_PAYMENTS_ALL"], "result_rows": 0, "approx_prompt_tokens": 3304, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "error": "ORA-00904: \"C\".\"PAYMENT_DATE\": invalid identifier", "split": "test"}} {"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 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 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 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-- 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 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-- 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 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);\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 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 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);\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 supplier cities have the highest total invoice amount over the past 90 days?"}, {"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\nWHERE i.INVOICE_DATE >= TRUNC(SYSDATE) - 90\nGROUP BY a.CITY\nORDER BY TOTAL_INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-01111", "tier": "T3", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "e632309c8ddd", "tables": ["AP_INVOICES_ALL", "POZ_SUPPLIER_ADDRESSES"], "result_rows": 5, "approx_prompt_tokens": 2999, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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-- 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 EXCHANGE_RATE NUMBER(12,6), -- Rate converting payment currency to ledger currency.\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 ORG_ID NUMBER, -- Business unit that owns the row. FK to FUN_BUSINESS_UNITS.BU_ID.\n);\n\n-- Accounting calendar periods: period name, year, number, start and end dates and quarter.\nCREATE TABLE GL_PERIODS (\n PERIOD_ID NUMBER, -- Unique period identifier. Primary key.\n PERIOD_SET_NAME VARCHAR2(15), -- Calendar the period belongs to.\n PERIOD_NAME VARCHAR2(15), -- Period name such as JAN-26.\n PERIOD_YEAR NUMBER, -- Fiscal year of the period.\n PERIOD_NUM NUMBER, -- Period number within the year.\n QUARTER_NUM NUMBER, -- Fiscal quarter of the period.\n START_DATE DATE, -- First day of the period.\n END_DATE DATE, -- Last day of the period.\n PERIOD_TYPE VARCHAR2(15), -- Type of period.\n ADJUSTMENT_PERIOD_FLAG VARCHAR2(1), -- Y if the period is an adjusting period.\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-- Employees and contingent workers: person master with name, number, hire date, job, department, manager and business unit.\n-- (showing 15 of 23 columns: join keys + those relevant to the question)\nCREATE TABLE PER_ALL_PEOPLE_F (\n PERSON_ID NUMBER, -- Unique person identifier. Primary key.\n PERSON_NUMBER VARCHAR2(30), -- Employee number.\n FIRST_NAME VARCHAR2(150), -- First name.\n LAST_NAME VARCHAR2(150), -- Last name.\n FULL_NAME VARCHAR2(240), -- Full display name.\n EMAIL_ADDRESS VARCHAR2(240), -- Work email address.\n HIRE_DATE DATE, -- Date the person was hired.\n EFFECTIVE_START_DATE DATE, -- Start of the effective-dated row.\n EFFECTIVE_END_DATE DATE, -- End of the effective-dated row.\n JOB_TITLE VARCHAR2(100), -- Job title. Values: AP CLERK, AP MANAGER, BUYER, CONTROLLER, ANALYST.\n DEPARTMENT_NAME VARCHAR2(100), -- Department. Values: FINANCE, PROCUREMENT, OPERATIONS.\n MANAGER_ID NUMBER, -- Person's manager. FK to PER_ALL_PEOPLE_F.PERSON_ID.\n BUSINESS_UNIT_ID NUMBER, -- Business unit the person works in. FK to FUN_BUSINESS_UNITS.BU_ID.\n ASSIGNMENT_STATUS VARCHAR2(25), -- Employment status. Values: ACTIVE, INACTIVE.\n LOCATION VARCHAR2(80), -- Work location.\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"}, {"role": "user", "content": "Recent conversation (for follow-up questions like 'now filter to APAC'):\nQ: Show the total payment amount per payment method\nSQL: SELECT c.PAYMENT_METHOD_CODE, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT FROM AP_CHECKS_ALL c GROUP BY c.PAYMENT_METHOD_CODE ORDER BY TOTAL_PAYMENT_AMOUNT DESC FETCH FIRST 200 ROWS ONLY;\n\nQuestion: Now do the same in the last 6 months"}, {"role": "assistant", "content": "```sql\nSELECT c.PAYMENT_METHOD_CODE, SUM(c.AMOUNT) AS TOTAL_PAYMENT_AMOUNT\nFROM AP_CHECKS_ALL c\nWHERE c.CHECK_DATE >= ADD_MONTHS(TRUNC(SYSDATE), -6)\nGROUP BY c.PAYMENT_METHOD_CODE\nORDER BY TOTAL_PAYMENT_AMOUNT DESC;\n```"}], "meta": {"id": "a-01767", "tier": "T3", "family": "followup", "kind": "followup", "source": "S2-templated", "group": "0d77fa9d44b4", "tables": ["AP_CHECKS_ALL"], "result_rows": 3, "approx_prompt_tokens": 2534, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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-- 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-- 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_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 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 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 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_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 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-- early payment discount => AP_PAYMENT_SCHEDULES_ALL.DISCOUNT_AMOUNT_AVAILABLE > 0\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\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: What is the early-payment discount on offer for each payment method for USD invoices only?"}, {"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 AND i.INVOICE_CURRENCY_CODE = 'USD'\nGROUP BY i.PAYMENT_METHOD_CODE\nORDER BY TOTAL_DISCOUNT_AVAILABLE DESC;\n```"}], "meta": {"id": "a-00663", "tier": "T2", "family": "spec-inst", "kind": "ask", "source": "S2-templated", "group": "7bd32c750659", "tables": ["AP_INVOICES_ALL", "AP_PAYMENT_SCHEDULES_ALL"], "result_rows": 1, "approx_prompt_tokens": 2864, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 CASH_POSTED_FLAG VARCHAR2(1), -- Y if cash-basis 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 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-- 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-- 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 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 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);\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-- past due / overdue => AP_PAYMENT_SCHEDULES_ALL.DUE_DATE < SYSDATE AND AP_PAYMENT_SCHEDULES_ALL.AMOUNT_REMAINING > 0\n"}, {"role": "user", "content": "Question: Give me the total amount paid on invoices last year."}, {"role": "assistant", "content": "```sql\nSELECT SUM(i.AMOUNT_PAID) AS TOTAL_AMOUNT_PAID\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_DATE >= ADD_MONTHS(TRUNC(SYSDATE, 'YYYY'), -12) AND i.INVOICE_DATE < TRUNC(SYSDATE, 'YYYY');\n```"}], "meta": {"id": "a-01134", "tier": "T3", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "b1a5b826d425", "tables": ["AP_INVOICES_ALL"], "result_rows": 1, "approx_prompt_tokens": 2876, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 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 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 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 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-- 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 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 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 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 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 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 CASH_POSTED_FLAG VARCHAR2(1), -- Y if cash-basis accounting entries were created.\n MATCHED_UOM_LOOKUP_CODE VARCHAR2(25), -- Unit of measure of the matched quantity. Values: EA, HR, KG, BOX.\n QUANTITY_INVOICED NUMBER, -- Quantity billed for the distribution.\n UNIT_PRICE NUMBER(18,2), -- Unit price on the distribution.\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 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-- 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-- 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 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 LEDGER_ID NUMBER -- Ledger the combination belongs to. FK to GL_LEDGERS.LEDGER_ID.\n);\n\n-- Business glossary (how analysts phrase common conditions):\n-- spend by GL account => SUM(AP_INVOICE_DISTRIBUTIONS_ALL.AMOUNT) grouped by DIST_CODE_COMBINATION_ID (join GL_CODE_COMBINATIONS for CONCATENATED_SEGMENTS)\n-- approved invoice => AP_INVOICES_ALL.WFAPPROVAL_STATUS = 'APPROVED'\n-- prepayment => AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'\n"}, {"role": "user", "content": "Question: Show the 5 business units with the highest total value of invoices counting only USD invoices"}, {"role": "assistant", "content": "```sql\nSELECT bu.BU_NAME, SUM(i.INVOICE_AMOUNT) AS TOTAL_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nJOIN FUN_BUSINESS_UNITS bu ON bu.BU_ID = i.ORG_ID\nWHERE i.INVOICE_CURRENCY_CODE = 'USD'\nGROUP BY bu.BU_NAME\nORDER BY TOTAL_INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-00486", "tier": "T2", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "4873b61832eb", "tables": ["AP_INVOICES_ALL", "FUN_BUSINESS_UNITS"], "result_rows": 5, "approx_prompt_tokens": 3145, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}} {"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 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 APPROVED_AMOUNT NUMBER(18,2), -- Amount approved through the approval workflow.\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 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 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 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);\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 TAX_RATE_ID NUMBER, -- Tax rate record applied. FK to ZX_RATES_B.TAX_RATE_ID.\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-- 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-- 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-- 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: Top 5 invoice sources by total invoice amount this month"}, {"role": "assistant", "content": "```sql\nSELECT i.SOURCE, SUM(i.INVOICE_AMOUNT) AS TOTAL_INVOICE_AMOUNT\nFROM AP_INVOICES_ALL i\nWHERE i.INVOICE_DATE >= TRUNC(SYSDATE, 'MM')\nGROUP BY i.SOURCE\nORDER BY TOTAL_INVOICE_AMOUNT DESC\nFETCH FIRST 5 ROWS ONLY;\n```"}], "meta": {"id": "a-01156", "tier": "T3", "family": "spec-inv", "kind": "ask", "source": "S2-templated", "group": "4182d36d201f", "tables": ["AP_INVOICES_ALL"], "result_rows": 3, "approx_prompt_tokens": 3038, "context_complete": true, "missing_tables": [], "schema_fingerprint": "a978c48ca1a87c06bf245b86f22e8007fb12ae2547639b52feeb82528e540a52", "prompt_template_sha256": "2a49640c73fcc680", "split": "test"}}