SQL

1. DECODE的语法:DECODE(value,if1,then1,if2,then2,if3,then3,...,else)

 

2.  to_date('2008-04-23 00:00:00' ,'yyyy-mm-dd hh24:mi:ss')

     SELECT TO_CHAR(CURRENT_DATE, 'YYYY-MM-DD') FROM dual;

 

3. SUBSTR 从1开始而不是0

    SUBSTR ('shidong', 2) return idong

 

4. Oracle PIPELINED

 Pipelined functions are useful if there is a need for a data source other than a table in a select statement.

Typical Pipelined Example:

4.1 The producer function must use the PIPELINED keyword in its declaration.

4.2 The producer function must use an OUT parameter that is a record, corresponding to a row in the result set.

4.3 Once each output record is completed, it is sent to the consumer function through the use of the PIPE ROW keyword

4.4 The producer function must end with a RETURN statement that does not specify any return value.

4.5 The consumer function or SQL statement then must use the TABLE keyword to treat the resulting rows from the PIPELINE function like a regular table.

定义返回类型:

CREATE OR REPLACE TYPE myObjectFormat
AS OBJECT
(
A INT,
B DATE,
C VARCHAR2(25)
)
/

 

CREATE OR REPLACE TYPE myTableType
AS TABLE OF myObjectFormat
/

 

定义包/包体:

CREATE OR REPLACE PACKAGE myDemoPack
AS
FUNCTION prodFunc RETURN myTableType PIPELINED;
END;
/

 

CREATE OR REPLACE PACKAGE BODY myDemoPack AS
FUNCTION prodFunc RETURN myTableType PIPELINED IS
BEGIN
FOR i in 1 .. 5
LOOP
PIPE ROW (myObjectFormat(i,SYSDATE+i,'Row '||i));
END LOOP;
RETURN;
END;
END;
/

客户端调用:

SELECT * FROM TABLE(myDemoPack.prodFunc());

摘自:http://www.itpub.net/608483.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值