Search code examples
oracle-apex

How can I execute DDL command CREATE or ALTER or DROP in oracle apex process?


I want to kill session from oracle apex form , how can I execute kill session command ,

I tried the following :

1- created an interactive report with form using this SELECT statement

select sid , serial# , blocking_session from v$session;

2- In the form linked with this grid I select SID and SERIAL

3- I created process and used the code :

begin
alter system kill session ''' ||  :P90_SID || ',' || :P90_SERIAL_H  || ''';
 end;

but I got the error :

ORA-06550: line 2, column 1: PLS-00103: Encountered the symbol "ALTER" when expecting one of the following: ( begin case declare exit for goto if loop mod null pragma raise return select update while with <an identifier> <a double-quoted delimited-identifier> <a bind variable> << continue close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe purge json_exists json_value json_query json_object json_array

how to solve this error and execute kill session ?

update :

I am using database link apex installed on 19c database and production database run on 10g database , the issue for this error was when I select the sessions i select using database link

select sid , serial# , blocking_session from v$session@kaash;

but when I run the command its try to kill the session on the current database and show the error ORA:00030 User session ID does not exist. how can I add the database link to kill session command @kaash ?

and thank you for professional ansewrs .


Solution

  • To me, it is easier to compose statement to be executed; doing that, it is simple to verify whether it looks OK or not. Then execute it.

    I'd create a button on form page which runs a process that looks like this:

    declare
      l_str varchar2(200);
    begin
      l_str := 'alter system kill session ' || chr(39) || :P90_SID || ', '|| :P90_SERIAL_H || chr(39);
      execute immediate l_str;
    end;
    

    Of course, user (who pushes that button) has to have appropriate privileges. Not everyone is allowed to alter system.