execute-immediate

Oracle PL/SQL Release 12.2.0.1.0 vs 12.1.0.2.0 - execute immediate with parameters

浪子不回头ぞ 提交于 2021-01-27 13:21:08
问题 DECLARE max_id INTEGER; BEGIN SELECT MAX(ID) + 1 INTO max_id FROM MY_TABLE; EXECUTE IMMEDIATE 'CREATE SEQUENCE MY_TABLE_ID MINVALUE 1 MAXVALUE 99999999999999 INCREMENT BY 1 START WITH ' || max_id || ' CACHE 100 NOORDER NOCYCLE NOPARTITION'; END; Above gives me ORA-00933: SQL command not properly ended when executed on Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production PL/SQL Release 12.2.0.1.0 - Production and works without errors on Oracle Database 12c Enterprise

Assign value to a field of rowtype where `field name` is a string

为君一笑 提交于 2020-01-01 00:12:01
问题 I want to assign a value to a rowtype's field but I don't know how to do it. Suppose that I have a table X inside my database. Suppose also that I have the following variables a ( X%ROWTYPE ), representing a row of the table X b ( VARCHAR2 ), containing a column name of the table X c ( VARCHAR2 ), containing what I want to store inside a.b What I want to do : something like a.b := c . I've come up with something like this : EXECUTE IMMEDIATE 'SELECT '|| c || ' INTO a.' || b || ' FROM DUAL';

Assign value to a field of rowtype where `field name` is a string

拥有回忆 提交于 2020-01-01 00:12:00
问题 I want to assign a value to a rowtype's field but I don't know how to do it. Suppose that I have a table X inside my database. Suppose also that I have the following variables a ( X%ROWTYPE ), representing a row of the table X b ( VARCHAR2 ), containing a column name of the table X c ( VARCHAR2 ), containing what I want to store inside a.b What I want to do : something like a.b := c . I've come up with something like this : EXECUTE IMMEDIATE 'SELECT '|| c || ' INTO a.' || b || ' FROM DUAL';

Dynamic SQL syntax using EXECUTE IMMEDIATE

泄露秘密 提交于 2019-12-25 00:43:15
问题 Dynamic SQL update statement as below: EXECUTE IMMEDIATE 'UPDATE '||l_prefix||'CRS_CUSTOMERS SET CUSTOMER_SOURCE_REF_ID = '||i.CUSTOMER_REF_ID||' WHERE CUSTOMER_ID = '||i.CUSTOMER_ID; l_prefix is the parameter hold the prefix of table name, the value assigned is T_ i.CUSTOMER_REF_ID and i.CUSTOMER_ID are the fields fetched from cursor. The dynamic statement encounter error ORA-00904: invalid identifier when data fetched. When rewrite it in static way, the query is working fine: UPDATE T_CRS

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

孤者浪人 提交于 2019-12-19 10:57:11
问题 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. 回答1: It actually doesn't work like what I wrote. I just code like: set @preparedstmt = concat('SELECT tid, LENGTH(message) len FROM ? where tid=? and first=1'); prepare stmt from prepared_stmt; execute stmt using v_tid; drop prepare stmt; Just take care

execute immediate alter sequence not working

ⅰ亾dé卋堺 提交于 2019-12-18 07:05:23
问题 I'm stuck on this pretty simple script. It isn't working like I expect it to. declare st VARCHAR(1024); begin for x in (SELECT sequence_name FROM USER_SEQUENCES) loop st := 'ALTER SEQUENCE ' || x.sequence_name || ' INCREMENT BY 1000'; execute immediate st; st := 'select ' || x.sequence_name || '.nextval from dual'; execute immediate st; st := 'ALTER SEQUENCE ' || x.sequence_name || ' INCREMENT BY 1'; execute immediate st; end loop; end; / When I run this it doesn't appear to work at all - all

Getting error due to variable When i execute stored procedure which dynamic PLSQL inside was there in the stored procedure [duplicate]

孤街醉人 提交于 2019-12-18 05:24:05
问题 This question already has answers here : Execute Immediate within a stored procedure keeps giving insufficient priviliges error (4 answers) Execute Immediate fails even with CREATE table grant (4 answers) Closed 5 months ago . When i execute stored procedure which contain EXECUTE IMMEDIATE along with create table statement inside the stored procedure then getting error while execute this Stored Proc. Here is the Stored proc- create or replace sp_exec as ....... v_mth date; ....... begin