Сalling PL/SQL function from select statement does not work [duplicate]

Technically, the answer ist yes. You can do the following:

create or replace function committest return number as 
begin 
  update my_table set col = 'x';
  commit;
  return 1;
end;
/

declare
  number n;
begin
  n := committest();
end;
/

However, you can't do the following:

select committest() from dual;

this would be a commit during a query and thus result in a

ORA-14552: Cannot Perform a DDL Commit or Rollback Inside a Query or DML


Yes, you can do that if you make the function an autonomous transaction. That way it will not be part of the current transaction anymore.

create or replace function doIt
as
  pragma autonomous_transaction;
begin
  ... code ...
  commit;
end;
/

More documentation