Oracle: access to column with name "all" - oracle

everybody. I have table, where one of the column names is "All" and I want to get this column. I trying to use next simple query:
SELECT All
FROM TableName
, but I have ORA-00936. When I use just:
SELECT *
FROM TableName
I see required column with "All" name. In table specification I see next SQL script:
create table TableName
(
houseid NUMBER not null,
id NUMBER not null,
note VARCHAR2(255),
all NUMBER
)
How I can get access to "All" column?

SELECT "ALL" from TABLENAME
this is a good reason not to use oracle reserved keywords as table or column names but by using the doublequote " " you can access them.
Keep in mind that when you use " " you must be consistent in your case in the statement. Not "All" and "all" in the same statement

Put it in quotes.
SELECT "all"
FROM TableName

Related

oracle change sign before and after column name

in mysql we use ` sign before and after column name in query
i want support both oracle and mysql but in oracle ` not support and it most be change to "
is ther anyway to force oracle use ` instead of " for before and after column ?
for example this is my mysql query
SELECT * FROM `md_menu` where `place`='1' AND `adminid`='1' ORDER BY `order` ASC
but it most be change for oracle to this
SELECT * FROM "md_menu" where "place"='1' AND "adminid"='1' ORDER BY "order" ASC
is ther any way?
IMO instead of forcing oracle follow mysql syntax, it will be easier just make mysql follow standard ASCI syntax :
add this line at the top of your mysql syntax, then the identifier change to " for object, ' for string, just like oracle.
SET SESSION sql_mode = 'ANSI';
here is some demonstration :
SET SESSION sql_mode = 'ANSI';
create table "a"
(
id int,
col varchar(1)
);
insert into "a" values (1,'1');
insert into "a" values (2,'2');
select * from "a" where col = '1'
also db<>fidddle.
and I totally agree #P.Salmon mention in comment, avoid using reserved word as object name.

Invalid column ORA- 00904 error while inserting into table from view

In my main table having table structure column without double quotes but when in View column with double quotes. While inserting data from view into table then getting error.
Here is the table structure of tbl
create table tbl (ID number(10),
name varchar2(50),
addr varchar2(200));
While View is-
create or replace view t_view as
select "ID", "name", "addr" from tbl;
While inserting data into tbl from t_view -
insert into tbl
select * from t_view;
Then getting error ORA- 00904: "addr": Invalid identifier.
So how to resolve this issue, can i remove the double quotes from creation of view.
Remove all double quotes from everywhere in your code.
If you use them while creating objects, you'll have to use them always, specifying exactly same letter case.
Get rid of those, Oracle is - by default - case insensitive and treats all names as uppercase (but you can reference them any way you want, just don't use double quotes!).
Oracle stores the name of any object in UPPERCASE by default. If you have provided double quotes then only Oracle stores the name of the object as it is.
Double quotes - Case sensitive
No quotes - Case insensitive - Stores the name in UPPERCASE
In your case, While writing the DDL of the table, you have not provided the name of the column in double quotes so your table name and column names are stored in UPPERCASE in the metadata.
You can see the same using the following query
select table_name, column_name from user_tab_columns where table_name = 'TBL';
For giving your answer, create the view either of the following syntaxes:
create or replace view t_view as
select ID, name, addr from tbl; -- no double quotes
create or replace view t_view as
select "ID", "NAME", "ADDR" from tbl; -- UPPERCASE column names in double quotes
See the demo here
Cheers!!
What is it you are trying to accomplish. Your request just doesn't make sense. Your intended statement
insert into tbl select * from t_view;
accomplishes exactly the same thing as
insert into tbl select * from tbl;
It's not that you cann't do this (you can), but it can only cause massive duplicate data issues or (hopefully) unique constraint violations.

How to use temporary table slug in database?

This query not working
SELECT word_name, word_id from words where REPLACE(slug, '-', ' ') like '%word%' AND 1=1 ORDER BY
length(word_name) ASC LIMIT 8
P.S EDIT : sorry I gave up on this quetion. Please ignore this question.
Not sure you need all those steps. You can check for existance, define and select all in one statement for example
drop table if exists t;
create temporary table if not exists t
(id int)
select id from users;

Creating a view using subquery,with alias for columns in ORACLE 9i!

This is my query,
CREATE VIEW employee_vu AS(
SELECT employee_id,last_name "employee",department_id
FROM employees);
I am giving alias of columns in lower case ,and in it is stored in lower case
after doing desc i have confirmed.
But when i am trying to select this column employee :error occurs
EMPLOYEE: invalid identifier
Since all column name is stored in upper case ,is this the problem,Please explain what is the concept behind!
You would need to select it using double quotes and matching case:
select employee_id, "employee", department_id from employees;
That's why creating columns with double quoted identifiers is considered bad practice in Oracle.

Sequence with variable

In SQL we will be having a sequence. But it should be appended to a variable like this
M1,M2,M3,M4....
Any way of doing this ?
Consider having the prefix stored in a separate column in the table, e.g.:
CREATE TABLE mytable (
idprefix VARCHAR2(1) NOT NULL,
id NUMBER NOT NULL,
CONSTRAINT mypk PRIMARY KEY (idprefix, id)
);
In the application, or in a view, you can concatenate the values together. Or, in 11g you can create a virtual column that concatenates them.
I give it 99% odds that someone will say "we want to search for ID 12345 regardless of the prefix" and this design means you can have a nice index lookup instead of a "LIKE '%12345'".
select 'M' || my_sequence.nextval from dual;

Resources