DB2

IBM DB2 is a family of relational database server products developed by IBM that have been extended to support object-relational features and non-relational structures like JSON and XML. There are three main products in the DB2 family: DB2 for Linux, UNIX and Windows (informally known as DB2 LUW), DB2 for z/OS (mainframe), and DB2 for i (formerly OS/400), plus a version for IBM's Virtual Storage Extended (VSE) operating system.

Share tech news, updates, or what's on your mind.

Sign up to Post

DB2 10.5 on Windows

I have a query I am trying to optimize and I want to test a couple of different things.  The issue is that after I run it for the first time the data is in cache so first run is 5 minutes and next run is 15 seconds.  In MS SQL I would clear the execution plan for the query before each run to compensate for that.  Is there something similar in DB2?

Thanks!
0
Learn by Doing. Anytime. Anywhere.
Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

DB2 10.5 on Windows

Is there anyway to create an index in an online mode?  I want to create a composite index on a large production table and I don't want to lock the table.  The table has about  29,063,052 million rows and is heavily used.

Thanks!
0
Hi everyone,

I would like to list all the tables which are in production and not in test.
I tried with  
          select * from QSYS2.SYSSCHEMAS
but I can't find a way to get the attribute.

Thank You !!
0
DB2 10.5 on Windows using TOAD for DB2 6.3

I am trying to get a list of users and their permissions, especially SYSADM users.  I was told I have SYSADM but I hit an error while trying to create a stored proc so I ran this...

SELECT * FROM SYSIBMADM.PRIVILEGES 
 WHERE AUTHID = 'ME' AND AUTHIDTYPE = 'U';

Open in new window


I get this.



I would expect to see SYSADM as one of my privileges if I were SYSADM.  Am I making a bad assumption?  How can get a definitive list of users with SYSADM permissions.  My thought is no one on the server may have SYSADM level permissions because ever query I run from what I find on Google returns nothing.

Thank you!
0
DB2 10.5 on Windows

We moved some large tables to new tablespaces in production and then restarted the server.  Now we can't log into our HADR server due to reason code 4.  From what I see reason code 4 is

Reason Code 4 = Connection requests to an HADR standby database are not allowed while the replay-only window is active. The replay-only window is active when DDL or maintenance operations are being replayed on the standby.

If the primary db was rebooted before the HADR changes were complete, could it get stuck like this?  I would assume it would just start up again when the primary came back online.

Thanks!
0
Running DB2 10.5 on Windows

We have a DB2 10.5 HADR server set up that I should be able to use for read only queries.  I can connect to it (using TOAD), but when I do any selects from any table I get the following.

Lookup Error - DB2 Database Error: ERROR [] [IBM][DB2/NT64] SQL1773N  The statement or command failed because it requires functionality that is not supported on a read-enabled HADR standby database. Reason code = "1".

I checked the DB2_HADR_ROS registry entry and it is set to ON as it should be.

Has anyone else run into this?

Thank you!

Jim
0
Is there a general script library for DB2?  I am looking for examples of how to set up and run regular maintenance, do restores and backups, and so on.  I can, of course, dig up the info piece by piece and put things together but it would be so much easier to see examples of working scripts.  

Also, is there a general script I can run that will look for common issues and setting in my DB2 instance and give me feedback?  Like this but for DB2:  https://www.brentozar.com/blitz/

Thank you!

Jim
0
I am running DB2 10.5 on Windows.

I have a process that will capture the REORGCHK data for indexes to table so I can go through and pick out the indexes that need reorg based on the REORG column.  My question is, when is it best to just reorg all indexes on a given table?

If I have a very large table with 5 indexes and 3 or them need to be reorged, should I do a reorg all or 3 separate reorg statements for indexes indicated?  Is reorg all faster than one at a time or slower or the same?  

Thank you!

Jim
0
I am running DB2 10.5 on windows.

When I run

CALL REORGCHK_IX_STATS('T', 'ALL')

Open in new window


I get the error

Lookup Error - DB2 Database Error: ERROR [22011] [IBM][DB2/NT64] SQL0138N  The statement was not executed because a numeric argument of a scalar function is out of range.

According to the IBN Knowledgecenter  I should be able to do this.

