execute-immediate

run string as query in oracle

落爺英雄遲暮 提交于 2019-12-01 07:49:02
问题 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 9999999999 START WITH ' || (max(ID)+1) || ' INCREMENT BY 1 CACHE 20;' INTO y FROM TEST_TABLE; --dbms_output.put_line(y); execute immediate y; end; I get the following error: Error report: ORA-00911: invalid character ORA-06512: at line 5 00911. 00000

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

别来无恙 提交于 2019-11-29 08:53:01
This question already has an answer here: Execute Immediate within a stored procedure keeps giving insufficient priviliges error 4 answers Execute Immediate fails even with CREATE table grant 4 answers 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 select TO_DATE('01-' || to_char(add_months(sysdate, -1), 'MON-YY'), 'DD-MON-YY') INTO v_mth FROM dual; execute immediate 'create

Why EXECUTE IMMEDIATE is needed here?

北城余情 提交于 2019-11-29 07:51: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_name = 'TEST'; IF table_count = 0 THEN EXECUTE IMMEDIATE var_sql; END IF; END; It works normally, so

Execute Immediate fails even with CREATE table grant

给你一囗甜甜゛ 提交于 2019-11-28 02:04:01
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> select * from session_privs; PRIVILEGE ---------------------------------------- CREATE SESSION UNLIMITED

Using bind variables with dynamic SELECT INTO clause in PL/SQL

家住魔仙堡 提交于 2019-11-27 06:53:01
I have a question regarding where bind variables can be used in a dynamic SQL statement in PL/SQL. For example, I know that this is valid: CREATE OR REPLACE FUNCTION get_num_of_employees (p_loc VARCHAR2, p_job VARCHAR2) RETURN NUMBER IS v_query_str VARCHAR2(1000); v_num_of_employees NUMBER; BEGIN v_query_str := 'SELECT COUNT(*) FROM emp_' || p_loc || ' WHERE job = :bind_job'; EXECUTE IMMEDIATE v_query_str INTO v_num_of_employees USING p_job; RETURN v_num_of_employees; END; / I was wondering if you could use a bind variables in a select statement like this CREATE OR REPLACE FUNCTION get_num_of

Why cannot I use bind variables in DDL/SCL statements in dynamic SQL?

不想你离开。 提交于 2019-11-26 16:39:24
I am trying to execute an SQL command within dynamic SQL with bind variables: -- this procedure is a part of PL/SQL package Test_Pkg PROCEDURE Set_Nls_Calendar(calendar_ IN VARCHAR2) IS BEGIN EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_CALENDAR = :cal' USING IN calendar_; END Set_Nls_Calendar; Then on the client side, I am trying to invoke the procedure: Test_Pkg.Set_Nls_Calendar('Thai Buddha'); But this get's me ORA-02248: invalid option for ALTER SESSION . And my question is: Why cannot I use bind variables in DDL/SCL statements in dynamic SQL? Bind variables are not allowed in DDL statements.

Using bind variables with dynamic SELECT INTO clause in PL/SQL

假装没事ソ 提交于 2019-11-26 12:13:26
问题 I have a question regarding where bind variables can be used in a dynamic SQL statement in PL/SQL. For example, I know that this is valid: CREATE OR REPLACE FUNCTION get_num_of_employees (p_loc VARCHAR2, p_job VARCHAR2) RETURN NUMBER IS v_query_str VARCHAR2(1000); v_num_of_employees NUMBER; BEGIN v_query_str := \'SELECT COUNT(*) FROM emp_\' || p_loc || \' WHERE job = :bind_job\'; EXECUTE IMMEDIATE v_query_str INTO v_num_of_employees USING p_job; RETURN v_num_of_employees; END; / I was

Why cannot I use bind variables in DDL/SCL statements in dynamic SQL?

☆樱花仙子☆ 提交于 2019-11-26 04:54:01
问题 I am trying to execute an SQL command within dynamic SQL with bind variables: -- this procedure is a part of PL/SQL package Test_Pkg PROCEDURE Set_Nls_Calendar(calendar_ IN VARCHAR2) IS BEGIN EXECUTE IMMEDIATE \'ALTER SESSION SET NLS_CALENDAR = :cal\' USING IN calendar_; END Set_Nls_Calendar; Then on the client side, I am trying to invoke the procedure: Test_Pkg.Set_Nls_Calendar(\'Thai Buddha\'); But this get\'s me ORA-02248: invalid option for ALTER SESSION . And my question is: Why cannot I