Variable table name
Hi all,
I tried to execute the statement below inside a push button on forms 6i
select count(*) into :global.temp from *:variable_table_name* where rownum=1;
but it fails to compile because it only accepts a static table name....I need such statement because i wanna check empty table that is to be selected by user
from list item (variable_table_name ) that contain table names
Any help or advice ? thanks
Hi,
You can not use statement like this in forms. You will have to use EXECUTE IMMEDIATE or DBMS_SQL
One example through EXECUTE IMMEDIATE.
Create one function in database as below...
CREATE OR REPLACE FUNCTION EXEC_STR(vStr IN VARCHAR2) RETURN NUMBER IS
vCnt NUMBER;
BEGIN
EXECUTE IMMEDIATE vStr INTO vCnt;
RETURN vCnt;
END;and then from your form you can use like below...
:GLOBAL.temp:=EXEC_STR('SELECT COUNT(*) FROM '||:variable_table_name);-Ammad
Similar Messages
-
Creating a form with variable table name(s)
Hi,
I am building a form that will allow user(s) switch to other user
(s) dynamically. I have been able able to do this by creating a
non-database table and use record group to read from the base
table of each user.(All the tables in question have the same
structure).
Record group is a read only, and I want to be able to do data
maninpulation with this form.
The questions are
(1) It possible to do data manipulation with record group and if
it is, how?
(2) Is it possible to build a form with a variable table name?
if possible, how?
Somebody pls help.
Thanks,
Olutunde.
nullOlutunde Babarinsa (guest) wrote:
: Hi,
: I am building a form that will allow user(s) switch to other
user
: (s) dynamically. I have been able able to do this by creating a
: non-database table and use record group to read from the base
: table of each user.(All the tables in question have the same
: structure).
: Record group is a read only, and I want to be able to do data
: maninpulation with this form.
: The questions are
: (1) It possible to do data manipulation with record group and
if
: it is, how?
: (2) Is it possible to build a form with a variable table name?
: if possible, how?
: Somebody pls help.
: Thanks,
: Olutunde.
Hi,
you can create and manipulate record groups at runtime(see Forms
Reference 'Create_Group' and 'Add_Group_Row') don't use
Create_Group_from_Query. For your purpose it's better to build a
cursor loop on your Query and add your datas after
manipulating with 'Add_Group_Row' to your Record Group.
It's possible to SET_BLOCK_PROPERTY(QUERY_DATA_SOURCE_NAME) but
it's not possible to change the item property 'Column Name'.
Therefor I would suggest to build a non database block and
populate these block by a programm unit, which works with a
pl/sql cursor loop and the 'create record' to populate these
block.
null -
Variable table name in the select statment ?
data: h_itab like hier_out occurs 0 with header line,
table_name(30) type C.
here i declare h_itab as the variable for the table name
itab_name = input_name
input_name is imported
select * from table_name
into table h_itab
where OBJVERS = 'A'.
it does not allow me to use table_name in the select statement i get the error 'table_name is not defined i the abap dictionary as a table, projection view or database view'.
Any suggestions are highly appreciated.
Thanks in advance,
BWerHi,
You must enclose the name of the table in braces to let the compiler know that the value will be supplied at run time.
For example -
tables mara.
data table_name(30) type c.
table_name = 'MARA'.
SELECT *
FROM (table_name)
endselect.
Regards,
Anand Mandalika. -
How user variable table names in select statement
Dear all,
I have three table gp1,gp2,g3. i want user variable table in sql query
for example at oracle forms have a list table showing table names gp1,gp2,gp3
at form i want user this query
select gpno from :table where gpno=120;
how i can specify table name Dynamicly in select query
ThanksForms_DDL is a one-way street: You can only pass DDL commands TO the database; you cannot get data back using Forms_DDL.
Exec_SQL is the Forms package that enables dynamic sql within a form. But to retrieve data, you have to make a Exec_SQL call for every column in every row. So it is not a good thing to use, either.
The ref cursor method should work. You could also retrieve the data into a record group using populate_group_with_query -- it also enables dynamic data retrieval.
But if you already know you have three distinct tables and you know their names, I would keep it simple and just write three sql select statements. -
Cursor using variable table name
I'm new to Oracle, and am wondering if I can create a cursor that can take a variable name as the table it's selecting from. I am working on an application that is loading data to 1 of 3 tables. The table name is stored as a variable and the loads are done using dymanic sql to constuct the insert statement. At the end, I want to select and process some specific info from the table that's been loaded by cycling thru a cursor on whichever of the 3 tables was populated. I could create 3 cursors, one for each table, test the table_name variable, and then reference the specific cursor that way, but I thought there must be another way to do this. I want to be able to do something like this:
CURSOR loaded_table is select distinct(process_key) from 'v_tablename' (where v_tablename is either TABLE2, TABLE2 or TABLE3)
Any suggestions would be greatly appreciated.
Tks...MCRIt's possible to use dynamic SQL for something like this. If we're only talking about three tables, though, my hunch is that you'll be much happier defining three different cursors. Dynamic SQL is significantly harder to write, debug, and maintain than static SQL, so you're better off resorting to it only when there are so many tables that static SQL is impractical.
Justin
Distributed Database Consulting, Inc.
www.ddbcinc.com/askDDBC -
In forms i want to give variable as table name.
e.g When_button_press
Insert into :txt1 values (select * from abc1)
return error on :txt1.
how can i do this.There are examples in the forum that show how. Here are some of them:
CAN I PASS A TABLE NAME AS A VARIABLE IN THE FROM CLAUSE?
DML issue in Oracle forms
Re: How to include variable on block's query
How to use table name as variable -
INNER join with dynamic table name ?
Hi,
I have a problem with this statement.
DATA: g_dso_bic_dofr TYPE tabname.
SELECT t1~/bic/ziparomr
t2~/bic/zifremom
INTO (wa_rater_paromr-/bic/ziparomr,
wa_rater_paromr-/bic/zifremom)
* FROM /bic/azd0bfr5100 AS t1 "equivalent to the dynamic statement below
" this is the problem
FROM (g_dso_bic_dofr )AS t1
INNER JOIN /bic/pzifremom AS t2
ON t1~/bic/ziparomr = t2~/bic/ziparomr
" --- to here
WHERE t1~/bic/zikom = v_kommune
The compile check doesnt work when i use the variable table name.
I get
"Wrong expression "INNER" in FROM clause. WHERE condition."
Can anyone help me.
Br Rasmus." this is the problem
* FROM (g_dso_bic_dofr )AS t1 "<<--- check spaces in here
FROM (g_dso_bic_dofr) AS t1 "<<--- and here
INNER JOIN /bic/pzifremom AS t2
ON t1~/bic/ziparomr = t2~/bic/ziparomr
" --- to here
I think there's the problem, the space behind the parenthesis.
Regards -
Hi
Using Apex 3.2
I have a cascading select box problem I hope you can help with:
The first select box dynamically displays a list of Oracle Views, constructed based on a specific pattern and strips out the sever name as the display value and holds the View Name as the return value. This works fine.
The second select box is supposed to return a list of distinct owners from the "owner" column in this view (same column for display and return values). This does not work!!
The cascade is supposed to work by reading the view name from select box 1 and using this in the "From" clause to specify the view to run the select from.
If I hard code a View name from the first select box into the second process it works ok.
So 2 questions:
1) Is it possible to pass a variable table name eg "select * from :var_name", If it is possible how can I fix this?
2) Is there an alternative way to select from different tables/views based on user selection?
Thanks in anticipation
Edited by: DarrenG on Nov 30, 2010 10:03 AM
Edited by: DarrenG on Nov 30, 2010 10:33 AMHi Darren,
What tables/views are you using to get the data for the lists?
Have you tried ALL_VIEWS? This gives you all of the view names and their owners.
I don't think that you can directly use PL/SQL type statements for a select list - but you can use Ajax to get the information and that does use PL/SQL and accepts variables.
However, your SQL statement - "SELECT * FROM :var_name" - implies that you want to generate a report from the selected view? If so, that can be done using a PL/SQL region of type: SQL Query (PL/SQL function body returning a SQL query). The source for that would be something like:
DECLARE
vSQL VARCHAR2(100);
BEGIN
vSQL := "SELECT * FROM " || :var_name;
RETURN vSQL;
END;and make sure that you use the "Use Generic Column Names (parse query at runtime only)" option underneath that so that column names are handled correctly.
Andy -
How to use bind variable value for table name in select statement.
Hi everyone,
I am having tough time to use value of bind variable for table name in select statement. I tried &p37_table_name. ,
:p37_table_name or v('p37_table_name) but none worked.
Following is the sql for interactive report:
select * from v('p37_table_name') where key_loc = :P37_KEY_LOC and
to_char(inspection_dte,'mm/dd/yyyy') = :P37_INSP_DT AND :p37_column_name is not null ;
I am setting value of p37_table_name in previous page which is atm_state_day_insp.
Following is error msg:
"Query cannot be parsed, please check the syntax of your query. (ORA-00933: SQL command not properly ended) "
Any help would be higly appreciated.
RajInterestingly enough I always had the same impression that you had to use a function to do this but found out from someone else that all you need to do is change the radio button from Use Query-Specific Column Names and Validate Query to Use Generic Column Names (parse query at runtime only). Apex will substitute your bind variable for you at run-time (something you can't normally do in pl/sql without using dynamic sql)
-
How to use a table name in the select statement using a variable?
Hi Everybody,
I got a internal table which has a field or a variable that gets me some tables names. Now I need to retrieve the data from all these tables in that field dynamically at runtime. So could you suggest me a way out to use the select query which uses this variable as a table ?
Regards,
Mallik.Hi all,
Actually i need some more clarification. How to use the same select statement, if i've to use the tabname in the where clause too?
for ex : select * from (tab_name) where....?
Can we do inner join on such select statements? If so how?
Thanks & Regards,
Mallik. -
CAN I PASS A TABLE NAME AS A VARIABLE IN THE FROM CLAUSE?
For some reason, I am trying to use a variable name containing the actual table name in the from clause and it won't allow me. I keep getting the error saying I need to declare the variable I'm using eventhough I've used it in another statement that is not the FROM clause.
Example
SELECT count(col1), sum(col2)
FROM v_table_name;
v_table_name was declared as:
v_tablename VARCHAR2(20);
v_tablename := real_table_name;
Is it not allowed to use variables in the FROM clause or am I missing something here?You can use the Forms "From Clause Query" as the datasource for the data block. Then you can change the QUERY_DATA_SOURCE_NAME using set_block_property, so you can use any SQL statement you like. Of course you must name/alias the columns in a consistent manner so that the number of database items on the block matches those being queried.
-
MySQL - In a Query, Using a Variable as a Table Name
Hello,
The code I have attached works. However, I would like to
replace the table name "tractors" with the variable "$result". How
do I do this? (It doesn't work if I just type "$result" where
"tractors" is.)
Thanks,
JohnArizonaJohn wrote:
> The code I have attached works. However, I would like to
replace the table
> name "tractors" with the variable "$result". How do I do
this?
You can't. In the code you have given $result is a MySQL
database result
resource. You need to extract the actual value from the
result resource
in the same way as you have done by using
mysql_fetch_array().
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS4",
"PHP Solutions" & "PHP Object-Oriented Solutions"
http://foundationphp.com/ -
Using a Variable for Table Name with a cursor
Hello All
Is it possible to use a Parameter passed to a procedure as the table name
in a cursor selection statment. I thought the below would work but I get
a error. Does anyone have any ideas?? The Error is listed below to.
Here's the code I just complied
CREATE OR REPLACE PROCEDURE Dup_Add(NEWQATABLE IN VARCHAR2) IS
CURSOR c1 IS SELECT MUNI,PROV FROM NEWQATABLE GROUP BY MUNI, PROV;
c1rec c1%ROWTYPE;
BEGIN
OPEN c1;
LOOP
FETCH c1 INTO c1rec;
EXIT WHEN c1%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(c1rec.MUNI);
END LOOP;
CLOSE c1;
END;
Here is the errors
LINE/COL ERROR
3/8 PLS-00341: declaration of cursor 'C1' is incomplete or malformed
3/15 PL/SQL: SQL Statement ignored
3/38 PLS-00201: identifier 'NEWQATABLE' must be declared
5/7 PL/SQL: Item ignored
10/3 PL/SQL: SQL Statement ignored
10/17 PLS-00320: the declaration of the type of this expression is
incomplete or malformed
12/3 PL/SQL: Statement ignored
12/24 PLS-00320: the declaration of the type of this expression is
incomplete or malformed
LINE/COL ERROR
Thanks
PeterIf you are going to have a table name or a column name as a parameter, then you have to open the cursor dynamically. The following example uses Native Dynamic SQL (NDS) to open a ref cursor dynamically. I also eliminated the group by clause, since it is intended for use with aggregate functions and you weren't using an aggregate function. Also notice that there are some other differences in terms of defining variables and fetching and so forth.
SQL> CREATE TABLE test_table
2 AS
3 SELECT deptno AS muni,
4 dname AS prov
5 FROM dept
6 /
Table created.
SQL> CREATE OR REPLACE PROCEDURE Dup_Add
2 (newqatable IN VARCHAR2)
3 IS
4 TYPE cursor_type IS REF CURSOR;
5 c1 cursor_type;
6 c1muni NUMBER;
7 c1prov VARCHAR2 (20);
8 BEGIN
9 OPEN c1 FOR 'SELECT muni, prov FROM ' || newqatable;
10 LOOP
11 FETCH c1 INTO c1muni, c1prov;
12 EXIT WHEN c1%NOTFOUND;
13 DBMS_OUTPUT.PUT_LINE (c1muni || ' ' || c1prov);
14 END LOOP;
15 CLOSE c1;
16 END;
17 /
Procedure created.
SQL> SHOW ERRORS
No errors.
SQL> SET SERVEROUTPUT ON
SQL> EXECUTE dup_add ('test_table')
10 ACCOUNTING
20 RESEARCH
30 SALES
40 OPERATIONS
PL/SQL procedure successfully completed. -
Table name to find a variable used in which queries
Hello,
what is table name to find a particular variable used in which queries.write 'Variable Name:'.
write vname.
write /.
write 'Variable Type:'.
write variabletype.
write /.
write 'Based on Infoobject:'.
write variobj.
write /.
write 'Variable Processing Type:'.
write varprocesstyp.
write /.
write 'Variable Select Parameters:'.
write varselectiontyp.
write /.
write 'Variable Ready for Input:'.
write varinputtyp.
write /.
write 'Variable Entry criteria:'.
write varentrytyp.
write /.
write 'Variable can be changed during navigation:'.
write varchangeable.
write /.
* write
Select single varuniid from rszglobv into varid where vnam = p_varnm.
select single TXTLG from RSZELTTXT into variabledescription where ELTUID = varid and OBJVERS = 'A'.
write 'Variable Description:'.
write variabledescription.
write /.
write /.
querydet-querytechname = 'Query Technical Name'.
querydet-querydesc = 'Query Description'.
write querydet-querytechname.
write querydet-querydesc.
write /.
Select SELTUID from RSZELTXREF into table queryuid where TELTUID = varid and laytp = 'VAR' and OBJVERS = 'A'.
loop at queryuid into querydets.
select single compID from rszcompdir into querydet-querytechname where COMPUID = querydets-queryid and OBJVERS = 'A'.
select single txtlg from RSZELTTXT into querydet-querydesc where ELTUID = querydets-queryid and objvers = 'A'.
write querydet-querytechname.
write querydet-querydesc.
write /.
*update querydet from querydetail.
endloop.
write 'Query View Details for affected queries'.
write /.
viewtab-viewtechname = 'View Technical Name'.
viewdesc = 'View Description'.
write viewtab-viewtechname.
write viewdesc.
write /.
clear viewtab.
clear viewdesc.
loop at queryuid into querydets.
select single compID from rszcompdir into querydet-querytechname where COMPUID = querydets-queryid and OBJVERS = 'A'.
select viewid from rszwview into table viewtab where compid = querydet-querytechname and objvers = 'A'.
loop at viewtab into viewdetails.
select single TXTLG from RSZWOBJTXT into viewdesc where objid = viewdetails-viewtechname.
write viewdetails-viewtechname.
write viewdesc.
write /.
endloop.
endloop. -
How to insert variable for table name in Select statement ?
I am creating a stored procedure which will take two table names as IN parameters. Within the procedures I would like to use the parameters in the following manner;
SELECT count(*)
INTO v_target_cnt
FROM TargetTable;
TargetTable is one of the parameters passed in. When I do this however it does not recognize the parameter. I have tried assigning the parameter to a local variable and using the variable, with not luck.
Any help....thanksNull,
What you are describing is called a LEXICAL parameter, which is allowed (preceded by an ampersand) in sql but not in pl/sql because it would not be possible to compile it. That is why you need to use Andrew's suggestion to make the sql dynamic. In older versions you would need to use DBMS_SQL which is horrible and now thankfully redundant.
Maybe you are looking for
-
X131e - weird browser tabs behaviour
Hello all. Took delivery of an X131e a few days ago. OVer the past few days I have noticed an intermittent issue with the behaviour of tabs in both Explorer and the latest version of Firefox I installed. Essentially, what happens is that every time I
-
Can I Use a Dell 2407FPW?
PowerMac Dual 2.3 G5, ATI Radeon 9600 with 128MB VRAM Can I drive a Dell 2407FPW or will I need a new graphics card?
-
I have made several iMovies. Can the DVD be converted or Burned to view on regular tv?
I have made several iMovies of family. Can these DVD's be converted or Burned so that they can be viewed on regular tv?
-
Getting an error -unable to get stable set..i cant identify why??
MERGE INTO aaa_interim ai USING (SELECT * FROM aaa_staging WHERE record_type = 3 or (record_type=2 and terminate_cause_id=1)) asi ON (ai.vendor_record_id = asi.vendor_record_id) ---remove the field for session_id WHEN MATCHED THEN UPDATE SET duration
-
How to redirect in java code not the jsp or any other
hello can any one help me how to redirect in java pages the code must be in java function not in jsp or any thing else thanks in advance