not data found exception in insert statement - plsql

I am having a big procedure where in I'm doing a insert in a scenario.
Unfortunately, I am getting NOT DATA FOUND exception in the INSERT statement where in it don't have select clause for values.
INSERT INTO CW_PC_CT
(BATCH_ID, CONTRACT_TYPE, CONTRACT_CATEGORY, ELEMENT_ID, COMMITMENT_REFERENCE, DURATION_UNITS, DURATION,
PLAN_ID_DISCOUNT, PLAN_ID_CREDIT, ACTIVATION_TYPE_ID_NRC, TERMINATION_TYPE_ID_NRC, IS_PROMOTION,DESCRIPTION_CODE,
FOREIGN_CODE, START_BY_UNITS, START_BY, ACTIVE_DATE, FIXED_START_DATE, FIXED_END_DATE, PARTIAL_PERIOD,
COMMITMENT_TYPE_ID_NRC, DISCOUNT_BASE_PERIOD, ROLLOVER_ORDER, ROLLOVER_GROUPING,BONUS_POINT_ID, PRORATE_CONTRACT_START,
PRORATE_CONTRACT_END, PRORATE_INTERIM_BILL, PRORATE_PERIOD_CHANGE, PRORATE_ACCOUNT_START,
PRORATE_ACCOUNT_END, PRORATE_TARGET_THRESHOLD, PRORATE_TARGET_REBATES, ALLOW_ACCOUNT, ALLOW_SERV_INST,
ALLOW_ACCT_GROUP, ALLOW_SI_GROUP, BILL_PERIOD, MIN_DURATION_UNITS, MIN_DURATION, MIN_NOTICE_UNITS, MIN_NOTICE_DELAY,
IS_CUSTOM, WHEN_APPLIED, APPLY_DURING_SUSPEND)
VALUES(V_BATCH_ID, V_CONTRACT_TYPE, 8, V_GET_PARAM_INT('P_ELEMENT_ID_CT'),
V_GET_PARAM_INT('P_COMMIT_REF_CT'), V_GET_PARAM_INT('P_DURATION_UNITS_CT_DIS'), V_GET_PARAM_INT('P_DURATION_CT_DIS'),
V_GET_PARAM_INT('P_PLAN_ID_DISC_CT'), V_PLAN_ID_CREDIT, V_GET_PARAM_INT('P_ACT_TYPE_ID_NRC_CT_DIS'),
V_GET_PARAM_INT('P_TERM_TYPE_ID_NRC_CT'), V_GET_PARAM_INT('P_IS_PROMOTION_CT'), V_DESCRIPTION_CODE,
V_GET_PARAM_INT('P_FOREIGN_CODE_CT'), V_GET_PARAM_INT('P_START_BY_UNITS_CT'), V_GET_PARAM_INT('P_START_BY_CT'),
V_COMPONENT_ACTIVE_DATE, NULL, NULL, V_GET_PARAM_INT('P_PARTIAL_PERIOD_CT'),
V_GET_PARAM_INT('P_COMMIT_TYPE_ID_NRC_CT'), V_GET_PARAM_INT('P_DISC_BASE_PERIOD_CT'),
V_GET_PARAM_INT('P_ROLLOVER_ORDER_CT'), V_GET_PARAM_INT('P_ROLLOVER_GRP_CT'),
V_GET_PARAM_INT('P_BONUS_POINT_ID_CT'), V_GET_PARAM_INT('P_PRORATE_CONTRACT_START_CT'),
V_GET_PARAM_INT('P_PRORATE_CONTRACT_END_CT'), V_GET_PARAM_INT('P_PRORATE_INTERIM_BILL_CT'),
V_GET_PARAM_INT('P_PRORATE_PERIOD_CHANGE_CT'), V_GET_PARAM_INT('P_PRORATE_ACCOUNT_START_CT'),
V_GET_PARAM_INT('P_PRORATE_ACCOUNT_END_CT'), V_GET_PARAM_INT('P_PRORATE_TARGET_TRSHLD_CT'),
V_GET_PARAM_INT('P_PRORATE_TARGET_REBATES_CT'), V_GET_PARAM_INT('P_ALLOW_ACCOUNT_CT'),
V_GET_PARAM_INT('P_ALLOW_SERV_INST_CT'), V_GET_PARAM_INT('P_ALLOW_ACCT_GROUP_CT'),
V_GET_PARAM_INT('P_ALLOW_SI_GROUP_CT'), V_GET_PARAM_INT('P_BILL_PERIOD_CT'),
V_GET_PARAM_INT('P_MIN_DURATION_UNITS_CT'), V_GET_PARAM_INT('P_MIN_DURATION_CT'),
V_GET_PARAM_INT('P_MIN_NOTICE_UNITS_CT'), V_GET_PARAM_INT('P_MIN_NOTICE_DELAY_CT'),
V_GET_PARAM_INT('P_IS_CUSTOM_CT'), V_GET_PARAM_INT('P_WHEN_APPLIED_CT'), V_GET_PARAM_INT('P_APPLY_DURING_SUSPEND_CT'));
Below is the exception I am getting..
ORA-01403: no data found
ORA-06512: at "ABC.ABCDEFGHIJKL", line 2500
ORA-06512: at line 9
I am wondering the insert statement don't have select clause for getting data but no data found exception was coming.
can someone help with this.
Edit:
V_GET_PARAM_INT is not a procedure or function.
TYPE T_DEFAULT_INT IS TABLE OF CW_PC_CONFIG_DEFAULT_MASTER.INT_VALUE%TYPE
INDEX BY CW_PC_CONFIG_DEFAULT_MASTER.PARAMETER_NAME%TYPE;
V_GET_PARAM_INT T_DEFAULT_INT;
V_GET_PARAM_CHAR T_DEFAULT_CHAR;
FOR C_PARAM_INT IN C_LOAD_PC_DEFAULT_INT
LOOP
V_PARAMETER_NAME := C_PARAM_INT.PARAMETER_NAME;
V_PARAM_INT_VALUE := C_PARAM_INT.INT_VALUE;
V_GET_PARAM_INT(V_PARAMETER_NAME) := V_PARAM_INT_VALUE;
END LOOP;

