2017-09-07 49 views
0

问题: 是否有与dbms_system.set_int_param_in_session等效的初始参数,其值是字符串而不是整数或布尔值?oracle 12c cursor_sharing更改多个会话

Backstory: 我有一个第三方应用程序的问题,其API不使用绑定变量。这导致高cpu和性能缓慢,因为应用程序反复发出相同的SQL。 (硬解析)我发现将cursor_sharing参数设置为FORCE可以提高性能,但是这样做存在安全问题。第三方应用程序维护许多会话(〜30-50)所以我目前的做法是在第三方应用程序正在做它的事情的时候强制设置cursor_sharing,然后在完成时将cursor_sharing设置回确切的时间。缺憾?是的,非常。我们做了一些研究,发现dbms_system.set_int_param_in_session过程似乎是一个适当的解决方案,只是它只适用于数据类型为integer的init参数。是否有与数据类型字符串值相关的参数?

回答

0

虽然IM使用使用dbms_system不精通的基础上,可用于dbms_systeminfo,我想在会话级使用add_parameter_value,并结束了以下错误:

SQL> set serveroutput on 
DECLARE 
sid_value VARCHAR2(10); 
BEGIN 
    dbms_system.get_env('ORACLE_SID', sid_value); 
    dbms_output.put_line(sid_value); 
    dbms_system.add_parameter_value('cursor_sharing', 'EXACT', 'MEMORY', sid_value, 4); 
END; 
/
show errorsSQL> 2 3 4 5 6 7 8 mydb 
DECLARE 
* 
ERROR at line 1: 
ORA-20004: cursor_sharing is not a list parameter 


SQL> 

所以,尝试下面的触发该方法仅为用户SCOTT设置cursor_sharingforce,您可以根据自己的要求进行更改。

SQL> create or replace trigger csf 
after logon 
on database 
begin 
    if user='SCOTT' then 
     execute immediate 'alter session set cursor_sharing=force'; 
    else 
     execute immediate 'alter session set cursor_sharing=exact'; 
    end if; 
end; 
/2 3 4 5 6 7 8 9 10 11 

Trigger created. 

SQL> 
SQL> 
SQL> conn scott/tiger 
Connected. 
SQL> show parameter cursor_sharing 

NAME     TYPE  VALUE 
--------------------- --------- --------------- 
cursor_sharing  string FORCE 
SQL> 
SQL> conn system/manager 
Connected. 
SQL> show parameter cursor_sharing 

NAME     TYPE  VALUE 
--------------------- --------- --------------- 
cursor_sharing  string EXACT 
SQL> 

希望这可以帮助您避免将值设置回原始值。