SQL Table does not exist - sql

This is what happens:
SQL> select table_name from user_tables;
TABLE_NAME
------------------------------
Discount
Taxes
Customer
Vehicles
WorkOrder
Task
TaskPart
Employee
EmplyeeTask
WorkOrderPart
InvoiceDetails
TABLE_NAME
------------------------------
Invoice
Parts
InvoicePrimaries
14 rows selected.
SQL> select * from Discount;
select * from Discount
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL>
I can't access that table. I can make it work just fine in C#, but in the Oracle GUI and the SQL Command Line, I cannot select the table. (It's a personal, self made database using Oracle Express)

Because in user_tables the table names are written in upper and lower case letters. I assume that you created these tables using something like
create table "Discount" ...
Generally oracle saves tablenames in upper case letters and table names without double quotas are searched in uppercase. Therefore your
select * from Discount
searches for a table named DISCOUNT and not Discount. You have to explicitly tell oracle that you want to preserve the letter case of your table names. That is done with double quotas as well. So
select * from "Discount"
should work.

Related

Why SQL statements do not work in table created in Oracle10g

I have an Oracle SQL database with 2 scripts I uploaded to Oracle, one includes tables, the other includes the registries.
I have a table DEPARTMENTS with 2 columns, CODE and NAME.
From Oracle 10g SQL home > SQL workshop > SQL commands, I type in this statement:
SELECT CODE, NAME
FROM DEPARTMENTS
The result is
"No data found"
I cannot retrieve results correctly either in Oracle 10g nor in livesql.oracle.com.
Is my statement incorrect? Is it not retrieving the data uploaded?
Result should actually be "no rows selected", not "no data found".
You said you have two scripts; I presume that one of them contains something like this:
SQL> create table departments
2 (code number,
3 name varchar2(20));
Table created.
Basically, you created an empty table. If you query it, there's nothing in there:
SQL> select code, name from departments;
no rows selected
Therefore, the second script most probably contains statements that populate tables created in the first script. Is that what you call "registries"?
SQL> insert into departments (code, name)
2 select 1, 'Accounting' from dual union all
3 select 2, 'Finance' from dual;
2 rows created.
Let's repeat the previous select statement:
SQL> select code, name from departments;
CODE NAME
---------- ----------
1 Accounting
2 Finance
SQL>
Right; now we got the result.
On the other hand, maybe you actually ran both scripts, created tables and inserted rows, but you didn't commit at the end of the second script. If you then opened a new session (in Oracle 10g SQL home > SQL workshop > SQL commands), then you saw tables (because create table is a DDL and it modified data dictionary so select you wrote didn't return "ORA-00942: table or view does not exist"), but insert is a DML and you have to COMMIT - otherwise only that session (that ran inserts) will see data.
Finally, check whether insert statements completed successfully; if not, there's a chance that you didn't insert anything and will first have to fix errors. Which ones? No idea, I don't have those scripts nor saw the screen (or log file, if there is any).

No Such Column in SQLite Temporary Table Statement

I have two SQLite tables (companies and complaints) I'm using to calculate a ratio of HR complaints to employees, but when attempting to run the query below in DB Browser, I'm getting this error:
-- Result: no such column: complaints.hrcomplaints
Here's the SQL I'm using:
CREATE TEMPORARY TABLE newratio AS SELECT companies.uniqueID, employees, complaints.hrcomplaints,
(ROUND(hrcomplaints * 100.0 / employees, 1)*.01) AS newratio
FROM companies
ORDER BY newratio
The column type for both hrcomplaints and employees is integer. I'm not seeing any extra whitespace in the column names when viewing the DB structure.

Oracle DB: any function to select all the database columns except for one (which is known)? [duplicate]

This question already has answers here:
Can you SELECT everything, but 1 or 2 fields, without writer's cramp?
(12 answers)
Closed 5 years ago.
I am using Oracle Database and I need to realize a query which retrieves all the values of a table record (for a specific WHERE condition), except for one which is known.
Imagine to have the following table:
Sample table
Where you do not want to retrieve the "Age" column, but where - in next releases of the software - the table could have more columns respect to the ones actually present.
Is there any command in Oracle which excludes a specific column (always known, as in the example "Age") and allows me to retrieve all the other values?
Thanks in advance!
You can make that particular column Invisible using following query:
alter table TABLE_NAME modify COLUMN_NAME INVISIBLE;
This will exclude that column from select * statement unless and until you specify that particular column in select clause like below:
select COLUMN_NAME from TABLE_NAME;
From Your sample data:
alter table SAMPLE_TABLE modify Age INVISIBLE;
select * FROM SAMPLE_TABLE will produce
select FirstName, LastName, Address, City, Age from SAMPLE_TABLE will produce:
There are several approaches
1)You can set column UNUSED.It won't be retrieved (and it wont be used) with the queries. This would be permanent. You can't get then column back, the only allowed op would be DROP UNUSED COLUMNS.
ALTER TABLE sample_table SET UNUSED(age);
2)You can set column INVISIBLE, this is temporary. It won't be retrieved, unless you explicitly reference it in SELECT query.
ALTER TABLE sample_table MODIFY age INVISIBLE;
// to change it back to VISIBLE
ALTER TABLE sample_table MODIFY age VISIBLE;
3)Create VIEW without age column and then query view instead of querying TABLE.
CREATE VIEW sample_table_view AS
SELECT first_name, last_name, address, city FROM sample_table;

