1
    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;

/

I want to switch session user but I am getting error at connect karuna/karuna line

3
  • 1
    What is the error? Also, is it karuna/password or karuna/karuna? Commented Mar 4, 2013 at 9:24
  • 2
    CONNECT is a SQL*Plus command, not SQL, so not something you can call from a PL/SQL block. Why do you want to reconnect though; is there a reason the user you're connecting as to do this check can't have privileges to whatever it needs to, without exposing the entire karuna schema? Do you just want to avoid prefixing objects with the schema (e.g. alter session set current_schema = 'KARUNA')? Commented Mar 4, 2013 at 9:35
  • hello every one thanx for your reply actually i have a table which holds some values which is to be accessed by the other users along with owner of that table.but for other users can not directly access that table they have to go through a security algorithm if they passes algorithm then only they can access that table thats why i want to use this as at time when a user connect to the database it will be redirected to the owner of table which we have to access.that why i have to change datbase user in a single script. Commented Mar 12, 2013 at 17:32

2 Answers 2

1

Look at Oracle's feature n-tier (proxy) authentication. Maybe it's not what you need. Oracle offers you:

  • n-tier auth
  • set role statement (to get more privs. from password "protected" roles)
  • alter session set current_schema=KARUMA. This will not switch your username/privs but the default schema.

The right choice really depends on your needs.

Sign up to request clarification or add additional context in comments.

Comments

0

you have to give dba privilege to connect from your user to KARUMA user or CONNECT privilege.

please follow this link http://docs.oracle.com/cd/B28359_01/java.111/b31224/proxya.htm

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.