在pl / sql脚本中切换用户会话

时间:2013-03-04 09:20:37

标签: sql oracle plsql

    set serveroutput on;
   declare
    username1 varchar2(40);
   cnt number;
    hello varchar2(20);
    c sys_refcursor;
    begin
    select sys_context('userenv','session_user') into username1 from dual;
     select lower(username1) into username1 from dual;
     select count(lower(username)) into cnt from karuna.tableusers where        lower(username)=username1;
     if cnt=1 then
     dbms_output.put_line('username found');
      execute immediate 'connect karuna/password ';
     open c for 'select item_name  from sells12 where item_id=12';
      fetch c into hello;
      dbms_output.put_line(hello);
      close c;
     else
     dbms_output.put_line('u dont have previllege to access database');
      ----raise_application_error(-20001,'error out');
       end if;
       end;

/

我想切换会话用户,但我在connect karuna / karuna line

收到错误

2 个答案:

答案 0 :(得分:0)

查看Oracle的功能n层(代理)身份验证。也许它不是你需要的。 Oracle为您提供:

  • n-tier auth
  • 设置角色声明(从密码&#34获得更多权限;受保护"角色)
  • alter session set current_schema = KARUMA。这不会切换您的用户名/权限,而是默认架构。

正确的选择实际上取决于您的需求。

答案 1 :(得分:0)

您必须提供dba权限才能从您的用户连接到KARUMA用户或CONNECT权限。

请点击此链接 http://docs.oracle.com/cd/B28359_01/java.111/b31224/proxya.htm

相关问题