execute-immediate

Why EXECUTE IMMEDIATE is needed here?

♀尐吖头ヾ 提交于 2019-12-18 05:10:32
问题 I am a SQL Server user and I have a small project to do using Oracle, so I’m trying to understand some of the particularities of Oracle and I reckon that I need some help to better understand the following situation: I want to test if a temporary table exists before creating it so I had this code here: DECLARE table_count INTEGER; var_sql VARCHAR2(1000) := 'create GLOBAL TEMPORARY table TEST ( hello varchar(1000) NOT NULL)'; BEGIN SELECT COUNT(*) INTO table_count FROM all_tables WHERE table

Execute Immediate fails even with CREATE table grant

六月ゝ 毕业季﹏ 提交于 2019-12-17 21:06:07
问题 I have a problem where I am creating a table using the execute immediate command in the stored procedure. However I get the error of "insufficient privileges". I checked other threads and made sure that the user has "CREATE TABLE" privilege granted to it. However I still keep seeing the same error. SQL> select * from USER_SYS_PRIVS; USERNAME PRIVILEGE ADM ------------------------------ ---------------------------------------- --- MYUSER CREATE VIEW NO MYUSER UNLIMITED TABLESPACE NO SQL>

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

百般思念 提交于 2019-12-11 07:41:24
问题 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: numeric or value error: character to number conversion error . Why and how I can bind also f ? I'm using 11.2.0.1.0. create or replace function so4fun ( a in number, b in number, f in varchar2 ) return number as decl constant varchar2(32767) :=

Ref cursor with Execute immediate

时光怂恿深爱的人放手 提交于 2019-12-07 22:50:29
问题 I want to get the results in ref_cursor, but I am not able to do that. Please suggest me how to get the results in ref_cursor using Execute immediate CREATE OR REPLACE PROCEDURE TEST_PROC_QT ( p_name IN VARCHAR2, p_result_set OUT sys_refcursor ) IS v_sql VARCHAR2(4000); BEGIN v_sql := ''; v_sql := 'SELECT * FROM USERS WHERE 1=1 '; IF p_name is not null THEN v_sql := v_sql || ' AND login_id = :v_name'; ELSE v_sql := v_sql || ' AND ((1=1) or :v_name is null)'; END IF; Dbms_output.put_line(v_sql

PL/SQL - execute immediate in pipelined function

三世轮回 提交于 2019-12-06 09:11:55
问题 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 function: CREATE OR REPLACE FUNCTION MyFunction(p_schema VARCHAR2) RETURN MyTableType Pipelined IS v_query VARCHAR2(1000); BEGIN v_query := 'SELECT * FROM TABLE ('||p_schema||'.somepackage.SomeFunction)'; --SomeFunction is another pipelined function EXECUTE

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

こ雲淡風輕ζ 提交于 2019-12-03 04:43: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'; Apparently, this isn't the right way to go. I get a ORA-0095: missing keyword error. Can anyone help me

Oracle Package inside a CLOB with length > 32767 characters. How to “execute immediate” it? [closed]

别说谁变了你拦得住时间么 提交于 2019-12-02 13:48:21
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed last year . Please suppose that I have a package creation script stored inside a table ALPHA, in a column BETA of type CLOB. The CLOB length is > 32767 characters. Using PL/SQL code, I would like to "execute immediate" the package creation script. I could I achieve this? Thank you in advance

EXECUTE IMMEDIATE Temp table in oracle does not get created ORA-00942

穿精又带淫゛_ 提交于 2019-12-02 05:59:46
问题 Based on this answer I was trying to create temp table, however I am getting exception ORA-00942:table or view does not exist I would assume there is something wrong with 'CREATE OR REPLACE GLOBAL TEMPORARY TABLE TempQandA(column1 number) ON COMMIT PRESERVE ROWS' statement, it fails on insert into TempQandA(column1) VALUES (1); . Please find SQL statement below. DECLARE TransactioDetailId numeric := 3132; HomePhoneNumber varchar(20); MobileNumber varchar(20); Email varchar(20); whatever

EXECUTE IMMEDIATE Temp table in oracle does not get created ORA-00942

冷暖自知 提交于 2019-12-02 02:10:29
Based on this answer I was trying to create temp table, however I am getting exception ORA-00942:table or view does not exist I would assume there is something wrong with 'CREATE OR REPLACE GLOBAL TEMPORARY TABLE TempQandA(column1 number) ON COMMIT PRESERVE ROWS' statement, it fails on insert into TempQandA(column1) VALUES (1); . Please find SQL statement below. DECLARE TransactioDetailId numeric := 3132; HomePhoneNumber varchar(20); MobileNumber varchar(20); Email varchar(20); whatever varchar(20); BEGIN EXECUTE IMMEDIATE 'CREATE OR REPLACE GLOBAL TEMPORARY TABLE TempQandA(column1 number) ON

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

大城市里の小女人 提交于 2019-12-01 13:27:03
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. 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 of the table name,it shouldn't be replaced with the placeholder.So the @preparedstmt should be generated