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
Kishore
Hi,
I am trying to build a select statement which uses table name in a variable. Please help me in building such statements.
Regards
Kishore
Similar Messages
-
How to use table name as variable in insert statement
Hi,
I want to insert data from the cursor into the table and I want to submit table name as a variable. I tried the code below but it's not working. Any ideas how to solve this problem? Thx
DECLARE
v_new_table_name VARCHAR2(30) := 'test';
--open cursor
CURSOR ACM IS
SELECT *
FROM DWH.CLI_DIMENSION@SLSPDW CLI
WHERE where_clause
FROM some_table;
BEGIN
FOR REC_ACM IN ACM LOOP
EXECUTE IMMEDIATE 'INSERT INTO ' || v_new_table_name || ' VALUES REC_ACM'; --table name as a variable in which the data from cursor will be inserted
V_ROWCOUNT := V_ROWCOUNT + 1;
IF MOD(V_ROWCOUNT, 100) = 0 THEN --this feature commits after 100 rows.
COMMIT;
END IF;
END LOOP;
COMMIT;
DBMS_OUTPUT.PUT_LINE('Number of inserted records:' || V_ROWCOUNT);
END;Try this and let me know if it works. I have not tested it so I can not say for sure.
DECLARE
v_new_table_name VARCHAR2(30) := 'test';
CURSOR ACM IS
SELECT * FROM DWH.CLI_DIMENSION@SLSPDW CLI
WHERE where_clause
FROM some_table;
BEGIN
loop
fetch ACM INTO REC_ACM
exit when ACM%NOTFOUND;
EXECUTE IMMEDIATE 'INSERT INTO ' || v_new_table_name || ' VALUES REC_ACM';
V_ROWCOUNT := V_ROWCOUNT + 1;
IF MOD(V_ROWCOUNT, 100) = 0 THEN
COMMIT;
END IF;
end loop;
COMMIT;
DBMS_OUTPUT.PUT_LINE('Number of inserted records:' || V_ROWCOUNT);
END; -
Create table where table name is a variable
I need to be able to create tables where the table name is a variable . Using PL/SQL in Oracle 9. Also need to insert and query the table.
THANK YOUUse 'execute immediate' in pl/sql:
execute immediate 'create table '||var_tablename||'...'; -
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 -
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 -
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 -
Am trying to give a table name by a variable but its giving me errors can anyone plz help... resNr is a int!
db2.insert("CREATE TABLE "+resNr+"(\n"+
"ID int(11) NOT NULL auto_increment,\n"+
"GAESTNR int(11) NOT NULL default '0',\n"+
"VARENR int(11) NOT NULL default '0',\n"+
"ANTAL int(11) NOT NULL default '0',\n"+
"VAREBETEGNELSE tinytext NOT NULL,\n"+
"PRIS int(11) NOT NULL default '0',\n"+
"BEL�B int(11) NOT NULL default '0',\n"+
"PRIMARY KEY (ID)\n"+
")TYPE=MyISAM");print out the statement to the java console (System.out.println) and type the command into the mysql console. I guess you are missing a space before the bracket:
db2.insert("CREATE TABLE "+resNr+" (\n"+
also, you must consider the naming conventions of mysql tables. a table cannot be named "1", "2", the name must start with a letter, I think. -
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 -
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.
-
ODI: Using Table Name in Dynamic filters
We have a requirement, where the filters have to be dynamically generated and applied on the source system data stores.
The requirement can be best explained by the below example.
I have EMPLOYEE and DEPARTMENT table as the source datastores and EMP_DEPT (flat table) as the target datastore.
The filter condition will be updated now and then by the admin in a table. They would like to run the integration interface with the condition mentioned in the table.
Metadata table and sample data: (DY_FILTERS)
TABLE_NAME | INTERFACE_NAME | CONDITION
EMPLOYEE | EMP_DEPT | EMPLOYEE.EMPLOYEE_NAME LIKE 'A%'
DEPARTMENT | EMP_DEPT | DEPARTMENT.DEPARTMENT_ID = 10
So now the interface has to run with the conditions 'EMPLOYEE.EMPLOYEE_NAME LIKE 'A%' and DEPARTMENT.DEPARTMENT_ID = 10.
To achieve, the best possible solution I can think of is, I have defined a variable for the dynamic filter and under the refresh section and I am planning to use the following query:
SELECT CONDITION FROM DY_FILTERS WHERE INTERFACE_NAME = <%=odiRef.getPop("POP_NAME")%> AND
TABLE_NAME = ***************.
I was able to pick the interface that is currently involved by using getPop() method where as I dont have clue for getting the table name.
Please share with me, if you have answer. Also if you have any other way to achieve this, please share the same.
Note: The actual scenario is more complex than the example given above. But the crux of the requirement is very well covered in the example.
Edited by: 986046 on Feb 14, 2013 2:06 PMHi,
If you've only one source datastore in your interface, you can retrieve it's name with <%=odiRef.getSrcTablesList("[RES_NAME]", "")%>.
If you have more than one source it will list all you sources.
However I can't see when you plan to refresh your variable. getSrcTablesList won't work before/after the interface execution.
Regards,
JeromeFr -
Using Table name in Read statement dynamically
Hi Experts,
I have the following requirement.
Based on a country code say "A" , "B", "C" and based on this i have to read different internal tables lt_tabA, lt_tabB and lt_tabC.
The table key can be given dynamically, but how can i use the internal table name dynamically without using if statements.
Please help.
Thanks!
Best Regards,
GayathriHi Gayathri,
something like
DATA:
lt_t100 TYPE TABLE OF t100,
lt_t000 TYPE TABLE OF t000.
FIELD-SYMBOLS:
<table> TYPE table,
<rec> TYPE ANY,
<field> TYPE ANY.
SELECT:
* INTO CORRESPONDING FIELDS OF TABLE lt_t100 FROM t100 UP TO 10 ROWS,
* INTO CORRESPONDING FIELDS OF TABLE lt_t000 FROM t000 UP TO 10 ROWS.
CASE abap_true.
WHEN space.
ASSIGN lt_t100 TO <table>.
WHEN OTHERS.
ASSIGN lt_t000 TO <table>.
ENDCASE.
READ TABLE <table> with key ('MANDT') = sy-mandt ASSIGNING <rec>.
Regards,
Clemens -
To know schema using table name
Can I know the schema using the table name.
I have a handy if probably overcomplicated script for this:
SQL> @which v$session
Objects matching 'v$session':
Name Type OWNER Granted? Synonym
V$SESSION SYNONYM PUBLIC
SYS.V_$SESSION (VIEW)
SQL> @which dual
Objects matching 'dual':
Name Type OWNER Granted? Synonym
DUAL SYNONYM PUBLIC
TABLE SYS Yes DUAL
SYS.DUAL (TABLE)
www.williamrobertson.net/scripts/which.sql -
Use Table Name in Summary Table
Hi,
I am looking for a way to use the names of tables in another table.
eq. I have tables named after the months. And I want to use this name in another table in which i summarize all the facts from the mont tables. Is there a way to refer to the table name?
Thanks in Advance PaulHi Jerrold
It seems that we made the same interpretation.
I just wished to give a soluce allowing the user to change easily the name of the referenced table.
In my sample, if I add a new table, the required task is just to add it's name in the first column and replicate the original formula with no change.
For a single formula, it changes quite nothing but if we use many cells, it's an efficient time saving.
I just gave a really bare example.
Here is one with more referenced cells.
Don't worry, the separator is semi-colon because I ran Numbers in English on my French system
Yvan KOENIG (VALLAURIS, France.) mardi 11 août 2009 17:19:46 -
Dear Experts,
I am unable to find table UI in my interactive form. I am using the NWDS version 7.0.13 and the ADLC version is 6.0. Do I need a higher version? Where I can get it?
Also, I am facing some problem with design as I give the type of my subform as Flow so that if no data exists it won't take the space. But in this case, it's not allowing me to allign the ui's properly one above another. It is taking it as one after one.
Please suggest you opinions in this regard.
Helpful answers will be appreciated.
Regards,
GauravGaurav,
For developing SAP Interactive forms you need atleast Designer 7.1. Check this thread for more on same:-
Error popup saying, "Could not start Layout Designer"
Chintan -
How to Use Table name at run time
Hi All
I have created a function that accepts a table name as a parameter and returns the maximam sequence number, but in my function body i can not write the parameter name as a table i.e.
CREATE OR REPLACE FUNCTION MAX_ID(TAB_NAME Varchar)
RETURN Number IS
max_id Number;
CURSOR curSalPoint IS
SELECT MAX(EMP_NUMBER)
FROM TAB_NAME ;
BEGIN
max_id:=0;
OPEN curSalPoint ;
FETCH curSalPoint INTO max_id;
CLOSE curSalPoint;
RETURN max_id
END
But it will give an error saying
(1):PL/SQL: ORA-00942: table or view does not exist
for "TAB_NAME"
Any help would be appreciate ........Yes, as i contcatinated table name with the original statement, so you can also continate fields' names with your statment and execute immediate the statement.
Sorry i forgot this statement in my function, to execute the statement you need to include following statement
CREATE OR REPLACE FUNCTION MAX_ID(TAB_NAME Varchar)
RETURN Number IS
max_id Number;
query varchar2(200);
BEGIN
max_id:=0;
query:=null;
query := query || 'select max(empno) into max_id from'|| tab_name;
EXECUTE IMMEDIATE query;
RETURN max_id;
END;
Message was edited by:
Salman Qureshi
Maybe you are looking for
-
My daughters iPod was stolen today and I disabled it and tracked it on the find iPhone to an address but law enforcement can't do anything yet since they have now turned the iPod off which means it's off the radar now but for the life of me I can not
-
Row level security not working if I hit the aggregate
I have applied row level security on presentation layer , however it does not work if the report hit the aggregate any idea on this...
-
Adobe Creative Cloud desktop app suddenly stopped to launch at boot...
Windows 8 64b (French). Adobe CC English version. Typekit sync activated. I was working on Illustrator this morning when Windows crashed for unknown reason (yes. This happend sometimes ^^). PC rebooted without any pb, I relaunched Illustrator and not
-
License Problem When Installing Data Integrator
Hi, I have downloaded the BOBJ DATA INTEGRATOR XI R2 ACC. I am trying to install on the server that has our BO XI Edge 3.1 installation. Its asking me for a Licence file?? The DI Getting Started Guide refers to licensing Business Object email address
-
HP Pavilon dv6 Notebook PC web cam will not turn on
I downloaded the driver from HP website but the error message says to turn on web cam . How do you turn on the Web cam?????