Query emp table in oracle 19c - sql

make a java program that queries the inbuilt table “emp” and display the first two columns (empno using column index and ename using column name ) of all the rows.
But problem here is :
ERROR:
ORA-04043: object emp does not exist
I am using oracle 19c on windows platform and using pluggable database orclpdb user "hr".
please tell me where to find this emp table.
And second question :
Even if I manually create a new Emp table in hr user ,what will be the sql command for the given
/*
* Using
* queries the inbuilt table “emp” and
* displays the first two columns
* (empno using column index and ename using column name )
* of all the rows.
*/
just tell me the sql command only.

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.

Simplest way to get inputs from text/xls file for update/delete SQL statement without using temp table/external table concepts

update department
set department_name = 'test.txt'
where department_id ='test.txt'
In other words: I simply need to get inputs for update statement from file (text file/xls) without using external table or temp table concepts in database.

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;

In creating a new table in SQL Server 2005

I have a table Company. Now I need to copy the contents of table Company in a new table Employee (that too while creating the Employee table). I just used the query shown below, but its showing an ERROR.
Create Table Employee as (Select * from Company)
Is there any other solution for this....?
Simply use INTO:
Select * into Employee from Company