简体   繁体   中英

Update statement not working getting error ORA-01031: Insufficient privileges

My update table query not working. if i am runing this query as a sub part it's working but as soon as i am runing as a whole it giving me exception ORA-01031: Insufficient privileges.

 declare
         var_sqlString varchar2(2500);
         begin    
    var_sqlString :='UPDATE (select ''A''||registration_id from sde.table_registry where table_name=''OPENPOINT'' and OWNER=''EDGIS'') 
    SET OPERATINGVOLTAGE=''21'' where GLOBALID=''{3B5C4257-12D8-4CA9-82E4-427AC9D79BB0}''' ;
    dbms_output.put_line(var_sqlString); 
          EXECUTE immediate var_sqlString;
          commit;        
         end;

When i am executing this query dbms_output.put_line giving me bellow result.

UPDATE (select 'A'||registration_id from sde.table_registry where table_name='OPENPOINT' and OWNER='EDGIS') 
SET OPERATINGVOLTAGE='21' where GLOBALID='{3B5C4257-12D8-4CA9-82E4-427AC9D79BB0}'

And when i am runing the above query than also i am getting the same error. Now the problem is when i am executing part one which is: select 'A'||registration_id from sde.table_registry where table_name='OPENPOINT' and OWNER='EDGIS' Its giving me the result which is A126 and then i am passing that result in my update statement, the update statement works fine. But as a whole is not working .....???

The error Insufficient privileges tells you that you are not allowed to do an UPDATE statement on this table.

Check the user rights on the user you are using for this query. You should grant UPDATE privileges for the user you are using.

You can read the Oracle documentation on how to manage user privileges .

I Found the solution, Problem was Oracle was treating table retrieval statement as a whole staring not a table, So that was the cause of my problem. So i added select statement at the beginning of my query and got the output. So updated query would be

set serveroutput on
declare
     var_sqlString varchar2(2500);
     begin

select 'UPDATE edgis.' || 
(select 'A'||registration_id from sde.table_registry where table_name='OPENPOINT' and OWNER='EDGIS') 
|| ' SET OPERATINGVOLTAGE=''21'' where GLOBALID=''{3B5C4257-12D8-4CA9-82E4-427AC9D79BB0}'''  into var_sqlString from dual;
dbms_output.put_line(var_sqlString);  
      EXECUTE immediate var_sqlString;
     commit;  
     end;

Thanks! For helping me but i found the solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM