db2

SQL - Find the closest price to a given argument

最后都变了- 提交于 2019-12-11 14:46:26
问题 I am trying to find the tuples which price is closest to a given parameter in SQL. Forexample: the parameter price = 6 would return id 1 and 2. Parameter price = 20 would return id 3. Table : ID PRICE 1 5 2 5 3 10 SELECT id FROM Table WHERE table.price ?? 6 Any Ideas how to do this? Thank you. 回答1: SELECT ID FROM TableX WHERE PRICE = @CheckPrice + ( SELECT MIN(ABS(PRICE - @CheckPrice)) FROM TableX ) OR PRICE = @CheckPrice - ( SELECT MIN(ABS(PRICE - @CheckPrice)) FROM TableX ) or (probably

DB2 trigger illegal token

点点圈 提交于 2019-12-11 14:42:55
问题 Fairly new to DB2 sql, so forgive my ignorance :) I have a trigger with a condition inside. I want to then insert some params depending on the condition.. Here it is: I've looked at DB2 documentation for triggers and also for if statements, and at least to my eyes it appears to comply with it, however i get a -104 error (Illegal symbol token) on the insert line. The insert works fine provided i use values not from 'N'. OK, it works if i have nothing in the if then statement.. but only if i

SQL query - Joining a many-to-many relationship, filtering/joining selectively

試著忘記壹切 提交于 2019-12-11 14:27:31
问题 I find myself in a bit of an unworkable situation with a SQL query and I'm hoping that I'm missing something or might learn something new. The structure of the DB2 database I'm working with isn't exactly built for this sort of query, but I'm tasked with this... Let's say we have Table People and Table Groups. Groups can contain multiple people, and one person can be part of multiple groups. Yeah, it's already messy. In any case, there are a couple of intermediary tables linking the two. The

how can I print details (table name, column name, data type) of each column/table in my db2 database?

我怕爱的太早我们不能终老 提交于 2019-12-11 14:09:07
问题 In my previous question Mark suggested a good answer for displaying count on every table in my database. I would like to expand this procedure and - instead of counts - display the specific info (TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, DATA_TYPE) about each column in the database. I so far have the following command: --#SET TERMINATOR @ CREATE OR REPLACE FUNCTION EXPORT_SCHEMAS() RETURNS TABLE (P_TABSCHEMA VARCHAR(128), P_TABNAME VARCHAR(128), P_COLUM_NNAME VARCHAR(128), P_DATA_TYPE VARCHAR

Reading db2 clob from binary download

a 夏天 提交于 2019-12-11 14:08:58
问题 More then a year ago I asked about reading DB2 EBCDIC data in a .Net program. The amazingly helpful answer included a routine for reading VARCHAR columns. I am now faced with reading CLOB columns. Is their internal structure similar in that the first word contains the actual size? Or is it the whole word, considering the possible length of the CLOB is much larger? Thanks! 回答1: Not the mainframe but DB2/400 (midrange) appears to store CLOB fields externally from the table itself: CREATE TABLE

How to use variables in SELECT?

半城伤御伤魂 提交于 2019-12-11 14:05:55
问题 I use IBM® Data Studio V4.1.0.1, DB2 v10.5. This is my stored procedure. CREATE PROCEDURE test () DYNAMIC RESULT SETS 1 P1: BEGIN DECLARE ageInterval INTEGER; SELECT (MAX("age")-min("age"))/5 INTO ageInterval FROM "Schema1"."adult"; create view "DiscreteTrain" as select "age"/ageInterval, "income" from "Schema1"."train"; END P1 When I deploy it, data studio says DB2ADMIN.TEST: 15: "AGEINTERVAL" is not valid in the context where it is used. SQLCODE=-206, SQLSTATE=42703, DRIVER=3.67.28 How

DB2 function error

不打扰是莪最后的温柔 提交于 2019-12-11 13:19:30
问题 What's wrong with the following DB2 function? CREATE FUNCTION MIGRATION.determineToTaxService (DIGI_NAAR_VLG CHAR, DIGI_VAN_VLG CHAR, NAARVLG CHAR) RETURNS CHAR BEGIN ATOMIC DECLARE returnValue CHAR; SET returnValue = '0'; IF (DIGI_NAAR_VLG = '1') THEN SET returnValue = '1'; ELSEIF (DIGI_VAN_VLG = '1') THEN SET returnValue = '1'; ELSEIF (NAARVLG = '1') THEN SET returnValue = '1'; END IF; RETURN returnValue; END; I'm getting this error: An unexpected token "CHAR" was found following " DECLARE

How to insert image as blob in DB2?

橙三吉。 提交于 2019-12-11 13:18:49
问题 I want to insert a PNG image in DB2. I am able to insert image in my SQL using Load File function. But I don't know how to insert image in DB2 column. 回答1: Check out the sample code provided with DB2, for example DtLob.java 回答2: db2 sql query to insert image into table create table table_name(column_name BLOB) /* BLOP is a data type insert into table_name(column_name)values(blob('c:\data\winter.jpg')) c:\data\winter.jpg is a path location , winter.jpg - image_name 来源: https://stackoverflow

SQL group - limit

会有一股神秘感。 提交于 2019-12-11 13:16:58
问题 Sometimes finding the best way to communicate a 'problem' is as difficult as finding the solution... LOL but here goes... I have a table with companies, I have a related table with some history for each company... I want to return a query with a record set of the last 3 'history' entries per company... so the recordset will look something like this... company A history Az history Ay history Ax company B history Bz history By history Bx company C history Cz history Cy history Cx The issue I'm

DB2 SQL query to compare 2 schemas

点点圈 提交于 2019-12-11 13:11:24
问题 I have been unable to find a solution in my searching for this throughout the web, most responses recommend a tool, which leads me to believe this may be very difficult with an SQL query or something, but... I have been told to write a query for our DB2 database, using Toad to interface, that will compare 2 schemas and provide a result if there are any differences. I know this capability exists in Toad, but for some reason our DBA does not want to use it. Purchasing additional software is not