A DB2 Cursor Fetch statement failed due to null values in the record.
What would happen if I try to execute the same fetch statement again immediately ?
Will it move to next record or stay at the same position throwing the same error ?
There are two ways to fix this error.
Method one
you need null indicators and you check them.
method two coalesce the field to a value RPG can handle natively.
declare mycsr cursor for
select cast(coalesce(myfield,' ') as char(10))
, cast(coalesce(mydec,0) as integer) from myfile.mylib
Related
I have a trigger that takes a line, grabs its ST_StartPoint and ST_EndPoint and then grabs the nearest point to those endpoints, and assigns a node_id to a column. This Fiddle shows the trigger as well as some example data. When running this trigger, I am getting an error on QGIS stating the following:
Could not commit changes to layer pipes
Errors: ERROR: 1 feature(s) not added.
Provider errors:
PostGIS error while adding features: ERROR: Operation on mixed SRID geometries
CONTEXT: SQL statement "SELECT
j.node_id,
i.node_id
FROM ST_Dump(ST_SetSRID(NEW.geom,2346)) dump_line,
LATERAL (SELECT s.node_id,(ST_SetSRID(s.geom,2346))
FROM structures s
ORDER BY ST_EndPoint((dump_line).geom)<->s.geom
LIMIT 1) j (node_id,geom_closest_downstream),
LATERAL (SELECT s.node_id,(ST_SetSRID(s.geom,2346))
FROM structures s
ORDER BY ST_StartPoint((dump_line).geom)<->s.geom
LIMIT 1) i (node_id,geom_closest_upstream)"
PL/pgSQL function sewers."Up_Str"() line 3 at SQL statement
I have attempted to resolve the issue by editing the trigger to this but this has not fixed the problem. Any ideas would be greatly appreciated.
The line ORDER BY ST_EndPoint((dump_line).geom)<->s.geom (and the similar one for the start point) is likely the faulty one.
You could, again, declare the CRS of s.geom. Note that by doing this any spatial index on structures would not be used, it would have to be created on ST_SetSRID(geom,2346)
The clean way would be to set the CRS at the column level on the structures table
alter table structures alter column geom TYPE geometry(point,2346) using st_setSRID(geom,2346);
How can I select an individual element from a record type returned by a function?
I have tried the following but returns an error near '.'
select working_hours_downtime().downtime from node.
the function working_hours_downtime returns a record of two fields message and downtime. How can I get downtime only from the record?
Remember I do not need this.
select downtime from working_hours_downtime(...)
since it does not suitable for my case since the query is part of a complex select query.
You need to enclose the record in parentheses:
select (working_hours_downtime()).downtime
from node;
But if working_hours_downtim() returns a setof or table you should put it into the from clause.
A user can only modify the ST_ASSMT_NM and , CAN_DT columns in the ST_ASSMT_REF record. In our system, we keep history in the same table and we never really update a record, we just insert a new row to represent the updated record. As a result, the "active" record is the record with the greatest LAST_TS timestamp value for a VENDR_ID. To prevent the possibility of an update to columns that cannot be changed, I wrote the logical UPDATE so that it retrieves the non-changable values from the original record and copies them to the new one being created. For the fields that can be modified, I pass them as params,
INSERT INTO GSAS.ST_ASSMT_REF
(
VENDR_ID
,ST_ASSMT_NM
,ST_CD
,EFF_DT
,CAN_DT
,LAST_TS
,LAST_OPER_ID
)
SELECT
ORIG_ST_ASSMT_REF.VENDR_ID
,#ST_ASSMT_NM
,ORIG_ST_ASSMT_REF.ST_CD
,ORIG_ST_ASSMT_REF.EFF_DT
,#CAN_DT
,CURRENT TIMESTAMP
,#LAST_OPER_ID
FROM
(
SELECT
ST_ASSMT_REF_ACTIVE_V.VENDR_ID
,ST_ASSMT_REF_ACTIVE_V.ST_ASSMT_NM
,ST_ASSMT_REF_ACTIVE_V.ST_CD
,ST_ASSMT_REF_ACTIVE_V.EFF_DT
,ST_ASSMT_REF_ACTIVE_V.CAN_DT
,CURRENT TIMESTAMP
,ST_ASSMT_REF_ACTIVE_V.LAST_OPER_ID
FROM
G2YF.ST_ASSMT_REF_ACTIVE_V ST_ASSMT_REF_ACTIVE_V --The view of only the most recent, active records
WHERE
ST_ASSMT_REF_ACTIVE_V.VENDR_ID = #VENDR_ID
) ORIG_ST_ASSMT_REF;
However, I am getting this error:
DB2 SP
:
ERROR [42610] [IBM][DB2] SQL0418N The statement was not processed because the statement contains an invalid use of one of the following: an untyped parameter marker, the DEFAULT keyword, or a null value.
It appears as though DB2 will not allow me to use a variable in a SELECT statement. For example, when I do this in TOAD for DB2:
select 1, #vendorId from SYSIBM.SYSDUMMY1
I get a popup dialog box. When I provide any string value, I get the same error.
I usually use SQL Server and I'm pretty sure I wouldn't have an issue doing this but I am not sure how to handle it get.
Suggestions? I know that I could do this in two seperate commands, 1 query SELECT to retreive the original VALUES and then supply the returned values and the modified ones to the INSERT command, but I should be able to do thios in one. Why can't I?
As you mentioned in your comment, DB2 is really picky about data types, and it wants you to cast your variables into the right data types. Even if you are passing in NULLs, sometimes DB2 wants you to cast the NULL to the data type of the target column.
Here is another answer I have on the topic.
I have a problem with execeute statement in a stored procedure and i cant figure it out, i try the text of the query in a variable, show it in a exception to see if was well, copy and execute it and worket, but inside the execute statement i get the same error "Unexpected end of command - line 1, column 532676549"
execute statement 'insert into rep_balancediario(id_rep_balancediario,id_plancuenta,id_saldocontable,nivel,codigoreducido,
SALDOANTERIOR,CREDITO,DEBITO,SALDODIA, cuentacontable,imputable,id_moneda,contracuenta,saldocontabledes,ID_SUCURSALAGENCIA)
values(gen_id(id_rep_balancediario,1),'||:v_id_PlanCuenta||','||:V_NROSALDOCONTABLE||','||:v_Nivel||',"'||:v_CodigoReducido||'",'||
:V_SALDOANTERIORMN||','||:V_CREDITOMN||','||:V_DEBITOMN||','||:v_resultadosaldoactual||',"'||cast(:v_CuentaContable as VARCHAR(11))||'","S",'
||:v_nromoneda||',
"'||cast(:v_contracuenta as VARCHAR (11))||'","'||cast(:V_DESSALDOCONTABLE as VARCHAR(255))||' >'||cast(:v_des_suc as varchar(100))||'",'
||:VE_IDSUCURSALAGENCIA||')'
--:V_str_sql
with AUTONOMOUS TRANSACTION;
does some one know what could by the problem?
Unexpected end of command usually means that the parser reached the end of the statement while it was still expecting tokens, or reached a parser state where it should be complete but there are still tokens left. The fact you are concatenating values into the query is a red flag. Also the "column 532676549" could be an indication of problem, as that exceeds query length limits (64k in Firebird 2.5 and earlier), and also suggests you have literals that are larger than supported (32k).
Execute statement supports parametrized queries: use it. I'd suggest that you rewrite your query to a parametrized query and see if that works, as an example:
execute statement ('insert into aTable (column1, column2) values (?, ?)') (aVariable, 'literal');
or
execute statement ('insert into aTable (column1, column2) values (:var1, :var2)') (var1 := aVariable, var2 := 'literal');
I also see that your query contains double quotes where I'd expect single quotes, which suggests that you use the deprecated dialect 1, which brings yet another set of potential problems.
Can anyone see why I'm getting the "No current record for fetch operation" below?
I'm successfully skipping duplicate records by catching and not re-throwing the unique key violation exception below. There is another error however.
FOR SELECT
...
FROM
P_SELECT_CLAIM_FILE cf
ORDER BY
cf.DATESBM, cf.TIMESBM, cf.TRANSCDE
INTO
...variables
DO BEGIN
INSERT INTO
CLAIM_TABLE (...)
VALUES (...variables);
WHEN GDSCODE unique_key_violation DO
TX_ID=0;
WHEN GDSCODE no_cur_rec DO
/* Why does this happen?
-508 335544348 no_cur_rec No current record for fetch operation
*/
EXCEPTION E 'no_cur_rec ' || TX_ID;
END
The procedure P_SELECT_CLAIM_FILE contains another FOR SELECT INTO with lots of trimming and finally a SUSPEND command. This reads from a fixed width text file.
I'm tempted to change this into a single INSERT SELECT where not exists statement. I prefer to make a minimal fix instead however; the holidays already here.