Find the column/field in error - db2

I am working on a mainframe and my DB2 Cobol program got abended with SQLCODE -407 while inserting a row in a table. I know the remedy to this error, but the INSERT query is inserting into more than 100 fields. Is there any other way other than putting displays to know which field is in error for the NULL values. Below is the error message I received:
DB2ERRD **ERROR** DB2 CALL UNSUCCESSFUL. SQLCODE = -407. WARNING FLAGS =
DSNT408I SQLCODE = -407, ERROR: AN UPDATE, INSERT, OR SET VALUE IS NULL, BUT THE OBJECT COLUMN CANNOT CONTAIN NULL
VALUES
DSNT418I SQLSTATE = 23502 SQLSTATE RETURN CODE
DSNT415I SQLERRP = DSNXRIHB SQL PROCEDURE DETECTING ERROR
DSNT416I SQLERRD = -136 0 0 -1 0 0 SQL DIAGNOSTIC INFORMATION
DSNT416I SQLERRD = X'FFFFFF78' X'00000000' X'00000000' X'FFFFFFFF' X'00000000' X'00000000' SQL DIAGNOSTIC
INFORMATION

Normally, I would expect the name of your column in error to show up in your SQLCODE message (and indeed, it appears as if there are two spaces between COLUMN and CANNOT, where I would expect the column name to be).
However, according to the docs, the actual column name may also show up in the SQLCA. I would try outputting the values of SQLERRMC to see if your column shows up in there.

Related

How to create a trigger before insert in db2

I have three tables below:
I need to create a trigger to disallow students to take a class without completing their pre-requisites (must use a trigger). The trigger must return an error message "Missing Pre-req" when trying to insert a class without its proper pre-req.
So far, I wrote a command below:
create trigger checkPrereq
before insert on HW3.SCHEDULE
referencing new as newRow
for each row
When
(
select GRADE
from HW3.SCHEDULE
where HW3.SCHEDULE.ClassId =
(
select PrereqId from HW3.CLASS_PREREQ
where newRow.ClassId = HW3.CLASS_PREREQ.ClassId
)
) in ('F', null)
begin atomic
set newRow.Semester = null;
signal sqlstate 'KILLED' set message_text = ('Missing Pre-req');
end
but I got a warning:
DB21034E The command was processed as an SQL statement because it was
not a valid Command Line Processor command. During SQL processing it
returned: SQL0104N An unexpected token "GRADE" was found following
"ach row When (select". Expected tokens may include: ")". LINE
NUMBER=1. SQLSTATE=42601
I can not understand what was happening here. Could you please help fix this? Any help is appreciated!

How to assign value to a variable in select query in postgresql

I am migrating from mssql to postgresql
I am trying to assign a value to a temporary variable in select query
Below is the query in mssql
select flag = 0
It gives 0 as output wit flag as column identifier in mssql
I tried the following in postgresql
select flag := 0
select flag [:=0]
It says syntax error at or near :=
Does anybody know where I am going wrong?
It gives 0 as output wit flag as column identifier in mssql
Postgres honors the SQL standard and a column alias is defined with the AS keyword there.
So to get a column named flag with the value zero use the following:
select 0 as flag
flag = 0 in standard SQL (and Postgres) is a boolean expression that compares the the column flag with the value zero and returns either true, false or null depending on the column's value.

DB2 query in RazorSQL for getting the next val from a sequence

I am trying to run a DB2 query in RazorSQL for getting the next val from a sequence but getting the following error. Can anybody plz help me out.
VALUES NEXT VALUE FOR SEQ_UPLOAD_MASTER;
ERROR: An undefined object or constraint name was detected.
DB2 SQL error: SQLCODE: -204, SQLSTATE: 42704, SQLERRMC:
DB2INST1.SEQ_UPLOAD_MASTER Error Code: -204
Query = VALUES NEXT
VALUE FOR SEQ_UPLOAD_MASTER
Thanks. I got the solution. I was trying with the wrong syntax. Correct one is
`select nextval for ARCH_TRANCHE.SEQ_UPLOAD_MASTER from sysibm.sysdummy1;`

Table Valued User Defined Functions in DB2 Z/OS