If scope has a value of 'T', use this argument to specify one of the following values:
A fully qualified table name
The value ALL for all tables
The value USER for all user-defined tables
The value SYSTEM for system-defined tables

Can anyone explain what I am doing wrong?  Thank you!

Jim
0
This is on DB2 10.5 for Windows using TOAD.

How can I save the output of CALL SYSPROC.REORGCHK_IX_STATS('S', 'Schema1');  to a table?

Jim
0
Free Tool: SSL Checker
LVL 9
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

My background is as a MS SQL Server DBA, very new to DB2.

I have a report query that I have in a file and I want to analyse it using db2advis.  I run this

C:\Windows\system32>db2advis -d depsvcs -n MainSchema -i c:\db2advis\sqlfile.in -t  5

And I get this.

execution started at timestamp 2017-07-26-10.55.06.475000
Error.  Could not open this input file [c:\db2advis\sqlfile.in]

Error.  No valid statements were found in this input file or in the
workload table.


In windows I set the security to the db2advis folder to full control by everyone.  Same for the sqlfile.in file.

So how do I get db2advis to actually open and use the file?

Thank you!
0
Hi Experts,

I try to check a value in a SQL where clause, but get the error: CPD4374

On the  Where xxxx in() of the next statement

Exec SQL Select * from my file
Where Field1 = :Parm1
  and Field2 = in(:Parm2)

Field2 is numeric(15,0)
Parm2 is Character(128) and contains  '12,13,45,16,32  '

What is missing?
0
Environment:
IIS:8.0
.net4.5
windows server 2012
11.PNG 22.PNG
My website sometime will show this error in the web server .

A process serving application pool 'XXX' suffered a fatal communication error with the Windows Process Activation Service. The process id was '6052'. The data field contains the error number.

please help.
0
Thanks for reading.

I have an SQL database with a linked DB2 server. My client software interfaces with SQL.

The DB2 server contains a parts table, which contains pricing and availability information.

I read a linked view from the DB2 server which is presented as a SQL view at the SQL end. It takes a few seconds to come over in its entirety, which isn't a problem unless I want to run some heavy interrogation on it. Which, I do.

Realistically this information shouldn't be more than 10 minutes behind. So, I thought a trigger might be the answer. I have a table I update every 5 minutes for a completely separate reason. I thought I could attach a trigger to this table to drop/insert a temp parts table, and then merge the information to a locally held table.

I've not got as far as the merge yet, just the first bit! Here is the trigger:

USE MyDB
GO

CREATE TRIGGER dbo.UpdateParts
ON dbo.T1
AFTER UPDATE  
  
AS

IF OBJECT_ID('dbo.TempParts', 'U') IS NOT NULL
DROP TABLE TempParts

SELECT     DB2PartsView.*
INTO            TempParts
FROM         DB2PartsView

GO

Open in new window


I can create the trigger fine, and if I run the SQL outside of the trigger the table is created successfully.

However, when I fire the trigger, I get the error:

"The row value(s) updated or deleted either do not make the row unique or they alter multiple rows"

I understand that triggers have hidden 'Inserted' and 'Deleted' tables, and that perhaps this might be something to do with it.

Is a trigger the right thing to use?

Thanks!

John.
0
Microsoft provides a development SQL server that can run on your laptop or PC for developers to work against. I can put a Northwind database on such for example, and devise queries against it. I am looking for similar tools that I can do so for these database formats, if there is such an animal...

DB2
Oracle
SAP
AS400
0
I have the need to get a BOM with all components , currently using Tc. CK86 , but this doesn't give enough information, so I want to do this by SQL, I come from oracle background and dont know how could I get this done in DB2 R/3, I do not have access to query builder or quickview , but i do have read access via SQL, I'm currently trying to figure out a way of getting this info using tables :

MAST Material to BOM Link
STKO BOM Header
STPO BOM item

Does any of you  have a solution for this?

In Oracle I did something like the following:
SELECT DISTINCT LEVEL
	,sys_connect_by_path(msil.segment1, ' @ ') AS "BOM TREE"
	,msi.segment1
	,lpad(' ', LEVEL, '') || msil.segment1 Cod_Component
	,msil.item_type
	,msil.description Desc_Component
	,BIC.component_quantity
	,msiL.primary_unit_of_measure
