Use of quotes in a table name?
Hello,
It seems Oracle treats a table name with and without quotes differently.
SQL> create table abc (x integer);
SQL> create table "abc" (y integer);
These two commands result in two different tables as can be seen from the following commands:
SQL> desc abc;
SQL> desc "abc";
However, I cannot get the list of tables.
SQL> select * from tab where tname like '%abc%';
returns just one row.
SQL> select * from all_objects where object_name like '%abc%' also does not show me abc and "abc" as two separate tables.
Q1. Is there a way to obtain the proper list?
Q2. What is the proper qualifier for specifing a table name? For example, SQL Server supports "[" and "]" around the table name. However, I could not find the equivalent grammar for PL/SQL.
The following command works (by trial and error):
SQL> select * from (abc);
However, the following doesn't:
SQL> drop table (abc);
which means that "(" and ")" are not the qualifiers.
Thank you in advance for your help.
Pradeep
Import and export and the other tools use quotes so
that objects will be properly re-created as they were
originally specified, even if some one uses reserved
words or case sensitive names. At least they should. I recently had a customer using FoxPro (!) to access my Oracle Datawarehouse and he named one of his column "ALTER" (age in german). Then he complained that my database is not working because he was getting an Oracle error (ORA-00936: missing expression)!
However, if some developer made me
type:
SELECT "MyCol1", "MyCol2", ...
FROM "HisTable"
WHERE "SomeStrangeColumnName" = 42every time,
I would think seriously of homocide :-).I know the feeling :-)
Similar Messages
-
Using a parameter for a table name?
In SQL Server, can you use a parameter for a table name? I'm working with Visual C# and want to do something like this:
SELECT MAX(ItemID) FROM @TableName;
Can this be done?
(Basically, I have three separate methods within a class--one for each table I have; and each one will perform the above query but on different table names. I'd like to see if there is a way that I can have just one method that will allow me to specify
the table name.)As pointed out in other posts, you can. But a more relevant question is whether you should.
A table in a relational database is supposed to model a unique entity, and each column in the table is supposed to model a unique attribute. This is not always how it is, but it is from this model a relational database is designed.
From this angle, having a dynamic table name does not really make sense for application code. (Administrative actions is a different story.) Think of it this way: have you ever wanted to make the class name dynamic in C#?
Admittedly, it is different in .NET, because everything inherits from System.Object, but in a relational database there is no inheritence.
Anyway, if you are using stored procedures, you should have one stored procedure per table. Physically, in the plan cache, there will be one query plan per table, no matter how you do it.
If you are submitting SQL statements from your application, it is a different matter. In this case, I find it difficult to object if you have a class that performs generic actions against tables. Then you build the SQL string in the client code.
However, no matter how you do it, you need to be careful to avoid SQL injection. We had the example:
DECLARE @TableName nvarchar(50),@sqlCommand nvarchar(max)
SET @TableName = ' ItemInformation'
SET @sqlCommand = 'SELECT MAX(ItemID) FROM ' + @TableName
EXEC (@sqlCommand)
But what if we have:
SET @TableName = ' sys.objects; SHUTDOWN WITH NOWAIT; --'
As long as we do it in T-SQL, we can (and we should do!) this to prevent SQL injection:
SET @sqlCommand = 'SELECT MAX(ItemID) FROM ' + quotename(@TableName)
If you build your SQL strings in C#, you will need to employ other checks. There is only an issue if the user can inject data somewhere, but your generic class will not have knowledge of this, and must assume the worst.
Erland Sommarskog, SQL Server MVP, [email protected] -
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 variable as a table name in PL/SQL?
Hello all.
I was given one day to wrote a piece of PL/SQL code to do a query. That is,
First select two columns from one table and use them to build another table's name, then
join the two tables. I'm not sure if variables can be used in the select list, if possible,
how to reference them?
-- My code is
DECLARE
tablename varchar2(40);
CURSOR c1 IS
select a.sourcesystemcode, a.adminorganizationno from cdb1.organization_mapping a
where exists( select 1 from cdb1.organization_mapping b where
a.cdborganizationno = b.cdborganizationno and a.adminorganizationno != b.adminorganizationno)
order by a.cdborganizationno,a.adminorganizationno;
v_src_sys_cod cdb1.organization_mapping.sourcesystemcode%TYPE;
v_adm_org_no cdb1.organization_mapping.adminorganizationno%TYPE;
BEGIN
OPEN c1;
LOOP
FETCH c1 INTO v_src_sys_cod, v_adm_org_no;
EXIT WHEN c1%NOTFOUND;
tablename := 'ODS1.SRC_' || v_src_sys_cod || v_adm_org_no || 'ACTORG_CURR';
select c.cdborganizationno, c.sourcesystemcode, c.adminorganizationno, c.sourceorganizationno, d.ibkcde, d.orgnam
from cdb1.organization_mapping c inner join tablename d on c.sourceorganizationno = d.orgidt;
END LOOP;
CLOSE c1;
END;
The error message says "... the table or view does not exist... line 18, column 66..."
It says the variable "tablename" wasn't build or build incorrectly.
Please give the solution.If the TABLEs being queried are already known, and it is just a matter of which one to query, perhaps you can CREATE a VIEW that uses all the TABLEs with a UNION ALL, and include an identifier COLUMN.
CREATE VIEW SRC_ALL_ACTORG_CURR
AS
SELECT 'aa' Name, ibkcde, orgnam FROM SRC_aa_ACTORG_CURR UNION ALL
SELECT 'bb' Name, ibkcde, orgnam FROM SRC_bb_ACTORG_CURR UNION ALL
SELECT 'cc' Name, ibkcde, orgnam FROM SRC_cc_ACTORG_CURR UNION ALL
SELECT 'dd' Name, ibkcde, orgnam FROM SRC_dd_ACTORG_CURR UNION ALL
SELECT 'ee' Name, ibkcde, orgnam FROM SRC_ee_ACTORG_CURR;
Then, in you query:
select c.cdborganizationno, c.sourcesystemcode, c.adminorganizationno, c.sourceorganizationno, d.ibkcde, d.orgnam
from cdb1.organization_mapping c inner join SRC_ALL_ACTORG_CURR d on c.sourceorganizationno = d.orgidt and d.Name = v_src_sys_cod || v_adm_org_no; -
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/ -
Can I use a cell text as table name
I would like to give my table name the same as the cell A1. the tables I am using are journals so the first cell is the date and I would like to give the table the same date. Can I link the two so I only have to write the date once?
lovattsa wrote:
I would like to give my table name the same as the cell A1. the tables I am using are journals so the first cell is the date and I would like to give the table the same date. Can I link the two so I only have to write the date once?
No. But, you can Copy the content of A1 and Paste into the Table Name field in the Sheets Pane.
Jerry -
Using sql query as a table name
hello,
I have a table(say table1) which is storing the names of some other tables. I want to access the name of a table from table1 using sql query and then use the result of this query as the table name to access the data from
retrieved table name. How can I do this ?
ex:
select * from (select tablename from table1 where tableid='1');
I want to do something likw this. How can I do this?I want to access the name of a table from table1 using sql query and then use the result of this query as the table name to access the data from retrieved table name. How can I do this ?e.g. like this:
SQL> with table1 as (
select 'emp' tablename from dual
select extractvalue(x.column_value, 'ROW/ENAME') ename
from table1, xmltable('ROWSET/ROW' passing dbms_xmlgen.getxmltype('select * from ' || tablename)) x
ENAME
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER
14 rows selected. -
Use a variable as a table name with NATIVE SQL
Hi all,
I am trying to execute a SELECT statement in order to fetch data from an external Oracle DB table to SAP with the following instructions:
EXEC SQL.
SELECT cityfrom, cityto
INTO STRUCTURE :wa
FROM spfli
WHERE mandt = :sy-mandt AND
carrid = :p_carrid AND connid = :p_connid
ENDEXEC.
However, I need to indicate the external table name from a variable instead of the solution above. That is, declaring a variable and store the name of the table (e.q. spfli) in it. The resulting ABAP code would be something like:
EXEC SQL.
SELECT cityfrom, cityto
INTO STRUCTURE :wa
FROM <VARIABLE>
WHERE mandt = :sy-mandt AND
carrid = :p_carrid AND connid = :p_connid
ENDEXEC.
Does anybody know if is possible to do that?
If not, is there any other solution?
Thank you in advanceYes, as Suhas said, you could use the ADBC API and his class CL_SQL_CONNECTION to achieve this...
Here is a small example:
PARAMETERS: p_carrid TYPE spfli-carrid,
p_connid TYPE spfli-connid.
DATA:
l_con_ref TYPE REF TO cl_sql_connection,
l_stmt TYPE string,
l_stmt_ref TYPE REF TO cl_sql_statement,
l_dref TYPE REF TO data,
l_res_ref TYPE REF TO cl_sql_result_set,
l_col1 TYPE spfli-carrid,
l_col2 TYPE spfli-connid,
l_wa TYPE spfli.
CONSTANTS:
c_tabname TYPE string VALUE 'SPFLI'.
* Create the connecction object
CREATE OBJECT l_con_ref.
* Create the SQL statement object
CONCATENATE 'select * from' c_tabname 'where carrid = ? and connid = ?'
INTO l_stmt SEPARATED BY space. "#EC NOTEXT
l_stmt_ref = l_con_ref->create_statement( ).
* Bind input variables
GET REFERENCE OF l_col1 INTO l_dref.
l_stmt_ref->set_param( l_dref ).
GET REFERENCE OF l_col2 INTO l_dref.
l_stmt_ref->set_param( l_dref ).
* Set the input value and execute the query
l_col1 = p_carrid.
l_col2 = p_connid.
l_res_ref = l_stmt_ref->execute_query( l_stmt ).
* Set output structure
GET REFERENCE OF l_wa INTO l_dref.
l_res_ref->set_param_struct( l_dref ).
* Show result
WHILE l_res_ref->next( ) > 0.
WRITE: / 'Result:', l_wa-carrid, l_wa-connid.
ENDWHILE.
* Close the result set object
l_res_ref->close( ).
Otherwise you can also use the FM DB_EXECUTE_SQL...
Kr,
m. -
Use of ( * ) prefix before the table name
Friends,
Can anybody clear me the importance of prefixing the *(asterik) before the table name in the program.
Eg. Tables: *mara,
*cstk.
Many Thanks,
Albert.When you need two distinct work areas of the same database table in your program, you can use two tables declarations like
Tables: mara, *mara.
Typical use is on a screen, that has a table control. Here same table fields may appear on the main screen as well as in the table control. You use normal work area ( mara) to refer to main screen fields and the other work area ( *mara) for table control fields. -
PL/SQL - Using a variable as a table name
I have a procedure like this -
PROCEDURE insert_food IS
BEGIN
INSERT INTO food_table
SELECT *
FROM fruit_table;
END insert_food;
So this proceudre would insert all the records in the 'fruit_table' into the 'food_table'.
Would there be any way to store the 'fruit_table' as a variable and use that in the script?
Something like -
PROCEDURE insert_food IS
table_name varchar(11) := 'fruit_table';
BEGIN
INSERT INTO food_table
SELECT *
FROM table_name;
END insert_food;
Any help would be great!create or replace PROCEDURE insert_food IS
table_name1 varchar(11) := 'emp';
BEGIN
execute immediate 'INSERT INTO emp2
SELECT *
FROM '||table_name1||'';
commit;
END insert_food;then
exec insert_food; -
Bug With Quoted Table Names?
I think I've encountered a bug in Oracle 9.2.0.1.0. If I create table with its name in quotes, I can't access it again unless I also use the name in quotes. But, in DBA_OBJECTS the table's name shows up without quotes.
For example:
CREATE TABLE "avalys" (test number);
SELECT * FROM "avalys"; --Works
SELECT * FROM avalys; --Doesn't
Any idea what the problem could be? Am I just not supposed to quote table names (I need to, because one of our tables is a reserved word, and unfortunately we can't change the name of the table).When you put quotes around a table name, you're telling Oracle to store the table name in a case-sensitive fashion, rather than the default case-insensitive fashion. When you use a non-quoted identifier, Oracle automatically upcases the whole thing and tries to resolve the name. Thus, you can do the following (not the uppercase table name in quotes)
SQL> create table "FOO" (n1 number);
Table created.
SQL> select * from foo;
no rows selected
because "select * from foo" implicitly upcases foo. If you declare a table with some lowercase letters, i.e.
SQL> create table "FOo" (n1 number);
Table created.
you'll only be able to access it with the same partially lowercase string, i.e.
SQL> select * from "FOo"
no rows selected
Justin -
Jdoql sql error.. puzzled why it puts quotes in table name
I keep getting a jdoql error when running my entity bean.. basically, something is wrong with the sql command the entity bean passes to the database.. when i set the log file to "fine" and looked at the log file, this is the sql statement it passes to the driver:
SQL statement<select t0."id", t0."parent_category", t0."name", t0."available", t0."available_date" from "drs_category" t0 where t0."genotype" = ?> with input values:
I noticed that it put quotes between the table name!!! this will always give me a syntax error if i run this quote straight into the informix database.. the problem is, where do i tell it to take out the quotes since it's programmed into the jdoql class... btw, i am using an informix databasenevermind... i figured it out.. create file INFORMIX DYNAMIC SERVER.properties and put in appserv-cmp.jar ..add these lines to the file:
# default properties for Informix SQL generation
FOR_UPDATE=for update
LEFT_JOIN=, outer
RIGHT_JOIN=,
RIGHT_JOIN_PRE=outer
IS_NULL=\= NULL
IS_NOT_NULL=!= NULL
RTRIM=trim (trailing \" \" from
RTRIM_POST=)
QUOTE_CHAR_START=
QUOTE_CHAR_END= -
Mixed case in column & table name
Hi,
How can tell SQL to use mixed case for column & table name?
For example:
create table PerNode (netId number, nodeId number);
select netId, nodeId from PerNode;
The above statements automatically made to upper case. But I wanted to retain the case sensitiveness in the column & table names.
I know a way by including the names in double quote in the case will make this to retain the case.
But I don't want to give all the time the column & table names within double quote.
What I wanted to know is that is there any ALTER kind of statement will make the SQL to use the case I use in the name of the column & table.
I greatly appreciate your advice.
Thanks,
--JKOracle column names and table names are case insensitive unless you enclose them in quotes.
Unless you want to have two tables, one called PerNode and one called pernode or some such, I'm not sure what benefit case sensitivity would have. One can certainly use mixed case SQL statements in stored procedures and ad-hoc SQL for readability-- only in the Oracle internals is everything changed to upper case.
Justin
Distributed Database Consulting, Inc.
www.ddbcinc.com/askDDBC -
How to change table name after creating page and application
Hi HTMLDB Team,
i have created a application with page where the region use master detail form with table name emp.Now after developing the page and the application i want to change the table from emp to emp2 where emp2 is the table with same structure of existing emp and same field properties.How can i edit the table as emp2 ?
Thanks in advance,
Cheers,
koushikKoushik,
Depending on the amount of customizations that you did, it may be easier to use the wizard to re-create the master-detail form & report.
If you still want to give it a go:
Assuming that you created the 2-page Master Detail report & form:
On the first page, you will have to chage the SQL to reflect the new table name. Once you do that, you'll have to re-create the link on the EMPID column.
On the second page, you'll need to do some more work. You'll have to change both Page Rendering Processes: Fetch Row from EMP and Get Next or Previous Primary Key. You'll then need to change the Page Processing Process: Process Row of EMP. Also, ensure that you have a proper Foreign Key relationship between EMP2 and DEPT (or your detail table).
Thanks,
- Scott - -
If I select table name from dba_tables for owner PONTO, I receive a table named ti87, written just like this, not TI87.
If I try to desc ponto.ti87, I receive an ORA-04043: object does not exist.
What kind of table is this? Does anybody know?
Thanks,
Julio PeixotoTry this and see if it works:
desc desc ponto."ti87"
The table name was created case sensitive. You need to put the double quotes around the table name to tell Oracle
the table name is case sensitive.
Maybe you are looking for
-
Creative cloud won't load, nor can I shut it down. Every time I click on the icon the drop down is blank. (using a mac)
-
Acrobat v9.5: Insufficient data for an image
Hi, There are several cases where I have scanned in a document on a Konica Minolta c203 or c451 and have been unable to open the file in Acrobat v9.5. The document fails to open with "Insufficient data for an image" error. I'm using Windows XP sp3.
-
Authorization in WAD 7.0
hi , i want to learn if there is a way of authorization reports in WAD 7.0 and i want to learn how to make a role menu in WAD 7.0 it was possible to make a role menu in WAD 3.5 but i can not make it in WAD 7.0 Thanks for answers.
-
Help With Essbase Outline Extractor Output
Hello Gurus I am using Essbase Outline Extractor 9.3.1 to extract from Essbase 9.3.1 and I need a bit of a hand interpreting the results\Output. I'm after properties but Dynamic Calc, Shared Member, Never Share, & the Aggregation. Can anyone please h
-
Watchguard IPS blocks help desk requests - sporadic
I have some staff members that receive a message from our Watchguard XTM 1250(enterprise firewall) when trying to submit a ticket for our IT Department. In the past this has never been an issue, but after the last 2 updates to SW they have been getti