Questions tagged [oracle]
Oracle Database is a Multi-Model Database Management System created by Oracle Corporation. Do NOT use this tag for other products owned by Oracle, such as Java and MySQL.
150,654
questions
1324
votes
15
answers
2.3m
views
How do I limit the number of rows returned by an Oracle query after ordering?
Is there a way to make an Oracle query behave like it contains a MySQL limit clause?
In MySQL, I can do this:
select *
from sometable
order by name
limit 20,10
to get the 21st to the 30th rows (skip ...
1206
votes
25
answers
2.4m
views
Get list of all tables in Oracle?
How do I query an Oracle database to display the names of all tables in it?
668
votes
35
answers
686k
views
Fetch the rows which have the Max value for a column for each distinct value of another column
Table:
UserId, Value, Date.
I want to get the UserId, Value for the max(Date) for each UserId. That is, the Value for each UserId that has the latest date.
How do I do this in SQL? (Preferably Oracle....
516
votes
18
answers
1.3m
views
How to create id with AUTO_INCREMENT on Oracle?
It appears that there is no concept of AUTO_INCREMENT in Oracle, up until and including version 11g.
How can I create a column that behaves like auto increment in Oracle 11g?
490
votes
34
answers
1.1m
views
How to select the nth row in a SQL database table?
I'm interested in learning some (ideally) database agnostic ways of selecting the nth row from a database table. It would also be interesting to see how this can be achieved using the native ...
459
votes
11
answers
623k
views
Can a foreign key be NULL and/or duplicate?
Please clarify two things for me:
Can a Foreign key be NULL?
Can a Foreign key be duplicate?
As fair as I know, NULL shouldn't be used in foreign keys, but in some application of mine I'm able to ...
447
votes
28
answers
783k
views
Is there a combination of "LIKE" and "IN" in SQL?
In SQL I (sadly) often have to use "LIKE" conditions due to databases that violate nearly every rule of normalization. I can't change that right now. But that's irrelevant to the question.
Further, I ...
443
votes
9
answers
686k
views
How to generate an entity-relationship (ER) diagram using Oracle SQL Developer
I want to use Oracle SQL Developer to generate an ER diagram for my DB tables but I am new to Oracle and this tool.
What is the process for creating an ER diagram in SQL Developer?
427
votes
8
answers
769k
views
What is the difference between Views and Materialized Views in Oracle?
What is the difference between Views and Materialized Views in Oracle?
416
votes
16
answers
658k
views
Oracle: If Table Exists
I'm writing some migration scripts for an Oracle database, and was hoping Oracle had something similar to MySQL's IF EXISTS construct.
Specifically, whenever I want to drop a table in MySQL, I do ...
401
votes
12
answers
363k
views
Liquibase lock - reasons?
I get this when running a lot of liquibase-scripts against a Oracle-server. SomeComputer is me.
Waiting for changelog lock....
Waiting for changelog lock....
Waiting for changelog lock....
Waiting ...
374
votes
9
answers
820k
views
Best way to do multi-row insert in Oracle?
I'm looking for a good way to perform multi-row inserts into an Oracle 9 database. The following works in MySQL but doesn't seem to be supported in Oracle.
INSERT INTO TMP_DIM_EXCH_RT
(EXCH_WH_KEY, ...
372
votes
15
answers
1.0m
views
Update statement with inner join on Oracle
I have a query which works fine in MySQL, but when I run it on Oracle I get the following error:
SQL Error: ORA-00933: SQL command not properly ended
00933. 00000 - "SQL command not properly ...
359
votes
15
answers
291k
views
Difference between a user and a schema in Oracle?
What is the difference between a user and a schema in Oracle?
337
votes
11
answers
531k
views
Is there any boolean type in Oracle databases?
Is there any Boolean type in Oracle databases, similar to the BIT datatype in Ms SQL Server?
331
votes
11
answers
526k
views
How to UPSERT (update or insert into a table?)
The UPSERT operation either updates or inserts a row in a table, depending if the table already has a row that matches the data:
if table t has a row exists that has key X:
update t set mystuff......
330
votes
31
answers
2.1m
views
ORA-12514 TNS:listener does not currently know of service requested in connect descriptor
We have an application running locally where we're experiencing the following error:
ORA-12514: TNS:listener does not currently know of service requested
in connect descriptor
I've tested the ...
327
votes
8
answers
1.3m
views
Update a table with data from another table
Table 1:
id name desc
-----------------------
1 a abc
2 b def
3 c adf
Table 2:
id name desc
-----------------------
1 x 123
2 y 345
In ...
315
votes
13
answers
1.2m
views
How do I list all the columns in a table?
For the various popular database systems, how do you list all the columns in a table?
310
votes
13
answers
843k
views
How do I find duplicate values in a table in Oracle?
What's the simplest SQL statement that will return the duplicate values for a given column and the count of their occurrences in an Oracle database table?
For example: I have a JOBS table with the ...
307
votes
6
answers
373k
views
What is the difference between varchar and varchar2 in Oracle?
What is the difference between varchar and varchar2?
306
votes
17
answers
686k
views
How can I create a copy of an Oracle table without copying the data?
I know the statement:
create table xyz_new as select * from xyz;
Which copies the structure and the data, but what if I just want the structure?
304
votes
21
answers
574k
views
Select count(*) from multiple tables
How can I select count(*) from two different tables (call them tab1 and tab2) having as result:
Count_1 Count_2
123 456
I've tried this:
select count(*) Count_1 from schema.tab1 union all ...
303
votes
19
answers
144k
views
Inner join vs Where
Is there a difference in performance (in oracle) between
Select * from Table1 T1
Inner Join Table2 T2 On T1.ID = T2.ID
And
Select * from Table1 T1, Table2 T2
Where T1.ID = T2.ID
?
298
votes
7
answers
630k
views
Oracle "Partition By" Keyword
Can someone please explain what the partition by keyword does and give a simple example of it in action, as well as why one would want to use it? I have a SQL query written by someone else and I'm ...
295
votes
8
answers
774k
views
How to connect to Oracle using Service Name instead of SID
I have a Java application that uses JDBC (via JPA) that was connecting to a development database using hostname, port and Oracle SID, like this:
jdbc:oracle:thin:@oracle.hostserver1.mydomain.ca:1521:...
292
votes
9
answers
871k
views
How do I do top 1 in Oracle? [duplicate]
How do I do the following?
select top 1 Fname from MyTbl
In Oracle 11g?
272
votes
3
answers
112k
views
Oracle SQL Developer multiple table views
In Oracle SQL Developer, one can list the data in a table using the Data tab when viewing a table. there where can add, delete, edit or just viewing records of table currently viewd
the problem is ...
265
votes
7
answers
374k
views
Case insensitive searching in Oracle
The default behaviour of LIKE and the other comparison operators, = etc is case-sensitive.
Is it possible make them case-insensitive?
265
votes
6
answers
673k
views
How to export query result to csv in Oracle SQL Developer?
I'm using Oracle SQL Developer 3.0. Trying to figure out how to export a query result to a text file (preferably CSV). Right clicking on the query results window doesn't give me any export options.
261
votes
12
answers
161k
views
Non-Repeatable Read vs Phantom Read?
What is the difference between non-repeatable read and phantom read?
I have read the Isolation (database systems) article from Wikipedia, but I have a few doubts. In the below example, what will ...
259
votes
14
answers
280k
views
What is the dual table in Oracle?
I've heard people referring to this table and was not sure what it was about.
250
votes
16
answers
1.4m
views
ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
Why am I getting this database error when I update a table?
ERROR at line 1:
ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
241
votes
10
answers
75k
views
Why does Oracle 9i treat an empty string as NULL?
I know that it does consider ' ' as NULL, but that doesn't do much to tell me why this is the case. As I understand the SQL specifications, ' ' is not the same as NULL -- one is a valid datum, and ...
239
votes
8
answers
280k
views
Oracle Differences between NVL and Coalesce
Are there non obvious differences between NVL and Coalesce in Oracle?
The obvious differences are that coalesce will return the first non null item in its parameter list whereas nvl only takes two ...
239
votes
9
answers
596k
views
How can I set a custom date time format in Oracle SQL Developer?
By default, Oracle SQL developer displays date values as 15-NOV-11. I would like to see the time part (hour/minute/second) by default.
Is there a way to configure this within Oracle SQL Developer?
230
votes
12
answers
388k
views
How can I find which tables reference a given table in Oracle SQL Developer?
In Oracle SQL Developer, if I'm viewing the information on a table, I can view the constraints, which let me see the foreign keys (and thus which tables are referenced by this table), and I can view ...
228
votes
11
answers
723k
views
What's the difference between RANK() and DENSE_RANK() functions in oracle?
What's the difference between RANK() and DENSE_RANK() functions? How to find out nth salary in the following emptbl table?
DEPTNO EMPNAME SAL
------------------------------
10 rrr 10000....
225
votes
9
answers
167k
views
When do I need to use a semicolon vs a slash in Oracle SQL?
We have been having some debate this week at my company as to how we should write our SQL scripts.
Background:
Our database is Oracle 10g (upgrading to 11 soon). Our DBA team uses SQLPlus in order ...
219
votes
12
answers
316k
views
What is the maximum length of a table name in Oracle?
What are the maximum length of a table name and column name in Oracle?
219
votes
33
answers
1.1m
views
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
I have installed Oracle 11g Express Edition Release 2 in my windows 7 64 bit OS and tried to execute JDBC program, then I got the following error:
java.sql.SQLException: Listener refused the ...
217
votes
26
answers
876k
views
How can I get column names from a table in Oracle?
I need to query the database to get the column names, not to be confused with data in the table. For example, if I have a table named EVENT_LOG that contains eventID, eventType, eventDesc, and ...
216
votes
14
answers
612k
views
error: ORA-65096: invalid common user or role name in Oracle database
I just installed Oracle database, and it was missing the SCOTT schema. So I am trying to generate it myself. I got the sql script of Scott schema, but when I try to run the query
CREATE USER SCOTT ...
215
votes
6
answers
511k
views
GROUP BY with MAX(DATE) [duplicate]
I'm trying to list the latest destination (MAX departure time) for each train in a table, for example:
Train Dest Time
1 HK 10:00
1 SH 12:00
1 SZ 14:...
215
votes
27
answers
16k
views
What resources exist for Database performance-tuning? [closed]
What good resources exist for understanding database tuning on the major engines and advancing your knowledge in that area?
The idea of this question is to collect the shed load of resources that ...
213
votes
12
answers
366k
views
How to add 'ON DELETE CASCADE' in ALTER TABLE statement
I have a foreign key constraint in my table, I want to add ON DELETE CASCADE to it.
I have tried this:
alter table child_table_name
modify constraint fk_name
foreign key (child_column_name)
...
211
votes
10
answers
472k
views
SQL Query to concatenate column values from multiple rows in Oracle
Would it be possible to construct SQL to concatenate column values from
multiple rows?
The following is an example:
Table A
PID
A
B
C
Table B
PID SEQ Desc
A 1 Have
A 2 a ...
203
votes
18
answers
723k
views
How do I reset a sequence in Oracle?
In PostgreSQL, I can do something like this:
ALTER SEQUENCE serial RESTART WITH 0;
Is there an Oracle equivalent?
203
votes
4
answers
310k
views
Oracle "(+)" Operator
I am checking some old SQL Statements for the purpose of documenting them and probably enhancing them.
The DBMS is Oracle.
I did not understand a statement which read like this:
select ...
from a,b
...
201
votes
6
answers
1.3m
views
Oracle SELECT TOP 10 records [duplicate]
I have an big problem with an SQL Statement in Oracle. I want to select the TOP 10 Records ordered by STORAGE_DB which aren't in a list from an other select statement.
This one works fine for all ...