求解 oracle系统表v$parameter v$SGASTAT里面参数的意思

wudidaqueer 2012-08-28 05:10:07
鄙人菜鸟遇一oracle的问题,

先贴sql语句: select round(100 * (1 - (a.bytes / b.value)), 2) MemoryUsage from v$sgastat a, v$parameter b
where a.pool = 'shared pool' and a.name = 'free memory' and b.name = 'shared_pool_size'

当程序运行到调用该sql语句的时候,由于系统表v$parameter.value=0(b.value=0)抛出异常,除数不能为0.

有没有哪位大神 能给我一个方法 得到当b.value=0是,查出memoryUsage的值。
...全文
894 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
wudidaqueer 2012-08-30
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 的回复:]

好吧,帮人帮到底

SQL code
with param as (select 1 as id, value as val from v$parameter where name = 'shared_pool_size'),
sgainfo as (select 1 as id, bytes as val from v$sgainfo where name = 'Shared ……
[/Quote]

我只能说我爱死你了~~大神
去http://topic.csdn.net/u/20120813/16/391076ad-b4fa-4817-9c8e-d000ad59a004.html 这留个言我结贴送分吧~~都没人鸟我这贴子~~~哈哈~~~~
fw0124 2012-08-29
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]
引用 3 楼 的回复:

我的意思是,
select bytes from v$sgainfo where name='Shared Pool Size';
查出来的东西替换你的b.value。


我在网上问的另外一个哥们 他说,在自动内存管理的情况下 可以用select current_size from v$sga_dynamic_components where COMPON……
[/Quote]

对,这两个查出来结果应该是一样的。

tony@ORCL1> select current_size from v$sga_dynamic_components where component='shared pool';

CURRENT_SIZE
------------
125829120

tony@ORCL1> select bytes from v$sgainfo where name='Shared Pool Size';

BYTES
----------
125829120
wudidaqueer 2012-08-29
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

我的意思是,
select bytes from v$sgainfo where name='Shared Pool Size';
查出来的东西替换你的b.value。
[/Quote]

我在网上问的另外一个哥们 他说,在自动内存管理的情况下 可以用select current_size from v$sga_dynamic_components where COMPONENT='shared pool' 来替换v$parameter.value的值呢。。

你觉得他说得对吗?
wudidaqueer 2012-08-29
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

我的意思是,
select bytes from v$sgainfo where name='Shared Pool Size';
查出来的东西替换你的b.value。
[/Quote]

哥们 谢谢你的回答,,
我想确定一下 在自动内存管理的情况下 select bytes from v$sgainfo where name='Shared Pool Size'; 查出来v$sgainfo.bytes,然后这个v$sgainfo.bytes是等价于 不是自动内存管理情况下 select value from v$parameter where name = 'shared_pool_size' 查询出来的v$parameter.value.你是这个意思吧?因为我也不知道这个情况怎么验证。
fw0124 2012-08-29
  • 打赏
  • 举报
回复
我的意思是,
select bytes from v$sgainfo where name='Shared Pool Size';
查出来的东西替换你的b.value。
wudidaqueer 2012-08-29
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

不要从v$parameter查,你应该用的是自动内存管理,oracle会根据memory_target参数(11g)或者sga_target参数(10g)自动分配共享池大小。

从v$sgainfo查共享池大小。
select bytes from v$sgainfo where name='Shared Pool Size';
[/Quote]

fw0124,,,select bytes from v$sgainfo where name='Shared Pool Size' 查出来的东西等价于 select round(100 * (1 - (a.bytes / b.value)), 2) MemoryUsage from v$sgastat a, v$parameter b
where a.pool = 'shared pool' and a.name = 'free memory' and b.name = 'shared_pool_size'查出来的东西吗?
fw0124 2012-08-29
  • 打赏
  • 举报
回复
好吧,帮人帮到底

with param as (select 1 as id, value as val from v$parameter where name = 'shared_pool_size'),
sgainfo as (select 1 as id, bytes as val from v$sgainfo where name = 'Shared Pool Size'),
sgastat as (select 1 as id, bytes as val from v$sgastat where pool = 'shared pool' and name = 'free memory')
select round(100 * (1 - (sgastat.val / (case param.val when '0' then sgainfo.val else (0+param.val) end))), 2) MemoryUsage
from param, sgainfo, sgastat where param.id=sgainfo.id and param.id=sgastat.id;
wudidaqueer 2012-08-29
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]

引用 5 楼 的回复:
引用 3 楼 的回复:

我的意思是,
select bytes from v$sgainfo where name='Shared Pool Size';
查出来的东西替换你的b.value。


我在网上问的另外一个哥们 他说,在自动内存管理的情况下 可以用select current_size from v$sga_dynamic_componen……
[/Quote]

亲,,问题基本上是你这样解决的。。
问最后一个问题,怎么在一个sql语句里面实现:
当v$parameter=0时,select round(100 * (1 - (a.bytes / b.bytes)), 2) MemoryUsage from v$sgastat a, v$sgainfo b where a.pool = 'shared pool' and a.name = 'free memory' and b.name = 'shared pool size'
当v$parameter不等于0时,select round(100 * (1 - (a.bytes / b.value)), 2) MemoryUsage from v$sgastat a, v$parameter b where a.pool = 'shared pool' and a.name = 'free memory' and b.name = 'shared_pool_size'。

我问了一个人说用case when语句,我表示oracle菜鸟自己研究压力大呀,谢谢大神~~
fw0124 2012-08-28
  • 打赏
  • 举报
回复
不要从v$parameter查,你应该用的是自动内存管理,oracle会根据memory_target参数(11g)或者sga_target参数(10g)自动分配共享池大小。

从v$sgainfo查共享池大小。
select bytes from v$sgainfo where name='Shared Pool Size';

17,086

社区成员

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

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