Specify schema name in select statements
Is there a way to specify the schema name for the connection so that I don't have to specify schema name with every statement?
Currently I am executing the statement:
Statement stmt = null;
ResultSet rs = null;
String getAllNames =
"SELECT NAME FROM " + schemaName +".NAMES " + schemaName +" WHERE STATUS_CODE != 12 ";
stmt = conn.createStatement();
rs = stmt.executeQuery(getAllNames);
But I have a lot of such statements, a few which uses parameters.
Is there a way I can specify the schemaName once and for all so that I don't have to perform string concat everytime the function is invoked.
well I tried that, since the application runs under CICS which uses the trusted connection with DB2, all CICS application will be using the same userid and there is no way to ensure that other applications would not be using the same table name in some other application. So the only option I have is to specify the schema name with the select statements but I don't want to append the schema name with each statement.
Similar Messages
-
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)
-
Need to include table name,schema name in select output
I need to output the table name and schema name of the current user into a table.. I have tried including
within a select statement..
table_name,
from user_tables
where table_name='mnme';
no rows returnedHi,
Its in upper case 'MNME'
Best.
EA -
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. -
Dynamically assigning table name in select statement
how can i assign the table name dynamically in Select statement?
i tried following code
create or replace procedure proc1
as
x varchar2(100);
y varchar2(10);
begin
x='UNIT_MASTER';
execute immediate 'select unit_code into y from x where
rownum=1';
dbms_output.put_line(y);
end;
the procedure is created but when i execute the procedure the
error is shown in the execute immediate statementDo the following :
Create or replace procedure pro1 as
x varchar2(100);
y varchar2(10);
begin
x := 'UNIT_MASTER';
EXECUTE IMMEDIATE 'select unit_code from '||x||' where rownum
= 1' INTO y;
dbms_output.put_line(y); -
Get the table names from a specified schema name
Can't any one can hlep me how to use OCIDescribeAny() to retrive the list of table names for a given schema name?
I have problem when I connect to the database using syste as usr id. I can't ge the table name form the SCOTT schema.If I understand you correctly, I don't think OCIDescribeAny() is the way to go.
You can get a list of tables owned by a particular schema by using the following SQL:-
SELECT TABLE_NAME FROM DBA_TABLES WHERE OWNER = 'SCOTT'
Just change the where clause to your needs.
Regards.
Adrian -
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. -
Cannot use alias for dynamic column name in SELECT statement
Hi,
I want to retrieve values from several tables by using dynamic column & table name as below:
DATA: tbl_name(30) TYPE c VALUE '/bic/tbi_srcsys', " staticly initialized for this example
col_name(30) TYPE c VALUE '/bic/bi_srcsys'. " staticly initialized for this example
SELECT (col_name) INTO CORRESPONDING FIELDS OF TABLE it_values FROM (tbl_name).
The internal table "it_values" does not contain a field named "/bic/bi_srcsys", instead it has another generic field "value" so that the above code can be applied to other tables. I tried to use alias (AS) as below:
SELECT (col_name) AS value INTO CORRESPONDING FIELDS OF TABLE it_values FROM (tbl_name).
But this cannot work. I know that there are other ways to solve this problem, such as by using a single field in SELECT .. ENDSELECT and subsequently appending it to the work area and internal table as below:
SELECT (col_name) INTO (lv_value) FROM (tbl_name).
wa_value-value = lv_value.
APPEND wa_value TO it_values.
ENDSELECT.
Just wonder if there is any other more elegant workaround, because I might have several other fields instead of only one?
Thanks.
Regards,
Joon MengHi Suhas,
thanks for the quick reply.
Sorry that I have not well described the structure of the internal table "it_values". This internal table contains several other fields (key, type, value, etc.).
I guess that the following code
SELECT (col_name) INTO TABLE it_values FROM (tbl_name).
works if the internal table only has one field (value) or the field "value" is in the first position, right?
In this case, I need to fill the "value" field of internal table it_values (ignore the other fields like type, key) with values retrieved from (col_name) of the DDIC table.
Looking forward to your reply.
BR,
Joon Meng -
Short table name in SELECT statement
Does Oracle support anything like the following sintax:
SELECT * FROM TABLE1 AS T1
Thanks in advancesyntex use like....
create table T1 select * from T2.
test@ORA10G>
test@ORA10G> create table t2 (x number);
Table created.
test@ORA10G> create table T1 select * from T2;
create table T1 select * from T2
ERROR at line 1:
ORA-00922: missing or invalid option
test@ORA10G>
test@ORA10G>pratz -
Secondary Index Select Statement Problem
Hi friends.
I have a issue with a select statement using secondary index,
SELECT SINGLE * FROM VEKP WHERE VEGR4 EQ STAGE_DOCK
AND VEGR5 NE SPACE
AND WERKS EQ PLANT
%_HINTS ORACLE
'INDEX("&TABLE&" "VEKP~Z3" "VEKP^Z3" "VEKP_____Z3")'.
given above statement is taking long time for processing.
when i check for the same secondary index in vekp table i couldn't see any DB index name with vekp~z3 or vekp^z3 or vekp____z3.
And the sy-subrc value after select statement is 4. (even though values avaliable in VEKP with given where condition values)
My question is why my select statement is taking long time and sy-subrc is 4?
what happens if a secnodary index given in select statement, which is not avaliable in that DB Table?Hi,
> ONe more question: is it possible to give more than one index name in select statement.
yes you can:
read the documentation:
http://download.oracle.com/docs/cd/A97630_01/server.920/a96533/hintsref.htm#5156
index_hint:
This hint can optionally specify one or more indexes:
- If this hint specifies a single available index, then the optimizer performs
a scan on this index. The optimizer does not consider a full table scan or
a scan on another index on the table.
- If this hint specifies a list of available indexes, then the optimizer
considers the cost of a scan on each index in the list and then performs
the index scan with the lowest cost. The optimizer can also choose to
scan multiple indexes from this list and merge the results, if such an
access path has the lowest cost. The optimizer does not consider a full
table scan or a scan on an index not listed in the hint.
- If this hint specifies no indexes, then the optimizer considers the
cost of a scan on each available index on the table and then performs
the index scan with the lowest cost. The optimizer can also choose to
scan multiple indexes and merge the results, if such an access path
has the lowest cost. The optimizer does not consider a full table scan.
Kind regards,
Hermann -
Index not being used in Select statement
Friends
I have the following SQL statement:
SELECT
a.acct,
a.date_field,
UPPER(b.feegroup) feegrp,
SUM (a.fee1) fee1,
SUM (a.fee2) fee2,
SUM (a.fee3) fee3
FROM table1 a, table2 b
WHERE 1 = 1
AND a.fee_id = b.fee_id
GROUP BY a.acct, a.date_field, b.feegroup;
Both the tables have index on fee_id column. When I run the explain plan for this statement, I am getting the following output:
Operation | Option | Object Name | Position
SELECT STATEMENT | | | 560299
HASH | GROUP BY| |1
TABLE ACCESS | FULL| table2 | 1
TABLE ACCESS | FULL| table1 | 2
Why Oracle is not using the index?
Edited by: darshilm on Dec 10, 2009 3:56 PMThe proposed plan is the optimal according to your current conditions in the "where clause" where you have only the equality join condition and therefore the CBO can use HASH JOIN. Using any kind of index access would just increase the amount of required work unless you would add some very restrictive conditions which will select rows from relatively small amount of blocks. Here I have to mention that what really counts in the CBO cost calculation is the amount of blocks accessed and not the number of rows. The "currency" for I/O in Oracle is a block and not a row. CBO always uses an assumption that there is nothing in the buffer cache and it will have to perform a physical read for every block.
How many blocks will actually be accessed depends on the data distribution. It can happen that every single row that you have to retrieve resides in a different block and although you access only 1000 rows out of a million row table you would have to visit almost every block of that table. For such a situation a FULL TABLE SCAN is the best access path and Oracle will use multiblock I/O for that. On the other side you can have those 1000 rows only in a few blocks and then the index access would be the most appropriate one. For index access Oracle uses single block I/O. Usually the actual situation is somewhere between this two extreme situations. But you can run some tests by yourself and see when an index access will be replaced by a full table scan while you will make your predicates less selective.
HTH, Joze
Co-author of the forthcoming book "Expert Oracle Practices"
http://www.apress.com/book/view/9781430226680
Oracle related blog: http://joze-senegacnik.blogspot.com/
Blog about flying: http://jsenegacnik.blogspot.com/
Blog about Building Ovens, Baking and Cooking: http://senegacnik.blogspot.com -
Retrieve floating point data with an sql select statement
Hi
I'm quite new to using sql but I have a system working where I can read and write strings to an access database.
Now I want to retrieve a a float, from a field where another field in the same post corresponds to a specified float, with a select statement.
When using strings I wrote
SELECT column_name FROM [table_name] WHERE column2_name='value'
in my query.
But instead of getting the desired value I get an error message telling me that I have a
"Data type mismatch in criteria expression".
I think I understand why but does anybody know what I should have written instead?Is the data type of column2_name String? If it's not, I think the single-quotes you have around 'value' will cause that error.
Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice -
Generating SQL SELECT statement with Schema
I develop a 3rd-party application that connects to various
databases via ODBC. Our program generates the SQL statement
so that the user does not have to. When connecting to oracle the
user often gets the error message: ORA-00942: table or view does
not exist.
To work around this our tech support department has tells the
customer to enter in the Schema name before the table name.
Thus,
SELECT ItemNo from Item
becomes
SELECT ItemNo from MySchema.Item
Is there a way that I can query the Data Source to find out
the Schema name so that our program can put in in the
statement. Is there a SQLGetInfo call I can make to get
this information?
Or, should I have the Server specified in the connection
string? For SQL Server we use SQLGetPrivateProfileString to
obtain the server name and then include it in the connection
string: SRVR=<servername>
Unfortunately, if this is the case the keyword is different
depending on the ODBC Driver involved. "Server" for Microsoft.
"SRVR" for Intersolv. "ServerName" for Oracle.
Note: We do not have Oracle in-house to test with. I'm
wondering if we could get Oracle for free for development
purposes.
Any and all information would be greatly appreciated.Thanks for the tip. I just finished downloading Oracle.
One user is able to successfully view the database with the
statement:
SELECT ItemNo from Item
But if another user tries it he gets the "table or view not
found" message. Changing the statement as follows will allow
the 2nd user to view the database:
SELECT ItemNo from "MAXIMO".Item
I want my application to query the database via ODBC for the
"MAXIMO" string so I can create the correct SQL statement.
Thanks!
<<Are you trying to view tables from a non-default schema?>>I don't know. You would know better than me from my
description. -
Access other schema's table without specify the schema name
Hi, need ur help again,
I would like to access other schema's table without specify the schema name. for example,
select * from hr.jobs;
What priviledges i need if i want to select the data in this way:
select * from jobs;
Thanks!Public synonyms have their place, but are not generally a good idea as they will cause conflicts with other schemas and applications. Another think that you can do is issue the
ALTER SESSION set CURRENT_SCHEMA = schema;
The CURRENT_SCHEMA (8i and above) parameter changes the current schema of the session to the specified schema. Subsequent nqualified references to schema objects during the session will resolve to objects in the specified schema. The setting persists for the duration of the session or until you issue another ALTER SESSION SET CURRENT_SCHEMA statement. CURRENT_SCHEMA is a session parameter only, not an initialization parameter.
This setting offers a convenient way to perform operations on objects in a schema other than that of the current user without having to qualify the objects with the schema name. This setting changes the current schema, but it does not change the session user or the current user, nor does it give you any additional system or object privileges for the session. -
Is there any way to Mask the Name when a select statement is issued?
Dear all,
Is there any way to mask the name .. i mean if User issue a select statement in a customer table the real name should come like ' ABCXXXDEFXXCFXX'... Which is not the actual name?
e.g if Name: CHIEV SONG MEE
If user issue a statment select * from customers;
The Result Should come something Like this:
Name
CHXXV SXNG MXX
Thank Youuser3029023 wrote:
but it seems there is no option in oracle it self which can be used as there they are saying to get a data masking software which we can't due to some internal issues....I would not say that. How one implements masking depends entirely on the requirements that need to be met.
For example, schema A owns all the tables. Schema B can be created as a "trusted" schema - in other words, schema A trusts schema B and allows it full access (with grants) to its tables. Schema B implements data masking as views. For each table in A, a view exists in B that implements the required masking. B can now grant select access on these views to user C. User C will see the same data object names in B as it would have if it used A - only, by using the B data objects it uses masked data objects and not the original source data objects.
Another example - schema Dev is to have all the data objects of schema Prod, but masked where needed. One can use CTAS (Create Table As Select) to create the required tables in Dev with masked values where relevant. This Dev schema can be "refreshed" on weekends by dropping all tables and getting a new fresh copy of production data and masking it - ready for the next week's development cycle.
If the application use is for example APEX, then instead of coding SQL directly as reporting regions to display, a function is used instead. APEX supports reporting regions where it calls a function and this function provides the APEX run-time with the SQL to execute and contents to render. It is easy to use this approach to implement logic in functions that masked column data depending on who the APEX user is, the security/role attributes of the user, and so on.
No there is not a single "+mask this column!+" feature in Oracle.. but that does not mean that such a feature is not supported and cannot be implemented. Oracle has a very comprehensive and rich set of tools - more so than most (if not all) other RDBMS products.
It is up to the architect/designer/developer to use this toolkit in creating a system that meets the specific requirements at hand.
Maybe you are looking for
-
Mac Pro - Separate HD for OSX and Windows?
Hello Mac Pro users - maybe some of you can help... Are going to buy a Mac Pro soon - which will be used for graphic artwork and Windows games. Today I have a Mac and a PC - for the same purpose - and now I want to build the Mac Pro with a harddisk f
-
The Mac version didn't seem to work as well as the Windows version but that may have been the result of transferring data from W to Mac. The sync function is useful. There are a lot of apps in the App Store are any of them as good as Roboform? The
-
Clearing agent service tax in import po
Hi, How to map Customs clearing agent service tax in import po? for ex: clearing agent service charge - Rs.2000 service tax 10% - Rs.200 E CESS 2% on ST - Rs.4 SHE CESS 1% on ST - Rs.2 Kindly give your suggestions Regards, Ramesh Kumar. V
-
HT201365 i have problem the server in not reach
i have iphone 4s and i turned on find my iphone but now show me a message that server is not reach and my iphone is turned lock
-
Read GP context data dynamically
Hi Experts, I am trying to achieve following 1) First WebDynpro GP callable object u2013 FirstCO Has a GP output node as data node. DataA This data node fields/attributes are decided dynamically in the program 2) Second WebDynpro GP callable object -