您的位置:首页 > 数据库 > Oracle

Oracle常用技巧及一些函数的总结

2019-07-17 14:16 435 查看
原文链接:https://www.geek-share.com/detail/2546397020.html

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

 参考地址:https://www.geek-share.com/detail/2546535742.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);

 

 

转载于:https://www.cnblogs.com/caroline/archive/2012/04/26/2470826.html

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: