SQL Server中生成某一用户的权限授权脚本

CREATE procedure ListUserPermission
(@UserName sysname)
AS
set nocount on
BEGIN
if (select object_id(’tempdb..#tt’)) is not null
drop table #tt
create table #tt
(owner sysname,
object sysname,
grantee sysname,
grantor sysname,
protecttype varchar(10),
actionname varchar(20),
columnname sysname
)
insert #tt execute sp_helprotect @username = @UserName
select
rtrim(protecttype) + ‘ ‘ + actionname + ” +
case object when ‘.’ then ” else ‘ on ‘ + ‘['+owner+'].['+object+']‘ +
case when columnname in(’(All+New)’,'(All)’,'(New)’,’.’) then ” else ‘(’+columnname+’)’ end end
+’ to ‘ + grantee
from #tt
union all
SELECT ‘EXEC sp_addsrvrolemember ”’+Users.name+”’,”’ +Roles.Name+””
FROM sysusers Users, sysusers Roles, sysmembers Members
WHERE Roles.uid = Members.groupuid
AND Roles.issqlrole = 1
AND Users.uid = Members.memberuid
AND Users.name = @UserName
END
GO

10gR2在Linux中出现Ora-600错误

今天同事告诉我 oracle 10g无法启动,我看了一下,启动的时候报如下错误:

ORA-00600: [keltnfy-ldmInit], [46]

大致了解了一下情况,由于办公室调整,服务器变更了位置,IP地址和hostname也变掉了。

在google上查了一下,发现跟xzh2000描述的很类似,于是修改hosts及network文件,将其中hostname的设定改成原来的hostname,然后再启动 oracle ,果然可以开启数据库了:)

这应该是 oracle 的一个bug,所以对于10gR2在Linux下不要随意修改hostname,如果要修改,一定要修改彻底,主要是修改/etc/hosts,/etc/sysconfig/network这两个文件。

SQL Server无法安装

今天一同事在安装SQL SERVER时出现如下错误:

以前的某个程序安装已在安装计算机上创建挂起的文件操作。运行安装程序之前必须重新启动计算机

之前也碰到过类似的问题,解决方式是:

打开注册表编辑器,在HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager中找到PendingFileRenameOperations项目,并删除它。这样就可以清除安装暂挂项目

然后再执行安装就可以了

Oracle中的rownum

Rownum:

rownum是 oracle 中的伪列,并不真正存在于表中,它只在查询的时候产生。也就是说表中的数据并没有一个真正的物理的列去表示一条记录是第几行,而只是在查询中才会对这些行进行标识。那到底rownum是什么时候赋给行的呢?

rownum是在where条件过滤之后,在任何排序(order by)或聚集(aggregation)之前赋给行的。

同时,只有当rownum被分配给行后才会递增。

rownum的初始值为1。rownum在查询中产生后就不再变化

rownum被分配的过程大致如下:

rownum = 1
for x in ( select * from A )
loop
if ( x satisifies the predicate )
then
OUTPUT the row
rownum = rownum + 1
end if;
end loop; (more…)

参考游标(refcursor)的使用

我们知道在sql server中可以直接在存储过程中使用select * from 来产生记录集,但在 oracle 的存储过程里却不可以。怎么办呢?可以用参考游标来实现。

参考游标(ref cursor)从 oracle 7.3开始引入,作用是允许在存储过程,函数,包中返回记录集。

oracle 9i之前,参考游标以如下方式定义:

首先定义一个参考游标:

TYPE ref_type_name IS REF CURSOR
[RETURN {cursor_name%ROWTYPE
|ref_cursor_name%ROWTYPE
|record_name%TYPE
|record_type_name
|table_name%ROWTYPE} ]; (more…)

稀疏文件与临时表空间文件

不知道大家有没有发现,当你往临时表空间里添加临时文件时速度很快,这是为什么呢?原来 oracle 采用了稀疏文件(Sparse Files )技术。那么什么是稀疏文件呢?

1。什么是稀疏文件

稀疏文件是指内部具有一个或多个未分派数据的区域的文件。程序将会发现这些未分派的包含零字节的区域,但是没有实际的磁盘空间用来代表这些零。换句话说,所有有意义或非零数据得到了分配,而所有无意义的数据(一大串由零组成的数据)没有得到分配。当读入稀疏文件时,已分配的数据以存储方式返回,在默认情况下,按照 C2 安全需求规范未分配的数据以零的方式返回。稀疏文件支持允许在文件的任意位置解除分配数据—-来自Windows在线帮助

A sparse file is a file where any ‘empty’ O/S blocks do not actually take up a full block but have a marker to show the block is empty. The operating system then finds a free block for use when the block is populated with data.—-来自 oracle 的解释

2。稀疏文件的优缺点

优点:通过稀疏文件, oracle 能快速创建临时文件

缺点:1。使用稀疏文件分配空间时如果空间不够会产生错误

2。容易产生磁盘碎片,因为在使用的过程中,有可能连续的空闲空间被其他文件使用,此时

oracle 只能去寻找另外的未使用块来供 oracle 填充数据

3。如何识别稀疏文件

在Linux下可以简单通过ls和df两个指令来辨别

临时文件的绝对文件号(AFN)

还是上次查询报错的例子:

ERROR:
ORA-01114: IO error writing block to file 201 (block # 1048178)
ORA-27069: skgfdisp: attempt to do I/O beyond the range of the file
OSD-04026: Invalid parameter passed. (OS 1048192)
ORA-01114: IO error writing block to file 201 (block # 1048178)
ORA-27069: skgfdisp: attempt to do I/O beyond the range of the file
OSD-04026: Invalid parameter passed. (OS 1048192)

我们看这里出现一个file 201,而查找数据字典就是找不到这个文件:

SQL> select file#,name from v$datafile; (more…)

由Bug引起的ORA-01114&ORA-27069错误

最近在执行一个大数据量查询时报如下错误:

ORA-01114: IO error writing block to file 201 (block # 523913)
ORA-27069: skgfdisp: attempt to do I/O beyond the range of the file
OSD-04026: Invalid parameter passed. (OS 523927)
ORA-01114: IO error writing block to file 201 (block # 523913)

经查询file 201是临时表空间的第一个文件,该文件初始大小为2GB,自动扩展,每次扩展640K,当到达4G时出现以上错误。后来又测试了一下,发现在跨越8G时也会出现以上错误:

SQL> select * from v_offtake_profit_inv_national;
ERROR:
ORA-01114: IO error writing block to file 201 (block # 1048178)
ORA-27069: skgfdisp: attempt to do I/O beyond the range of the file
OSD-04026: Invalid parameter passed. (OS 1048192)
ORA-01114: IO error writing block to file 201 (block # 1048178)
ORA-27069: skgfdisp: attempt to do I/O beyond the range of the file
OSD-04026: Invalid parameter passed. (OS 1048192) (more…)

主键约束引起ORA-02429错误

drop index时出现如下错误:

SQL> drop index oos_index;

drop index oos_index

*

ERROR at line 1:

ORA-02429: cannot drop index used for enforcement of unique/primary key

我们知道当创建Primary key和unique约束时,如果在该key上不存在索引,则 oracle 会自动创建对应的unique索引,而当你要删除该索引时,必须先Disable或Drop该约束。看下面的例子: (more…)

截断事物日志的几种方法

今天部门经理问我如何截断SQL SERVER的日志文件,刚好之前有做过,如下:

1。DBCC SHRINKFILE (DataFil1, 7): 其中datafil1为你要收缩的日志文件名,或者用文件号去代替,一般日志文件号问2, 7为你要收缩到的大小,这里是7MB

2。backup log database_name with no_log

3。设定database的recovery mode为simple,但这种方法是永久性的,且已经增长的日志没办法立即截断

  Recent Comments:

    搜索本站

    站点日历

    3月 2010
    « 11    
    1234567
    891011121314
    15161718192021
    22232425262728
    293031  

    订阅本站

    文章分类

    最新日志

    热点文章

    日志存档

    常用标签