Oracle SQL - Column has no Corresponding Table

I came across something that makes no sense.
This is the SAAADMS form containing the Curriculum tab. The form has fields (columns) from different sources (tables). Most of these columns have a corresponding table, but the User ID and Activity Date (in the red rectangle) do not have a corresponding table!
You can see that the SOVLCUR_ACTIVITY_DATE and SOVLCUR_USER_ID do not have a corresponding table. It states "N/A." The other two columns I listed (I only listed a couple since there are several) do have a corresponding table.
I am trying to pull data from the two columns with no corresponding table.
The SOVLCUR table I currently have in the code does NOT exist.
How do I find where this SOVLCUR_USER_ID and SOVLCUR_ACTIVITY_DATE data is stored or pull from a column that seems to have no table?
If the data is not really stored in SOVLCUR_USER_ID and SOVLCUR_ACTIVITY_DATE is there a way for me to see where it is stored? find all associated columns?
SELECT
SP.SPRIDEN_ID AS "STUDENT_ID",
SP.SPRIDEN_LAST_NAME AS "LAST",
SP.SPRIDEN_FIRST_NAME AS "FIRST",
SD.SARADAP_TERM_CODE_ENTRY AS "TERM",
SD.SARADAP_APPL_DATE AS "APP_DATE",
SV.SOVLCUR_USER_ID AS "USER_ID", /*SOVLCUR table does not exist*/
SV.SOVLCUR_ACTIVITY_DATE AS "ACTIVITY_DATE", /*SOVLCUR table does not exist*/
SYSDATE
FROM
SPRIDEN SP
JOIN SARADAP SD
ON SPRIDEN_PIDM = SARADAP_PIDM
JOIN SOVLCUR SV /*This table does not exist*/
ON SPRIDEN_PIDM = SOVLCUR_PIDM
WHERE
SP.SPRIDEN_CHANGE_IND IS NULL
AND
SD.SARADAP_TERM_CODE_ENTRY >= '201510'
AND
SV.SOVLCUR_USER_ID NOT IN ('SSmith', 'JJones')
AND
SV.SOVLCUR_ACTIVITY_DATE BETWEEN SYSDATE-1 AND SYSDATE
Oracle provides views/tables that can be query to find out that type of information:
select table_name from all_tab_columns
where column_name = 'COLUMN NAME';
This query will return all the table where that column exists.
As user1261620 said, use ALL_TAB_COLUMNS to see the table_name corresponding to a column_name. But, as you say that few tables does not exist, perhaps, those are not tables, rather VIEWS.
To confirm whether those are TABLE or VIEW, you can query ALL_OBJECTS
SELECT object_name, object_type
FROM all_objects
WHERE object_name = 'SOVLCUR';
If the above returns no rows, that would mean the object really doesn't exist. But, in that case the query won't be executed, as it won't be parsed at all. You would get error : table/view does not exist`.
Also, not all values needs to be always stored in database. The computed values are generally calculated through a query and returned to the user for display. And other than computed values, few static values like SYSDATE can be dynamically generated rather than storing it in database and querying it.
So, I think, those are not tables, rather VIEWS. Follow the steps as I mentioned to have a clear understanding.
Update Based on OP's new inputs
So, now you know that SOVLCUR is a synonym. Execute the following query to see its details :
SELECT * FROM all_synonyms WHERE synonym_name = 'SOVLCUR';
For example,
I am user LALIT, and I create a synonym for EMP table in SCOTT schema.
SQL> show USER
USER is "LALIT"
SQL>
SQL> CREATE OR REPLACE SYNONYM lalit FOR scott.emp
2 /
Synonym created.
SQL>
SQL> SELECT owner, synonym_name, table_owner, table_name
2 FROM all_synonyms
3 WHERE synonym_name = 'LALIT'
4 /
OWNER SYNONYM_NAME TABLE_OWNER TABLE_NAME
---------- --------------- ------------ ----------
LALIT LALIT SCOTT EMP
So, the table_owner and table_name shows the SCHEMA is SCOTT and TABLE is EMP.

SQL select with "" netbeans without ""

I'm trying to bind data from SQL table to JTable using netbeans, but my database is reacting only if select is written as SELECT * FROM "table" and netbeans is using SELECT * FROM table without "". Can you tell me how to change it in netbeans to use "" or in Oracle SQL to don't need "?
When you use double quotes and lower case, table name is case sensitive . If not, Oracle converts it to upper case, and makes it non case sensitive . For instance,
create table "table1" (id int not null);
select * from table1 ; -- ORA-00942: table or view does not exist
select * from TABLE1; -- ORA-00942: table or view does not exist
select * from "table1"; --ok
----------------------------
create table table2 (id int not null); -- or TABLE2, or even "TABLE2"
select * from table2 ; -- ok
select * from TABLE2; --ok
select * from "TABLE2"; --ok
The same rule applied to other object names (such as fields, functions, procedures, packages, etc).
I'm not very familiar with netbeans but you usually should not need to put the table-name in quotes.
It sounds like your table-name has special characters in it. Have you tried it with another table?
Also your actual query would be useful.