db2

DB2 storing results from final table clause

蹲街弑〆低调 提交于 2020-01-13 06:50:47
问题 The FINAL TABLE clause is great for getting values back from DML in DB2, for example: SELECT id FROM FINAL TABLE ( INSERT INTO mySchema.myTable (val) VALUES ('data') ) However, there doesn't seem to be a way to store the results of this query into another table, persisting the contents somewhere. For example, both of the following fail with the error "Data change table reference not allowed where specified." (I am running DB2 for i v7.1): CREATE TABLE mySchema.otherTable AS ( SELECT id FROM

DB2行列转换

余生颓废 提交于 2020-01-13 02:19:58
行转列 给出下面的数据: CREATE TABLE Sales (Year INT, Quarter INT, Results INT) YEAR QUARTER RESULTS 2004 1 20 2004 2 30 2004 3 15 2004 4 10 2005 1 18 2005 2 40 2005 3 12 2005 4 27 1 2 3 4 5 6 7 8 想要的到结果: YEAR Q1 Q2 Q3 Q4 2004 20 30 15 10 2005 18 40 12 27 1 2 这个SQL就可解决这个问题: SELECT Year, MAX(CASE WHEN Quarter = 1 THEN Results END) AS Q1, MAX(CASE WHEN Quarter = 2 THEN Results END) AS Q2, MAX(CASE WHEN Quarter = 3 THEN Results END) AS Q3, MAX(CASE WHEN Quarter = 4 THEN Results END) AS Q4 FROM Sales GROUP BY Year 解释一下为什么要加max的原因,因为不加max的话结果会是这样: YEAR Q1 Q2 Q3 Q4 2004 20 - - - 2004 - 30 - - 2004 - - 15 -

How to handle stale connections?

本小妞迷上赌 提交于 2020-01-11 17:06:13
问题 Ours is a J2EE app, using Struts-EJB-Hibernate on Websphere 6.1 over Mainframe/DB2 backend, that was recently moved to production. We are getting stale connection exception when the user login to the application first time or some times this exception occurs intermittently. on the second try the user able to log in to the application. The exact error message i am getting is empcom.ibm.websphere.ce.cm.StaleConnectionException: Execution failed due to a distribution protocol error that caused

How to handle stale connections?

人盡茶涼 提交于 2020-01-11 17:05:49
问题 Ours is a J2EE app, using Struts-EJB-Hibernate on Websphere 6.1 over Mainframe/DB2 backend, that was recently moved to production. We are getting stale connection exception when the user login to the application first time or some times this exception occurs intermittently. on the second try the user able to log in to the application. The exact error message i am getting is empcom.ibm.websphere.ce.cm.StaleConnectionException: Execution failed due to a distribution protocol error that caused

How to handle stale connections?

帅比萌擦擦* 提交于 2020-01-11 17:05:01
问题 Ours is a J2EE app, using Struts-EJB-Hibernate on Websphere 6.1 over Mainframe/DB2 backend, that was recently moved to production. We are getting stale connection exception when the user login to the application first time or some times this exception occurs intermittently. on the second try the user able to log in to the application. The exact error message i am getting is empcom.ibm.websphere.ce.cm.StaleConnectionException: Execution failed due to a distribution protocol error that caused

Close db2cmd prompt after command execution from a batch file

混江龙づ霸主 提交于 2020-01-11 14:12:30
问题 I am trying to close the db2cmd after executing a command. Goal is to get this file perfect before I schedule it with a task scheduler to run everyday at 2100 hours. The batch file starts execution of the command, the command gets executed but the prompt doesn't close. I have been through the below links but no combination is working. How to close the command line window after running a batch file? How to automatically close cmd window after batch file execution? Here is my short script start

Fastest most/efficient way to do pagination with SQL searching DB2

守給你的承諾、 提交于 2020-01-11 06:18:13
问题 Right now I do two separate SQL statements, one doing a SELECT COUNT(*) on basically the same criteria as the search statement. I am not the best at making these statements and sometimes are a little slow and I would like to know if there is a better way to be doing what I do. Possibly doing only one SQL statement and some more work in PHP? Here is an example "search contains" I have the statements for. On the second statement you will see the X between Y, that's partially calculated by the

Validate dates before conversion, aka. ISDATE() equivalent

你离开我真会死。 提交于 2020-01-11 05:43:15
问题 DB2 version is 9.7.0.7 I have a flat file, and need to validate fully prior to insert into a production table. For analysis, I've parsed it into a table where all columns are VARCHAR . One of the tasks is to validate dates. I need to be able to locate the specific invalid dates, to report on the scope (frequency) and solution (reason). I use ISDATE() in Sybase and SQL Server, which returns a 1 for a valid date, and a 0 for an invalid date. In Teradata, I left join to the SYS_CALENDAR table in

Can I join data from 2 different DB2 databases? (Like SQL Server linked databases)

萝らか妹 提交于 2020-01-11 05:04:09
问题 I'm enhancing an existing java application. There is data in 2 different DB2 databases. The app already gets data from 2 different databases, but it always does a lookup from one and then the other. Is there a way to join data from 2 different DB2 databases using one SQL SELECT? This is what I tried: CREATE ALIAS remote_orders FOR remote_db.schema.orders; select * from myid.remote_orders a inner join local_schema.parts b on (a.key = b.key) with ur FETCH FIRST 200 ROWS ONLY I get this error:

How do I LIMIT the number of rows in a DELETE with DB2?

耗尽温柔 提交于 2020-01-11 04:40:08
问题 I want to add a security on a sensitive table when I delete lines with an SQL request on a DB2 table. I want to mimic the way MySQL allows you to limit the numbers of rows deleted in an SQL request. Basically I want to do this with DB2 : DELETE FROM table WHERE info = '1' LIMIT 1 Is there a way to do that with DB2 ? 回答1: delete from table where id in (select id from table where info = '1' order by id fetch first 1 rows only) 回答2: It really depends on your platform. If you're using DB2 on