Oracle创建循环bat脚本

xcluii 2010-11-04 03:52:16
将一系列表TableXXX的权限授予给其他用户,其中表名包含的XXX是递增的数字序列,比如table001,table002,table003.....
执行脚本时,要求输入参数包括开始编号vi1和结束编号vi2
如输入21,50,那么执行后的结果便是将table021至table050的30个表格的select权限授给用户OtherUser
望高人解答,谢谢啦
...全文
214 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xcluii 2010-11-05
  • 打赏
  • 举报
回复
感谢楼上的解答

忘记说了一点,不能在后台创建存储过程。
YY_MM_DD 2010-11-04
  • 打赏
  • 举报
回复

Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
Connected as scott


SQL>
SQL> create or replace procedure grantToUser(startBy in number,endBy in number)
2 is
3 v_sql varchar2(2000);
4 begin
5 for i in startBy .. endBy loop
6 v_sql := 'grant select on table'||lpad(i,'0')||' to system';
7 execute immediate v_sql;
8 end loop;
9 end grantToUser;
10 /

Procedure created

SQL>

我这里没有你的表所以报错了

Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.

C:\Documents and Settings\lkf12998>E:

E:\>more todo.bat
sqlplus scott/tiger @test.sql

E:\>more test.sql
begin
grantToUser(&startBy,&endBy);
end;
/

E:\>todo.bat

E:\>sqlplus scott/tiger @test.sql

SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 11月 4 16:57:49 2010

Copyright (c) 1982, 2005, Oracle. All rights reserved.


连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

输入 startby 的值: 1
输入 endby 的值: 2
原值 2: grantToUser(&startBy,&endBy);
新值 2: grantToUser(1,2);
begin
*
第 1 行出现错误:
ORA-00903: 表名无效
ORA-06512: 在 "SCOTT.GRANTTOUSER", line 7
ORA-06512: 在 line 2


xcluii 2010-11-04
  • 打赏
  • 举报
回复
对~~~ 运行bat文件时需要输入参数
YY_MM_DD 2010-11-04
  • 打赏
  • 举报
回复
oracle 要接受操作系统的传过来的参数?

17,090

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