zoukankan      html  css  js  c++  java
  • Oracle常用技巧及一些函数的总结

    1、将字符串转换为日期:可以不用TO_DATE

    1 SELECT * FROM EMP E WHERE E.HIREDATE < DATE '2012-08-09'

    2、从子查询中删除数据

    1 DELETE FROM (SELECT * FROM DUAL)

    3、查询所有的系统默认参数

    1 SELECT * FROM NLS_DATABASE_PARAMETERS;
    2 SELECT * FROM NLS_SESSION_PARAMETERS;

    4、查询数据库的信息

    1 SELECT * FROM v$database;

    4、查询实例的相关信息:包括主机名,启动时间,当前的状态,版本信息

    1 SELECT * FROM v$instance;

    --使用CAST函数:

         CAST converts one built-in datatype or collection-typed value into another built-in datatype or collection-typed value.(操作集合类型和内部支持的数据类型)

         CAST lets you convert built-in datatypes or collection-typed values of one type into another built-in datatype or collection type(将内部类型或集合类型的值转换为另一种集合类型或者内部类型). You can cast an unnamed operand (such as a date or the result set of a subquery) or a named collection (such as a varray or a nested table) into a type-compatible datatype or named collection. The type_name must be the name of a built-in datatype or collection type and the operand must be a built-in datatype or must evaluate to a collection value:

    When you use CAST ... MULTISET to get a collection value, each select list item in the query passed to the CAST function is converted to the corresponding attribute type of the target collection element type.

    User-defined types such as collections cannot be implicitly converted, but must be explicitly converted using CAST ... MULTISET

    语法:

    1 SELECT CAST ('1' AS NUMBER) FROM dual

    --使用collect函数:

    结合cast使用的collect

     参考地址:http://www.cnblogs.com/caroline/archive/2012/04/27/2474281.html

    1 SELECT Deptno,
    2        Tab_To_String(CAST(COLLECT(Ename) AS t_Varchar2_Tab)) AS Employees
    3   FROM Emp
    4  GROUP BY Deptno;

    使用cast聚合成集合:

    1 SELECT CAST(COLLECT(Ename) AS t_Varchar2_Tab) AS Employees
    2   FROM Emp
    3  GROUP BY Deptno;
    4  

    使用table函数,把集合变为一行一行的记录:

    1 SELECT *
    2   FROM TABLE (SELECT CAST(COLLECT(Ename) AS t_Varchar2_Tab) AS Employees
    3                 FROM Emp);

  • 相关阅读:
    Remote Debugging (2)
    Remote Debugging (3)
    在面试中常见额智力测试
    异常处理和约束
    方法&函数区别,反射
    类与类之间的关系
    成员
    初识面向对象
    一些令你""呵呵''的题目
    内置函数二 & 递归 & 二分查找
  • 原文地址:https://www.cnblogs.com/caroline/p/2470826.html
Copyright © 2011-2022 走看看