我有一个包含4个参数的包。所有参数都来自并发请求。在基于事务类型参数的那个包中,应该执行一组语句。我刚开始使用oracle。以下是我的代码
GET /test/doc/_search
{
"query" : {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"term" : {
"Val" : "a - copy"
}
}
}
}
}
我的方法会起作用吗?请帮我完成这件事!
答案 0 :(得分:2)
您应该在 ref cursor
中处理if else逻辑在普通光标内,你不能做if / else。因此声明一个引用游标,然后你的逻辑应该工作。见下面的链接。
答案 1 :(得分:0)
你错误地在你的声明块中有条件。如果您至少编译过它,Oracle会向您抛出错误消息。
你的实际实施是凌乱的,老实说不确定你在做什么。 即使您确实将IF块从声明移动到可执行部分,也会出现另一个编译错误,因为需要将SELECT语句提取到本地变量(您还没有完成),然后可能会因为SQL语句而获得运行时异常必须返回一行(我怀疑你的SQL语句没有按照它应该做的那样)。
这应该是它应该看起来的样子,但是如果没有解释你想要做什么,这只是一个镜头中的一个镜头
CREATE OR REPLACE PACKAGE BODY vat_reg_6 IS
PROCEDURE xx_po_vat_reg_proc_par(errbuf OUT VARCHAR2,
retcode OUT VARCHAR2,
p_startdate DATE,
p_enddate DATE,
p_legal_entity_id NUMBER,
p_trantype VARCHAR2) IS
CURSOR po_cursor IS
SELECT al.tax_rate_code AS taxcode,
al.amount AS netamount,
al.amount AS taxamount,
ai.invoice_date AS reportingdate,
ai.invoice_num AS invoicenumber,
ai.invoice_date AS invoicedate,
ai.invoice_amount AS grossamount,
ai.invoice_num AS documentnumber,
ai.invoice_date AS documentdate,
ai.vendor_id AS suplierid,
hz.tax_reference AS suppliervatnumber,
gl.segment1 AS companycode,
'AP' AS transactiontype
FROM apps.ap_invoice_lines_all al
INNER JOIN apps.ap_invoices_all ai
ON ai.invoice_id = al.invoice_id
INNER JOIN apps.hz_parties hz
ON ai.party_id = hz.party_id
INNER JOIN apps.ap_invoice_distributions_all dl
ON dl.invoice_id = al.invoice_id
INNER JOIN apps.gl_code_combinations gl
ON gl.code_combination_id = dl.dist_code_combination_id
WHERE ROWNUM < 200
AND ai.invoice_date BETWEEN p_startdate AND p_enddate
AND ai.legal_entity_id = p_legal_entity_id;
BEGIN
--============================My Approach=================
IF p_trantype = 'AP' THEN -- Should execute below block
SELECT al.tax_rate_code AS taxcode,
al.amount AS netamount,
al.amount AS taxamount,
ai.invoice_date AS reportingdate,
ai.invoice_num AS invoicenumber,
ai.invoice_date AS invoicedate,
ai.invoice_amount AS grossamount,
ai.invoice_num AS documentnumber,
ai.invoice_date AS documentdate,
ai.vendor_id AS suplierid,
hz.tax_reference AS suppliervatnumber,
gl.segment1 AS companycode,
'AP' AS transactiontype
-- INTO
FROM apps.ap_invoice_lines_all al
INNER JOIN apps.ap_invoices_all ai
ON ai.invoice_id = al.invoice_id
INNER JOIN apps.hz_parties hz
ON ai.party_id = hz.party_id
INNER JOIN apps.ap_invoice_distributions_all dl
ON dl.invoice_id = al.invoice_id
INNER JOIN apps.gl_code_combinations gl
ON gl.code_combination_id = dl.dist_code_combination_id
WHERE ROWNUM < 200
AND ai.invoice_date BETWEEN p_startdate AND p_enddate
AND ai.legal_entity_id = p_legal_entity_id;
ELSE
apps.fnd_file.put_line(
apps.fnd_file.output,
RPAD('TaxCode', 8)
|| RPAD('NetAMount', 15)
|| RPAD('TaxAmount', 15)
|| RPAD('ReportingDate', 20)
|| RPAD('InvoiceNumber', 20)
|| RPAD('InvoiceDate', 20)
|| RPAD('GrossAmount', 20)
|| RPAD('DocumentNumber', 20)
|| RPAD('DocumentDate', 20)
|| RPAD('SuplierID', 20)
|| RPAD('SupplierVATNumber', 20)
|| RPAD('CompanyCode', 20)
|| RPAD('TransactionType', 20));
apps.fnd_file.put_line(
apps.fnd_file.output,
'--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------');
/*FND_FILE.put_line(FND_FILE.output,'Starting processing:');*/
FOR po_rec IN po_cursor LOOP
apps.fnd_file.put_line(
apps.fnd_file.output,
RPAD(po_rec.taxcode, 8)
|| RPAD(po_rec.netamount, 15)
|| RPAD(po_rec.taxamount, 15)
|| RPAD(po_rec.reportingdate, 20)
|| RPAD(po_rec.invoicenumber, 20)
|| RPAD(po_rec.invoicedate, 20)
|| RPAD(po_rec.grossamount, 20)
|| RPAD(po_rec.documentnumber, 20)
|| RPAD(po_rec.documentdate, 20)
|| RPAD(po_rec.suplierid, 20)
|| RPAD(po_rec.suppliervatnumber, 20)
|| RPAD(po_rec.companycode, 20)
|| RPAD(po_rec.transactiontype, 20));
/*APPS.FND_FILE.put_line(APPS.FND_FILE.output,
po_rec.TaxCode || po_rec.NetAMount ||
po_rec.TaxAmount || po_rec.ReportingDate||po_rec.InvoiceNumber||po_rec.GrossAmount||po_rec.DocumentNumber||po_rec.DocumentDate||po_rec.SuplierID||
po_rec.SupplierVATNumber||po_rec.CompanyCode||po_rec.TransactionType);*/
/*INSERT INTO APPS_RO.VAT_TEMP VALUES (po_rec.TaxCode,
po_rec.NetAMount,
po_rec.TaxAmount,
po_rec.ReportingDate,
po_rec.InvoiceNumber,
po_rec.InvoiceDate,
po_rec.GrossAmount,
po_rec.DocumentNumber,
po_rec.DocumentDate,
po_rec.SuplierID,
po_rec.SupplierVATNumber,
po_rec.CompanyCode,
po_rec.TransactionType);*/
END LOOP;
--FND_FILE.put_line(FND_FILE.output,'Done!');
END IF;
COMMIT;
-- Return 0 for successful completion.
errbuf := '';
retcode := '0';
/*exception
when others then
errbuf := sqlerrm;
retcode := '2';*/
--FND_FILE.put_line(FND_FILE.output,'Done!');
COMMIT; -- Return 0 for successful completion.
errbuf := '';
retcode := '0';
/*exception
when others then
errbuf := sqlerrm;
retcode := '2';*/
END xx_po_vat_reg_proc_par;
END vat_reg_6;
答案 2 :(得分:0)
我认为你应该使用动态sql语句来实现这种方法。 像:
readonly