How to set dynamic table name in sql query?
I want set dynamic table name by parameter in sql query,just like:
select * from :tbname
but run report is error,BI P report table name is invalidation.
What can i do? Thanks!
Hi,
that's only possible inside a data template with a lexical parameter.
Regards
Rainer
Similar Messages
-
How to pass dynamically table name in my cursor declaration
Hi:
I am new. could you please let me know how to pass a table name dynamically in my cursor declaration? for instance I am declaring the following cursor in my pl/sql procedure:
CURSOR crs_validate IS
select * FROM <ACT_JUN_2006_LOB>;
this ACT_JUN_2006_LOB table name, I should able to pass it when I open the cursor ... any help appreciated. thanks.
sriniThanks all for the response. REFCURSOR does work: here is an example ... which I found on-line
procedure emp_test(
month varchar2,
year varchar2)
is
type cur_typ is ref cursor;
c cur_typ;
query_str varchar2(200);
emp_number number := 7900;
salary number;
name varchar2(30);
Begin
query_str := 'Select empno, ename, sal from emp_' || month ||'_'||year
|| ' where empno = :id';
open c for query_str using emp_number;
loop
fetch c into emp_number, name, salary;
exit when c%notfound;
dbms_output.put_line(emp_number);
end loop;
close c;
end; -
Urgent Help on Dynamic Table name change in query !!!!!!!!
Hi Everyone,
I'm having a repeating frame which displays table_name, count_validate and count_error. How can i dynamically change my table_name in formula column apllied on count_validate and count_error. I can do this with multiple elsif statement, which makes my report slow at runtime. Select statement is same , only change is table_name ?
Kindly let me know......Try to use dynamic ref cursors (defined in a database package).
This is not exactly what you need, but see:
"Dynamic Table in the Second Query with Oracle Reports"
http://www.quest-pipelines.com/pipelines/plsql/tips03.htm#JULY
Regards,
Zlatko Sirotic -
How to set dynamic host name in the URL of a URL iView?
Hello,
I am using a standard URL iView that points to some J2EE app I've written and deployed on the same server.
I would like to set the host name to be a dynamic one, this way I won't need to change the iView URL when transporting it from one portal to another. As far as I know the system for a URL iView only controls authorizations but cannot replace the full URL set in the iView.
Any idea who can this be achieved?
RoyHi Mrityunjay,
forced URL at runtime will require me to call the URL iView from another iView that I will need to code (setting the URL in the Request object). If I did all this I might as well call it from this iView already.
I would like to do it with no further developments. I would have thought that SAP has constants that can be plugged in the URL for this type of thing, i.e. $hostname...
Rgds,
Roy
Edited by: Roy Cohen on Aug 21, 2008 4:03 PM -
How to know primary key column name form a table name in sql query
Suppose I only know the table name. How to get its primary key column name from the table name?
ThanksViews don't have primary keys though their underlying tables might. You'd need to pick apart the view to determine where it's columns are coming from.
You can select the text of the view in question from user_views. -
How to set dynamic IN clause in VO Query
Hi ADFExperts,
I have a requirement like I have a viewObject
Let say "Select * from contact" Result of this query is 20 lakhs records
My Requirement,
I have to apply "IN" clause in that view object so It will bring only required row.
E.g Select * from contact where First_name IN : bindName;
In bindName param of string type I am passing "('James','John')"
and I am executing VO.
But it is not returning the result.
Please help.Oracle db doesn't support construction: where something in :bind_var.
You can follow one of these approaches:
Decompiling ADF Binaries: Using oracle.jbo.domain.Array with ViewCriteria
Decompiling ADF Binaries: Using bind variable for the SQL statements with IN clause
Or try pure sql solution(I hope that [code] tag works on this new forum ):
[code]
select *
from contact
where first_name in (select substr(list,
instr(list, ',', 1, level) + 1,
instr(list, ',', 1, level+1) - instr(list, ',', 1, level) - 1)
from (select ','||:bindName||',' list from dual)
connect by level <= length(:bindName) - length(replace(:bindName,',',''))+1)
[/code]
So you can pass: James,John as value to :bindName variable
Dario -
Dynamic table name in native sql query
Can i pass a dynamic table name in this query ---
EXEC SQL PERFORMING APPEND_MTO.
SELECT
LTOG_QUANTITY_TYPE,
FCONO,
WBSELEMENT,
PROJECT
INTO :IMTO
FROM RWORKS.MTO_ISO_V2
WHERE LTOD_DATE > TO_DATE(:MAXD,'YYYYMMDDHH24MISS')
ENDEXEC.
How can i pass this table name RWORKS.MTO_ISO_V2 dynamically in the query
Edited by: Madhukar Shetty on Nov 26, 2009 2:40 PMCan i pass a dynamic table name in this query ---
EXEC SQL PERFORMING APPEND_MTO.
SELECT
LTOG_QUANTITY_TYPE,
FCONO,
WBSELEMENT,
PROJECT
INTO :IMTO
FROM RWORKS.MTO_ISO_V2
WHERE LTOD_DATE > TO_DATE(:MAXD,'YYYYMMDDHH24MISS')
ENDEXEC.
How can i pass this table name RWORKS.MTO_ISO_V2 dynamically in the query
Edited by: Madhukar Shetty on Nov 26, 2009 2:40 PM -
After run (or test) of procedure
create or replace procedure tmp_select_dymanic
( AInTable IN VARCHAR2,
ACount OUT NUMBER
) as
begin
EXECUTE IMMEDIATE 'BEGIN SELECT count(*) INTO :Count FROM :InTable END;'
USING ACount, AInTable;
end tmp_select_dymanic;
error message: invalid table name.
I know the table exists and contains data. I can make SELECT in SQL (not dynamic).
What a reason for error? May be privileges in database? But i make SELECT on my own table?
How can i set dynamic table name in other way?
My Oracle Version 10g.What you are asking can be done by REF_CURSOR;
look this example and try your self the rest:
CREATE OR REPLACE PROCEDURE insert_to_table_dinamic (
table1 IN VARCHAR2,
table2 IN VARCHAR2
AS
rc sys_refcursor;
v_sql VARCHAR2 (2000);
v_deptno NUMBER;
BEGIN
v_sql :=
'SELECT DEPTNO FROM '
|| table1
|| ' WHERE ROWNUM = 1 AND DEPTNO IS NOT NULL';
OPEN rc FOR v_sql;
LOOP
FETCH rc
INTO v_deptno;
EXIT WHEN rc%NOTFOUND;
v_sql :=
'UPDATE '
|| table2
|| ' SET DEPTNO = '
|| v_deptno
|| ' WHERE DEPTNO IS NULL';
EXECUTE IMMEDIATE v_sql;
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line (SQLCODE || SQLERRM);
END insert_to_table_dinamic;when i give DEPT , EMP as my 2 parameters above code will set the deptno in EMP table where deptno is null;
--Just a test proc. -
How to assign table name for select query in loop.
Hi friends my requirement is count the no of records of all the database table which comes into an internal table ."Check the below coding". Iam fetching the tables from dd03l table into an internal table .plz give me a sujjesion how to assign a table name in select query in a loop.
SELECT tabname FROM dd09l
INTO TABLE i_dd09l
WHERE protokoll = 'X'.
IF sy-subrc = 0.
SORT i_dd09l BY tabname.
ENDIF.
LOOP AT i_dd09l.
SELECT COUNT(*) INTO val FROM i_dd09l-tabname.
IF sy-subrc = 0.
i_dd09l-count = val.
ENDIF.
MODIFY i_dd09l INDEX sy-index.
CLEAR val.
ENDLOOP.
error : 'I_DD09L-TABNAME' is not defined in the abap dictionary as a table.data: dy_table type ref to data,
dy_line type ref to data,
xfc type lvc_s_fcat,
ifc type lvc_t_fcat,
dy_field type ref to data.
LOOP AT i_dd09l.
perform get_structure using i_dd09l-tabname .
CREATE DATA dy_table TYPE TABLE OF (_dd09l-tab_name).
UNASSIGN <dyn_table>.
ASSIGN dy_table->* TO <dyn_table>.
SELECT COUNT(*) INTO val FROM <dyn_table>.
IF sy-subrc = 0.
i_dd09l-count = val.
ENDIF.
MODIFY i_dd09l INDEX sy-index.
CLEAR val.
ENDLOOP.
form get_structure using p_table.
data : idetails type abap_compdescr_tab,
xdetails type abap_compdescr.
data : ref_table_des type ref to cl_abap_structdescr.
Get the structure of the table.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( p_table ).
idetails = ref_table_des->components.
loop at idetails into xdetails.
clear xfc.
xfc-fieldname = xdetails-name .
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
append xfc to ifc.
endloop.
endform. "get_structure
Try like this hope it will work.
Regards,
madan. -
Dynamic table name in native SQL
Hi,
How can i use dynamic table name in native SQL?
My req is to select data from a external database table , but the table name will be only poulated during runtime.
How can i acheive this?
Regards,
Arun.It should work OK - see demo below.
Jonathan
report zsdn_jc_adbc_test.
start-of-selection.
perform demo_lookup.
form demo_lookup.
data:
l_error_msg type string,
ls_t001 type t001, "Company
ls_t003 type t003. "Doc types
perform dynamic_lookup
using
'T001'
changing
ls_t001
l_error_msg.
write: / l_error_msg.
perform dynamic_lookup
using
'T003'
changing
ls_t003
l_error_msg.
write: / l_error_msg.
endform.
form dynamic_lookup
using
i_tabname type tabname
changing
os_data type any
o_error_msg type string.
* Use ADBC to select data
data:
l_mandt_ref type ref to data,
l_result_ref type ref to data,
l_mandt type symandt,
l_tabname type tabname,
l_sql_statement type string,
lo_cx_root type ref to cx_root,
lo_cx_sql type ref to cx_sql_exception,
lo_connection type ref to cl_sql_connection,
lo_statement type ref to cl_sql_statement,
lo_result_set type ref to cl_sql_result_set.
clear: os_data, o_error_msg.
get reference of l_mandt into l_mandt_ref.
get reference of os_data into l_result_ref.
l_mandt = '222'. "i.e. select from client 222
l_tabname = i_tabname.
try.
lo_connection = cl_sql_connection=>get_connection( ).
lo_statement = lo_connection->create_statement( ).
* Set criteria for select:
lo_statement->set_param( l_mandt_ref ).
concatenate
'select * from' l_tabname
'where mandt = ?'
into l_sql_statement separated by space.
* Execute
call method lo_statement->execute_query
exporting
statement = l_sql_statement
hold_cursor = space
receiving
result_set = lo_result_set.
* Get the data from the resultset.
lo_result_set->set_param_struct( l_result_ref ).
while lo_result_set->next( ) > 0.
write: / os_data.
endwhile.
* Tidy up:
lo_result_set->close( ).
lo_connection->close( ).
catch cx_sql_exception into lo_cx_sql.
o_error_msg = lo_cx_sql->get_text( ).
catch cx_root into lo_cx_root.
o_error_msg = lo_cx_root->get_text( ).
endtry.
endform. -
How to set dynamic name of the mail attachment according to source file ?
Hi,gurus:
Our scenario is like below:
Sending files from an FTP server to another FTP server without using the integraiton repositary,and the file name is not changed .Now, we want to also send the file to some with by mail adapter.The scenario now works by using two business services in receiver determination.But the name of the attachment is "untitled.xml".We know how to set the file name staticly,but how to set the name dynamicly according to the source file name ?
I have checked miachel's blog "XI: Dynamic name in the mail attachment - pseudo "variable substitution"(/people/michal.krawczyk2/blog/2006/02/23/xi-dynamic-name-in-the-mail-attachment--pseudo-variable-substitution),but how can I get the source file name?
And another question:Must we restart the adapter or j2ee engine to make the user defined module work?Hi,
>>>but how can I get the source file name?
form dynamicconfiguration (ASMA)
>>>And another question:Must we restart the adapter or j2ee engine to make the user defined module work?
no need for a restart
Regards,
Michal Krawczyk -
How to replace a table name with an item value in report region SQL query?
I've got a SQL query in a report region that goes like this:
SELECT :P30_HIDDEN FROM v_dms_dataset
GROUP BY :P30_HIDDEN
P30_HIDDEN is populated from a textfield input. Why doesn't this work, and is there a way to achieve what I'm trying to do here? I really need the ability to dynamically generate SQL queries in this way.Ben - you could either:
1. case when :P30_HIDDEN = 'COL1' then col1 else ... end
in order to determine which column to select (only really useful if you have a small number of predetermined columns to select from), or
2. generate the SQL dynamically.
Set the report region to SQL Query (PL/SQL function body returning SQL query), then have something like:
declare
l_sql VARCHAR2(4000);
begin
l_sql := 'SELECT ' || :P30_HIDDEN || ' FROM v_dms_dataset
GROUP BY ' || :P30_HIDDEN;
return l_sql;
exception
etc.
end;
John. -
Problem with Dynamic Table Name
Hello all,
I am having trouble using a dynamic table name. I have the following code.....
declare l_cur sys_refcursor;
l_ID int;
l_tableName varchar(30);
BEGIN
open l_cur for
select hkc.ColumnID, mapping from &HKAPPDB_Schema_Name..doctablemapping ddm
inner join &HKDB_Schema_Name..HKColumns hkc on hkc.doctablemappingid = ddm.id
where ddm.id > 0;
LOOP
FETCH l_cur into l_ID, l_tableName;
EXIT WHEN l_cur%notfound;
-- update missing VerbID in DocumentDocMapping table
UPDATE &HKAPPDB_Schema_Name..IndexedDocument
SET VerbID = (SELECT t.VerbID
FROM (SELECT DocRef, VerbID, DateUpdated
FROM &HKAPPDB_Schema_Name..l_tableName dd - this is where the dynamic table name is used
WHERE dd.VerbID is not NULL))
WHERE HKColumnID = l_ID AND VerbID is NULL;
END loop;
end;
/When I try to execute this i get an error
ORA-00942: table or view does not exist
What am I doing wrong?
Regards,
Tobyredeye wrote:
I only started about 6 weeks ago, with no tutorials and learning it on the fly; Same here.. only my introduction was to a 12 node Oracle OPS cluster all those years ago.. and required a whole new mind set after using SQL-Server extensively. But it was fun. Still is. :-)
but thats what you get when a company throws you in at the deep end with a ridiculous time constraint to migrate a whole MSSQL DB.Migrating SQL-Server to Oracle is not a simple thing. A lot of best practices in SQL-Server are absolutely worse practices in Oracle - they are that different. Simple example is lock escalation - an issue in SQL-Server. In Oracle, the concept of a lock being escalated into a page lock simply does not exist.
In terms of getting the migration done as quickly and painlessly as possible I try to reuse all the logic as it appears in the MSSQL code - in this case it was using dynamic table names. I do not doubt that i am probably shooting myself in the foot in the long run.....As long as you do not splatter too much blood on us here.. not a problem :D
Seriously though - just keep in mind that what works in SQL-Server may not work as well (or even at all) in Oracle. So do not hesitate to refactor (from design to code to SQL) mercilessly when you think it is warranted. -
Passing dynamic table name in ADO. net destination
I am new to SSIS and I have a requirement where i need to pass dynamic table name in ADO .net destination .
My package contains an "Execute Sql task" in the control flow which computes the destination table name to be provided at run time and stores it in a variable expression
"@[User::Table_name]"(which has a scope of full package).
Now, the problem I'm facing right now is that , I am unable to use this variable expression in the ADO .Net Destination .
I need to pass this variable expression as the table name in ado .net destination.
But, whenever I use this variable in place as the table name I keep on getting this error and my package fails:-
[ADO NET Destination [403]] Error: The Table or View name is not expected. \n\t If you are quoting the table name, please use the prefix " and the suffix " of your selected data provider for quotation. \n\t If you are using multipart name,
please use at most three parts for the table name.
Although ,I am able to run my package when i am providing the existing(static) table name.So there is nothing wrong with the package.
Tried a lot of things still not working..Please help...I am having the result stored in the variable expression . I just need a way to be able to use it as the Destination table in ADO .net Destination.
I am not sure if this will work for you, but I am able to store the table name in variable and use it dynamically (via data flow task expression property ) as shown.
Thanks, hsbal
Hi Adeep,
Based on my further research, just as hsbal said, we can set a variable as ADO.NET Destination table via Expressions property in Data Flow Task.
If there are any other questions, please feel free to ask.
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
How to create Dynamic Table Control
Hi
How to create Dynamic Table control , The field names and values to be displayed in table control are to be fetched from Add-on Tables.
Regards
PrasathHi Jonathan,
Actually the columns to be displayed are not constant . It will be increased based on the database values, Anyhow it will not exceed 100.
Please confirm my understanding.
1. In this case I have to create 100 custom columns and make it visible / invisible based on my requirement and I can set the title at runtime.
2. How can i assosicate / reassociate the datadictionary reference for the columns that i use. Because I need to show the search help values for the
dynamic columns.
Your opinion on this will be helpful.
Regards
Prasath
Maybe you are looking for
-
How to upload file from one machine (windows) to another (linux)through cre
How to upload a file from windows platform to linux platform. on both platforms sun app server is running. from creator is there any methode to open ftp port and upload
-
Encapsulating web services in CAF core
Hi, I am trying to call external services namely web services in caf core. I read the earlier posts and i guess I am missing out on something. 1. what is the difference between encapsulating external service as entity service VS application service.
-
Poor picture quallity through iPhoto purchased pictures?
I just recently ordered over 150 prints of a recent vacation from iPhoto with two different cameras. One is a 5 MP and the other a 8 MP camera. Pictures from both cameras when I received them in the mail were very poor quality. I contacted apple supp
-
Hi Everybody, I am new to Labview so I am looking for your help. I am looking for the most basic control diagram for a PID level control circuit.Thanks.
-
Node/Machine fail behavior of distributed caches
My high level question is: what happens to a distributed cache when nodes fail? We have 2 servers which run 4 JVMs each. We have the default of 1 backup set. What happens when an entire machine fails (all 4 JVMs go down with the ship)? What happens w