I’m having some trouble when running a code snippet as a stored procedure, where I get an error :
An error occured - 2fea40e7-87b3-4488-a225-c24a80e4224f
itgenpse009:
A select … into statement in PSQL must retrieve exactly one row, but multiple rows were retrieved.
Please adapt the logic of your select statement in PSQL to always return exactly one row instead of 2 rows.
When I´m running it in the SQL Editor I have no issues.
I think the error might be due to the LoketNlRest.PayrollRun.PayrollRunsByPayrollAdministrationId returns two PayrollRunIds, since it works fine when only one is returned.
Query:
select distinct runs.id
from LoketNlRest.PayrollAdministration.PayrollAdministrationsByEmployerId('XXX') payrollAdministration
join LoketNlRest.PayrollRun.PayrollRunsByPayrollAdministrationId(payrollAdministration.id) runs
on runs.payrollRunStatus_key = 9 and TRUNC(runs.approvalTime) = TO_DATE('11/01/2018','DD/MM/YYYY')
join LoketNlRest.PayrollRunResults.PayrollRunPayslipTypeComponentsByPayrollRunId(runs.id) runSpecifications;
Yes, here’s the rest of the stored procedure. I do think however that it’s the snippet with a query in
‘LoketNlRest.PayrollRunResults.PayrollRunPayslipTypeComponentsByPayrollRunId(runs.id) runSpecifications;’ which causes the problem.
declare
l_output varchar2;
in_employerId guid;
batchDate varchar2;
periodNumber varchar2;
periodYear varchar2;
begin
in_employerId := cast(cloud_http.get_request_query_parameter_value('employerId') as guid);
batchDate := cast(cloud_http.get_request_query_parameter_value('batchDate') as varchar2);
create or replace table payrollRuns@inmemorystorage
as
select runs.payrollRunStatus_key
, runs.payrollRunStatus_value
, runs.approvalTime
, runs.sequenceNumber
, runSpecifications.payrollComponent_key
, runSpecifications.payrollComponent_value
, runSpecifications.payrollComponent_category_key
, runSpecifications.payrollComponent_category_value
, runSpecifications.payrollComponent_costsEmployer_value
, runSpecifications.value
, runSpecifications.valueSpecialTariff
, runSpecifications.payrollPeriod_year
, runSpecifications.payrollPeriod_periodNumber
, runSpecifications.employmentId
from LoketNlRest.PayrollAdministration.PayrollAdministrationsByEmployerId('XXX') payrollAdministration
join LoketNlRest.PayrollRun.PayrollRunsByPayrollAdministrationId(payrollAdministration.id) runs
on runs.payrollRunStatus_key = 9
and TRUNC(runs.approvalTime) = TO_DATE('11/01/2018','DD/MM/YYYY')
join LoketNlRest.PayrollRunResults.PayrollRunPayslipTypeComponentsByPayrollRunId(runs.id) runSpecifications;
on runs.payrollPeriod_year = runspecifications.payrollPeriod_year
;
create or replace table payrollPeriodData@inmemorystorage
as
select employmentId
, payrollPeriodData.distributionUnit_code
, payrollPeriodData.distributionUnit_description
, payrollPeriodData.payrollPeriod_year
, payrollPeriodData.payrollPeriod_periodNumber
from ( select distinct employmentId
from payrollRuns@inMemoryStorage) employmentIds
join LoketNlRest.PayrollPeriodData.PayrollPeriodDataByEmploymentId(employmentIds.employmentId
) payrollPeriodData
;
select pr.payrollRunStatus_key
, pr.payrollRunStatus_value
, pr.approvalTime
, pr.sequenceNumber
, pr.payrollComponent_key
, pr.payrollComponent_value
, pr.payrollComponent_category_key
, pr.payrollComponent_category_value
, pr.payrollComponent_costsEmployer_value
, pr.value
, pr.valueSpecialTariff
, pr.payrollPeriod_year
, pr.payrollPeriod_periodNumber
, pr.employmentId
, pd.distributionUnit_code
, pd.distributionUnit_description
into l_output
from payrollRuns@inMemoryStorage pr
join payrollPeriodData@inMemoryStorage pd
on pr.employmentId = pd.employmentId
and pr.payrollPeriod_periodnumber = pd.payrollPeriod_periodnumber
and pr.payrollPeriod_year = pd.payrollPeriod_year
for json auto
;
cloud_http.set_response_content_type('application/json');
cloud_http.set_response_body_text(l_output);
end;
The error itgenpse009 can not be reproduced using a statement such as:
declare
l_output varchar2;
begin
create or replace table t1@inmemorystorage
as
select 1 c, dummy_int16 from dual@datadictionary union all select 2 c, dummy_int16 from dual@datadictionary
;
create or replace table t2@inmemorystorage
as
select 1 c, dummy_string from dual@datadictionary union all select 2 c, dummy_string from dual@datadictionary
;
select *
into l_output
from t1@inmemorystorage x
join t2@inmemorystorage y
on x.c = y.c
for json auto
;
dbms_output.put_line(l_output);
end;
Can you simplify the PSQL code to the absolute minimum which still throws an itgenpse009?
This question was automatically closed after 2 weeks of inactivity. The last answer given has been marked as a solution.
Please ask a new question via a separate topic if the problem occurs again. Please include a link to this topic in the new question by pasting its URL into the text.