Sample Header Ad - 728x90

Database Administrators

Q&A for database professionals who wish to improve their database skills

Latest Questions

1 votes
1 answers
43 views
Ipv6 creating table load data and retriving in mysql using ip_poly
``` CREATE TABLE `ipv6_table` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `ip_poly` POLYGON NOT NULL, `start_network` BIGINT(20) NOT NULL DEFAULT '0', `end_network` BIGINT(20) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), SPATIAL KEY `idx_ip_poly` (`ip_poly`) ) ENGINE=Innodb; LOAD DATA LOCAL INFILE...
CREATE TABLE ipv6_table (
  id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  ip_poly POLYGON NOT NULL,
  start_network BIGINT(20) NOT NULL DEFAULT '0',
  end_network BIGINT(20) NOT NULL DEFAULT '0',
  PRIMARY KEY (id),
  SPATIAL KEY idx_ip_poly (ip_poly)
) ENGINE=Innodb; 
  
LOAD DATA LOCAL INFILE '/var/lib/mysql-files/19225.csv'
INTO TABLE ipv6_table
FIELDS TERMINATED BY ',' ENCLOSED BY '\"'
LINES TERMINATED BY '\n'
(
  @start_network,
  @end_network )
SET
  id = NULL,
	ip_poly = ST_GeomFromText(CONCAT(
	  'POLYGON((',
	  @start_network - 1, ' -1, ',
	  @end_network + 1, ' -1, ',
	  @end_network + 1, ' 1, ',
	  @start_network - 1, ' 1, ',
	  @start_network - 1, ' -1))'
	)),
  start_network = @start_network,
  end_network = @end_network ;	
  
SELECT * FROM ipv6_table WHERE ST_Intersects(ip_poly, ST_GEOMFROMTEXT(concat('POINT(', 2306128953120655672, ' 0)')));
I have raw data in csv file like this
2306128950956392448,2306128951224827903
2306128951224827904,2306128951241605119
2306128951241605120,2306128951493263359
2306128951493263360,2306128951510040575
2306128951510040576,2306128952030134271
2306128952030134272,2306128952046911487
Like this I'm trying to create table for Ipv6 data. and I'm loading data from csv file into it and I'm trying to fetch ipv6 data using start_network or end_network or range between them but it is returning multiple data. can anyone help me in this.
Aravind (11 rep)
Feb 26, 2025, 10:17 PM • Last activity: Feb 27, 2025, 05:40 AM
0 votes
1 answers
39 views
Best way to test credentials?
I've got a C# app where I need to validate credentials for a DB2 database (V7R3). The way historically we've done this is to append the credentials to a connection string and actually attempt to connect to the database and just see whether the connection succeeds or fails. But is there a better way...
I've got a C# app where I need to validate credentials for a DB2 database (V7R3). The way historically we've done this is to append the credentials to a connection string and actually attempt to connect to the database and just see whether the connection succeeds or fails. But is there a better way to do that, like an API for testing credentials or something?
Sarov (281 rep)
Aug 28, 2024, 03:28 PM • Last activity: Aug 28, 2024, 05:14 PM
0 votes
1 answers
153 views
Why cannot I create a generated column with a CASE expression?
I'm trying to add a generated column to a table in V7R3 of IBM DB2: ``` ALTER TABLE MYLIB.MYTABLE ADD COLUMN NEW_COL VARCHAR(255) GENERATED ALWAYS AS ( COALESCE( CASE WHEN ENV = 'A' THEN (SELECT GUIDE_URL FROM MYLIBA.PROGRAM WHERE CODE = PGM) WHEN ENV = 'B' THEN (SELECT GUIDE_URL FROM MYLIBB.PROGRAM...
I'm trying to add a generated column to a table in V7R3 of IBM DB2:
ALTER TABLE MYLIB.MYTABLE
    ADD COLUMN NEW_COL VARCHAR(255) GENERATED ALWAYS AS (
        COALESCE(
            CASE
                WHEN ENV = 'A' THEN (SELECT GUIDE_URL FROM MYLIBA.PROGRAM WHERE CODE = PGM)
                WHEN ENV = 'B' THEN (SELECT GUIDE_URL FROM MYLIBB.PROGRAM WHERE CODE = PGM)
                ELSE (SELECT GUIDE_URL FROM MYLIBC.PROGRAM WHERE CODE = PGM)
            END
            , URL
        )
    )
But it's giving the following error: >  SQL State: 42601 Vendor Code: -199 Message: [SQL0199] Keyword WHEN not expected. Valid tokens: . ACCTNG USERID APPLNAME PROGRAMID WRKSTNNAME. Cause . . . . . :   The keyword WHEN was not expected here.  A syntax error was detected at keyword WHEN.  The partial list of valid tokens is . ACCTNG USERID APPLNAME PROGRAMID WRKSTNNAME. This list assumes that the statement is correct up to the unexpected keyword.  The error may be earlier in the statement but the syntax of the statement seems to be valid up to this point. Recovery  . . . :   Examine the SQL statement in the area of the specified keyword.  A colon or SQL delimiter may be missing. SQL requires reserved words to be delimited when they are used as a name. Correct the SQL statement and try the request again. Am I doing something wrong? Or is it just impossible to create such a generated column in 7.3? Would upgrading to 7.5 help? I tried to find specifics on what generated columns can be made in what versions, but couldn't find anything in the docs.
Sarov (281 rep)
Sep 6, 2023, 08:18 PM • Last activity: Sep 6, 2023, 08:31 PM
-1 votes
1 answers
79 views
Query for grouping by comparing sum of value for group, stopping when quantity is reached
Trying to calculate values for a FIFO report. Is there a way using SQL to group data such that you're comparing the sum of a particular value against different values for each group, including taking only part of a row if necessary? Request: For each Item Number, order the Purchased Items in descend...
Trying to calculate values for a FIFO report. Is there a way using SQL to group data such that you're comparing the sum of a particular value against different values for each group, including taking only part of a row if necessary? Request: For each Item Number, order the Purchased Items in descending order by Date, and get the maximum amount such that the sum of the Quantities is = the Amount Sold for that Item Number, taking only a part of the final row if necessary to get the quantities to match. Then output a result containing ItemNumber, NumShipments, and CostSum (which is the sum of the product of CostPer and Quantity) for the remaining stock that has not been sold. For example, consider the following schema:
CREATE TABLE MYLIB.TOTAL_ITEM_SOLD (ITEM_NUMBER VARCHAR(15) NOT NULL NOT HIDDEN , QUANTITY_SOLD DECIMAL(5, 2) NOT HIDDEN , PRIMARY KEY (ITEM_NUMBER)  ) NOT VOLATILE UNIT ANY KEEP IN MEMORY NO ;

CREATE TABLE MYLIB.ITEM_PURCHASE (ITEM_NUMBER VARCHAR(15) NOT NULL NOT HIDDEN , DATE_ORDERED TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP NOT NULL NOT HIDDEN , QUANTITY DECIMAL(4, 2) NOT NULL NOT HIDDEN , COST_PER DECIMAL(10, 2) NOT NULL NOT HIDDEN , PRIMARY KEY (DATE_ORDERED, ITEM_NUMBER) ) NOT VOLATILE UNIT ANY KEEP IN MEMORY NO ;

INSERT INTO MYLIB.TOTAL_ITEM_SOLD (ITEM_NUMBER, QUANTITY_SOLD) VALUES ('APPLE', 5);

INSERT INTO MYLIB.ITEM_PURCHASE (ITEM_NUMBER, QUANTITY, COST_PER) VALUES ('APPLE', 2, 1.23);
INSERT INTO MYLIB.ITEM_PURCHASE (ITEM_NUMBER, QUANTITY, COST_PER) VALUES ('APPLE', 4, 2.34);
INSERT INTO MYLIB.ITEM_PURCHASE (ITEM_NUMBER, QUANTITY, COST_PER) VALUES ('APPLE', 2, 5.55);
Expected result:
{ITEM_NUMBER: "APPLE", QTY_REMAINING: 3, COST_SUM: 13.44}
Because 5.55+5.55+2.34 = 13.44.
Sarov (281 rep)
Aug 4, 2023, 07:03 PM • Last activity: Aug 6, 2023, 05:43 PM
0 votes
1 answers
163 views
Query for grouping by comparing sum of value for group
Is there a way using SQL to group data such that you're comparing the sum of a particular value against different values for each group? For example, consider the following schema: ``` Table: ITEM Columns: ITEM_NUMBER (VARCHAR(15)) QUANTITY_ON_HAND (DECIMAL(5,2)) Primary Key: ITEM_NUMBER Table: ORDE...
Is there a way using SQL to group data such that you're comparing the sum of a particular value against different values for each group? For example, consider the following schema:
Table: ITEM
Columns:
	ITEM_NUMBER (VARCHAR(15))
	QUANTITY_ON_HAND (DECIMAL(5,2))
Primary Key: ITEM_NUMBER

Table: ORDER_ITEM_REQUIREMENTS
Columns:
	ITEM_NUMBER (VARCHAR(15), Foreign Key to ITEM)
	DATE_ORDERED (TIMESTAMP)
	QUANTITY (DECIMAL(4,2))
	COST_PER (DECIMAL(10,2))
Primary Key: ITEM_NUMBER+DATE
Request: For each Item Number, order the Order Item Requirements in ascending order by Date, and get the maximum amount such that the sum of the Quantities is <= the Quantity On Hand for that Item Number (get all Order Item Requirements if the sum is less than the Quantity On Hand). Then output a result containing ItemNumber, NumShipments, QtySum, and CostSum (which is the sum of the product of CostPer and Quantity). If it matters, we're using IBM DB2 Version 7 Revision 3. ----- For example, given the following data:
{ITEM_NUMBER: "APPLE", QUANTITY_ON_HAND: 5}
{ITEM_NUMBER: "APPLE", DATE_ORDERED: Jan 1, 12:01, QUANTITY: 2, COST_PER: 1.23}
{ITEM_NUMBER: "APPLE", DATE_ORDERED: Jan 1, 12:02, QUANTITY: 2, COST_PER: 2.34}
{ITEM_NUMBER: "APPLE", DATE_ORDERED: Jan 2, 12:03, QUANTITY: 2, COST_PER: 5.55}
Or in terms of SQL:
CREATE TABLE MYLIB.ITEM (ITEM_NUMBER VARCHAR(15) NOT NULL NOT HIDDEN , QUANTITY_ON_HAND DECIMAL(5, 2) NOT HIDDEN , PRIMARY KEY (ITEM_NUMBER)  ) NOT VOLATILE UNIT ANY KEEP IN MEMORY NO ;

CREATE TABLE MYLIB.ORDER_ITEM_REQUIREMENTS (ITEM_NUMBER VARCHAR(15) NOT NULL NOT HIDDEN , DATE_ORDERED TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP NOT NULL NOT HIDDEN , QUANTITY DECIMAL(4, 2) NOT NULL NOT HIDDEN , COST_PER DECIMAL(10, 2) NOT NULL NOT HIDDEN , PRIMARY KEY (DATE_ORDERED, ITEM_NUMBER) , FOREIGN KEY (ITEM_NUMBER) REFERENCES MYLIB.ITEM (ITEM_NUMBER) ON DELETE NO ACTION ON UPDATE NO ACTION  ) NOT VOLATILE UNIT ANY KEEP IN MEMORY NO ;

INSERT INTO MYLIB.ITEM (ITEM_NUMBER, QUANTITY_ON_HAND) VALUES ('APPLE', 5);

INSERT INTO MYLIB.ORDER_ITEM_REQUIREMENTS (ITEM_NUMBER, QUANTITY, COST_PER) VALUES ('APPLE', 2, 1.23);
INSERT INTO MYLIB.ORDER_ITEM_REQUIREMENTS (ITEM_NUMBER, QUANTITY, COST_PER) VALUES ('APPLE', 2, 2.34);
INSERT INTO MYLIB.ORDER_ITEM_REQUIREMENTS (ITEM_NUMBER, QUANTITY, COST_PER) VALUES ('APPLE', 2, 5.55);
I would like the following result:
{ITEM_NUMBER: "APPLE", NUM_SHIPMENTS: 2, QTY_SUM: 4, COST_SUM: 7.14}
Sarov (281 rep)
Aug 1, 2023, 09:55 PM • Last activity: Aug 2, 2023, 06:30 PM
0 votes
2 answers
527 views
How to set column name when creating a view?
By default, when creating a view, for the name of each column, if the column is a direct selection from a table/physical file, then it will use the name of that table/physical file's column. If it's not (e.g. a `CASE` statement), then it's blank. How can I override it to set what I want for the view...
By default, when creating a view, for the name of each column, if the column is a direct selection from a table/physical file, then it will use the name of that table/physical file's column. If it's not (e.g. a CASE statement), then it's blank. How can I override it to set what I want for the view's columns' names?
Sarov (281 rep)
Jun 19, 2019, 08:58 PM • Last activity: May 22, 2023, 12:39 AM
2 votes
2 answers
552 views
DROP ALIAS unable to drop existing alias?
We're unable to drop aliases. So, I found an alias by running: ``` SELECT TABLE_NAME FROM QSYS2.SYSTABLES WHERE BASE_TABLE_NAME IN ('OE0711P','OE0712P') AND TABLE_TYPE = 'A' AND SYSTEM_TABLE_SCHEMA = 'AMPLIBX'; ``` and picked the first one, which was `OE0712PD506202270`. So I tried running `DROP ALI...
We're unable to drop aliases. So, I found an alias by running:
SELECT
    TABLE_NAME
FROM
    QSYS2.SYSTABLES
WHERE
    BASE_TABLE_NAME IN ('OE0711P','OE0712P')
    AND TABLE_TYPE = 'A'
    AND SYSTEM_TABLE_SCHEMA = 'AMPLIBX';
and picked the first one, which was OE0712PD506202270. So I tried running DROP ALIAS AMPLIBX.OE0712PD506202270; and it gives the following error: > SQL State: 42704 > > Vendor Code: -204 > > Message: [SQL0204] OE07100001 in AMPLIBX type *FILE not found. Cause . . . . . :   OE07100001 in AMPLIBX type *FILE was not found. If the member name is *ALL, the table is not partitioned. If this is an ALTER TABLE statement and the type is *N, a constraint or partition was not found. If this is not an ALTER TABLE statement and the type is *N, a function, procedure, trigger or sequence object was not found. If a function was not found, OE07100001 is the service program that contains the function.  The function will not be found unless the external name and usage name match exactly.  Examine the job log for a message that gives more details on which function name is being searched for and the name that did not match. Recovery  . . . :   Change the name and try the request again.  If the object is a node group, ensure that the DB2 Multisystem product is installed on your system and create a nodegroup with the CRTNODGRP CL command. If an external function was not found, be sure that the case of the EXTERNAL NAME on the CREATE FUNCTION statement exactly matches the case of the name exported by the service program. The job log only says: > OE07100001 in AMPLIBX type *FILE not found. ...but how can it not be found? I literally just found it in the metadata. Also note: Weird behaviour when trying to delete via the IBM i Access Client Solutions app, as well. - The summary shows the 1097 existing aliases. But when I right-click on the first one and select Definition, it has a different name from the one I selected. Both are existing (but separate) aliases according to the QSYS2.SYSTABLES. - When I try to right-click then Delete from the summary, nothing happens. No error message, not deleted. Am I doing something wrong? How can I drop these aliases?
Sarov (281 rep)
Nov 22, 2022, 04:58 PM • Last activity: Nov 29, 2022, 05:51 PM
0 votes
1 answers
32 views
why does the order of fields return 0 rows, but move the field does
I have two queries that return the same data, only the calculating field with the case is moved. I am using the Access Client Solutions "run query" to execute the query. If I run this one ``` Select storenum, businessdate, kitchensenttime, parkcartime as delivertime, (parkcartime-kitchensenttime) as...
I have two queries that return the same data, only the calculating field with the case is moved. I am using the Access Client Solutions "run query" to execute the query. If I run this one
Select storenum,
       businessdate,
       kitchensenttime,
       parkcartime as delivertime,
       (parkcartime-kitchensenttime) as deliveryseconds,
       case
           when parkcartime-kitchensenttime>360 then 1
           else 0
       end as disastrouscount
from irislib.tblorder
where not(kitchensenttime='01/01/0001'
          or parkcartime='01/01/0001')
    and parkcartime>kitchensenttime
    and businessdate='05/18/2022'
No rows are returned. While this one
Select storenum,
       businessdate,
       kitchensenttime,
       case
           when parkcartime-kitchensenttime>360 then 1
           else 0
       end as disastrouscount,
       parkcartime as delivertime,
       (parkcartime-kitchensenttime) as deliveryseconds
from irislib.tblorder
where not(kitchensenttime='01/01/0001'
          or parkcartime='01/01/0001')
    and parkcartime>kitchensenttime
    and businessdate='05/18/2022'
Will return rows. If I try the "broken" query with just the storenum and businessdate with just the disastrouscount calculation will it return rows.
Paul (1 rep)
May 19, 2022, 03:47 PM • Last activity: May 20, 2022, 02:25 PM
0 votes
1 answers
187 views
How to run merge statement based on logic of joined table?
When I try to run a query like the following: ``` MERGE INTO MYTABLE_A AS MERGE_TARGET USING ( SELECT MYTABLE_A.A, MYTABLE_B.B, MYTABLE_A.C, MYTABLE_D, MYTABLE_E FROM MYTABLE_A INNER JOIN MYTABLE_B ON MYTABLE_B.A = MYTABLE_A.A WHERE MYTABLE_A.LOGIC = 1 AND MYTABLE_B.LOGIC = 2 ) AS MERGE_USING ON MER...
When I try to run a query like the following:
MERGE INTO
	MYTABLE_A
AS MERGE_TARGET
USING
(
	SELECT
		MYTABLE_A.A, MYTABLE_B.B, MYTABLE_A.C, MYTABLE_D, MYTABLE_E
	FROM
		MYTABLE_A
		INNER JOIN MYTABLE_B
			ON MYTABLE_B.A = MYTABLE_A.A
	WHERE
		MYTABLE_A.LOGIC = 1
		AND MYTABLE_B.LOGIC = 2
) AS MERGE_USING
	ON MERGE_USING.C = MERGE_TARGET.C
	AND MERGE_TARGET.OTHERLOGIC = 1
	AND MERGE_TARGET.A IN (
		SELECT
			MYTABLE_A.A
		FROM
			MYTABLE_A
			INNER JOIN MYTABLE_B
				ON MYTABLE_B.A = MYTABLE_A.A
		WHERE
			MERGE_USING.B = MYTABLE_B.B
	)
WHEN MATCHED THEN UPDATE SET
        MERGE_TARGET.D = MERGE_USING.D,
        MERGE_TARGET.E = MERGE_USING.E
It gives me this error: > Message: [SQL0115] Comparison operator IN not valid. Cause . . . . . : Simple comparison operators other than equal and not equal cannot be used with a list of items. ANY, ALL, and SOME comparison operators must be followed by a fullselect, rather than an expression or a list of items. Subqueries cannot be specified in a JOIN condition or in a CASE expression. Recovery . . . : Change either the comparison or the operand. Try the request again. DB2 version: V7R1
Sarov (281 rep)
Feb 18, 2022, 04:56 PM • Last activity: Feb 22, 2022, 12:07 AM
0 votes
1 answers
184 views
iSeries journaling performance
I am responsible for a legacy application deployed on an iSeries V7R3. The application is fairly high volume, 2 million or so transactions per month. The database for this app spans multiple libraries and I am currently journaling each library individually. I've been looking on the web for suggestio...
I am responsible for a legacy application deployed on an iSeries V7R3. The application is fairly high volume, 2 million or so transactions per month. The database for this app spans multiple libraries and I am currently journaling each library individually. I've been looking on the web for suggestions as to whether this is the best approach or if a single journal for the application might be better or at least be just as efficient. So far I haven't found any clear advice on this topic, with some advising separate journals for each physical file. Of course searching for anything about the iSeries brings back ancient results often with no mention of the OS version or date of the information. I'm not experiencing any problems other than managing multiple journals is sometimes a pain.
John Kuhns (103 rep)
Feb 14, 2022, 02:14 PM • Last activity: Feb 14, 2022, 04:01 PM
0 votes
2 answers
1959 views
Add days to date (char column with decimal) in DB2
I have a table named INVOICE_ET which has column of below definition ``` INVDATE CHARACTER 10 ``` result of select INVDATE from INVOICE_ET is as below ``` INVDATE 2021-07-31 ``` In another table INVOICE_DY, I have a column named INV_DAYS, which has below definition ``` INV_DAYS DECIMAL 3 ``` result...
I have a table named INVOICE_ET which has column of below definition
INVDATE CHARACTER 10
result of select INVDATE from INVOICE_ET is as below
INVDATE
2021-07-31
In another table INVOICE_DY, I have a column named INV_DAYS, which has below definition
INV_DAYS  DECIMAL 3
result of select INV_DAYS from INVOICE_DY is as below
INV_DAYS 
88
----- Now my question is, I am trying to add INVOICE_DY.INV_DAYS field with INVOICE_ET.INVDATE field, but the char casting is not working, Please suggest how can I add these two columns. I am trying to get something like below
Select a.INVDATE, b.INV_DAYS, (a.INVDATE + b.INV_DAYS) as DUE_DATE 
from INVOICE_ET a 
join INVOICE_DY b 
On a.INVNUM = b.INVNUM //(edited this portion, because join is based on Invoice numbers)
Result should be 
INVDATE       INV_DAYS       DUE_DATE 
2021-07-31    88             2021-10-27
Any suggestions/ thoughts are welcome.
mrsorrted (21 rep)
Oct 12, 2021, 10:02 AM • Last activity: Oct 14, 2021, 09:24 AM
0 votes
2 answers
1283 views
Column or globale Variable not found
Error msg: > DataSource.Error: ODBC: ERROR [42S22] [IBM][System i Access > ODBC-stuurprogramma][DB2 for i5/OS]SQL0206 - Kolom of globale > variabele AADETX niet gevonden. Details: > DataSourceKind=Odbc > DataSourcePath=dsn=I-Make > OdbcErrors=[Table] Google translate of the error message: Column or...
Error msg: > DataSource.Error: ODBC: ERROR [42S22] [IBM][System i Access > ODBC-stuurprogramma][DB2 for i5/OS]SQL0206 - Kolom of globale > variabele AADETX niet gevonden. Details: > DataSourceKind=Odbc > DataSourcePath=dsn=I-Make > OdbcErrors=[Table] Google translate of the error message: Column or global variable AADETX not found. Request:
SELECT

A.G1AATX AS Artikel,
A.GIG4NU ATP_aantal_cum,
A.G1HADT BEGIN_periode

FROM MIFA.VIS#MOGEM.V1G1REP A

LEFT JOIN (
SELECT 

B.AAAATX AS Artikel,
B.AADATX Artikelgroep,
B.AADETX Artikeltype

FROM MIFA.VIS#MOGEM.VIAAREP 

WHERE B.AADATX  'SMEE'
AND B.AADATX  'LIJM'
AND B.AADATX  'UMEC'
AND B.AADETX ='I'

GROUP BY AAAATX
) B on B.AAAATX = A.G1AATX

LEFT JOIN (
SELECT 

C.ELAATX AS Artikel,
C.ELCXST Status

FROM MIFA.VIS#MOGEM.VOELREP

WHERE C.ELCXST IN ('A',' ')

GROUP BY ELAATX
) C on C.ELAATX = A.G1AATX

WHERE A.G1AATX = '4022-480-9858'
The column AADETX the error reffers to does exist. If i look it up in just the table i can find the specifiek data. I'm trying to fix the duplicates errors i got from the request below: First attempt:
SELECT

A.G1AATX As Artikel, 
A.G1G4NU ATP_aantal_cum,
A.G1HADT Begindatum_periode,
B.AADETX I

FROM

MIFA.VIS#MOGEM.V1G1REP A
LEFT OUTER JOIN MIFA.VIS#MOGEM.VIAAREP B on B.AAAATX=A.G1AATX
LEFT OUTER JOIN MIFA.VIS#MOGEM.VOELREP C on C.ELAATX=A.G1AATX

WHERE B.AADATX  'SMEE'
AND B.AADATX  'LIJM'
AND B.AADATX  'UMEC'
AND C.ELCXST IN ('A',' ')
AND B.AADETX ='I'
AND A.G1AATX = '4022-480-9858'
Jeffrey Hazeleger (11 rep)
Aug 20, 2021, 09:43 AM • Last activity: Aug 20, 2021, 10:48 PM
0 votes
1 answers
811 views
What's the difference between REGEXP_SUBSTR and REGEXP_EXTRACT?
What's the difference between REGEXP_SUBSTR and REGEXP_EXTRACT? As far as I can tell, they seem to do the same thing. Is there some difference in side-effects, or how they perform for certain inputs? How do I know which to choose?
What's the difference between REGEXP_SUBSTR and REGEXP_EXTRACT? As far as I can tell, they seem to do the same thing. Is there some difference in side-effects, or how they perform for certain inputs? How do I know which to choose?
Sarov (281 rep)
Nov 30, 2020, 03:12 PM • Last activity: Nov 30, 2020, 03:41 PM
0 votes
2 answers
1104 views
How to add generated column to db2 table?
I've got a table with the following: ``` Columns: --- URL [nullable, e.g. "https://dba.stackexchange.com/"] APPFK [nullable, e.g. 654654] LINKTYPE ["Page", "Link", or "App"] Check Constraints: --- (URL IS NULL AND LINKTYPE "Link") OR (URL IS NOT NULL AND LINKTYPE = "Link") (APPFK IS NULL AND LINKTYP...
I've got a table with the following:
Columns:
---
URL [nullable, e.g. "https://dba.stackexchange.com/ "]
APPFK [nullable, e.g. 654654]
LINKTYPE ["Page", "Link", or "App"]

Check Constraints:
---
(URL IS NULL AND LINKTYPE  "Link") OR (URL IS NOT NULL AND LINKTYPE = "Link")
(APPFK IS NULL AND LINKTYPE  "App") OR (APPFK IS NOT NULL AND LINKTYPE = "App")
Since LinkType is calculable based on the nullability of URL and APPFK, I figured this was a perfect opportunity for a computed/generated/virtual column. So, I tried to run:
alter table MYLIB.MYTABLE
add column testcol VARCHAR(4) generated always as
(
	CASE
		WHEN URL IS NOT NULL THEN 'LINK'
		WHEN APPFK IS NOT NULL THEN 'APP'
		ELSE 'PAGE'
	END
)
Annnd DB2 spat this back at me: > SQL State: 42601 Vendor Code: -104 Message: [SQL0104] Token ( was not valid. Valid tokens: IDENTITY. Cause . . . . . : A syntax error was detected at token (. Token ( is not a valid token. A partial list of valid tokens is IDENTITY. This list assumes that the statement is correct up to the token. The error may be earlier in the statement, but the syntax of the statement appears to be valid up to this point. Recovery . . . : Do one or more of the following and try the request again: -- Verify the SQL statement in the area of the token (. Correct the statement. The error could be a missing comma or quotation mark, it could be a misspelled word, or it could be related to the order of clauses. -- If the error token is , correct the SQL statement because it does not end with a valid clause. I tried running the first example in [this DB2 documentation](https://www.ibm.com/support/knowledgecenter/SSEPGG_11.1.0/com.ibm.db2.luw.admin.dbobj.doc/doc/c0020109.html) , but it gave me the same error. What's going wrong, here? Am I doing something wrong? Is the documentation wrong? Is it just because our DB2 is outdated (we're running Version 7, Revision 1), and if so is there a workaround?
Sarov (281 rep)
Nov 16, 2020, 09:03 PM • Last activity: Nov 17, 2020, 03:34 PM
0 votes
1 answers
495 views
Create View giving SQL7029
If relevant, I'm using IBM i V7R1M0. I have some code in C#: ```c# var generateSqlSql = $@" CALL QSYS2.GENERATE_SQL( '{obj.Name}', '{obj.Library}', 'VIEW', CREATE_OR_REPLACE_OPTION => '1', HEADER_OPTION => '0', COMMENT_OPTION => '1', PRIVILEGES_OPTION => '0', LABEL_OPTION => '0' )"; ... //get result...
If relevant, I'm using IBM i V7R1M0. I have some code in C#:
#
var generateSqlSql = $@"
CALL QSYS2.GENERATE_SQL(
    '{obj.Name}',
    '{obj.Library}',
    'VIEW',
    CREATE_OR_REPLACE_OPTION => '1',
    HEADER_OPTION => '0',
    COMMENT_OPTION => '1',
    PRIVILEGES_OPTION => '0',
    LABEL_OPTION => '0'
)";
...
//get results
//split on semicolon
//change library
//write back to database
The sql that it's then trying to write is:
CREATE OR REPLACE VIEW AMMLIBC.BBI_USER_MY_VIEW FOR SYSTEM NAME         BBIU_00001 ( 
/* view columns */ ) 
AS 
/*view definition */
RCDFMT BBIU_00001
When I try to run it, it gives the following error:
iDB2SQLErrorException: SQL7029 New name BBIU_00001 is not valid.
...Why? What's causing this, and how do I make it work?
Sarov (281 rep)
Sep 10, 2019, 02:49 PM • Last activity: Oct 17, 2020, 03:03 AM
0 votes
1 answers
1101 views
db2cli license file not being used
I'm using the db2 driver for CLI and ODBC to configure an ODBC connection to DB2 on IBM i/OS from CentOS. I'm trying the following command: db2cli execsql -connstring "protocol=TCPIP;database=MyDB;hostname=MyHost;ServiceName=446;uid=MyUser;pwd=MyPass" And getting the following error which seems pret...
I'm using the db2 driver for CLI and ODBC to configure an ODBC connection to DB2 on IBM i/OS from CentOS. I'm trying the following command: db2cli execsql -connstring "protocol=TCPIP;database=MyDB;hostname=MyHost;ServiceName=446;uid=MyUser;pwd=MyPass" And getting the following error which seems pretty straightforward: [IBM][CLI Driver] SQL1598N An attempt to connect to the database server failed because of a licensing problem. SQLSTATE=42968 I believe I have the paths and everything correct: # Environment export PATH=$PATH:/opt/DB2/odbc_cli/clidriver/bin/ export DB2_CLI_DRIVER_INSTALL_PATH=/opt/DB2/odbc_cli/clidriver export LD_LIBRARY_PATH=/opt/DB2/odbc_cli/clidriver/lib license file: /opt/DB2/odbc_cli/clidriver/license/db2consv_is.lic I have also attempted to move the license to a few other paths without any success. It is valid and works on another (windows) installation without issues. Any idea what I can troubleshoot from here?
Cpt.Whale (165 rep)
Sep 9, 2020, 03:11 PM • Last activity: Sep 9, 2020, 03:35 PM
1 votes
1 answers
117 views
Find what values are not in multiple columns
I need to find what "Codes" from column "RMS_CODE" and column "RMS_ALT1_Cde" are not being used in the Child # (starting in position 6 for a length of 4) column within the "APC_Spec" number. I tried using the sql in the image provided, but it only looks in the row and doesn't check the whole column...
I need to find what "Codes" from column "RMS_CODE" and column "RMS_ALT1_Cde" are not being used in the Child # (starting in position 6 for a length of 4) column within the "APC_Spec" number. I tried using the sql in the image provided, but it only looks in the row and doesn't check the whole column within the "APC_Spec" requirement. Can anyone suggest a method to check which codes are not being used per "APC_Spec" in the Child column #? SQL Example
Maven BeJayjay (13 rep)
Apr 30, 2020, 03:15 PM • Last activity: Aug 5, 2020, 07:51 PM
0 votes
3 answers
930 views
Convert two integers into timestamp
How do I convert two integers, one for date and one for time, into a timestamp? - Given 20200304 and 1046, return a timestamp for April 3, 2020, 10:46 AM. - Given 20200304 and 946, return a timestamp for April 3, 2020, 9:46 AM. - Given 20200304 and 2359, return a timestamp for April 3, 2020, 11:59 P...
How do I convert two integers, one for date and one for time, into a timestamp? - Given 20200304 and 1046, return a timestamp for April 3, 2020, 10:46 AM. - Given 20200304 and 946, return a timestamp for April 3, 2020, 9:46 AM. - Given 20200304 and 2359, return a timestamp for April 3, 2020, 11:59 PM. - Given 20200304 and 0, return a timestamp for April 3, 2020, 0:00 AM. I'm running Version 7, Revision 1.
Sarov (281 rep)
Apr 3, 2020, 03:51 PM • Last activity: Apr 3, 2020, 04:51 PM
0 votes
1 answers
872 views
Is there a way to get the contnents of an RPG program using SQL?
So, I've got myself a query to list our RPG programs: ``` SELECT OBJNAME FROM (SELECT OBJNAME AS SCHEMA FROM TABLE (QSYS2.OBJECT_STATISTICS('*ALLSIMPLE', 'LIB')) S) AS SCHEMAS ,LATERAL (SELECT * FROM TABLE(QSYS2.OBJECT_STATISTICS(SCHEMAS.SCHEMA, 'PGM')) X) AS PROGRAMS LEFT JOIN QSYS2.PROCEDURES ON Q...
So, I've got myself a query to list our RPG programs:
SELECT OBJNAME
FROM
    (SELECT OBJNAME AS SCHEMA FROM TABLE (QSYS2.OBJECT_STATISTICS('*ALLSIMPLE', 'LIB')) S) AS SCHEMAS
    ,LATERAL (SELECT * FROM TABLE(QSYS2.OBJECT_STATISTICS(SCHEMAS.SCHEMA, 'PGM')) X) AS PROGRAMS
    LEFT JOIN QSYS2.PROCEDURES
        ON QSYS2.PROCEDURES.PROCNAME = PROGRAMS.OBJNAME
        AND QSYS2.PROCEDURES.PROCSCHEMA = PROGRAMS.OBJLONGSCHEMA
WHERE
    PROCNAME IS NULL
    AND SCHEMAS.SCHEMA = 'MYLIB'
;
Now, is there any way, given the name of an RPG program, to get the contents of it via SQL? (Or, failing SQL, some other way to get the contents from within a C# application?)
Sarov (281 rep)
Feb 19, 2020, 06:28 PM • Last activity: Feb 19, 2020, 09:18 PM
0 votes
1 answers
1000 views
Linked server to DB2 table locks
I have a problem with a SQL linked server connected to a DB2 database on an AS400 IBM iSeries. I configured an ODBC connection from the ODBC Data Source utility. Once configured the ODBC, i created the LinkedServer and start using it for querying the DB2 database using `SELECT * FROM OPENQUERY([LINK...
I have a problem with a SQL linked server connected to a DB2 database on an AS400 IBM iSeries. I configured an ODBC connection from the ODBC Data Source utility. Once configured the ODBC, i created the LinkedServer and start using it for querying the DB2 database using SELECT * FROM OPENQUERY([LINKED_SERVER], 'SELECT * FROM [TABLE] FOR READ ONLY'). Once the query is executed, the DB2 table is locked and when the query ends the lock is not released. I temporarily solved the issue setting the ODBC connection type as read only and not as default. Also all the DB2 tables that are used by the linked server are locked at every query even if they are not involved in the query. enter image description here enter image description here Can someone help me figuring out how to not lock all the tables and set the linked server to read/write and not in read only mode. Like in the image, i executed a query only on SHPAV20F but locks are taken also for TTB03ACF and TTB0301P that are not involved in the query. ODBC settings for commit mode is *CHG, PREFETCH for query data is enabled and LAZYCLOSE is disabled.
Riccardo Francescato (3 rep)
Nov 25, 2019, 04:35 PM • Last activity: Nov 26, 2019, 08:40 AM
Showing page 1 of 20 total questions