Pass Pl/sql table in the USING clause in the EXECUTE IMMEDIATE statement
Getting error when I try to pass the PL/SQL table in the USING clause in the EXECUTE IMMEDIATE statement:Declare
result NUMBER;
TYPE values_tab IS TABLE OF NUMBER INDEX OF directory;
lv_tab values_tab;
lv_exp varchar2 (300);
lv_exec varchar2 (300);
BEGIN
lv_tab (1): = 5;
lv_tab (2): = 48;
lv_tab (3): = 7;
lv_tab (4): = 6;
lv_exp: = ': + b1: b2 + (: b3 *: b4)';
lv_exec: = 'SELECT'. lv_exp | ' THE DOUBLE '.
IMMEDIATE EXECUTION
lv_exec
IN
result
USING
lv_tab;
DBMS_OUTPUT. Put_line (result);
END;
/
Error on line 1
ORA-06550: line 20, column 12:
PLS-00457: expressions must be SQL types
ORA-06550: line 15, column 8:
PL/SQL: Statement ignored
I am trying to evaluate the expression ': + b1: b2 + (: b3 *: b4) "which is stored in the table. This table has different expressions (expressions about 300). I want to use the bind variable in the expression because each expression evaluated thousands of time may be more in some cases. If I use bind variable can he fill pool.
Is there a way I can pass parameters with the HELP of (IN) dynamically instead of write "help lv_tab (1), lv_tab (2), lv_tab (3), lv_tab (4)? As number of change of the input parameters depend on the expression in the table.
If it is possible please suggest any other ideas/approaches
Help, please...
Published by: satnam on June 11, 2009 11:50
Well, you keep changing faster reqs that I can follow. In any case, assuming that N-th variable bind (left to right) corresponds to n-th collection item:
Declare
result NUMBER;
lv_tab values_tab := values_tab();
lv_exp varchar2(300);
lv_exec varchar2(300);
lv_i number := 0;
BEGIN
lv_tab.extend(4);
lv_tab(1) := 5;
lv_tab(2) := 48;
lv_tab(3) := 7;
lv_tab(4) := 6;
lv_exp := ':5000135+:5403456+(:5900111*:5200456)';
lv_exec := lv_exp;
While regexp_like(lv_exec,':\d+') loop
lv_i := lv_i + 1;
lv_exec := REGEXP_REPLACE(lv_exec,':\d+',':b(' || lv_i || ')',1,1);
end loop;
lv_exec := 'BEGIN :a := ' || lv_exec || '; END;';
DBMS_OUTPUT.PUT_LINE(lv_exec);
EXECUTE IMMEDIATE lv_exec USING OUT result,IN lv_tab;
DBMS_OUTPUT.PUT_LINE(result);
END;
/
BEGIN :a := :b(1)+:b(2)+(:b(3)*:b(4)); END;
95
PL/SQL procedure successfully completed.
SQL>
SY.
Tags: Database
Similar Questions
-
The concatenation of the EXECUTE IMMEDIATE statement.
Hi all
The situation is that I am trying to find all customers whose Date of birth (DOB) is greater than or equal to 150 days. Unfortunately, when I run this SQL I get the error message:
(1) ORA-00904: "FEB": invalid identifier
(1) ORA-06512: at line 4 level
I'm not sure what I should do to solve this problem, I hope you can help.
Note: I have to encapsulate this statement in an immediate execution due to problems of roles/Privilidge. In the full version, I also use AUTHID CURRENT_USER.
Edited by: DaveyB February 23, 2012 08:39DECLARE curr_date Date := SYSDATE; BEGIN EXECUTE IMMEDIATE ' SELECT cust_name, cust_dob, -- date of birth cust_shoe_size FROM tblCustDetails c WHERE SUBSTR(c.cust_name, 1,7) = ''Bob'' AND cust_dob >= NEXT_DAY(' || curr_date ||' - 150 , ''SATURDAY'') '; END;
The right way to use dynamic queries like this would get stuck in the variables you use... for example
DECLARE curr_date Date := SYSDATE; BEGIN EXECUTE IMMEDIATE ' SELECT cust_name, cust_dob, -- date of birth cust_shoe_size FROM tblCustDetails c WHERE SUBSTR(c.cust_name, 1,7) = ''Bob'' AND cust_dob >= NEXT_DAY(:1 - 150 , ''SATURDAY'') ' USING curr_date; END;
However, you also have to take into account the fact that the results of the query are currently disappearing into the ether, so you need an INTO statement...
DECLARE curr_date Date := SYSDATE; BEGIN EXECUTE IMMEDIATE ' SELECT cust_name, cust_dob, -- date of birth cust_shoe_size FROM tblCustDetails c WHERE SUBSTR(c.cust_name, 1,7) = ''Bob'' AND cust_dob >= NEXT_DAY(:1 - 150 , ''SATURDAY'') ' INTO var1, var2, var3 USING curr_date; END;
ensure that your variables are declared as appropriate, and then...
... you have to take into account the possibility that there is more than 1 line returned, in which case you will have the results of the query to a collection.
Of course, it is useless for dynamic SQL statements in the first place...
DECLARE curr_date Date := SYSDATE; BEGIN SELECT cust_name, cust_dob, -- date of birth cust_shoe_size INTO var1, var2, var3 FROM tblCustDetails c WHERE SUBSTR(c.cust_name, 1,7) = 'Bob' AND cust_dob >= NEXT_DAY(curr_date - 150 , 'SATURDAY'); END;
still, you should always take into account the bulk collection in a collection if it were going to be more than one row returned.
-
suffixing date in the EXECUTE IMMEDIATE statement
Hi could one please let me know how I can the suffix of the name of the table to the year, which the calculation is being in the select statement. Output should be as an example: test_2007declare abc number; begin select (to_char(sysdate, 'YYYY') - 4) into abc from dual; EXECUTE IMMEDIATE 'CREATE TABLE test_&abc as select * from emp where 1=2'; end;
You can do it like this
BEGIN EXECUTE IMMEDIATE 'CREATE TABLE test_' || (TO_CHAR ( SYSDATE, 'YYYY') - 4) || ' as select * from emp where 1=2'; END;
You can use your variable as well, if this can change dynamically.
DECLARE abc NUMBER; BEGIN SELECT (TO_CHAR ( SYSDATE, 'YYYY') - 4) INTO abc FROM DUAL; EXECUTE IMMEDIATE 'CREATE TABLE test_'||abc||' as select * from emp where 1=2'; END;
Edited by: g. March 1, 2011 11:49
-
Creating external Tables using the EXECUTE IMMEDIATE in PL/SQL
Hi guys,.
I am trying to create an external Table using the EXECUTE IMMEDIATE in a procedure and I managed to compile and no errors were generated. But when I try to run it from sql using the exec command I get the following error:
------------------------------------------------------------------------
ERROR on line 5:
ORA-00911: invalid character
ORA-06512: at "GEO. TEST_DDL', line 4
ORA-06512: at line 5
-------------------------------------------------------------------------
I tried to check the whole statement to create the external table, but I can't find where is the error. Surprisingly, if I simply run the command table create external on sqlplus it works, but not a procedure.
If anyone can help with ideas or experience?
Geoffrey KossamiThe error means that there is an identifier somewhere that starts with a nonalphanumeric. This is a typical mistake of editing. A procedure compiles correctly is not of course because the underlying dynamic sql running is OK. Which of course only be resolved when you try to run it.
There is certainly a problem with the text you provide to be run as a piece of dynamic sql code. You should try to watch it with dbms_output and run this code in sqlplus. But your problem is with the code you run as dynamic PL/SQL, it is not itself compilable.
Jack
-
Is it possible to use the record type or a PL/SQL table in the Select statement
Hi all
My requirement is that.
I want to write a query and write a function, function, I want to return multiple columns at the same time in a Select statement.
I select the return values in the Select no statement in a PL/SQL block.
Is it possible to use the PL/SQL Table or Variable of Type record, or any other method in the statement Select?
Please help me understand the solution.
Kind regards830960 wrote:
do we like it?In general, Yes, if the function is a function table, you can do something like:
select t.col1, t.col2, f.col1, f.col2, f.col3 from table_name t, table(some_table_function(param1,...paramN)) f /
SY.
-
PL/SQL table for the TWG vs
Hi, I want to know why we use of TWG when we can store temporary data in PL/SQL tableAdding to the list of knapen,.
(5) the contents of a TWG will obey the semantics of rollback, and rollback to savepoint. An associative array is not.
-
Workshop SQL->; Tables->; create the Lookup Table
It is perhaps a SQL issue rather than an issue of Apex, but...
With my experience of amateur to create database tables, I usually start with a parent table and create children and link them.
While playing with Apex, I have the ability to create a Lookup Table of in any table.
And, what is created is a new table that is, indeed, a parent.
So I have been working from the bottom to the top.
I understand that correctly?
Thank you-
MarionMarion...
Yes...
Lookup tables store data from reference and a link to your main table with a standard primary/foreign key relationship.
This feature is particularly useful if you are creating your tables of data in the worksheet and you want to standardize it.
Gus... -
Help the fetaching data in dynamic PL/SQL tables
Hello
I'm develioping a PL/SQL procedure in which I'm 24 tables of PL/SQL creation of the same type.
But while inserting data in them, I need to use the table dynamically names for example, immediate enforcement to put the data in the tables would remain even just I need for each loop for the Execute immediate statement, it must use the name in the other table.
See the code example below:
Varchar2 column (20);
Type RA_TABLE is table of the CALL_DETAIL_EXCEPTION. TYPE % IC_CIRCT_GR_CD
index of directory;
MY_RA1 RA_TABLE;
MY_RA2 RA_TABLE;
MY_RA3 RA_TABLE;
MY_RA4 RA_TABLE;
BEGIN
for idx in 1.cnt_interval loop
Column: = "MY_RA" | IDX;
Query1: = 'select Trunk_info bulk collect INTO MY_RA | IDX |' dbl.vw_cgi v where there is no (select 1 of dbl.varun f
where f.ic_circt_gr_cd = v.TRUNK_INFO and f.call_gmt_dnect_dt_time between
to_date('''|| stime ||'') (', "yyyymmddhh24miss") and to_date('''|| eTime ||'') ((', 'yyyymmddhh24miss'))';
Now, when I run this code, it gives me an error for query1 saying that it's a function not implemented in Oracle.
He is not able to choose this dynamic table name.
Help, please!dbms_output.put_line(l_outertab(1)(1));
-
What is the best TWG or Pl/Sql Table
Hello
One of the best MNC asked me a question. for example,.
What is the global temporary Table table / b/w difference Pl/Sql? What is the best to maintain the data manipulations?
Pls advise me... !!
for example, it is very useful.
Adv.Thanks
PrabhuAs usual if you search for it you would have found your answer at this time.
He has already been asked here before and responded. The link is
Concerning
REDA
-
How to create a type of record and a pl/sql table of this record type in the database
Hello
I want to create a record type, and then I want to create a PL/SQL table in the oracle 9i database.
I did block PL/SQL.
But when I'm doing it in the database it throws me a few errors.
Could you please tell me how can I do?
Concerninguser576726 wrote:
Hello
I want to create a record type, and then I want to create a PL/SQL table in the oracle 9i database.
I did block PL/SQL.
But when I'm doing it in the database it throws me a few errors.
Could you please tell me how can I do?Concerning
RECORD type is only supported in PL/SQL for SQL, you must use the OBJECT type.
-
How to remove duplicates from the PL - SQL table?
Hi gurus,
I have a PL - SQL table with the following structure
Authors (SR_NO, Auth_Code, Change_Date, cost)
This table is filled using a slider. However, this table can have a few lines in double (for column (Auth_Code)
for example
I need to get the above result set select the separate lines of Auth_Code including the Change_Date is maximum (and store in another PL - SQL table for treatment later or even the removal of this table will be also!)SR_NO Auth_Code Change_Date Cost 1 A1 14-FEB-09 08.18.47 AM 11.00 2 A2 14-FEB-09 08.18.56 AM 2839.00 3 A1 15-FEB-09 08.00.02 AM 1299.00 4 A1 15-FEB-09 07.00.00 AM 789.00 5 A3 14-FEB-09 08.18.56 AM 312.00 6 A4 14-FEB-09 08.19.02 AM 233.00
of the data A1 is duplicated and a maximum Change_Date above = 15 February 09 08.00.02 AM.
Where my PL - SQL Table that results must have given below
I'm not very aware of the PL - SQL tables and there is no chance to change the existing cursor that fills the data in this table PL - SQL.SR_NO Auth_Code Change_Date Cost 2 A2 14-FEB-09 08.18.56 AM 2839.00 3 A1 15-FEB-09 08.00.02 AM 1299.00 5 A3 14-FEB-09 08.18.56 AM 312.00 6 A4 14-FEB-09 08.19.02 AM 233.00
I guess that I need to compare each record of PL - SQL table with others, but do not know how to do this.
Could you please help?Hello
Like this?:
Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0 Connected as hr SQL> SQL> with data as( 2 select 1 as SR_NO, 'A1' as Auth_Code, to_date('14-FEB-09 08.18.47', 'dd-mon-yy hh24:mi:ss') as change_date, 11.00 as cost from dual union all 3 select 2 as SR_NO, 'A2' as Auth_Code, to_date('14-FEB-09 08.18.56', 'dd-mon-yy hh24:mi:ss') as change_date, 2839.00 as cost from dual union all 4 select 3 as SR_NO, 'A1' as Auth_Code, to_date('15-FEB-09 08.00.02', 'dd-mon-yy hh24:mi:ss') as change_date, 1299.00 as cost from dual union all 5 select 4 as SR_NO, 'A1' as Auth_Code, to_date('15-FEB-09 07.00.00', 'dd-mon-yy hh24:mi:ss') as change_date, 789.00 as cost from dual union all 6 select 5 as SR_NO, 'A3' as Auth_Code, to_date('14-FEB-09 08.18.56', 'dd-mon-yy hh24:mi:ss') as change_date, 312.00 as cost from dual union all 7 select 6 as SR_NO, 'A4' as Auth_Code, to_date('14-FEB-09 08.19.02', 'dd-mon-yy hh24:mi:ss') as change_date, 233.00 as cost from dual) 8 select * from data d where change_date = (select max(change_date) from data d2 where d.auth_code = d2.auth_code); SR_NO AUTH_CODE CHANGE_DATE COST ---------- --------- ----------- ---------- 2 A2 14/02/2009 2839 3 A1 15/02/2009 1299 5 A3 14/02/2009 312 6 A4 14/02/2009 233 SQL>
Kind regards
-
Insert rows in the PL/SQl table
Hello
I have a PL/SQl table that I filled through bulk collect and now I'm trying to loop through the table (actually quite a few nested loops)... Now in one of my curls, I might need to insert a new row by splitting the field in the existing row in the table. Can I insert the line in the pl/sql table in the loop without affecting the "FOR i IN tab.first... Tab.Last' loop?
Also, what would be the index of such a line inserted into the table. Can I access it with tab.last + 1 (doesn't look like it can be done if I insert into various levels of loops).
OR
If I insert the lines insde loops nested, then I can access the new lines as soon as I close all the loops and open a new loop? The new lines will be at the last table.
Any help will be appreciated...The expression v_arr. LAST gives the index of the last entry, so you can refer to this element as
v_arr(v_arr.LAST)
Then the attributes of this element will be
v_arr(v_arr.LAST).attr
for example
DECLARE TYPE table_defs_tt IS TABLE OF user_tables%ROWTYPE INDEX BY PLS_INTEGER; v_mytables table_defs_tt; BEGIN SELECT * BULK COLLECT INTO v_mytables FROM user_tables WHERE ROWNUM <= 100; DBMS_OUTPUT.PUT_LINE(v_mytables(v_mytables.LAST).table_name); END;
-
dynamic SQL for OPEN will not take the SQL string in the form of a string variable
Hello
I use "OPEN-for", not "EXECUTE IMMEDIATE" because I want to do multi lines request. However, 'OPEN-for' won't take a variable "strSQL' in the clause, it only took fixed ropes?
create or replace function fnEnumSystemUser
(
LogonFilter nvarchar2,
...
AdditionalWhereClause nvarchar2,
OrderByClause nvarchar2
)
RETURN xxxxx.cursorType
AS
strSQL nvarchar2 (2000);
FormatAdditionalWhereClause nvarchar2 (2000);
FormatOrderByClause nvarchar2 (2000);
SystemUserCursor xxxxx.cursorType;
BEGIN
If AdditionalWhereClause IS NULL THEN
FormatAdditionalWhereClause: = ' ';
ON THE OTHER
FormatAdditionalWhereClause: = TRIM (AdditionalWhereClause);
END IF;
If OrderByClause IS NULL THEN
FormatOrderByClause: = ' ';
ON THE OTHER
FormatOrderByClause: = TRIM (OrderByClause);
END IF;
strSQL: = 'select Id, FirstName, MiddleName, LastName, PrimaryEmail, PersonType, CreateDate, CreatedBy, LastUpdate, LastUpdateBy, connection, PasswdHash, IsSuspended, had left join SystemUser person on SystemUser.PersonId = Person.Id';
-It won't work, just says "WARNING: compiled, but with compilation errors" when I tried to create the function
Open SystemUserCursor for strSQL;
-This is to call "ORA-01006: bind variable does not exist.
Open SystemUserCursor
' select Id, FirstName, MiddleName, LastName, PrimaryEmail, PersonType, CreateDate, CreatedBy, LastUpdate, LastUpdateBy, connection, PasswdHash, IsSuspended, had left join SystemUser person on SystemUser.PersonId = Person.Id WHERE SystemUser.Logon like: x: y ' using LogonFilter, OrderByClause;
-This failed also (on call, "ORA-00900: invalid SQL statement")
Open SystemUserCursor
' select Id, FirstName, MiddleName, LastName, PrimaryEmail, PersonType, CreateDate, CreatedBy, LastUpdate, LastUpdateBy, connection, PasswdHash, IsSuspended, had left join SystemUser person on SystemUser.PersonId = Person.Id WHERE SystemUser.Logon like: x' | OrderByClause using LogonFilter;
RETURN SystemUserCursor;
END;
That's how I invoked:
declare
Int NumItemsSelected;
lstResult xxxxx.cursorType;
TYPE SystemUserRecordType IS RECORD
(
ID numeric (19.0),.
FirstName nvarchar2 (50).
MiddleName nvarchar2 (50).
LastName nvarchar2 (50).
PrimaryEmail nvarchar2 (190),
PersonType int,
CreateDate timestamp,
CreatedBy numeric (19.0),.
LastUpdate timestamp,
LastUpdateBy numeric (19.0),.
Logon nvarchar2 (75).
PasswdHash int,
IsSuspended tank,
Display timestamp
);
SystemUserRecordType oUser;
Start
lstResult: = fnEnumSystemUser (...) '%',... Person.PrimaryEmail like '% a %', "order by ASC Logon", 0, 10, NumItemsSelected);
LOOP
extract lstResult in oUser;
When the output lstResult % notfound;
dbms_output.put_line ('Id: ' | oUser.Id);
END LOOP;
end;
I need the ability to add to the SQL string because ultimately say I need to join:
1. ORDER BY section
2 call a FUNCTION in WHERE Clause
3 pagination and ROW_NUMBER() clause
What can I do? Thank you!1. why you use NVARCHAR2 to the SQL string. Use VARCHAR2 or LONG.
2. use
tags to preserve formatting of your code. 3. In the bind variable does not exist example it looks like you have one bind, :y, but are trying to bind two variables logonfilter and orderbyclause. 4. In the third example, try logging the sql string in a table or dbms_output and running it in sql - you should get the same error and it might then be easier to diagnose. Cheers, Dominic
-
Changing table via the package with immediate execution (problem)
Hello
I have a unusual problem. I have a package that contains the procedure that via execute immediate statement, creates a table on which he performs different actions for example:
-alter table some_owner.dummy_table noparallel
-create index some_owner.idx_name on some_owner.dummy_table (column)...
But I only managed to run move and create synonym table/public via execute immediate statement. Actions as alter table and create index fails with error ORA-01031: insufficient privileges.
Note If call these commands outside the package (a simple script) this all done OK.
I found a way, where I set the AUTHID CURRENT_USER command create package statement. In this way all the actions executed OK.
I wonder why I can't change the table via the package with immediate execution on a table that is in the tablespace "SOME_TABLESPACE" and the title of owner "SOME_OWNER", without putting the AUTHID command on the package.
There must be a problem why a package cannot change the table which is owned by the user 'SOME_OWNER '.
All useful responses would be appreciated.
I have a unusual problem.
No - you don't have. This question has been answered SEVERAL times on this forum and others.
But I only managed to run move and create synonym table/public via execute immediate statement. Actions as alter table and create index fails with error ORA-01031: insufficient privileges.
OK - your username doesn't have privileges to do these operations or only received privileges through roles.
Roles are DISABLED in named PL/SQL blocks that use of the AUTHOR's rights.
Note If call these commands outside the package (a simple script) this all done OK.
I found a way, where I set the AUTHID CURRENT_USER command create package statement. In this way all the actions executed OK.
Of course - the roles are NOT disabled in named PL/SQL blocks that use the rights of the APPELLANT or in anonymous blocks.
I wonder why I can't change the table via the package with immediate execution on a table that is in the tablespace "SOME_TABLESPACE" and the title of owner "SOME_OWNER", without putting the AUTHID command on the package.
Well now you know!
-
Hi all!
What is the PL/SQL table and why use us it?
Help me.Hello
A PL/SQL table is a table that exists only in PL/SQL blocks. It could be used to create one or more dimension tables in memory, but it has no direct relationship with Oracle Forms.
Try Google on it and you will find many interesting links.François
Maybe you are looking for
-
Strange activity on Satellite L50-A00M HDD
My hard drive has recently decided to start the race to 100% for long periods of time without being connected to any process to do so. As you can imagine many that steals the focus and slows everything I want to do what I'm waiting for a lull in the
-
TestStand Menu (source control)
Is it possible to use Source code control for TestStand sequence and I don't use TestStand workspace
-
Difficulties to download an application form (in Word).
Hello. I tried to simply download an application form for a teaching position off the coast of a school Web site. Initially, the message I got was 'cannot start the converter mswrd632. I went online and then followed the instructions to remove the in
-
How to recover the default games in Windows XP
I accidentally deleted the games that come with Windows XP. Is it possible to recover. I don't have a CD more.
-
Necessary mandatory STP on wlc?
Hello We use several wlc440x that bind each with two links to two different basic switches that are interconnected; one of the basic switches is stp root for all the VLANS. Is there a need for the wlcs to have stp enabled on their ports? AFAIK they d