逍 遥 谷

SQL-Plus 学习日记(随时更新)

   Oracle2005-3-30 15:41
1。
计算两个日期之间的天数(除去星期六,星期日)
create or replace function getDaysBetween(start_date date,end_date date)
return number
is
i number;
temp_date date;
begin
i:=0;
temp_date:=start_date;
while temp_date<=end_date
loop
if to_char(temp_date,'day') not in ('星期六','星期日') then i:=i+1; end if;
temp_date:=temp_date+1;
end loop;
return i;
end;



2.PL-SQL 里的循环

目标:实现对一张新表的循环添加纪录

1 declare
2 i integer;
3 begin
4 for i in 1 .. 33 loop
5 insert into mm values (i);
6 end loop;
7 commit;
8 end insPro;
9 /


3。
Oracle Enterprise Manager Console 的命令 : oemapp console


4。查找数据链

select table_name from dict where table_name like '%LINK%';
ALL_DB_LINKS
DBA_DB_LINKS
USER_DB_LINKS
GV$DBLINK
V$DBLINK


5。创建典型用户的 SQL 语句

CREATE USER "ROMEO" PROFILE "DEFAULT"
IDENTIFIED BY "love" DEFAULT TABLESPACE "USERS"
ACCOUNT UNLOCK;
GRANT SYSDBA TO "ROMEO"
GRANT "CONNECT" TO "ROMEO";
GRANT "DBA" TO "ROMEO";



6.随机产生七个彩票数字

select * from( select * from mm order by dbms_random.value )
where rownum <= 7



7.获取索引或表的DDL语句

select dbms_metadata.get_ddl('TABLE','SZT_PQSO2','SHQSYS') from dual;


8.
start with ... connect by 主要用于分级查询
比如你有部门信息表
dept(
deptno 部门号
deptname 部门名称
mgrno 上级部门
)
有如下记录
deptno , deptname , mgrno
1 总公司 null
2 上海分公司 1
3 浙江分公司 1
4 杭州分公司 3
...

你想查询总公司下所有的分公司,可以使用如下语句
select * , level from dept connect by PRIOR deptno = mgrno ;
显示:
deptno , deptname , mgrno , level
1 总公司 null 1
2 上海分公司 1 2
3 浙江分公司 1 2
4 杭州分公司 3 3



9.
SQL>
SQL> SELECT *
2 FROM (SELECT P.*, ROW_NUMBER() OVER(ORDER BY P.LL DESC) RK
3 FROM (SELECT LEVEL AS LL, TREE.*
4 FROM TREE
5 START WITH NODE = 'node2'
6 CONNECT BY NODE = PRIOR PNODE) P)
7 WHERE RK = 1
8 /

LL NODE PNODE RK
---------- -------------------- -------------------- ----------
3 node4 root 1

SQL>




10.

大家好,问个问题,我登陆到数据库主机,我用什么sql语句可以查看到我登陆用户的权限啊?

select * from user_role_privs;

select * from user_sys_privs;
第一个查询角色,第二个查询系统权限
标签集:TAGS:
回复Comments()点击Count()

回复Comments

{commenttime}{commentauthor}

{CommentUrl}
{commentcontent}
Categories
-=Oracle资料,文章=-
Links
New Comments
Counter
RSS
我的 Blog:
romeo 最新的 20 条日志
[J2EE]
[Oracle]
[PowerBuilder]
[Linux]
[管理]
[个人随笔]
[休闲娱乐]
[经典瞬间]
全站 Blog:
全站最新的 20 条日志
Calendar