Writing procedure using table name as parameter
I want to write a procedure to sample size any table. It could be employees, departments, etc. It will not know anything about the table (what table, columns, datatypes) until it is called.
I want to invoke it sample_size(table_name_in, table_name_out, sample_sz).
Table_out will be created and empty. It will determine the columns to be selected from table_in.
It is a given that all columns in table_out exist in table_in with same name/datatypes.
Pseudocoding:
determine increment using size of table_in and sample_sz
build out_var list from table_out
select out_list from table_in
for (rows in table_in) loop by increment
insert into table_out
end for
I wrote function to get cursor:
create or replace
FUNCTION get_cursor
(table_nm IN VARCHAR2,
flds IN VARCHAR2)
RETURN sys_refcursor
IS
cur sys_refcursor;
vQry VARCHAR2(4000);
BEGIN
vQry := 'SELECT ' || flds || ' FROM ' || table_nm;
OPEN cur FOR vQry;
RETURN cur;
END get_cursor;
What I cannot figure out is how to define rowtype in calling procedure:
PROCEDURE
sample_size( table_in IN VARCHAR2,
table_out IN VARCHAR2,
sample_sz IN NUMBER )
IS
c1 sys_refcursor;
vInto VARCHAR2(4000);
BEGIN
-- code to get variables desired into variable vInto (I know how to do this)
c1 := get_cursor(table_in,vInto);
LOOP
FETCH c1;
EXIT WHEN c1%NOTFOUND;
-- code to decide wether to insert row into table_out
END LOOP;
CLOSE c1;
END sample_size;
I get error on FETCH c1; line:
Error(47,15): PLS-00103: Encountered the symbol ";" when expecting one of the following: . into bulk
All discussions I found about subject will have something similar to:
Rec emp%rowtype
and then
fetch c1 into Rec
None of the discussions showed me how to process an unknown table.
If tomorrow someone tells me to sample_size table CITIES, I want to use function without having to change it.
This is my first post. I hope I gave enough information. Thanks for any answer.
Welcome to the forum.
If yours is not an exercise why you don't want to use just
<tt><b>[url http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_10002.htm#SQLRF01702]select * from table_name {sample_clause}</b></tt> ;)
Regards
Etbin
Similar Messages
-
Problem with writing a procedure with table name as an input parameter
Hi all,
I am writing a procedure with table name as an input parameter:
below is the code
create or replace procedure prc(in_tbl in varchar2)
as
begin
execute immediate ' truncate table tlb ';
insert into tbl
select a,b,c from in_tbl;
end;user579585 wrote:
Hi all,
I am writing a procedure with table name as an input parameter:
below is the code
create or replace procedure prc(in_tbl in varchar2)
as
begin
execute immediate ' truncate table tlb ';
insert into tbl
select a,b,c from in_tbl;
end;You'll also need to use dynamic sql for the insert:
execute immediate 'begin insert into tbl select a,b,c from '||in_tbl||'; end'; -
How to use table name dynamically in report procedure
Hello every body
I want to use table name dynamically means at runtime i want to pass table name.
I can do this by lexical parameter in main query.
But my problem is that i want to crate new format trigger or new function that use 1 cursor in which that lexical parameter : table name is used.
so how to do that?
i can not use that lexical parameter it is giving error.
please help me how to do that.Call a database function which you pass the lexical parameter. Then in the database function you use dynamic sql or the execute immediate option to build the SQL string.
Return the information from this function to build your business logic on in your format trigger.
Marcos -
Pass table name as parameter in prepared Statement
Can I pass table name as parameter in prepared Statement
for example
select * from ? where name =?
when i use setString method for passing parameters this method append single colon before and after of this parameter but table name should be send with out colon as SQL Spec.
I have another way to make sql query in programing but i have a case where i have limitation of that thing so please tell me is it possible with prepared Statment SetXXx methods or not ?
Thanks
Haroon Idrees.haroonob wrote:
I know ? is use for data only my question is this way to pass table name as parameterI assume you mean "how can I do it?" As I have already answered "is this the way?" with no.
Well, I would say (ugly as it is) String concatenation, or stored procedures. -
Use table name in UPDATE statement as variable
Hi All,
I am using ORACLE 9i AIX base. I want to write following procedure:
PROCEDURE update_header (
p_care_msg_nbr IN NUMBER,
p_care_msg_id IN NUMBER,
p_care_msg_gkey IN NUMBER,
p_old_status IN VARCHAR2,
p_new_status IN VARCHAR2
IS
l_table varchar2(50);
BEGIN
l_table := 'CARE_EDI_MESSAGES';
UPDATE '&l_table'
SET status = p_new_status,
changed = sysdate,
changer = user
WHERE care_msg_no = p_care_msg_nbr
AND care_msg_id = p_care_msg_id
AND gkey = p_care_msg_gkey
AND status = p_old_status;
END;
I want to give the table name by passing value in a variable or parameter. Is it the write way or can I do this function in any other way.
Pleae tell me in urgency.
Thanks & Regards
Hassan RazaThis implies that you have several tables with identical or near identical structures, otherwise you will get errors if any of the mentioned columns do not exist in the table passed but ...
You cannot use a substitution variable that way. Oracle will ask for a value when you try to create the procedure, and compile what ever value you supply into the procedure viz.
SQL> CREATE PROCEDURE p AS
2 l_id NUMBER;
3 BEGIN
4 SELECT id INTO l_id FROM &t;
5 END;
6 /
Enter value for t: T
old 4: SELECT id INTO l_id FROM &t;
new 4: SELECT id INTO l_id FROM T;
Procedure created.
SQL> SELECT text FROM user_source WHERE name = 'P'
2 ORDER BY line;
TEXT
PROCEDURE p AS
l_id NUMBER;
BEGIN
SELECT id INTO l_id FROM T;
END;Even if that is the effect you want, note that there are no quotes around the substitution variable in the CREATE statement.
If you want to be able to pass the name of the table to the procedure, then you need to make the table name a parameter, then build the sql statement and execute it using EXECUTE IMMEDIATE. Something more like:
PROCEDURE update_header (p_care_msg_nbr IN NUMBER,
p_care_msg_id IN NUMBER,
p_care_msg_gkey IN NUMBER,
p_old_status IN VARCHAR2,
p_new_status IN VARCHAR2,
p_table IN VARCHAR2) IS
l_sqlstr VARCHAR2(4000);
BEGIN
l_sqlstr := 'UPDATE '||p_table||' SET status = :b1 '||
'changed = sysdate, changer = user '||
'WHERE care_msg_no = :b1 and care_msg_id = :b3 and '||
'gkey = :b4 and status = :b5';
EXECUTE IMMEDIATE l_sqlstr
USING p_new_status, p_care_msg_nbr, p_care_msg_id, p_care_msg_gkey, p_old_status;
END;HTH
John -
Dynamic SQL : passing table name as parameter
Hi
I have a SQL query (a store procedure ) that i want to convert to PLSQL
This is a part of my SQL query that i am trying to to find a solution for it, because i cant convert it to oracle :
DECLARE lookupTableRow CURSOR FOR
SELECT TableName FROM SYS_LookUpTable
OPEN lookupTableRow
FETCH NEXT FROM lookupTableRow INTO @tableName
WHILE @@FETCH_STATUS=0
BEGIN
SET @sql='SELECT * FROM '+@tableName
EXECUTE sp_executesql @sql
IF @counter=0
BEGIN
INSERT INTO T_TABLE_MAPPING VALUES('P_MAIN_METADATA', 'Table', @tableName)
END
ELSE
BEGIN
INSERT INTO T_TABLE_MAPPING VALUES('P_MAIN_METADATA', 'Table'+CONVERT(NVARCHAR(10),@counter), @tableName)
END
SET @counter=@counter+1
FETCH NEXT FROM lookupTableRow INTO @tableName
END
CLOSE lookupTableRow
DEALLOCATE lookupTableRow
As i understand i can't use ORACLE dynamic sql (execute immediate) when the table name is a parameter
Furthermore when i execute this dynamic query in my SQL store procedure each SELECT statement return me as a result the relevant table rows , those result are different in each loop .
So i cant do this too with ORACLE dynamic sql .
Please advice for any solution
* how can i use dynamic sql with table name as parameter ?
* how can i use a "dynamic" cursor, in order to be able to display the dynamic results ?
Thanks for the adviceHi,
b003cf5e-e55d-4ff1-bdd2-f088a662d9f7 wrote:
Hi
I have a SQL query (a store procedure ) that i want to convert to PLSQL
This is a part of my SQL query that i am trying to to find a solution for it, because i cant convert it to oracle :
DECLARE lookupTableRow CURSOR FOR
SELECT TableName FROM SYS_LookUpTable
OPEN lookupTableRow
FETCH NEXT FROM lookupTableRow INTO @tableName
WHILE @@FETCH_STATUS=0
BEGIN
SET @sql='SELECT * FROM '+@tableName
EXECUTE sp_executesql @sql
IF @counter=0
BEGIN
INSERT INTO T_TABLE_MAPPING VALUES('P_MAIN_METADATA', 'Table', @tableName)
END
ELSE
BEGIN
INSERT INTO T_TABLE_MAPPING VALUES('P_MAIN_METADATA', 'Table'+CONVERT(NVARCHAR(10),@counter), @tableName)
END
SET @counter=@counter+1
FETCH NEXT FROM lookupTableRow INTO @tableName
END
CLOSE lookupTableRow
DEALLOCATE lookupTableRow
As i understand i can't use ORACLE dynamic sql (execute immediate) when the table name is a parameter
Furthermore when i execute this dynamic query in my SQL store procedure each SELECT statement return me as a result the relevant table rows , those result are different in each loop .
So i cant do this too with ORACLE dynamic sql .
Please advice for any solution
* how can i use dynamic sql with table name as parameter ?
* how can i use a "dynamic" cursor, in order to be able to display the dynamic results ?
Thanks for the advice
I have a SQL query (a store procedure ) that i want to convert to PLSQL
I doesn't help when you use one term to mean another thing.
SQL is a language used in both Oracle and other products, such as Microsoft's SQL Server. I don't know much about SQL Server, but Oracle (at least) doesn't support stored procedures in SQL itself; they have to be coded in some other language, such as PL/SQL.
As i understand i can't use ORACLE dynamic sql (execute immediate) when the table name is a parameter
If the table name is a parameter (or only known at run-time for any reason), that's exactly the kind of situation where you MUST use dynamic SQL.
The number of columns that a query produces (and their datatypes) is fixed when you compile a query, whether that query is dynamic or not. If you have multiple queries, that produce result sets with different numbers of columns, then you can't combine them into a single query. The best you can do with one query is to add NULL columns to some of the queries so they all produce the same number of columns.
If you're just displaying the results, there might not be any reason to combine separate result sets. Just display one result set after another.
Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002 -
How to find the list of un used table names in a schema?
Hi,
I have a doubt in Oracle. The doubt is that If we are using any tables in Function Or Proc.... Then...We can list all those used table names from USER_DEPENDENCIES system table. Right...
But, If the table is used with Execute Immediate Statement, then, those table names are not coming out with USER_DEPENDENCIES system table. Because they are identified at run time and not compile time.
It is fine. And I agree.. But, If I want to list out those tables also...then...How to do? Any idea?
I think ‘USER_SOURCE’ system table may not be the right one. If there is any other system table avails for this purpose...then..it would be very grateful to extract right...
So I am wanting that exact system table.
Please let me know about this, if you have any idea or check with your friends if they have any idea.
Regards,
Subramanian GHi Guys,
Thanks for all your answers.
Yes....You are all right. We can list out the used tables upto certain extent. Anyhow, I have done some R&D to derive the SQL's which is given below:
SELECT TABLE_NAME FROM USER_TABLES
MINUS
SELECT DISTINCT UPPER(REFERENCED_NAME)
FROM user_dependencies
where
referenced_type='TABLE' and UPPER(NAME) in
select distinct UPPER(object_name) from user_objects where UPPER(object_type) in
'MATERIALIZED VIEW',
'PACKAGE',
'PACKAGE BODY',
'PROCEDURE',
'TRIGGER',
'VIEW',
'FUNCTION'
UNION
SELECT UT.TABLE_NAME FROM
SELECT TABLE_NAME FROM USER_TABLES
MINUS
SELECT DISTINCT UPPER(REFERENCED_NAME)
FROM user_dependencies
where
referenced_type='TABLE' and UPPER(NAME) in
select distinct UPPER(object_name) from user_objects where UPPER(object_type) in
'MATERIALIZED VIEW',
'PACKAGE',
'PACKAGE BODY',
'PROCEDURE',
'TRIGGER',
'VIEW',
'FUNCTION'
AND REFERENCED_OWNER=(SELECT sys_context('USERENV', 'CURRENT_SCHEMA') FROM dual)
) UT,
( SELECT * FROM USER_SOURCE
WHERE NAME IN
( SELECT DISTINCT NAME FROM USER_SOURCE
WHERE TYPE NOT IN ('TYPE')
AND
UPPER(TEXT) LIKE '%EXECUTE IMMEDIATE%'
) US
WHERE
UPPER(US.TEXT) LIKE '%'||UPPER(UT.TABLE_NAME)||'%'
AND
(UPPER(US.TEXT) NOT LIKE '%--%')
The above SQL Query can list out unused tables by checking the Dynamic SQL Statement also upto some level only.
Once we extracted the list of unused tables, having a manual check would be also greater to verify as it is should not impact the business applications.
Regards,
Subramanian G -
Problem in using table name dynamically in PL/SQL
I tried to create a procedure to use table name dynamically and got the following error. Anything wrong with my procedure?
NFADV>declare
2 cnt number;
3 cursor cur is select table_name from user_tables where table_name in ('EMP','DEPT');
4 begin
5 for c1 in cur
6 loop
7 execute immediate select count(*) into cnt from c1.table_name;
8 dbms_output.put_line('Count is : '||cnt);
9 end loop;
10 end;
11 /
declare
ERROR at line 1:
ORA-06550: line 7, column 21:
PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
( - + case mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current exists max min prior sql stddev sum variance
execute forall merge time timestamp interval date
<a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
<an alternatively-quoted string literal with character set specification>
<an alternatively-quo
ORA-06550: line 8, column 5:
PLS-00103: Encountered the symbol "DBMS_OUTPUT"
ORA-06550: line 8, column 45:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
. ( , * % & - + / at mod remainder rem <an identifier>
<a double-quoted delimited-identifier> <an exponent (**)> as
from into || multiset bulkThanks and Regards
KaustubhHi,
The wrong part is in execute immediate, it should be as follows:
execute immediate ('select count(*) from '|| c1.table_name)
into cnt
(not tested)
Regards
AK -
Can we use Column Names in Parameter Cursor
Hi
can we use Column Names in Parameter Cursor??
DECLARE
CURSOR Emp_Cur (P_Deptno NUMBER)
IS
SELECT Empno, Ename
FROM Emp
WHERE Deptno = P_Deptno;
BEGIN
FOR Emp IN Emp_Cur(10)
LOOP
DBMS_OUTPUT.PUT_LINE('The Employee Number is: '||emp.Empno);
DBMS_OUTPUT.PUT_LINE('The Employee Name is: '||emp.Ename);
END LOOP;
FOR Emp IN Emp_Cur(20)
LOOP
DBMS_OUTPUT.PUT_LINE('The Employee Number is: '||emp.Empno);
DBMS_OUTPUT.PUT_LINE('The Employee Name is: '||emp.Ename);
END LOOP;
END;
In the above Program, I send Deptnumber. If i send Column names like Empno, Ename. What can i do??
If Declare Samething Through Parameter Cursor, it doesn't accept VARCHAR2(Size)For parameters you don't use size, just the type (DATE, NUMBER, VARCHAR2, CLOB, ...)
DECLARE
CURSOR Emp_Cur (P_Ename VARCHAR2)
IS
SELECT Empno, Ename
FROM Emp
WHERE Ename = P_Ename;
BEGIN
FOR Emp IN Emp_Cur('SCOTT')
LOOP
DBMS_OUTPUT.PUT_LINE('The Employee Number is: '||emp.Empno);
DBMS_OUTPUT.PUT_LINE('The Employee Name is: '||emp.Ename);
END LOOP;
END; -
Unable to use Table name in a variable
Hi,
I am trying to build a select statement which uses table name in a variable. Please help me in building such statements.
Regards
KishoreHi,
I am trying to build a select statement which uses table name in a variable. Please help me in building such statements.
Regards
Kishore -
Help passing table name as parameter to a procedure
Hello,
i'm trying to write a procedure that takes a table name as input and uses a cursor to select a column,count(1) from the passed table to the cursor. The procedure i've come up with is as follows,
CREATE OR REPLACE
PROCEDURE excur(
p_tbl user_tables.table_name%type )
AS
type rc is ref cursor;
c rc;
res BOOLEAN;
BEGIN
open c for 'SELECT columnA,COUNT(1) FROM'|| p_tbl||';';
close c;
END excur;When i try to execute it, an error pops up informing that a table cannot be used in this context. As in i cannot pass a table name as an argument to a procedure. Kindly guide as to how to solve this situation.vishm8 wrote:
Hello,
i'm trying to write a procedure that takes a table name as input and uses a cursor to select a column,count(1) from the passed table to the cursor. The procedure i've come up with is as follows,
CREATE OR REPLACE
PROCEDURE excur(
p_tbl user_tables.table_name%type )
AS
type rc is ref cursor;
c rc;
res BOOLEAN;
BEGIN
open c for 'SELECT columnA,COUNT(1) FROM'|| p_tbl||';';
close c;
END excur;When i try to execute it, an error pops up informing that a table cannot be used in this context. As in i cannot pass a table name as an argument to a procedure. Kindly guide as to how to solve this situation.Generally speaking, Dynamic code is a bad idea for a staggering number of reasons.
That aside, what do you want to return? You're selecting a column and applying an aggregate function (count) but you're not grouping, that doesn't usually work out too well.
TUBBY_TUBBZ?select owner, count(*) from all_objects;
select owner, count(*) from all_objects
ERROR at line 1:
ORA-00937: not a single-group group functionWhy do you perceive the need to be able to take in ANY table name, can't you design an application where table names are known at compile time and not run time? -
Table name as parameter to function
Hi all,
can anybody help me on the below issue..
i have a function like this:
**create or replace**
**function "IL_SUM_AVG_FN" return number is**
**cursor c1 is**
** select sum_avg_val value**
** from wel_10_tab**
** where type='1';**
**v_sum number;**
**v_count number;**
**BEGIN**
** v_sum:=0;**
** v_count:=0;**
** for i in c1 loop**
** if v_count=0 then**
** v_sum:=i.value;**
** else**
** v_sum:=abs(i.value+v_sum);**
** end if;**
** v_count:=v_count+1;**
** end loop;**
** return v_sum;**
**END;**
now my requirement is like..i want to pass a value as parameter to the function..say i will pass 10 or11 or 12
then it should change the table name in the cursor according to the parameter.i.e
if the parameter is 10 it should be: select sum_avg_val value from wel_10_tab where type='1';
if the parameter is 11 it should be: select sum_avg_val value from wel_11_tab where type='1';
if the parameter is 12 it should be: select sum_avg_val value from wel_12_tab where type='1';
parameter has only these three possible values..
how to achieve this?
please help..Hi,
you can do without execute immediate and one cursor is sufficient, if you use open cursor for ...:
set serveroutput on;
drop table TestTab1;
drop table TestTab2;
create table TestTab1 (
val number
create table TestTab2 as (select * from TestTab1 where 0 = 1);
create or replace procedure TestProc (
TableName in varchar2)
is
rec TestTab1%rowtype;
cur sys_refcursor;
curStr varchar2(1024) := 'select * from ' || TableName;
begin
open cur for curStr;
loop
fetch cur into rec;
exit when cur%notfound;
dbms_output.put_line ('value = ' || rec.val);
end loop;
end;
insert into TestTab1 (val) values (1);
insert into TestTab1 (val) values (2);
insert into TestTab1 (val) values (3);
insert into TestTab1 (val) values (4);
insert into TestTab2 (val) values (101);
insert into TestTab2 (val) values (102);
insert into TestTab2 (val) values (103);
insert into TestTab2 (val) values (104);
begin TestProc('TestTab1'); end;
begin TestProc('TestTab2'); end;
/regards,
Frank
Edited by: user8704911 on Jul 11, 2011 10:35 PM
Edited by: user8704911 on Jul 11, 2011 10:36 PM -
Passing Table name as parameter to proc.
Hi,
I need to know how to pass a table name to a oracle procedure.
In that procedure I will put that table name in a variable and then I will make operations on that table like DELETE, UPDATE and INSERT.
Kinldy give me the solution for the above problem as soon as possible..
Thanks & regards,
KiranYou shouldn't do it, but if you do, you can use something like this:
Anton
create or replace type my_parm as object
( name varchar2(30)
, val anydata
create or replace type my_parms as table of my_parm
create table t1( c1 number, c2 varchar2(10), c3 date )
create or replace procedure doital( p_action in varchar2, p_tab in varchar2, parms in my_parms )
is
p_stmt1 varchar2(32000);
p_stmt2 varchar2(32000);
ind pls_integer;
curs integer;
dummy integer;
t_a anytype;
t_v varchar2(32000);
t_n number;
t_d date;
begin
curs := dbms_sql.open_cursor;
if upper( p_action ) = 'I'
then
ind := parms.first;
loop
exit when ind is null;
p_stmt1 := p_stmt1 || ', ' || parms( ind ).name;
p_stmt2 := p_stmt2 || ', :b' || to_char( ind );
ind := parms.next( ind );
end loop;
p_stmt1 := 'insert into ' || p_tab || ' (' || substr( p_stmt1, 2 ) || ' ) values (' || substr( p_stmt2, 2 ) || ' )';
dbms_sql.parse( curs, p_stmt1, dbms_sql.native );
ind := parms.first;
loop
exit when ind is null;
case parms( ind ).val.GetType( t_a )
when dbms_types.typecode_varchar2
then
dummy := parms( ind ).val.GetVarchar2( t_v );
dbms_sql.bind_variable( curs, ':b' || to_char( ind ), t_v );
when dbms_types.typecode_number
then
dummy := parms( ind ).val.GetNumber( t_n );
dbms_sql.bind_variable( curs, ':b' || to_char( ind ), t_n );
when dbms_types.typecode_date
then
dummy := parms( ind ).val.GetDate( t_d );
dbms_sql.bind_variable( curs, ':b' || to_char( ind ), t_d );
end case;
ind := parms.next( ind );
end loop;
end if;
dummy := dbms_sql.execute( curs );
dbms_sql.close_cursor( curs );
end;
begin
doital( 'I', 't1', my_parms( my_parm( 'c2', anydata.ConvertVarchar2( 'testje' ) )
, my_parm( 'c1', anydata.ConvertNumber( 3 ) )
, my_parm( 'c3', anydata.ConvertDate( sysdate ) )
doital( 'I', 't1', my_parms( my_parm( 'c1', anydata.ConvertNumber( 77 ) )
, my_parm( 'c2', anydata.ConvertVarchar2( 'goedzo' ) )
, my_parm( 'c3', anydata.ConvertDate( sysdate - 5 ) )
end;
/ -
Passing TABLE NAME as parameter is possible or not?
I want develop a small/simple report like this
TABLE NAME :
WHERE :
ORDER BY :
QUERY ROWS
In the above model i want to pass all the three (TABLE NAME,WHERE and ORDER BY) as a parameter.
My doubt, is that possible to pass TABLE NAME as a parameter? If so!
When i enter any TABLE NAME it has to fetch me out the records of that table (Based on WHERE condition and ORDER BY).
Is that possible to do?
Need some help!
Edited by: Muthukumar Seshadri on Aug 10, 2012 6:19 PMYes, it is possible with lexical parameters. Look in the help for examples:
SELECT Clause
SELECT &P_ENAME NAME, &P_EMPNO ENO, &P_JOB ROLE FROM EMP
P_ENAME, P_EMPNO, and P_JOB can be used to change the columns selected at runtime. For example, you could enter DEPTNO as the value for P_EMPNO on the Runtime Parameter Form.
Note that in this case, you should use aliases for your columns. Otherwise, if you change the columns selected at runtime, the column names in the SELECT list will not match the Report Builder columns and the report will not run.
FROM Clause
SELECT ORDID, TOTAL FROM &ATABLE
ATABLE can be used to change the table from which columns are selected at runtime. For example, you could enter ORD for ATABLE at runtime.
If you dynamically change the table name in this way, you may also want to use lexical references for the SELECT clause (look at the previous example) in case the column names differ between tables.
WHERE Clause
SELECT ORDID, TOTAL FROM ORD WHERE &CUST
ORDER BY Clause
SELECT ORDID, SHIPDATE, ORDERDATE, TOTAL FROM ORD ORDER BY &SORT You have to be really careful with this approach. Dynamic SQL may cause serious performance problems.
Edited by: InoL on Aug 10, 2012 10:06 AM -
Pasing table name as parameter
hiiii
i have the following PROCEDURE ..
i want the table name in the FROM clause to be (user_table) ... but its not working in the way am using now ... HOW can i do that ??
PROCEDURE LOGIN(u_name varchar2,PWD varchar2,user_table varchar2) IS
nm varchar2(50);
BEGIN
select F_NAME into nm from user_type ;
END;
thanx in advancehiii
thanx for replying
i used the following
PROCEDURE LOGIN(u_name varchar2,PWD varchar2,user_type varchar2) IS
nm varchar2(50);
BEGIN
execute immediate 'select f_name from ' || user_table into nm;
END;
i got the following error
This feature is not supported in client-side programs
identifier 'USER_TABLE' must be declared
by the way am working on my Graduation Project so i have both(DB & Developer on the same machine)
Maybe you are looking for
-
Error trying to update web.xml
I'm trying to update web.xml via these instructions: https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/d0eb8120-b66c-2910-5795-894f384fc054 The upload fails, and I see this excetpion in the log: Caused by: java.rmi.RemoteException:
-
TABLE CONTROL IN TAB STRIP CONTROL
hi experts, I have a problem with table control in tab strip control i have table control in first tab and some text fields in second tab . i enter data into table control in first tab and enter into second tab and i fill data into second tab also
-
I plan to purchase a new computer. How do I transfer my subscription to a new device?
I plan to purchase a new computer. How do I transfer my subscription to a new device?
-
i purchased Logic Pro 8 but i have recently moved house and managed to lose the discs except the installating disc luckily, i had the serial written on the disc case, but when i install it asks me for the Audio Content and Jam Pack discs which i dont
-
Applications crashing when iMac (Intel) goes idle
Hello Evryone, I'm facing some challenges with my iMac Intel 27" as several applications simply crash after the iMac sleeps and goes idle. When I leave applications like iTunes, Skype, Firefox running in the iMac I realize that after a while (btw 30-