Related

How to unserialize R model in SQL Server for predicting?

I've created a model in R, published into SQL Server table and validated the model by calling it into SQL Server.
However, I'm failing in an attempt to use the model for prediction over new data.
Here's my script:
DROP PROCEDURE IF EXISTS predict_risk_new_data;
GO
CREATE OR ALTER PROCEDURE predict_risk_new_data (#q nvarchar(max))
AS
BEGIN
DECLARE #model varchar(30) = 'risk_rxLogit'
DECLARE #rx_model varbinary(max) = (SELECT model FROM rx_models WHERE model_name = #model);
EXEC sp_execute_external_script
#language = N'R'
,#script = N'
require("RevoScaleR");
input_data = InputDataSet;
model <- unserialize(rx_model);
prediction <- rxPredict(model, input_data, writeModelVars = TRUE);
OutputDataSet <- cbind(predictions[1], predictions[2]);'
,#input_data_1 = #q
,#parallel = 1
,#params = N'#rx_model varbinary(max), #r_rowsPerRead int'
,#input_data_1_name = N'InputDataSet'
,#rx_model = #rx_model
,#r_rowsPerRead = 100
WITH result sets (("Risk_Pred" float, "ZIP" int));
END
GO;
/*
EXEC predict_risk 'SELECT TOP 100 [ZIP], [Week], [Age], [Risk] FROM dbo.Risk'
*/
Here's the error output:
Msg 39004, Level 16, State 20, Line 223 A 'R' script error occurred
during execution of 'sp_execute_external_script' with HRESULT
0x80004004. Msg 39019, Level 16, State 2, Line 223 An external script
error occurred: Error in unserialize(rx_model) : read error Calls:
source -> withVisible -> eval -> eval -> unserialize
Error in execution. Check the output for more information. Error in
eval(expr, envir, enclos) : Error in execution. Check the output
for more information. Calls: source -> withVisible -> eval -> eval ->
.Call Execution halted
New to R/ML in SQL Server, help would be aprreciated.
Thanks in advance.
When I did something like this I had to add as.raw to the model.
Try this
model <- unserialize(as.raw(rx_model));

Application Engine Peoplecode bind variables

I have the below PeopleCode step in an Application Engine program that reads a CSV file using a File Layout and then inserts the data into a table, and I am just trying to get a better understanding of how the the line of code (&SQL1 = CreateSQL("%Insert(:1)");) in the below script gets generated. It looks like the CreateSQL is using a bind variable (:1) inside the Insert statement, but I am struggling as where to find where this variable is defined in the program.
Function EditRecord(&REC As Record) Returns boolean;
Local integer &E;
&REC.ExecuteEdits(%Edit_Required + %Edit_DateRange + %Edit_YesNo + %Edit_OneZero);
If &REC.IsEditError Then
For &E = 1 To &REC.FieldCount
&MYFIELD = &REC.GetField(&E);
If &MYFIELD.EditError Then
&MSGNUM = &MYFIELD.MessageNumber;
&MSGSET = &MYFIELD.MessageSetNumber;
&LOGFILE.WriteLine("****Record:" | &REC.Name | ", Field:" | &MYFIELD.Name);
&LOGFILE.WriteLine("****" | MsgGet(&MSGSET, &MSGNUM, ""));
End-If;
End-For;
Return False;
Else
Return True;
End-If;
End-Function;
Function ImportSegment(&RS2 As Rowset, &RSParent As Rowset)
Local Rowset &RS1, &RSP;
Local string &RecordName;
Local Record &REC2, &RECP;
Local SQL &SQL1;
Local integer &I, &L;
&SQL1 = CreateSQL("%Insert(:1)");
rem &SQL1 = CreateSQL("%Insert(:1) Order by COUNT_ORDER");
&RecordName = "RECORD." | &RS2.DBRecordName;
&REC2 = CreateRecord(#(&RecordName));
&RECP = &RSParent(1).GetRecord(#(&RecordName));
For &I = 1 To &RS2.ActiveRowCount
&RS2(&I).GetRecord(1).CopyFieldsTo(&REC2);
If (EditRecord(&REC2)) Then
&SQL1.Execute(&REC2);
&RS2(&I).GetRecord(1).CopyFieldsTo(&RECP);
For &L = 1 To &RS2.GetRow(&I).ChildCount
&RS1 = &RS2.GetRow(&I).GetRowset(&L);
If (&RS1 <> Null) Then
&RSP = &RSParent.GetRow(1).GetRowset(&L);
ImportSegment(&RS1, &RSP);
End-If;
End-For;
If &RSParent.ActiveRowCount > 0 Then
&RSParent.DeleteRow(1);
End-If;
Else
&LOGFILE.WriteRowset(&RS);
&LOGFILE.WriteLine("****Correct error in this record and delete all error messages");
&LOGFILE.WriteRecord(&REC2);
For &L = 1 To &RS2.GetRow(&I).ChildCount
&RS1 = &RS2.GetRow(&I).GetRowset(&L);
If (&RS1 <> Null) Then
&LOGFILE.WriteRowset(&RS1);
End-If;
End-For;
End-If;
End-For;
End-Function;
rem *****************************************************************;
rem * PeopleCode to Import Data *;
rem *****************************************************************;
Local File &FILE1, &FILE3;
Local Record &REC1;
Local SQL &SQL1;
Local Rowset &RS1, &RS2;
Local integer &M;
&FILE1 = GetFile("\\nt115\apps\interface_prod\interface_in\Item_Loader\ItemPriceFile.csv", "r", "a", %FilePath_Absolute);
&LOGFILE = GetFile("\\nt115\apps\interface_prod\interface_in\Item_Loader\ItemPriceFile.txt", "r", "a", %FilePath_Absolute);
&FILE1.SetFileLayout(FileLayout.GH_ITM_PR_UPDT);
&LOGFILE.SetFileLayout(FileLayout.GH_ITM_PR_UPDT);
&RS1 = &FILE1.CreateRowset();
&RS = CreateRowset(Record.GH_ITM_PR_UPDT);
REM &SQL1 = CreateSQL("%Insert(:1)");
&SQL1 = CreateSQL("%Insert(:1)");
/*Skip Header Row: The following line of code reads the first line in the file layout (the header)
and does nothing. Then the pointer goes to the next line in the file and starts using the
file.readrowset*/
&some_boolean = &FILE1.ReadLine(&string);
&RS1 = &FILE1.ReadRowset();
While &RS1 <> Null
ImportSegment(&RS1, &RS);
&RS1 = &FILE1.ReadRowset();
End-While;
&FILE1.Close();
&LOGFILE.Close();
The :1 is coming from the line further down &SQL1.Execute(&REC2);
&REC2 gets assigned a record object, so the line &SQL1.Execute(&REC2); evaluates to %Insert(your_record_object)
Here is a simple example that's doing basically the same thing
Here is a description of %Insert
Answer because too long to comment:
The table name is most likely (PS_)GH_ITM_PR_UPDT. The general consensus is to name the FileLayout the same as the record it is based on.
If not, it is defined in FileLayout.GH_ITM_PR_UPDT. Open the FileLayout, right click the segment and under 'Selected Node Properties' you will find the 'File Record Name'.
In your code this record is carried over into &RS1.
&FILE1.SetFileLayout(FileLayout.GH_ITM_PR_UPDT);
&RS1 = &FILE1.CreateRowset();
The rowset is a collection of rows. A row consists of records and a record is a row of data from a database table. (Peoplesoft Object Data Types are fun...)
This rowset is filled with data in the following statement:
&RS1 = &FILE1.ReadRowset();
This uses your file as input and outputs a rowset collection, mapping the data to records based on how you defined your FileLayout.
The result is fed into the ImportSegment function:
ImportSegment(&RS1, &RS);
Function ImportSegment(&RS2 As Rowset, &RSParent As Rowset)
&RS2 in the function is a reference to &RS1 in the rest of your code.
The table name is also hidden here:
&RecordName = "RECORD." | &RS2.DBRecordName;
So if you can't/don't want to check the FileLayout, you could output &RS2.DBRecordName with a messagebox and your answer will be Message Log of your Process Monitor.
Finally a record object is created for this database table and it is filled with a row from the rowset. This record is inserted into the database table:
&REC2 = CreateRecord(#(&RecordName));
&RS2(&I).GetRecord(1).CopyFieldsTo(&REC2);
&SQL1 = CreateSQL("%Insert(:1)");
&SQL1.Execute(&REC2);
TLDR:
Table name can be found in the FileLayout or output in the ImportSegment Function as &RS2.DBRecordName

XQuery Type of value does not match

declare variable $fb := doc("factbook.xml")/mondial;
for $c in $fb//country
where ($c/encompassed/#continent = 'f0_119') and ($c/#population < 100000)
return concat('Country: ',$c/name, ', Population: ',$c/#population);
it returns:
Type Error: Type of value '
()
' does not match sequence type: xs:anyAtomicType?
At characters 11681-11698
At File "q2_3.xq", line 4, characters 13-67
At File "q2_3.xq", line 4, characters 13-67
At File "q2_3.xq", line 4, characters 13-67
however, if i do not do a concat return, just name or population it will work, and most strange thing is i have another program :
declare variable $fb := doc("factbook.xml")/mondial;
for $c in $fb//country
where $c/religions = 'Seventh-Day Adventist'
order by $c/name
return concat('Country: ',$c/name, ', Population: ',$c/#population);
The return syntax is exactly same, however, it works.
Why this happens?
Without seeing an example of your data it's impossible to say for sure, but if $c/name returns more than one value, then your error would make sense. Do you have any results where there are more than one name element?

Running embedded R code in Oracle raise error

I am a newbie in Oracle R embedded execution.
well, I have following code registered as
BEGIN
sys.rqScriptDrop('TSFORECAST');
SYS.RQSCRIPTCREATE('TSFORECAST',
'function(dat){
require(ORE)
require(forecast)
myts <- ts(dat,frequency=12)
model <- auto.arima(myts)
fmodel <- forecast(model)
fm = data.frame(fmodel$mean, fmodel$upper,fmodel$lower)
names(fm) <- c("mean","l80","l95","u80","u95")
return(fm)
}'
);
END;
as I execute the function for the first time with this code:
select *
from table(
rqTableEval(
cursor(select balance from tmp_30),
cursor(select 1 as "ore.connect" from dual),
'select 1 mean, 1 l80, 1 l95, 1 u80, 1 u95 from dual',
'TSFORECAST'
)
)
it generates the results I expected. But after that it will never produce any result but instead it raises this error:
ORA-20000: RQuery error
Error in (function () :
unused arguments (width = 480, bg = "white", type = "raster")
ORA-06512: at "RQSYS.RQTABLEEVALIMPL", line 112
ORA-06512: at "RQSYS.RQTABLEEVALIMPL", line 109
20000. 00000 - "%s"
*Cause: The stored procedure 'raise_application_error'
was called which causes this error to be generated.
*Action: Correct the problem as described in the error message or contact
the application administrator or DBA for more information.
I have searched this error but could not find anything helpful. Can anyone help me with this error?

SAS - hash tables and has_next

I'm looking for an elegant solution to the below issue that will help avoid code duplication. You can see that this line:
put auction_id= potential_buyer= ;* THIS GETS REPEATED;
Gets repeated in this code:
data results;
attrib potential_buyer length=$1;
set auction;
if _n_ eq 1 then do;
declare hash ht1(dataset:'buyers', multidata: 'y');
ht1.definekey('auction_id');
ht1.definedata('potential_buyer');
ht1.definedone();
call missing (potential_buyer);
end;
**
** LOOP THROUGH EACH POTENTIAL BUYER AND PROCESS THEM
*;
if ht1.find() eq 0 then do;
put auction_id= potential_buyer= ;* THIS GETS REPEATED;
ht1.has_next(result: ht1_has_more);
do while(ht1_has_more);
rc = ht1.find_next();
put auction_id= potential_buyer= ;* THIS GETS REPEATED;
ht1.has_next(result: ht1_has_more);
end;
end;
run;
I've simplified the above example to a single line as the real code block is quite long and complex. I'd like to avoid using a %macro snippet or a %include if possible as I'd like to keep the logic "within" the data step.
Here's some sample data:
data auction;
input auction_id;
datalines;
111
222
333
;
run;
data buyers;
input auction_id potential_buyer $;
datalines;
111 a
111 c
222 a
222 b
222 c
333 d
;
run;
I figured it out. Turned out to be pretty simple in the end just had a little trouble wrapping my brain around it:
data results;
attrib potential_buyer length=$1;
set auction;
if _n_ eq 1 then do;
declare hash ht1(dataset:'buyers', multidata: 'y');
ht1.definekey('auction_id');
ht1.definedata('potential_buyer');
ht1.definedone();
call missing (potential_buyer);
end;
**
** LOOP THROUGH EACH POTENTIAL BUYER AND PROCESS THEM
*;
if ht1.find() eq 0 then do;
keep_processing = 1;
do while(keep_processing);
put auction_id= potential_buyer= ;* THIS GETS DOESNT GET REPEATED ANYMORE =);
ht1.has_next(result: keep_processing);
rc = ht1.find_next();
end;
end;
run;
You can solve it this way....but Rob's answer is better.
data results;
%Macro NoDuplicate;
Put auction_id= potential_buyer= ; * No Longer Duplicated;
%Mend noduplicate;
attrib potential_buyer length=$1;
set auction;
if _n_ eq 1 then do;
declare hash ht1(dataset:'buyers', multidata: 'y');
ht1.definekey('auction_id');
ht1.definedata('potential_buyer');
ht1.definedone();
call missing (potential_buyer);
end;
**
** LOOP THROUGH EACH POTENTIAL BUYER AND PROCESS THEM
*;
if ht1.find() eq 0 then do;
%NoDuplicate
ht1.has_next(result: ht1_has_more);
do while(ht1_has_more);
rc = ht1.find_next();
%NoDuplicate
ht1.has_next(result: ht1_has_more);
end;
end;
run;

Resources