Dynamic schema name in query
hi there,
who knows how to cheat a little and add schema name dynamically in report query?
curently trying PLSQL function body returning SQL
...from ' || '&P1_SCHEMA.' ||'.IM_INVOICES_V
where...
any bright thoughts?
crazy Simon
Hi,
You could try something like this...
CREATE OR REPLACE FORCE VIEW IM_INVOICES_V_VW AS
SELECT 'SCHEMA_1'.the_schema,
IM_INVOICES_V.*
FROM schema1.IM_INVOICES_V
UNION ALL
SELECT 'SCHEMA_2'.the_schema,
IM_INVOICES_V.*
FROM schema2.IM_INVOICES_V;
and then...
SELECT *
FROM IM_INVOICES_V_VW
WHERE the_schema = :P1_SCHEMA
AND ...Cheers
Ben
Similar Messages
-
I want to use a dynamic schema name in the from clause but its not working.
DECLARE
vblQueryName VARCHAR2(20);
vblSchemaName VARCHAR2(20);
BEGIN
SELECT CurrentSchemaName INTO vblSchemaName FROM HR_989_SCHEMA;
vblQueryName:='060_525_020';
INSERT /*+ APPEND(HP_ELIGIBILITIES,4) */ INTO HP_ELIGIBILITIES
LVL1ID,
LVL1Desc,
LVL2ID,
LVL2Desc,
LVL3ID,
LVL3Desc,
LVL4ID,
LVL4Desc
SELECT /*+ PARALLEL(a,4) */
LVL1ID,
LVL1Desc,
LVL2ID,
LVL2Desc,
LVL3ID,
LVL3Desc,
LVL4ID,
LVL4Desc
FROM
bold vblSchemaName.HP_ELIGIBILITIES a
WHERE
UPPER(LVL2ID) = 'XX' ;
COMMIT;
DBMS_OUTPUT.PUT_LINE( 'Query Executed: ' || vblqueryName);
INSERT INTO HP_QUERYEXECLOG(QueryName) VALUES(vblQueryName);
EXCEPTION WHEN NO_DATA_FOUND THEN NULL;
END;
I want to create a rules table so that the schema name in front of the table name in the from clause can be controlled by a separate table that is maintained but its not working . Help and your valuable inputs needed for this issueI want to use a dynamic schema name in the from clauseyou can alternatively set the current schema as e.g. in:
declare
vblqueryname varchar2 (20);
vblschemaname varchar2 (20);
begin
select currentschemaname into vblschemaname from hr_989_schema;
vblqueryname := '060_525_020';
execute immediate 'alter session set current_schema=' || vblschemaname;
insert /*+ APPEND(HP_ELIGIBILITIES,4) */
into hp_eligibilities (lvl1id,
lvl1desc,
lvl2id,
lvl2desc,
lvl3id,
lvl3desc,
lvl4id,
lvl4desc
select /*+ PARALLEL(a,4) */
lvl1id,
lvl1desc,
lvl2id,
lvl2desc,
lvl3id,
lvl3desc,
lvl4id,
lvl4desc
from hp_eligibilities a
where upper (lvl2id) = 'XX';
commit;
dbms_output.put_line ('Query Executed: ' || vblqueryname);
insert into hp_queryexeclog (queryname)
values (vblqueryname);
exception
when no_data_found
then
null;
end; -
Is it possible to use dynamic alias name in query for interactive report?
I have this SELECT and I would like to use the parameters used in alias request to build a dynamic crosstab report:
SELECT p.annee AS "Année", p.desc_rls AS "RLS",
SUM(CASE WHEN p.age BETWEEN :P2_AGE1 AND :P2_AGE2 THEN p.pop END) "0-4 ANS",
SUM(CASE WHEN p.age BETWEEN :P2_AGE3 AND :P2_AGE4 THEN p.pop END) "5-9 ANS",
SUM(CASE WHEN p.age BETWEEN :P2_AGE5 AND :P2_AGE6 THEN p.pop END) "10-14 ANS"
FROM pop_rls_isq_111 p
GROUP BY ROLLUP(p.annee, p.desc_rls);
Instead of coding "0-4 ANS" as alias, I would like for example use the parameters ":P2_AGE1 - :P2_AGE2 ANS".Hi,
to make your column headings dynamic you can use the substitution syntax in the "Column Heading" property of your IR columns. For example:
&P2_AGE1. - &P2_AGE2. ANSHope that helps
Patrick
My blog: http://www.oracleapex.info/
New Check out the Oracle APEX Essentials! -
How to configure the schema name dynamically based on user input.
configure the schema name dynamically based on user input.
For ex:
We have two schemas:
Schema1 - base schema having 15 tables.
Schema2 - tables which is specific to modules. Having only 10 tables which is also available in Schema1
Login to application using Schema 1
Access a particlular module and select the country. Here country selection is identified.
Based on the country selection, we need to connect the schema respectively.
If the user selects France --> It should connect Schema1
If the user selects Germeny --> It should connect schema2.
Used: EclipselinkYou may want to have a different persistence unit for each country, then you just need to switch persistence units, and can put the schema in your orm.xml file.
You may also want to investigate EclipseLink multi-tenant support,
http://www.eclipse.org/eclipselink/documentation/2.5/jpa/extensions/a_multitenant.htm
You can the schema in a persistence unit in code using a SessionCustomizer and the tableQualifier. -
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 -
Dynamic table name, how to query?
Hi!
There is a table name that is decided dynamically. the name is:
someNameYYY where YYY denotes the client number.
I get the client number by sy-mandt and concatenate it with someNameYYY to lc_table_name but then comes the problem:
I cannot do
SELECT *
FROM lc_table_name
because I get compiler error "lc_table_name" is not defined in ABAP dictionary.
How do I query a table with the name decided dynamically?
regards
BaranYou can have do something like this :
REPORT ZTABLE_DOWNLOAD .
tables :
dd02l, "SAP Tables
dd03l, "Table fields
dd04t. "R/3 DD: Data element texts
constants : c_activation_status(1) value 'A',
c_tabclass(6) type c value 'INTTAB',
c_language(2) type c value 'EN'.
type-pools : slis.
selection-screen begin of block b1 with frame title text-003.
*parameters :p_mandt like t001-mandt obligatory default '560'.
parameters :p_table like dd03l-tabname obligatory.
selection-screen end of block b1.
data:
table_desc(70) type c,
table_field like dd03l-fieldname,
total_rows type i,
t_rows(20) type c.
field-symbols:
<fs_line> type any,
<fs_field> type any.
at selection-screen.
*Check for the existence of the table
select single * from dd02l where tabname = p_table
and as4local = c_activation_status.
if sy-subrc ne 0.
*Table is not active in dictionary
message e999(zs) with 'Table is not active in dictionary'.
elseif dd02l-tabclass = c_tabclass.
*It is a structure not a table
message e999(zs) with 'This is a structure not a table'.
endif.
start-of-selection.
perform table_data_display.
end-of-selection.
form table_data_display.
data:
l_long_type type i,
lx_struct type ref to data,
lt_table type ref to data,
lcl_sdescr type ref to cl_abap_structdescr,
lx_lvc_cat type lvc_s_fcat,
lt_lvc_cat type lvc_t_fcat, "Field catalog
lx_fieldcat type slis_fieldcat_alv,
lt_fieldcat type slis_t_fieldcat_alv,
lx_layout type slis_layout_alv,
lt_sort type slis_t_sortinfo_alv, "Sort table
ls_sort type slis_sortinfo_alv.
field-symbols :
<fieldcat> type slis_fieldcat_alv,
<lt_table> type table,
<fs> type any,
<components> type abap_compdescr.
*Dynamic creation of a structure
create data lx_struct type (p_table).
assign lx_struct->* to <fs>.
*Get the field structure
lcl_sdescr ?= cl_abap_typedescr=>describe_by_data( <fs> ).
loop at lcl_sdescr->components assigning <components>.
*Do not display field "MANDT"
IF sy-tabix = 1 AND <components>-name = 'MANDT'.
CONTINUE. "next loop
ENDIF.
*Build fieldcatalog
lx_lvc_cat-fieldname = <components>-name.
lx_lvc_cat-ref_table = p_table.
append lx_lvc_cat to lt_lvc_cat.
lx_fieldcat-fieldname = <components>-name.
lx_fieldcat-ref_tabname = p_table.
append lx_fieldcat to lt_fieldcat.
endloop.
*Create an internal table
call method cl_alv_table_create=>create_dynamic_table
exporting it_fieldcatalog = lt_lvc_cat
importing ep_table = lt_table.
assign lt_table->* to <lt_table>.
*Read the data
select * from (p_table)
into corresponding fields of table <lt_table>
order by primary key.
loop at <lt_table> assigning <fs_line>.
assign component 'MANDT' of
structure <fs_line> to <fs_field>.
<fs_field> = p_mandt.
endloop.
if <lt_table>[] is initial.
*No table enties are existing
message e003(zdynamictable) with p_table.
exit.
else.
describe table <lt_table>[] lines total_rows.
t_rows = total_rows.
shift t_rows left deleting leading space.
endif.
*Specify the layout
lx_layout-zebra = 'X'.
lx_layout-colwidth_optimize = 'X'.
*Display the ALV List
select single ddtext into table_desc from dd02t
where tabname eq p_table and ddlanguage eq c_language.
check not table_desc is initial.
concatenate 'Entries from table:'
p_table '(' table_desc ')' '-:' t_rows 'Entries Found' into
table_desc
separated by space.
*Start - Download the data to excel sheet by validating the file path.
data:
*lv_filename type string,
lv_fname_validate like rlgrap-filename.
*CONCATENATE 'C:\ZTABLE_DWN\' P_TABLE '.Xls' INTO LV_FILENAME.
*CONCATENATE '
Pc-p31061\Harman\Tasks\ZTABLE_DWN\' P_TABLE '.xls' INTO
CONCATENATE 'C:\ZTABLE_DWN\' P_TABLE '.xls' INTO
LV_FNAME_VALIDATE.
call function 'WS_FILE_DELETE'
exporting
file = lv_fname_validate
IMPORTING
RETURN =
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
BIN_FILESIZE = ' '
CODEPAGE = ' '
FILENAME = LV_FNAME_VALIDATE
FILETYPE = 'DAT'
IMPORTING
FILELENGTH =
TABLES
DATA_TAB = <lt_table>.
*call function 'GUI_DOWNLOAD'
exporting
BIN_FILESIZE =
filename = lv_fname_validate
filetype = 'ASC'
write_field_separator = 'X'
IMPORTING
FILELENGTH =
tables
data_tab = <lt_table>.
End of Download.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_background_id = 'ALV_BACKGROUND'
i_grid_title = table_desc
is_layout = lx_layout
it_fieldcat = lt_fieldcat
tables
t_outtab = <lt_table>
exceptions
program_error = 1
others = 2
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
clear table_desc.
endform. " table_data_display -
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 -
Dynamic change in the query name based on user input
Hi Gurus,
In a scenario, country appears as a user input variable.When the user specifies his country, the same query displays <b>Business trends</b>' data pertaining to his own country and rest of the world(international) in two tables.The reports are developed using Web application designer.
Can the name(description) of the query be changed so that the user input value for country gets dynamically reflected in the query name like <b>Business trends:Selected country vs International</b>?
Regards,
BalajiHi Bala,
ya this can be done by text variables. create a text variable( replacement path on the country infoobject) by going to the query properties on the description.
if the user enters country value then it will be displaed on the description of the query .
assign points if useful .
regards
santosh -
Dynamic prefix of schema name in PL/SQL objects
I have a requirement where schema name would be passed as a parameter to the procedure and I am supposed to write some DML statements on some of the fixed tables. The table names are common among any schemas, but then only the schema names change.
This weird requirment is because, here they do not maintain same names for schemas on DEV,QA,UAT and PROD databases, and I can not change that. My thoughts are that it can be acheived only using Dynamic SQL. I want to know whether any alternate ways exist since this is going to be the case on various packages and procedures. For example I have a package with around 80 procedures in it which have couple of DML statements in it. Now they want to pass the schema name to main procedure and want the 80 procedures to perform the DML on the schema name passed :)
So, should I change all the 80 procedures and make all the DML in it to Dynamic SQL (I am afraid I might end up doing that)? Please not that I can not change all the environments to same schema names (Not in my hands)
Please suggest.You can make use of this inside you programs. We do this.
You can prefix the value before the object names.
When the procedure can run from same user who has privs on other schemas.
Just set the current_schema to HR , SCOTT or others.
You will not need to Pass Parameters for each procedure.
Current User can be same as the procedure run from or owner of the procedure.
SQL> SELECT sys_context('USERENV', 'CURRENT_SCHEMA') FROM dual;
SYS_CONTEXT('USERENV','CURRENT_SCHEMA')
SCOTT
SQL> alter session set current_schema=hr;
Session altered.
SQL> SELECT sys_context('USERENV', 'CURRENT_SCHEMA') FROM dual;
SYS_CONTEXT('USERENV','CURRENT_SCHEMA')
HR
SQL> alter session set current_schema=scott
Session altered.
SQL> SELECT sys_context('USERENV', 'CURRENT_SCHEMA') FROM dual;
SYS_CONTEXT('USERENV','CURRENT_SCHEMA')
SCOTTSS -
I have the permission of DBA.
I want the query to rename a Schema name from abc to xyz
Please help me
Thanks,Do a user-level export of user X
create new user A
import system/manager fromuser=X touser=A
drop user X -
Schema name added to SQL query after SQL Command
Post Author: rickeb1
CA Forum: Data Connectivity and SQL
Hello,
I am using Crystal Reports XI. I have created a Crystal report in the usual manner using a set of tables from a given database schema. When I look at the SQL query that Crystal generates, there are no data schema qualifiers anywhere.
Then I added an SQL Command object that I use as an additional table. Now when I look at the generated SQL query, the data schema name is added to the beginning of the original query as well as to the new SQL Comand code. It also creates an EXTERNAL JOIN which uses this hard-coded schema name (not exactly sure what an "external join" is).
This hard-coding of the schema name is causing a problem when we try to migrate the report to a different environment. Is there some way to avoid having Crystal generate a query with the schema name imbedded in the query, or is there a way to remove it after it is generated?
Thanks!Post Author: rickeb1
CA Forum: Data Connectivity and SQL
Actually, our problem may be related to this:
http://boardreader.com/t/Crystal_XI_249231/The_Show_SQL_Query_SQL_command_changes_89667.html
Any help greatly (and desparately) apapreciated! -
How to parameterize the schema name in APEX
Hi,
How to parameterize the schema name in APEX , in order to access different tables from the respective schema.
For example:-
select NAME display_value, CODE return_value
from paramSchema.DESC_LIST WHERE SELECTION_FLG = 'Y'
order by 1
in the above code, paramSchema will be replaced with the actual schema name duing runtime. I tried doing so by some hidden fields on page, but it didn't worked out.
I took the schema name from the respective server as per the IPof the server.
stored in a hidden field named as schema.
And replaced the same in place of schema name. But no luck.
select NAME display_value, CODE return_value
from :schema.DESC_LIST WHERE SELECTION_FLG = 'Y'
order by 1
Please help me in shorting it out.
Thanks,
AnuradhaHi
In order to do that, you would need to use dynamic SQL by changing the report type to PL/SQL Function Body Returning SQL Query and have code along the lines of
DECLARE
l_sql VARCHAR2(32767);
BEGIN
l_sql := 'select NAME display_value, CODE return_value
from '||:schema||'.DESC_LIST WHERE SELECTION_FLG = 'Y'
order by 1';
RETURN l_sql;
END;However, by doing this, you lose alot of flexibility. The other options would be...
To have seperate report regions that are conditional on the value of the variable.
To use a WITH clause at the tope of the query like...
WITH src_data AS
(SELECT * FROM schema1.my_table
WHERE :schema = 'schema1'
UNION ALL
SELECT * FROM schema2.my_table
WHERE :schema = 'schema2')
SELECT *
FROM src_dataOther than that you could look at using synonyms and doing something similar.
Hope this helps.
Cheers
Ben -
How to know database name and schema name
Hi ,
Once after logging in the database,how is it possible to know the current database and schema which we r using?Is there any system table where we can get the database names and schema names?
please help me out.itz urgent.
Regards,
SravanProbably not.
If the database name is the name of the current database, it would be essentially redundant. If the database name is the name of some other database, in order to get the names of all the tables in the specified schema, you could create a database link to the remote system (which assumes you have a login and password to the remote database with appropriate privileges, that the database server's tnsnames.ora file has an entry for the remote database, etc) and query the remote data dictionary tables. Even if you could do that, however, you could not dynamically create triggers on the remote database since DDL over a database link.
In theory, you could also load an appropriate JDBC driver into the database and write a Java stored procedure that would connect to the remote database (again, with an appropriate user name & password, host name, and port number) and issue DDL against that remote database. I have a hard time believing, however, that this would be a particularly beneficial approach. It would be easier just to put the appropriate code into each database that needs triggers generated or to have a separate Java application that generates triggers for a number of different databases.
Justin -
Parse schema name - Avoiding hard-coded schema names
Hi all,
I have been trying to find a similar thread but had no luck. I want to avoid hard-coding schema names in my reports. I have tried to use a Substitution string but I don't seem to be able to reference it by just doing :default_schema. I already reference the parsing schema like this: #OWNER# which is saving me a lot of time. Is there any way to create additional variables like that one instead of those substitution strings that can't be parsed in a query?
Thanks a lot for your help.
Regards,
werot.Werot wrote:
I have been trying to find a similar thread but had no luck. I want to avoid hard-coding schema names in my reports. I have tried to use a Substitution string but I don't seem to be able to reference it by just doing :default_schema. I already reference the parsing schema like this: #OWNER# which is saving me a lot of time. Is there any way to create additional variables like that one instead of those substitution strings that can't be parsed in a query?
Will you actually get any benefit from using substitution strings? They are also hard-coded at design time. You could use application items if you need something dynamic.
Bind variable syntax (:default_schema) will not work for lexical substitution of substitution string and application item values in report queries. You have to use static text (&DEFAULT_SCHEMA.) references (and be aware of the potential for SQL injection that this exposes).
I wouldn't recommend using schema qualifiers directly in APEX applications. I would use grants, synonyms and views at the database level. -
How to change recordset bahaviour to accept dynamic column names in the where clause
Hi
im using php-mysql and i make a recordset and i want to make the column names in the where clause to be dynamic like
"select id,name from mytable where $tablename-$myvar";
but when i do this my i break the recordset and it disappear
and when i use variables from advanced recordset it only dynamic for the value of the column not for the column name
and when i write the column name to dynamic as above by hand it truns a red exclamation mark on the server behaviour panel
so i think the only way is to change the recordset behaviour is it? if so How to make it accept dynamic column names?
thanks in advance.As bregent has already explained to you, customizing the recordset code will result in Dreamweaver no longer recognizing the server behavior. This isn't a problem, but it does mean that you need to lay out your dynamic text with the Bindings panel before making any changes. Once you have changed the recordset code, the Bindings panel will no longer recognize the recordset fields.
Using a variable to choose a column name is quite simple, but you need to take some security measures to ensure that the value passed through the query string isn't attempting SQL injection. An effective way of doing this is to create an array of acceptable column names, and check that the value matches.
// create array of acceptable values
$valid = array('column_name1', 'column_name2', 'column_name3');
// if the query string contains an acceptable column name, use it
if (isset($_GET['colname']) && in_array($_GET['colname'], $valid)) {
$col = $GET['colname'];
} else {
// set a default value if the submitted one was invalid
$col = 'column_name1'
You can then use $col directly in the SQL query.
Maybe you are looking for
-
'Fiscal year period not expected error in BI 7.0
Hi Guys, When I am loading data into Target(DSO, CUBE) It gives a error 'Fiscal year period not expected'. I got same error when I am loading into any target. Source is ECC 6.0 and Target is BI 7.0. I am extracting the data from FI/CO module. Could
-
An error occurred when executing a REMOTE FUNCTION CALL.
Dear all, We have two syetms called DXD and GRD , we have a remote enabled function module in the DXD system , when i am trying to call this Function module from GRD system it is going for the short dump, and giving the follwing error, <b>Error analy
-
In Finder since 10.8.3 – delay when quickly moving items around
I think this is new since the Finder of OS X 10.8.3. It's kind of hard to explain, but here goes: If one triest to move items around quickly after each other, there's like a second delay before you can do the second "grab". Like this: click and drag
-
Process Train Only goes Forward
I am trying to implement the process train sample from the programming guide. I have it all wired up and things show up correctly, but the process will only go foward, can anybody see something I missed? From my Faces File <!--First train node --> <m
-
Over all the sound on the z3 is good. It's loud when turn up the volume on music and videos but for some reason the notifications tone is lower than when I select it to preview. I did check the audio settings and made sure the notification Sounds are