Tuesday, April 16, 2013

Grant readonly access to PL/SQL (Function, procedures, packages etc) user logged in through SQL Developer

Sometimes developer need read only access to the code of you PL/SQL in oracle, this is not difficult to achieve. You can create a user
create user readonlyU identified by strongpassword default tablespace users temporary tablespace temp;
grant connect to readonlyU;
grant select on sys.dba_source to readonlyU;

This will work great but if you log in through SQL Developer you will not able to see the PL/SQL objects.

There are two solutions to this problem. After implementation of these solutions readonlyU should be able to view the source code in SQL Developer like the image below:


1. Grant select access to all tables under database and then set O7_DICTIONARY_ACCESSIBILITY=TRUE

This would allow user to have select access on all the tables including data dictionary tables. This could not be the best option.

grant select any table to readonlyU;
alter system set O7_DICTIONARY_ACCESSIBILITY=TRUE scope=spfile;
shutdown immediate
startup

2. SQL Developer us two dba views to show the PL/SQL objects under left navigation and those are dba_objects and dba_plsql_object_settings. Hence granting select on these two views will do the trick.

grant select on sys.dba_objects to readonlyU;
grant select on sys.dba_plsql_object_settings to readonlyU;







Monday, April 15, 2013

Tower of hanoi solution python


resl=0
count =0

def main():
    num_discs=3
    from_peg=1
    to_peg=3
    temp_peg=2
    resl=move_discs(num_discs, from_peg, to_peg, temp_peg)
    print ('All the pegs are moved!')
    print ('done in: ', resl ,' Moves !')

def move_discs(num, from_peg, to_peg, temp_peg):
    global count
    count +=1
    print ('inside 1: ', count)
    if num >0:
        print ('inside 2: ', count)
        move_discs(num -1, from_peg, to_peg, temp_peg)
        print('Move a disc from peg', from_peg, 'to_peg', temp_peg)
        print ('inside 3: ', count)
        move_discs(num -1, temp_peg,to_peg,from_peg)
        print ('inside 4: ', count)
   
    print ('a',count)
    return count
    #else:
        #print(count)
main()