Reputation: 1504
I need for some reason to alter and show the size of db_cahce_size for an ORACLE 10g database from C# (using ODP.NET) I use the following commands on SQL+
"alter system set db_cache_size = Xm scope=both;
"
and that command to show it current value
"show parameter db_cache_size;
"
but when I tried to issue that commands from C# via ODP.NET command object I got that error [ORA-00900: invalid SQL statement]
It seems that it doesn't accept such kind of command so What to do please to do it?
Upvotes: 0
Views: 947
Reputation: 52913
Why not just create a small procedure to alter the system:
create or replace procedure change_cache_size (Px in number) is
begin
execute immediate 'alter system set db_cache_size = Xm scope=both';
end;
You can then call this from C#.
In order to find the current value of a parameter in SQL you can query V$PARAMETER
select value
from v$parameter
where name = 'db_cache_size'
This can then be queried normally. Alternatively, you can combine them into one using an OUT parameter.
create or replace procedure change_cache_size (Psize out varchar2) is
begin
execute immediate 'alter system set db_cache_size = Xm scope=both';
select value into Psize
from v$parameter
where name = 'db_cache_size';
end;
I would be extremely wary of changing an initialization parameter in an application in this manner. It's highly indicative that something needs to be changed in your database. I would be much more comfortable coming up with a cache size that works for all applications using a database rather than changing it based on the requirements of one at a single moment in time.
If you want X to be variable then simply make this another parameter:
create or replace procedure change_cache_size (PX in number, Psize out varchar2) is
begin
execute immediate 'alter system set db_cache_size = ' || X || 'm scope=both';
select value into Psize
from v$parameter
where name = 'db_cache_size';
end;
It's worth noting that you'd now be performing system changes dynamically with user input... ensure you sanitise the input first.
Upvotes: 1