Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set timeout for anonoymous block or query in plsql?

I know you can set user profiles or set a general timeout for query.

But I wish to set timeout to a specific query inside a procedure and catch the exception, something like :

begin
      update tbl set col = v_val; --Unlimited time
      delete from tbl where id = 20; --Unlimited time

      begin
            delete from tbl; -- I want this to have a limited time to perform
            exception  when (timeout???) then
            --code; 

      end;

end;

Is this possible? is there any timeout exceptions at all I can catch? per block or query? didn't find much info on the topic.

like image 760
eric.itzhak Avatar asked Dec 11 '13 12:12

eric.itzhak


People also ask

How do I set query timeout?

Using SQL Server Management StudioIn Object Explorer, right-click a server and select Properties. Click the Connections node. Under Remote server connections, in the Remote query timeout box, type or select a value from 0 through 2,147,483,647 to set the maximum number seconds for SQL Server to wait before timing out.

When a PL SQL anonymous block is executed?

The PL/SQL anonymous block statement is an executable statement that can contain PL/SQL control statements and SQL statements. It can be used to implement procedural logic in a scripting language. In PL/SQL contexts, this statement can be compiled and executed by the data server.

How do you call an anonymous block in PL SQL?

Execute a PL/SQL anonymous block using SQL*Plus Second, turn on the server output using the SET SERVEROUTPUT ON command so that the DBMS_OUTPUT. PUT_LINE procedure will display text on the screen. Third, type the code of the block and enter a forward slash ( / ) to instruct SQL*Plus to execute the block.

How do I force a SQL timeout?

Try using the WAITFOR command in T-SQL. That'll pause the execution of the query and you should see a timeout. Try using the WAITFOR command in T-SQL. That'll pause the execution of the query and you should see a timeout.


1 Answers

No, you can not set a timeout in pl/sql. You could use a host language for this in which you embed your sql and pl/sql.

like image 200
ik_zelf Avatar answered Oct 26 '22 13:10

ik_zelf