Usinga CLOB variable in an execute immediate
HI,
I'm trying to concatenate a huge sql statement and then pass the variable to an execute immediate . the sql statement could be bigger than 4000bytes and so I'm using a clob variablle. Is it possible for me to pass this clob variable to an execute immediate?
DECLARE
var_stmt clob;
Begin
var_stmt := 'The statement I want which may be more than 4000bytes'
execute immediate var_stmt;
END;
This how I'm trying to do it. Has anybody come acroos something like this?
Thanks,
Mamata
if your sql statement will not exceed 32K, you could use the PL/SQL VARCHAR2(32767) type variable to hold upto 32K of the SQL statement.
DECLARE
var_stmt LONG;
Begin
var_stmt := 'The statement I want which may be more than 4000bytes'
execute immediate var_stmt;
END;
Similar Messages
-
Variable contents inside "EXECUTE IMMEDIATE" not working properly.
Hello,
I have the following package:
CREATE OR REPLACE PACKAGE "BACKUP"."PKG_BACKUP"
IS
PROCEDURE BACKUP_TABLE (TABLE_NAME IN VARCHAR);
END PKG_BACKUP;
CREATE OR REPLACE PACKAGE BODY "BACKUP"."PKG_BACKUP"
IS
PROCEDURE BACKUP_TABLE (TABLE_NAME IN VARCHAR) IS
MYDATE VARCHAR(10);
BEGIN
MYDATE := to_char(sysdate,'YYYYMMDD');
DBMS_OUTPUT.PUT_LINE(' Backing up '||TABLE_NAME||' table...');
EXECUTE IMMEDIATE 'CREATE TABLE "BACKUP"."'||TABLE_NAME||'_'||MYDATE||'" AS SELECT * FROM "MYSCHEMA"."'||TABLE_NAME||'" COMPRESSED';
END backup_table;
END "PKG_BACKUP";
/However, every time I execute it I get the following error:
SQL> exec BACKUP.PKG_BACKUP.BACKUP_TABLE('POOL');
** Backing up POOL table...*
BEGIN BACKUP.PKG_BACKUP.BACKUP_TABLE('POOL'); END;
ERROR at line 1:
ORA-00942: table or view does not exist
*ORA-06512: at "BACKUP.PKG_BACKUP
", line 9*
*ORA-06512: at line 1*
Table does exist and user executing the statement has the proper privileges (i've even executed the contents of "execute immediate" by hand and it works fine)
What am I missing?
Thanks in advance.SQL> CREATE OR REPLACE PACKAGE pkg_backup AUTHID CURRENT_USER
2 IS
3 PROCEDURE backup_table (table_name IN VARCHAR);
4 END pkg_backup;
5 /
Package created.
SQL> CREATE OR REPLACE PACKAGE BODY PKG_BACKUP
2 IS
3 PROCEDURE backup_table (table_name IN VARCHAR)
4 IS
5 mydate VARCHAR (10);
6 BEGIN
7 mydate := TO_CHAR (SYSDATE, 'YYYYMMDD');
8 DBMS_OUTPUT.put_line (' Backing up ' || table_name || ' table...');
9
10 EXECUTE IMMEDIATE 'CREATE TABLE BACKUP'||table_name||'_'||mydate||' AS SELECT * FROM '|| table_name || ' COMPRESSED';
11 END backup_table;
12 END PKG_BACKUP;
13 /
Package body created.
SQL> EXEC PKG_BACKUP.backup_table('EMP');
Backing up EMP table...
PL/SQL procedure successfully completed.
SQL> SELECT * FROM BACKUPEMP_20090130;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 12-JAN-83 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10
14 rows selected.Edited by: user10594152 on Jan 30, 2009 5:18 PM
Edited by: user10594152 on Jan 30, 2009 5:19 PM -
Create Partition tables in PL/SQL using Execute Immediate
Hi
I have to create a partiton table in PL/SQL using Execute Immediate. I concat the necessary Create Table syntax into a variable and use Execute Immediate variable name. This gives a error ORA-00900: invalid SQL statement. However if i cut and paste the SQL statement from DBMS_OUTPUT, the table creation goes through without any problem.
What could be the issue. Has anyone face this before please.
I am using 10G DBThanks for your reply. It is a big code. I am pasting the part required.
v_sqlstmtout :='CREATE TABLE a_10(MYDATE DATE NOT NULL,ID NUMBER(14) NOT NULL)';
v_sqlstmtout := v_sqlstmtout || ' PARTITION BY RANGE (MYDATE) ';
v_sqlstmtout := v_sqlstmtout || 'SUBPARTITION BY HASH(id) ';
v_sqlstmtout := v_sqlstmtout || 'SUBPARTITION TEMPLATE(';
v_sqlstmtout := v_sqlstmtout || 'SUBPARTITION SP1,SUBPARTITION SP2) ';
v_sqlstmtout := v_sqlstmtout || '(PARTITION mth_dummy VALUES LESS THAN ';
v_sqlstmtout := v_sqlstmtout || '('||V_SQLSTMT3||')' || v_sqlstmt||')';
EXECUTE IMMEDIATE ''''||v_sqlstmtout||'''';
variables are substituted through data from different tables.
The output looks like the following
CREATE TABLE a_10(MYDATE DATE NOT NULL,ID NUMBER(14) NOT NULL)
PARTITION BY RANGE (mydate) SUBPARTITION BY HASH(id) SUBPARTITION
TEMPLATE(SUBPARTITION SP1,SUBPARTITION SP2) (PARTITION mth_dummy VALUES
LESS THAN ('01-MAY-2006'), PARTITION mth_JAN2007 VALUES LESS THAN
('01-FEB-2007'))
The above is the output from DBMS_OUTPUT. If i run this statement the table is created. Please help.. -
Execute immediate with a string longer than 32767
hello,
is there a possibility to make an execute immediate with a statement, that is longer than the 32767 max. bytes for varchar`s? We get in a CLOB SQL-Statements with data that are longer than 32767. It would be easy if it were possible to make an execute immediate but because of the length limit it seems impossible. Does anybody know an alternative way to execute the sql-statements in the CLOB-Column?
Anna6 execute immediate to_char(sql_text) into var_num;As a matter of interest have you tried this with a CLOB that is bigger than 32K?
When I try it the PL/SQL limit gets enforced:
SQL> declare
2 c clob;
3 begin
4 dbms_lob.createtemporary(c, true);
5 dbms_lob.writeappend(c, 43, 'CREATE OR REPLACE PROCEDURE big_p AS BEGIN ');
6 for i in 1..800 loop
7 dbms_lob.writeappend(c, 6, 'null;'||chr(10));
8 end loop;
9 dbms_lob.writeappend(c, 4, 'END;');
10 execute immediate to_char(c);
11 end;
12 /
PL/SQL procedure successfully completed.
SQL> declare
2 c clob;
3 begin
4 dbms_lob.createtemporary(c, true);
5 dbms_lob.writeappend(c, 43, 'CREATE OR REPLACE PROCEDURE big_p AS BEGIN ');
6 for i in 1..8000 loop
7 dbms_lob.writeappend(c, 6, 'null;'||chr(10));
8 end loop;
9 dbms_lob.writeappend(c, 4, 'END;');
10 execute immediate to_char(c);
11 end;
12 /
declare
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at line 10
SQL> Cheers, APC -
Copy the result of Execute immediate result into a variable.
Hi All,
Is there any way to copy the result of execute immediate result into a variable.
am doing following steps but am getting an error.
varSQLstmt1:='select count(*) into'||vararch_ct||' from '||vararch_count;
dbms_output.put_line(varSQLstmt1);
execute immediate varSQLstmt1;
But am getting sql statement as select count(*) into from SALES
the variable(vararch_ct) is missing in select statement .
please help me to solve this issue. Or is there any way to insert the count of records into any variable.
Thanks
Sreedeclare
varSQLstmt1 varchar2(4000);
v_count number;
begin
varSQLstmt1:='select count(*) from '||vararch_count;
dbms_output.put_line(varSQLstmt1);
execute immediate varSQLstmt1 into v_count;
dbms_output.put_line('Coutn :: ' || v_count);
end; -
Problem when using execute immediate str variable into refcursor var
Hi,
I have a packaged function which returns a "strong refcursor" variable to the calling program.
inside this packaged function, i had to use dynamic sql ....
i am doing it somethingl like this...
execute immediate lc_submit_Sql into lrc_submitted;
where lc_submit_Sql contains the query. and lrc_submitted is declared as a refcursor variable which is a recordtype.
when calling this packaged function from an anonymous block getting an error.....
"ora-00932 inconsistent datatypes:expecting - got -"
I checked the select statment columns and the record type columns, their types and order. they are fine.
not sure abt the reason.
any help is appreciated. have some dead lines to meet.
Thanks in advance.
KiranHi John,
the following is the code ....
package spec...
CREATE OR REPLACE PACKAGE refcur_kk IS
--Sample submitted Function
TYPE r_submitted IS RECORD(
q_party_name apps.bpsicc_crm_quote_header_v.party_name%TYPE,
q_party_id apps.bpsicc_crm_quote_header_v.cust_party_id%TYPE,
q_quote_header_id apps.bpsicc_crm_quote_header_v.quote_header_id%TYPE,
q_creation_date apps.bpsicc_crm_quote_header_v.quote_creation_date%TYPE,
q_created_by apps.bpsicc_crm_quote_header_v.quote_created_by%TYPE,
q_quote_status apps.bpsicc_crm_quote_header_v.quote_status%TYPE,
q_quote_name apps.bpsicc_crm_quote_header_v.quote_name%TYPE,
q_quote_number apps.bpsicc_crm_quote_header_v.quote_number%TYPE,
q_internal_project_details apps.bpsicc_crm_quote_line_v.internal_project_details%TYPE,
ql_item apps.bpsicc_crm_item_all_v.item_number%TYPE,
ql_item_link apps.bpsicc_crm_item_all_v.item_link%TYPE,
ql_party_link apps.bpsicc_gcm_party_details_v.party_link%TYPE,
ql_quantity apps.bpsicc_crm_quote_line_v.quantity%TYPE,
q_country apps.bpsicc_gcm_party_sites_v.party_site_country_name%TYPE,
q_territory apps.bpsicc_crm_party_by_terr_mv.territory%TYPE,
q_region apps.bpsicc_crm_party_by_terr_mv.region%TYPE,
q_created_disp apps.bpsicc_crm_quote_header_v.quote_created_by_username%TYPE,
reqst_shipdate apps.bpsicc_crm_quote_header_v.date_of_request%TYPE,
q_item_color apps.bpsicc_crm_item_all_v.item_color%TYPE
TYPE rc_submitted IS REF CURSOR;
RETURN r_submitted;
FUNCTION get_submitted(
pd_start_date IN DATE,
pc_time IN VARCHAR2,
pd_end_date IN DATE,
pc_party_id IN VARCHAR2,
pc_price_class IN VARCHAR2,
ps_section IN VARCHAR2,
pn_sales_channel IN NUMBER,
pc_country IN VARCHAR2,
pc_territory IN VARCHAR2,
pc_region IN VARCHAR2)
RETURN rc_submitted;
and the body of it.....
ls_submit_sql:= 'SELECT bcqhv.party_name q_party_name,'||
'bcqhv.cust_party_id q_party_id,'||
'bcqhv.quote_header_id q_quote_header_id,'||
'TRUNC(bcqhv.quote_creation_date) q_creation_date,'||
'bcqhv.quote_created_by q_created_by,'||
'bcqhv.quote_status q_quote_status,'||
'bcqhv.quote_name q_quote_name,'||
'bcqhv.quote_number q_quote_number,'||
'bcqlv.internal_project_details q_internal_project_details,'||
'bciav.item_number ql_item,'||
'bciav.item_link ql_item_link,'||
'bgpdv.party_link ql_party_link,'||
'bcqlv.quantity ql_quantity,'||
'bgpsv.party_site_country_name q_country,'||
'bcpbtv.territory q_territory,'||
'bcpbtv.region q_region,'||
'bcqhv.quote_created_by_username q_created_disp,'||
'bcqhv.date_of_request reqst_ship_date,'||
'bciav.item_color q_item_color '||
'FROM apps.bpsicc_crm_quote_header_v bcqhv,'||
'apps.bpsicc_crm_party_by_terr_mv bcpbtv,'||
'apps.bpsicc_gcm_party_sites_v bgpsv,'||
'apps.bpsicc_crm_quote_line_v bcqlv,'||
'apps.bpsicc_crm_item_all_v bciav,'||
'apps.bpsicc_gcm_party_details_v bgpdv '||
'WHERE bciav.inventory_item_id = bcqlv.inventory_item_id '||
'AND bcqhv.cust_party_id = bcpbtv.party_id '||
'AND bcqhv.sold_to_party_site_id = bgpsv.party_site_id '||
'AND bgpdv.party_id = bcqhv.cust_party_id '||
'AND bcqlv.quote_header_id = bcqhv.quote_header_id '||
'AND bcqhv.quote_status IN ('||chr(39)||'Submitted to Lab for Review'||chr(39)||','||chr(39)||'Submitted to US Lab for Review'||chr(39)||')';
execute immediate ls_submit_sql into lrc_submitted;
returning lrc_submitted to the report which is calling this function.
using oracle report builder.
kiran -
Hi All,
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
I am getting error when trying to use CLOB with execute immediate.
DECLARE
v_clob CLOB;
BEGIN
EXECUTE IMMEDIATE 'SELECT DBMS_METADATA.GET_DDL(''TABLE'',''T_FDB_TMP'') from dual'
INTO v_clob_part_ddl;
EXECUTE IMMEDIATE 'DROP TABLE T_FDB_TMP';
EXECUTE IMMEDIATE to_char(v_clob_part_ddl);
END;
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at line 1
ORA-06502: PL/SQL: numeric or value error
ORA-31605: the following was returned from LpxXSLResetAllVars in routine kuxslResetParams:
LPX-1: NULL pointer
ORA-06512: at line 3
06502. 00000 - "PL/SQL: numeric or value error%s"Please helpIf you can't upgrade to 11g then you'll have to use DBMS_SQL package...
e.g.
SQL> ed
Wrote file afiedt.buf
1 declare
2 v_large_sql CLOB;
3 v_num NUMBER := 0;
4 v_upperbound NUMBER;
5 v_sql DBMS_SQL.VARCHAR2S;
6 v_cur INTEGER;
7 v_ret NUMBER;
8 begin
9 -- Build a very large SQL statement in the CLOB
10 LOOP
11 IF v_num = 0 THEN
12 v_large_sql := 'CREATE VIEW vw_tmp AS SELECT ''The number of this row is : '||to_char(v_num,'fm0999999')||''' as col1 FROM DUAL';
13 ELSE
14 v_large_sql := v_large_sql || ' UNION ALL SELECT ''The number of this row is : '||to_char(v_num,'fm0999999')||''' as col1 FROM DUAL';
15 END IF;
16 v_num := v_num + 1;
17 EXIT WHEN DBMS_LOB.GETLENGTH(v_large_sql) > 40000 OR v_num > 800;
18 END LOOP;
19 DBMS_OUTPUT.PUT_LINE('Length:'||DBMS_LOB.GETLENGTH(v_large_sql));
20 DBMS_OUTPUT.PUT_LINE('Num:'||v_num);
21 --
22 -- Now split that large SQL statement into chunks of 256 characters and put in VARCHAR2S array
23 v_upperbound := CEIL(DBMS_LOB.GETLENGTH(v_large_sql)/256);
24 FOR i IN 1..v_upperbound
25 LOOP
26 v_sql(i) := DBMS_LOB.SUBSTR(v_large_sql
27 ,256 -- amount
28 ,((i-1)*256)+1 -- offset
29 );
30 END LOOP;
31 --
32 -- Now parse and execute the SQL statement
33 v_cur := DBMS_SQL.OPEN_CURSOR;
34 DBMS_SQL.PARSE(v_cur, v_sql, 1, v_upperbound, FALSE, DBMS_SQL.NATIVE);
35 v_ret := DBMS_SQL.EXECUTE(v_cur);
36 DBMS_OUTPUT.PUT_LINE('View Created');
37* end;
SQL> /
Length:40015
Num:548
View Created
PL/SQL procedure successfully completed.
SQL> select count(*) from vw_tmp;
COUNT(*)
548
SQL> select * from vw_tmp where rownum <= 10;
COL1
The number of this row is : 0000000
The number of this row is : 0000001
The number of this row is : 0000002
The number of this row is : 0000003
The number of this row is : 0000004
The number of this row is : 0000005
The number of this row is : 0000006
The number of this row is : 0000007
The number of this row is : 0000008
The number of this row is : 0000009
10 rows selected.
SQL> -
How can i pass multiple values by a single variable to EXECUTE IMMEDIATE
Hi All,
I want to pass multiple values for where condition for execute immediate. Something Like this:-
bold
Declare
v_cond varchar(1000);
Begin
v_cond := '''INR','USD'''; --(OPTION 1)
v_cond := 'INR,USD'; --(OPTION 2)
EXECUTE IMMEDIATE 'Delete from table where colm in (:v_cond)' using v_cond;
END;
bold
I am using this into a procedure
Now option 1 gives an error ie a syntax error (; expected or something like that)(I am sorry, i can't tell the exact error here as i am not in the office right now)
and option 2 makes the procedure execute but obviously doesn't delete the records, as it takes the whole as one.
Please Help
Regards
Neeraj BansalSee the links containing examples under
*7. List of values in an IN clause?*
SQL and PL/SQL FAQ
from the SQL and PL/SQL FAQ. -
How to insert String variables in Execute Immediate Statement
Hi,
I have query
dept varchar2(10);
dept :='electronics'
l_dyn_sql_input600_cbs := 'select EmployeeName,AGE,' || dept ||' from Employee'
EXECUTE immediate l_dyn_sql_input600_cbs;
when i run the query it says "electonics" Invalid identifier.
Can anyone help to rectify the queryWhat are you actually trying to do here:
- Select employee name, age and the string literal 'electronics' from the employee table?
- Select employee name, age and the dept field from the employee table?
- Select employee name, age and dept from the employee table where dept = 'electronics'?
- Something else...?
Doesn't seem to make much sense as it is right now...
cheers,
Anthony -
Inserting variables to table by "execute immediate' statement
EXECUTE IMMEDIATE 'INSERT INTO aTABLETKA_HISTORY
(update_id,
update_type,
update_date,
old_db_version,
description,
patch_number)
values
(' || m_id(v_rec) || ',
'||m_package(v_rec)||',
''07-NOV-07'',
''snezi'',
'||m_desc(v_rec)||',
'||m_new(v_rec)||')';
ORA-00917: missing comma
ORA-06512: at line 142
i cannot solve this,. can anybody help me?
i have simillar insert:
EXECUTE IMMEDIATE 'INSERT INTO ab_table_VERSION(property,version) values (''wiz_datalink'',' || my_version || ')';
and this one statement work correctlyDo NOT use "execute immediate". What is the reason for trying it this way?
If the column update_date is of type date, then you have a bug in the code, as you are trying to insert a string. If it is not a date data type, then you have a bug, because it is not of type date.
What is the outcome of:
INSERT INTO aTABLETKA_HISTORY (update_id, update_type, update_date,
old_db_version, description, patch_number)
values (m_id(v_rec), m_package(v_rec), to_date('07-NOV-2007', 'dd-MON-yyyy'),
snezi, m_desc(v_rec), m_new(v_rec) )
/ -
Java Stored Procedure in EXECUTE IMMEDIATE
Hi,
I need advice for the following.
I'm on Oracle 11g R2. I'm testing application in Oracle 11gR1 and R2 and Oracle Express.
Purpose is to generate XML reports.
I have PLSQL Stored Procedure which does that, but since there is bug in Oracle11gR2 related to XMLTRANSFORM I have and Java Stored Procedure which is workaround. They are both compiled, valid etc.
Java class is :
import java.io.PrintWriter;
import java.io.Writer;
import oracle.xml.parser.v2.DOMParser;
import oracle.xml.parser.v2.XMLDocument;
import oracle.xml.parser.v2.XSLProcessor;
import oracle.xml.parser.v2.XSLStylesheet;
* This class is used as Java stored procedure
* There is a bug on Oracle11gR2, related to the limitation on the number of style sheet instructions
* This stored procedure is workaround when PLSQL code can not be used.
* File must not have package, otherwise is wrongly compiled in DB
public class JavaXslt {
public static void XMLTtransform(oracle.sql.CLOB xmlInput,oracle.sql.CLOB xslInput,oracle.sql.CLOB output) throws Exception{
DOMParser parser;
XMLDocument xml;
XMLDocument xsldoc;
try{
parser = new DOMParser();
parser.parse(xmlInput.getCharacterStream());
xml = parser.getDocument();
parser.parse(xslInput.getCharacterStream());
xsldoc = parser.getDocument();
XSLProcessor processor = new XSLProcessor();
XSLStylesheet xsl = processor.newXSLStylesheet(xsldoc);
Writer w = output.setCharacterStream(1L);
PrintWriter pw = new PrintWriter(w);
processor.processXSL(xsl, xml, pw);
}catch (Exception ex){
throw ex;
PROCEDURE Java_XmlTransform (xml CLOB, xslt CLOB, output CLOB) AS LANGUAGE JAVA
NAME 'JavaXslt.XMLTtransform(oracle.sql.CLOB, oracle.sql.CLOB, oracle.sql.CLOB)';
I'm calling Java stored procedure from PLSQL Stored procedure (if it is Oracle11gR2) like that :
Java_Proc.Java_XmlTransform(inputXML, xslt, res);
So till here everything works ok. XSLT as applied and output XML (res) is OK.
But when Oracle Express is used Java is out of the question, so there is no Java stored procedure. Howewer PLSQL Stored procedure is still needed.
So I had to put call to Java Stored procedure in EXECUTE IMMEDIATE statement in order to compile to PLSQL package.
But when I do that :
EXECUTE IMMEDIATE 'BEGIN Java_Proc.Java_XmlTransform (:1, :2, :3); END;' USING inputXML, xslt, res;
result value CLOB (res) has zero length...
What am I missing? Should i set return value to Java class?
Hope my explanations are clear though.
ThanksHi odie_63,
Thanks for quick response.
I didn't clearly explained.
When using Oracle 11gR1 and Oracle Express I'm using only PLSQL Procedure.
When using Oracle 11gR2 i have to use Java Stored procedure because there is documented bug in R2.
That's why i have to use EXECUTE IMMEDIATE. I don't know which version is the client DB and whether there is or no Java procedures.
I did tried
EXECUTE IMMEDIATE 'BEGIN Java_Proc.Java_XmlTransform (:1, :2, :3); END;' USING IN inputXML, IN xslt, OUT res; and the result was ORA-06537: OUT bind variable bound to an IN position
When using IN OUT for last parameter i.e.
EXECUTE IMMEDIATE 'BEGIN Java_Proc.Java_XmlTransform (:1, :2, :3); END;' USING IN inputXML, IN xslt, IN OUT res;
there is no exception, but still DBMS_LOB.getlength(res) = 0
Thanks -
Error while insert data using execute immediate in dynamic table in oracle
Error while insert data using execute immediate in dynamic table created in oracle 11g .
first the dynamic nested table (op_sample) was created using the executed immediate...
object is
CREATE OR REPLACE TYPE ASI.sub_mark AS OBJECT (
mark1 number,
mark2 number
t_sub_mark is a class of type sub_mark
CREATE OR REPLACE TYPE ASI.t_sub_mark is table of sub_mark;
create table sam1(id number,name varchar2(30));
nested table is created below:
begin
EXECUTE IMMEDIATE ' create table '||op_sample||'
(id number,name varchar2(30),subject_obj t_sub_mark) nested table subject_obj store as nest_tab return as value';
end;
now data from sam1 table and object (subject_obj) are inserted into the dynamic table
declare
subject_obj t_sub_mark;
begin
subject_obj:= t_sub_mark();
EXECUTE IMMEDIATE 'insert into op_sample (select id,name,subject_obj from sam1) ';
end;
and got the below error:
ORA-00904: "SUBJECT_OBJ": invalid identifier
ORA-06512: at line 7
then when we tried to insert the data into the dynam_table with the subject_marks object as null,we received the following error..
execute immediate 'insert into '||dynam_table ||'
(SELECT887684 wrote:
ORA-00904: "SUBJECT_OBJ": invalid identifier
ORA-06512: at line 7The problem is that your variable subject_obj is not in scope inside the dynamic SQL you are building. The SQL engine does not know your PL/SQL variable, so it tries to find a column named SUBJECT_OBJ in your SAM1 table.
If you need to use dynamic SQL for this, then you must bind the variable. Something like this:
EXECUTE IMMEDIATE 'insert into op_sample (select id,name,:bind_subject_obj from sam1) ' USING subject_obj;Alternatively you might figure out to use static SQL rather than dynamic SQL (if possible for your project.) In static SQL the PL/SQL engine binds the variables for you automatically. -
How can i have '&' in EXECUTE IMMEDIATE statement?
I have PL/SQL procedure, where i will be inserting data to a table. Data which i am inserting is having a '&' value in it. If i use the below statement for insert then sqlplus is prompting for the value '&' like a substitution value while compile this procedure.
EXECUTE IMMEDIATE 'INSERT INTO TABLE_TEST VALUES (:1,:2)' USING 'root/direct/&text', SYSDATE;If i replace the '&' by assigning this value to VARCHAR field then it is working properly. But when i populate an xml from this table using DBMS.XMLGEN, then the value '&' is not entity escaped in the XML which is normally replaced with '&' in XML.
Please help.Vel wrote:
i can't go by both ways because i am using '&' in various files to get some values. Also in this package i am using the '&' to get another substitution variable. Is there any other workaround possible?I prefer not to mess with server-side SQL and PL/SQL code to fix, or work around, a problem on the client-side. Not a very sensible thing IMO.
In such a case as you've described, I would set the substitution character to a character that I'm not using in server-side code. I have done this a couple of times in the past for db create and installation scripts. Oracle uses the same approach for their Apex installation scripts.
I think Oracle uses the +#+ character for their Apex install scripts. E.g.
set define '#'I think I used the tilde (char <i>~</i>) at a stage as substitution char as it is very seldom used in PL/SQL and SQL code.
The bottom line is that you will need to change your code. Set define off and on where needed to ensure substitution only happens where needed. Set the substitution char to a different char and update your substitution variables. Or hack your server-side code (as suggested above) and use the char() function instead. -
Execute immediate -- udpate statement
Hello,
I am fairly new to scripting sql..pl/sql.. any help will be really appreciated!!
I have a table where i am trying to update one of the column with table name i am passing dynamically.
However i get the invalid identifier error. ORA-00904. The column AD.MIR_PARENT i am updating is of compatible data type.
Any help please.. where i am doing a mistake..
fyi -- the reason i am updating the column with table name is because i need to know which table i make a hit.
DECLARE
p_table varchar2(200);
P_SCHEMA varchar2(200);
p_acct NUMBER;
v_acct NUMBER;
P_column varchar2(200);
cursoR c is
select schema_name, table_name, column_name from addnl_sources where TABLE_NAME = 'ACCT';
BEGIN
FOR R IN C LOOP
p_TABLE := R.TABLE_NAME;
P_SCHEMA := R.SCHEMA_NAME;
P_column := R.column_name;
execute immediate 'UPDATE ACCT_DELETE AD
SET AD.MIR_PARENT = '||p_table || '
WHERE EXISTS (select "'||p_table || '" from "' || P_SCHEMA||'"."'||p_table || '" where "' || P_column ||'" = ad.acct_id )
AND AD.EXCLUDE IS NULL
AND AD.ACCT_ID = 472039
AND AD.MIR_PARENT IS NULL' ;
END LOOP;
end;Edited by: 982806 on Jan 18, 2013 10:47 AM
Edited by: 982806 on Jan 18, 2013 11:04 AMWelcome to the forum!
Whenever you post provide your 4 digit Oracle version (result of SELECT * FROM V$VERSION)
>
I am fairly new to scripting sql..pl/sql.. any help will be really appreciated!!
I have a table where i am trying to update one of the column with table name i am passing dynamically.
However i get the invalid identifier error. ORA-00904. The column AD.MIR_PARENT i am updating is of compatible data type.
Any help please.. where i am doing a mistake..
>
Just about everything you are doing is a mistake.
1. You using PL/SQL instead of SQL to do this job? That is usually a red flag that something is wrong about what you are trying to do or how you are trying to do it.
2. You are 'fairly new to scripting' and have chosen to use dynamic sql? That is one of the harder techniques to learn and to use properly and is another red flag. Experienced professionals often don't use dynamic sql properly and often use it when they shouldn't.
3. You are using a loop to execute against multiple tables? It is extremely difficult to perform proper error handling and recovery when you do this. What if some of the tables get updated and others don't? How will you know which ones still need to be updated? How will you roll back the data if you need to.
4. You have opened a GIGANTIC opportunity for sql injection where the wrong tables could accidentally be updated. That could corrupt the data and reek havoc on the system. Anyone could, accidentally or intentionally, put the wrong schema, table or column in your lookup table and cause enormous damage.
5. You are using double quotes in PL/SQL? Where did you learn that?
WHERE EXISTS (select "'||p_table || '" from "' || P_SCHEMA||'"."'||p_table || '" where "' || P_column ||'" = ad.acct_id ) Finally, it is standard practice when you do have a use case for dynamic sql to construct the query in a variable and then print the query or write it to a log file so it can be tested independently.
If you do that you will likely see your error.
query VARCHAR2(4000);
query := 'UPDATE . . .';
execute immediate query;SUMMARY: don't try to automate something until you can first do it manually. Write a query that works properly first. Then, and only then, convert it to dynamic sql. -
Execute Immediate with SQL in Stored Procedure
Dear Experts, Please help / guide on below statement which i want to execute in stored procedure,
EXECUTE IMMEDIATE 'INSERT INTO TABLE
SELECT COUNT(AGENTID) FROM TABLE_1 A,
TABLE_2 B, TABLE_3 C
WHERE A.COL = B.COL AND B.COL = C.COL AND
DT BETWEEN TRUNC(SYSDATE-1) + 1/24 + 0/12/60/60 AND TRUNC(SYSDATE-1) + 25/24 - 0/12/60/60';
Edited by: DBA on Dec 3, 2011 3:57 PMSo what's the problem? The only thing I can see is:
INSERT INTO TABLETABLE is reserved word, so name your table differently.
Also, I am assuming the above statement is actually generated from some variables based on some conditions, otherwise why would you need dynamic SQL, just issue:
INSERT INTO TABLE
SELECT COUNT(AGENTID) FROM TABLE_1 A,
TABLE_2 B, TABLE_3 C
WHERE A.COL = B.COL AND B.COL = C.COL AND
DT BETWEEN TRUNC(SYSDATE-1) + 1/24 + 0/12/60/60 AND TRUNC(SYSDATE-1) + 25/24 - 0/12/60/60;
Maybe you are looking for
-
How to create a Maintenance view in order to update 4 tables
Hello, I want to update 4 tables having the same key. MANDANT + SIRET (fiscal french ID). I try to create a maintenace view, i need to update the 4 tables using a single screen. When i use the relationship the system display a message "Relationships
-
Array of strings strict type def not updating
I have defined an Array of Strings (ctrl) as a strict type def. When I update this array (add another string to it) the values don't update where this control is used. Can someone please explain why this is occuring.
-
Is it possible to hv a FORM with out Print Prog.?
Hi Experts, 1) Is it possible to hv a smart form with out having the Print/driver prog.? coz, I checked in TNAPR tbl, I did not find any entry! I guess, NACE wuld do give some info? 2) How Can I know that my_z_form_1 created in Which SAP version? 3)
-
I want a slideshow that when any individual image is clicked on it goes full screen
Right now I have a slideshow that only fills the centre of the page, which is how I want it. I do not want a fullscreen slideshow. However, what I want is that when anyone clicks a particular image within this slideshow, that image becomes full-size
-
FMLA standard hours infotype 2001 not editable when working with date range
Hi All, The issue described below arises at the Juncture between FMLA Workbench and Absence Infotype IT2001. When we try to tie a FMLA Request to Absences the process takes us to the Infotype PA2001 screen wherein we would like the Absence Hours Fiel