2
0
mirror of https://github.com/chubin/cheat.sheets synced 2024-11-19 03:25:44 +00:00
cheat.sheets/sheets/_db2/queries
Andres Gomez Casanova 805c0634dc
Create queries
2019-01-07 11:57:43 -05:00

42 lines
1.0 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

--Put a lock at table level
LOCK TABLE mytable1 IN EXCLUSIVE MODE
--Execute a query without regard of commit rows
SELECT * FROM mytable WITH UR
--Execute a query with only 5 rows
SELECT * FROM mytable FETCH FIRST 5 ROWS ONLY
--Perform a query to a dummy table (dual)
SELECT 'Any string' FROM SYSIBM.SYSDUMMY1
--Perform a query calling a function
SELECT HEX(mycol2) FROM mytable1
--Call a function
VALUES HEX('AnyText')
--Perform a cast
VALUES CAST('123' AS INTEGER)
--Concatenate
VALUES 'AnyText' || 5
VALUES 'AnyText' concat 5
--Escape a single quote in a text field
VALUES 'Sinead o''Connor'
--Query the database catalog
SELECT * FROM SYSCAT.TABLES
SELECT * FROM SYSCAT.TABAUTH
SELECT * FROM SYSCAT.ROUTINES
--Create a compound statement Anonymous block
BEGIN DECLARE val SMALLINT; SET val = 1; WHILE (val <= 5) DO INSERT INTO mytable VALUES (val, val); SET val = val + 1; END WHILE; END @
--Perform a reorg via ADMIN_CMD
CALL SYSPROC.ADMIN_CMD('REORG TABLE mytable')
--Call a stored procedure with an IN and an OUTPUT parameter
CALL myproc(5, ?)