FROM mtl_system_items msi
	,bom_bill_of_materials bom
	,BOM_INVENTORY_COMPONENTS BIC
	,MTL_SYSTEM_ITEMS MSIL
WHERE msi.organization_id = 332
	AND BOM.ASSEMBLY_ITEM_ID = MSI.INVENTORY_ITEM_ID
	AND BOM.ORGANIZATION_ID = MSI.ORGANIZATION_id
	AND bom.bill_sequence_id = bic.bill_sequence_id
	AND nvl(bic.disable_date, sysdate) >= SYSDATE
	AND BIC.component_ITEM_ID = MSIL.INVENTORY_ITEM_ID
	AND Bom.ORGANIZATION_ID = MSIL.ORGANIZATION_ID
	AND msil.inventory_item_status_code = 'Active'
	AND msi.inventory_item_status_code = 'Active' connect BY prior bic.component_item_id = bom.assembly_item_id
	START
                  WITH msi.segment1 = trim(:parte)
        ORDER BY 2

Open in new window

0
Hi All,

I could be going about this completely wrong; however, I'm working with a field that is originally a number; however, I need to use the Like command in a where clause to isolate certain results.  To further compound this, I need to use the left command to have the where clause only look at the first 5 characters.  

Here is what I have so far:

CAST(MBRLOG.MLCHDT AS VARCHAR(7)) LIKE(LEFT(Date_Table.EligMstrConvert, 5))

Open in new window


I don't always use sql with db2 so I might be slightly off on my logic, but any help or suggestions here would be greatly appreciated.

-Anthony
0
I need to combine address fields(addr_1, addr_2, City, St_cd, zip) into new Mail_Address field where most of the time the addr_2 contains null using DB2

In sql server I can do
rtrim(ltrim(a.addr_1)) + ' ' + rtrim(ltrim(isnull(a.addr_2,''))) + ', '  + rtrim(ltrim(a.City)) + ', ' + rtrim(ltrim(a. St_cd)) + ', ' + rtrim(ltrim(a.zip))
but unable to use in DB2.

I've tried a.addr_1 || '' '' || a.addr_2 || '', '' ||  a.City || '', '' ||  a.St_cd  || '', '' || a.zip  which only return a value in the new field if all fields are not null

I've also tried
Coalesce(a.addr_1,'') || '' '' || Coalesce(a.addr_2,'') . This only returned what was in a.addr_1 even if a.addr_2 wasn't null and I couldn't add the city, st_cd or zip to the coalesce
0
Greetings!

As I make my transition from working on "DB2 for I" to "DB2 for z/OS", I'm finding subtle differences that are tripping me up.

For example, I copied the following simple stored procedure from a website:

CREATE PROCEDURE MYSCHEMA.UPDATE_SALARY_1 (
  IN EMPLOYEE_NUMBER CHAR(10),
  IN RATE NUMERIC(6,2))
LANGUAGE SQL
MODIFIES SQL DATA
  UPDATE MYSCHEMA.EMP
     SET SALARY = SALARY * RATE
   WHERE EMPNO = EMPLOYEE_NUMBER

Open in new window


But, when creating the procedure, it throws the following error:

WLM ENVIRONMENT NAME MUST BE SPECIFIED

I googled that error, and it was recommended that I add "DISABLE DEBUG MODE":

CREATE PROCEDURE MYSCHEMA.UPDATE_SALARY_1 (
  IN EMPLOYEE_NUMBER CHAR(10),
  IN RATE NUMERIC(6,2))
LANGUAGE SQL
MODIFIES SQL DATA
DISABLE DEBUG MODE
  UPDATE MYSCHEMA.EMP
     SET SALARY = SALARY * RATE
   WHERE EMPNO = EMPLOYEE_NUMBER

Open in new window


But, it now throws these errors:

REBIND AUTHORIZATION ERROR USING MYSCHEMA AUTHORITY PACKAGE =
LOCDBT1.MYSCHEMA.UPDATE_SALARY_1.(V1) PRIVILEGE = BIND.      

What am I doing wrong?

Thanks for your help!
DaveSlash
0
Free Tool: Port Scanner
LVL 9
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

I had this question after viewing iSeries DB2 SQL - Request user input.

I also have similar requirement and code also follows:-

