Questions tagged [execute-immediate]

An Oracle statement to execute a dynamic query or anonymous PL/SQL block.

The EXECUTE IMMEDIATE statement can be used within PL/SQL to build and run dynamically generated SQL.

Dynamically generated SQL can be vulnerable to SQL Injection. To guard against this bind variables and the system package dbms_assert should be used.

Questions tagged should normally also be tagged and / or .

Further Reading

167 questions
2
votes
2 answers

Oracle SQL: Use outer loop identifiers in inner loop in execute immediate

I have to execute 32 times a very similar operation, that is setting the value of a column in a row for a given record (for a given quarter). To simplify my code and thrive for beauty, I wanted to use a for loop with an execute immediate, using…
2
votes
2 answers

PL/SQL EXECUTE IMMEDIATE inside LOOP (procedure to truncate all tables in schema)

I need to create procedure which will delete all data from tables in one schema. I try something like that CREATE OR REPLACE PROCEDURE CLEAR_ALL IS sql_truncate VARCHAR2(50); cursor c1 is SELECT table_name FROM all_tables WHERE owner…
Karol Chudzik
  • 81
  • 1
  • 1
  • 9
2
votes
2 answers

error in EXECUTE IMMEDIATE insert ORACLE

good night. I have a problem with the EXECUTE IMMEDIATE in oracle. I look in others topics, but no answer was helpful. This is the code: First, the table that i need insert inside of trigger... create global temporary table TEMP_PK (COL_NAME…
2
votes
1 answer

Oracle Execute Immediate with DDL and Nested table

I have a problem trying to use an Execute Immediate statement containing a CREATE TABLE statement and a user defined Table Type. I get error ORA-22905 on Oracle 11g. Is there any workaround to solve this issue? CREATE TYPE MY_TABLE_TYPE AS TABLE OF…
2
votes
1 answer

run string as query in oracle

i got a little problem in Oracle. I try to create a sequence for generating IDs in a table that already has data in it. I try to use the following anonymous block. declare y varchar2(2000); BEGIN SELECT 'CREATE SEQUENCE ID_SEQ MINVALUE 1 MAXVALUE…
mitereiter
  • 35
  • 1
  • 4
2
votes
1 answer

PL/SQL Execute immediate exception handling inside for loop

In the below PL/SQL code, TABLE_ONE holds table name tname , column name cname and rowid rid. The For loop fetches records from TABLE_ONE and updates column cname in table tname for the record with row id rid. But if the record to be updated in…
user194210
  • 33
  • 1
  • 1
  • 5
2
votes
2 answers

How to Delete/Insert from different Tables and Views

I've got a wicked problem. In Oracle 10 there are pairs of Views and Tables where something like that is done over and over again: proc_log('DELETE 1'); DELETE FROM table_1; proc_log('INSERT 1'); INSERT INTO table_1 SELECT * FROM…
Joshua
  • 2,624
  • 2
  • 23
  • 39
2
votes
3 answers

execute immediate truncate table in sqlplus

Why does execute immediate 'truncate table trade_economics'; in a sqlplus script give the following error ? BEGIN immediate 'truncate table trade_economics'; END; * ERROR at line 1: ORA-06550: line 1, column 17: …
Vishal Saxena
  • 127
  • 2
  • 2
  • 6
2
votes
3 answers

PL/SQL - execute immediate in pipelined function

I want to execute dynamic query in my pipelined function and return results of this query. Is it possible to do this? Pipelined function is convenient for me to achieve good interface for my application cause it behaves like a table. The…
dzb
  • 61
  • 1
  • 1
  • 6
1
vote
2 answers

Is there a way to execute code dynamically in MySQL, similar to "execute immediate" in Oracle?

Like EXECUTE IMMEDIATE in Oracle, is there any way to execute code dynamically in a MySQL stored procedure? I really want to use a prepared statement within a MySQL stored procedure, to generate a new SQL statement in each iteration of a loop.
Eric_Chen
  • 217
  • 1
  • 4
  • 13
1
vote
2 answers

Why I can't use a bind variable in an execute immediate statement?

I'd like to use bind variables instead of a string concatenation when I build up a dynamic SQL statement for execute immediate. In the example below I can use bind variables for a, b and ret, but when I try to bind for f I get a ORA-06502: PL/SQL:…
user272735
  • 9,795
  • 8
  • 57
  • 86
1
vote
0 answers

UPDATE Statement doesn't update any row

I got two tables (ORACLE): D_CONTROL_CARGA and F_PS_CARGA_DIARIA_D SELECT control_id, control_cd, control_query_tx FROM ONHR_DIM.D_CONTROL_CARGA; SELECT FECHA_ID, CONTROL_ID, CONTROL_CD, CANTIDAD_CA FROM onhr_dim.F_PS_CARGA_DIARIA_D; I want to…
1
vote
2 answers

How to use a field from an input parameter of a HANA stored procedure to generate table name dynamically for execute_immediate statement?

I have been trying to solve a requirement with no luck where I have to pass a table containing 3 fields: object name, customer & location from an AMDP to a stored procedure. The stored procedure should be used to return a table that stores the same…
1
vote
2 answers

How update a table in Big Query where the name of fields to update are values in another table

Folks! I need some ideas, with the follow problem: I have two tables: Table 1: +-------+------------+---------+ | ID | field_name | value | +-------+------------+---------+ | 1 | usd | 10.08 | | 1 | gross_amt | 52.0 | | 1 …
Leo
  • 47
  • 5
1
vote
1 answer

Error numeric overflow oracle when call execute immediate

I define a procedure do parse a formula (type value String) to a value number: Some case value in formula can execute or raise error numeric overflow. Code : DECLARE formula VARCHAR2(1000) := '1111111111 * 2'; val NUMBER; BEGIN EXECUTE…
1 2
3
11 12