Does anyone know if DB2 v9.1 z/OS supports Table Valued User Defined Functions?
This is what I am trying to create but I keep getting the error message below.
CREATE FUNCTION func_test(v_vchCol CHAR(10))
RETURNS TABLE(col_a char(10), row_cnt integer)
LANGUAGE SQL
SPECIFIC FUNCINFO
NOT DETERMINISTIC
READS SQL DATA
return
select col_1, count(*)
from SCHEMA_NAME.TEST1
where col_1 = v_vchCol
group by col_1;
Error Message:
ERROR [56038] [IBM][DB2] SQL0969N There is no message text
corresponding to SQL error "-4700" in the message file on this
workstation. The error was returned from module "DSNHSMS1" with
original tokens "". SQLSTATE=56038
Any help would be much appreciated
Yes, but it appears to require new function mode which apparently isn't enabled yet in the DB2 instance you're connected to.

How to trigger automatic update upon data insertion?

I am using SSIS 2008 and am trying to update one column in my table at the time of insertion. This one column is a uniqueidentifier field and I also wrote a trigger for updating this field. This code is below:
CREATE TABLE dbo.rd_information3_cleaned (
c1 uniqueidentifier NULL,
c2 nvarchar(50),
c3 nvarchar(50),
c4 nvarchar(50)
)
create trigger dbo.trg_client_information_id
on client_information
after insert
as
begin
update client_information
set client_information_id = newid()
from Inserted
end
I know this code works cause I tested it in SSMS and it does update this column. Also, my table looks like:
c1 c2 c3 c4
xxxx-xxxx-xxxx-xxxx A BB C5
xxxx-xxxx-xxxx-xxxx A2 BB C
xxxx-xxxx-xxxx-xxxx A3 BB C7
xxxx-xxxx-xxxx-xxxx A4 BB C
But when I try to run this SSIS package, I only write to c2 - c4, since the trigger should update column "c1". But instead, I am getting an error:
Information: 0x40043007 at Write to Client_Information, SSIS.Pipeline: Pre-Execute phase is beginning.
Information: 0x4004300C at Write to Client_Information, SSIS.Pipeline: Execute phase is beginning.
Error: 0xC0202009 at Write to Client_Information, Client_Information [27]: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005.
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0" Hresult: 0x80004005 Description: "The statement has been terminated.".
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0" Hresult: 0x80004005 Description: "Cannot insert duplicate key row in object 'dbo.Client_Information' with unique index 'IX_Client_Demographics_Unique'.".
Error: 0xC0209029 at Write to Client_Information, Client_Information [27]: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "input "OLE DB Destination Input" (40)" failed because error code 0xC020907B occurred, and the error row disposition on "input "OLE DB Destination Input" (40)" specifies failure on error. An error occurred on the specified object of the specified component. There may be error messages posted before this with more information about the failure.
Error: 0xC0047022 at Write to Client_Information, SSIS.Pipeline: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "Client_Information" (27) failed with error code 0xC0209029 while processing input "OLE DB Destination Input" (40). The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running. There may be error messages posted before this with more information about the failure.
Information: 0x40043008 at Write to Client_Information, SSIS.Pipeline: Post Execute phase is beginning.
Information: 0x402090DF at Write to Client_Information, Client_Information [27]: The final commit for the data insertion in "component "Client_Information" (27)" has started.
Information: 0x402090E0 at Write to Client_Information, Client_Information [27]: The final commit for the data insertion in "component "Client_Information" (27)" has ended.
Information: 0x4004300B at Write to Client_Information, SSIS.Pipeline: "component "Client_Information" (27)" wrote 2 rows.
Information: 0x40043009 at Write to Client_Information, SSIS.Pipeline: Cleanup phase is beginning.
Task failed: Write to Client_Information
SSIS package "Echo Information Migration2.dtsx" finished: Success.
The program '[2564] Echo Information Migration2.dtsx: DTS' has exited with code 0 (0x0).
I am almost sure the cause of this error is that client_information_id field. cause I am able to write more than one row in SSMS if I just make that field uniqueidentifier; otherwise I can't write more than one row to this table. So I am wondering. Is it possible that I need to set a TIME property in SSIS to give the trigger enough time to work? Why else could I be getting this error?
Also, I edited the OLE DB Destination and I set Maximum insert commit size = 1, but I still got the same error.
Long story short, don't use a trigger, just use a DEFAULT as shown in the documentation. The table DDL and trigger code you posted seem to have nothing to do with each other, but I assume you really want something like this:
create table dbo.Clients (
ClientID uniqueidentifier not null primary key default newid(),
ClientAttributeA nvarchar(50) not null,
-- etc.
)
I suspect that when you tested in SSMS you tested inserting one row at a time, but your SSIS package is inserting multiple rows. The NEWID() function is called only once in the trigger, so if you insert one row it will work but if you insert multiple rows then you get same NEWID() value for each one, causing your duplicate key violation.