Sub ChangeQueryVariables()
DIM ssql AS String, NUM AS Interger       
Dim qd as dao.QueryDef,db as dao.Database

Set db=CurrentDb()
Set qd=db.QuerDefs("BM")

NUM=Inputbox()

ssql=select ABAN8,ABALPH from ascrpdta.F0101 where ABAN8=&NUM"
qd.SQL=ssql
Do cmd.OpenQuery "BM"x
End sub

And error is

ERROR: [IBM][System i Access ODBC Driver][DB2 for i5/OS]SQL0104 -
Token SUB was not valid. Valid tokens: ( CL END GET SET CALL DROP
FREE HOLD LOCK OPEN WITH ALTER BEGIN. Error Code: -104

Query = Sub ChangeQueryVariables()
DIM ssql AS String, NUM AS Interger       
Dim qd as dao.QueryDef,db as dao.Database

Set db=CurrentDb()
Set qd=db.QuerDefs("BM")

NUM=Inputbox()

ssql=select ABAN8,ABALPH from ascrpdta.F0101 where ABAN8=10000
qd.SQL=ssql
Do cmd.OpenQuery "BM"x
End sub

Please suggest

Regards
Suresh
0
How do I find out to see if there is any open transaction in DB2 database ? in sql server we used to use DBCC OPENTRAN. I am using toad for db2

Many Thanks
0
Hi,

Can we have CDC data mirroring between 2 different version servers.
Example a table is in V5R3 and we create the same table in V7R2 and we would like to have the data replicated from V5R3 to V7R2.

Is this possible. Do you see any issues.

Thanks
Chaitu
0
Hi,

I'm working in the DATA WAREHOUSE PROJECT, Does anyone have the industry best practices on how to build a  TEST cases.

Such as Tools, Technique, the methodology used?
0
Greetings, experts!

After almost 25 years of working primarily on DB2 for the midrange (AS/400, IBM i), I now have a new job where I need to quickly come up to speed on DB2 for the mainframe (z/OS). Fortunately, the system catalogs in the SYSIBM schema look to be almost the same, so I’ve been able to glean some information about the database-layout from there. But, I keep thinking, “There HAS TO be a better way!”

For example, on DB2 for i, there’s a fat-client GUI application (called “System i Navigator”) where I can easily view and modify table-structure (including column-definition and indexes) and even run SQL queries. I’ve asked around at the new job, but nobody seems to know of a similar application for DB2 on z/OS.

Can anyone point me in the right direction?

Thanks!
DaveSlash
0
I have access database that runs 3 business rules and updates a final table in access.  The logic is in the module rule mod.   I need to loop through 1 million row tables in access and perform procedure logic against the record set.  I am thinking before the database gets to big I should process this information on Teradata platform.  Somehow convert this access module in a stored procedure if that is possible. Or there might be another way through subqueries to get the final outcome.

Sample Database
Customer      Product      Orderdate
11111      VIP      01/01/2017
11111      PLANE      01/16/2017
11111      HOTEL      02/05/2017
22222      VIP      01/01/2017
22222      PLANE      02/28/2017
33333      VIP      01/01/2017
33333      VIP      01/06/2017
33333      HOTEL      01/17/2017
44444      VIP      01/01/2017
55555      VIP      01/01/2017
55555      VIP      02/15/2017
66666      VIP      01/01/2015
66666      VIP      01/28/2017
66666      PLANE      01/29/2017
66666      OTHER      02/01/2017


Business Rule 1 - The first product that has to be ordered is the VIP PRODUCT by customer.
If the VIP PRODUCT is not ordered all rules fail.
Business Rule 2 - If VIP PRODUCT was ordered where there any orders placed within 30 days of the first order for each customer.

Final Output - should look like this:
CustomerID      CustomerName      OrderRuleTest      ProductRuleTest      OrderDateTest      OrderDateFlag
11111      Customer A      PASS   …
0

DB2

IBM DB2 is a family of relational database server products developed by IBM that have been extended to support object-relational features and non-relational structures like JSON and XML. There are three main products in the DB2 family: DB2 for Linux, UNIX and Windows (informally known as DB2 LUW), DB2 for z/OS (mainframe), and DB2 for i (formerly OS/400), plus a version for IBM's Virtual Storage Extended (VSE) operating system.