DB2 SQL PL介绍
DB2 SQL PL
SQL PL是DB2所支持的过程化语言,它是SQL/PSM标准的一个子集。其根据应用范围不同,又分为Inline SQL PL,Embeded SQL PL和Compiled SQL PL。
Inline SQL PL
适用范围:触发器、函数和方法,支持部分SQL PL,使用时要注意一些限制
语法规则:BEGIN ATOMIC ... END
Embeded SQL PL
适用范围:嵌入式,配合宿主语言一起使用,有点类似于PowerBuilder编程形式
语法规则:BEGIN COMPOUND [ATOMIC|NOT ATOMIC] STATIC ... END
Compiled SQL PL
适用范围:支持所有的SQL PL
语法规则:BEGIN ... END
SQL Routine
包括过程、函数和方法(method),所谓的方法就是按照目的不同而创建出的概念,用于操作某个自定义类型(CREATE TYPE ...)的方法,有些类似于PL/SQL的面向对象概念。
DB2对PL/SQL的支持
DB2支持Oracle的PL/SQL,但在默认情况下这个功能是被关闭的,只有通过手动打开。
启动步骤:
db2start
db2set DB2_COMPATIBILITY_VECTOR=ORA
db2set DB2_DEFERRED_PREPARE_SEMANTICS=YES
db2stop
db2start
db2 CREATE DATABASE DB
测试结果:
CONNECT TO DB;
SET SQLCOMPAT PLSQL;
-- Semicolon is used to terminate
-- the CREATE TABLE statement:
CREATE TABLE t1 (c1 NUMBER);
-- Forward slash on a new line is used to terminate
-- the CREATE PROCEDURE statement:
CREATE OR REPLACE PROCEDURE testdb(num IN NUMBER, message OUT VARCHAR2)
AS
BEGIN
INSERT INTO t1 VALUES (num);
message := 'The number you passed is: ' || TO_CHAR(num);
END;
/
CALL testdb(100, ?);
相关文档:
原网站无法访问,故保留google快照
How things work :
SQL
Select
Statement
Introduction
:
Ever asked your self how things work inside the
SQL
Select
statement? In this article we won’t be talking about how to writeSQL
Select
statem ......
SQL位运算
select 2|8 --10
select 2|8|1 --11
select 10&8 --8,包含,10=8+2
select 10&2 --2,包含,10=2+8
select 10&4 --0,不包含
select 19&16 --16,包含,19=16+2+1
s ......
-- FUN:存储过程分页
-- @Table nvarchar(255), -- 表名
-- @Fields nvarchar(1000) = ' * ', -- 需要返回的列
-- @OrderField nvarchar(255), -- 排序的字段名,一般为唯一标识
-- @OrderType bit = 0, -- 设置排序类型, 非 0 值则降序
-- @PageSize int = 10, -- 每页有多少条记录
-- @PageIndex int = 1, -- 第 ......
Suppose we have a recursive hierarchy stored in a relational database and we want to write it to XML. This might be for a variety of reasons – e.g. as a pre-cached input to a UI control, to export to another system using a pre-defined format, etc.
In SQL Server 2000, in order to ......
一:Select语句:
select 字段名 from 表名 where 条件 order by 排序
see:select distinct 从多个相同字段中抓唯一值
see:查找ld_det_andy表中有数据但ld_det_temp表中没数据的数据
select * from ld_det_a ......