Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
create table samp
(
empno number(2),
ename varchar2(30),
sal number(7,2),
dob date
)
SQL> /
SQL> insert into samp values(1,'MASTAN',24000,'24-JUL-1987');
1 row created.
here i did not commit data so it is in redo log buffer,but when retrieving , how the below Query giving data? How internally works ?kindly suggest me
SQL> SELECT * FROM SAMP;
EMPNO ENAME SAL DOB
---------- ------------------------------ ---------- ---------
1 MASTAN 24000 24-JUL-87
It seems you did not commit or rollback so you are seeing the correct result from your select statement because it happens in single transaction. Try rollback and check the results. Another good way to understand transactions is to try opening two separate sqlplus shell and trying insert statements in one and select statements in the other shell.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
Improve this question
i am trying to create a table in oracle sql as shown below
create table Employee
(
S.NO NUMBER(2) PRIMARY KEY,
NAME VARCHAR(20),
DESIGNATION VARCHAR(20),
BRANCH VARCHAR(20)
)
it shows an error "only simple column names allowed here"
please help!!
Generally, it's a bad idea to name columns like that because it might (and will) make your code less readable.
But if you really-really-really need it, you can use quotes
create table test(
"s.no" number
);
dbfiddle
Almost every character can be used in an identifier if and only if you're using quotation at table definition. Let's see an example.
SQL> create table t1 ("S.NO" number, "!##$%^&*()" varchar2(10));
Table created.
SQL> desc t1;
Name Null? Type
----------------------------------------- -------- ----------------------------
S.NO NUMBER
!##$%^&*() VARCHAR2(10)
From now on, you have to use quotation to wrap these weird identifiers in every statement you used.
SQL> insert into t1 ("S.NO", "!##$%^&*()") values (1, 'abc');
1 row created.
SQL> select "!##$%^&*()" from t1 where "S.NO" = 1;
!##$%^&*()
----------
abc
Normally, we don't use quotation to define column or table identifier, simply because it's error prone.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have a production database with 1500 tables. Want to cleanup few tables that are created for testing purpose. Is there any process to identify unused tables.
Note: Auditing is not enabled in the database
You need to take snapshots of v$segment_statistics on a regular basis and then compare the data over time.
Something like:
create table usage_statistics
(
as_of timestamp,
table_name varchar(30),
table_owner varchar(30),
num_logical_reads number,
num_physical_reads number,
num_full_scans
);
Then create e.g. a cron or dbms_scheduler job to run the following
insert into usage_statistics (as_of, table_name, table_owner, num_logical_reads, num_physical_reads, num_full_scans)
select current_timestamp,
object_name,
owner,
sum(case when statistic_name = 'logical reads' then value end),
sum(case when statistic_name = 'physical reads' then value end),
sum(case when statistic_name = 'segment scans' then value end),
from v$segment_statistics
where owner in ('USER_NAME_1', 'USER_NAME_2')
and object_type = 'TABLE'
group by object_type, object_name
order by object_type, object_name;
Of course you will need to adjust the names of the owners you want to monitor.
The above statement only checks for three statistics. Use the view V$SEGSTAT_NAME to see a list of all available statistic names in v$segment_statistics
Then after a while you can compare the changes in the reads for each table.
I started from this:
select table_name, last_analyzed
from user_tables
order by last_analyzed desc;
select table_name, last_analyzed
from all_tables
order by last_analyzed desc;
I ask programmers and I droped the oldest tables.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I am using Oracle 12c on an instance of Amazon Web Services EC2.
I want to export data from one Oracle table with 5M records to a local folder in CSV format.
Is there a script or program to do that quickly in Redhat/bash environment?
I am looking for minimal installation and setup.
You want it quickly? How about a simple SPOOL SQLPlus command? You can make it prettier using different SET commands (type HELP SET on SQLPlus command prompt), but the general idea is as follows:
SQL> set colsep ','
SQL> spool emp.csv
SQL> select employee_id, first_name, last_name
2 from employees
3 where rownum < 5;
EMPLOYEE_ID,FIRST_NAME ,LAST_NAME
-----------,--------------------,-------------------------
100,Steven ,King
101,Neena ,Kochhar
102,Lex ,De Haan
103,Alexander ,Hunold
SQL> spool off;
SQL> $type emp.csv
SQL> select employee_id, first_name, last_name
2 from employees
3 where rownum < 5;
EMPLOYEE_ID,FIRST_NAME ,LAST_NAME
-----------,--------------------,-------------------------
100,Steven ,King
101,Neena ,Kochhar
102,Lex ,De Haan
103,Alexander ,Hunold
SQL> spool off;
SQL>
[EDITED by LF, after seeing OP's comment]
OK then, as you didn't take that effort and examine what SET offers, here you go: if you want to get a clean output (no headings, underlines, SELECT command, etc.), create a SQL file (let's name it SP.SQL):
SET ECHO OFF
SET VERIFY OFF
SET TRIMSPOOL ON
SET TRIMOUT ON
SET LINESIZE 9999
SET PAGESIZE 0
SET FEEDBACK OFF
SET TIMING OFF
SET TIME OFF
SET COLSEP ','
SPOOL emp.csv
SELECT employee_id, first_name, last_name
FROM employees
WHERE rownum < 5;
SPOOL OFF
Now connect to SQLPlus and run that script:
SQL> #sp
100,Steven ,King
101,Neena ,Kochhar
102,Lex ,De Haan
103,Alexander ,Hunold
SQL>
Finally, if you take a look at EMP.CSV, you'll see that it is nice and clean.
Satisfied?
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
As i know inline view is not a database object and it is just like writing a sub query in from clause so what is the use of naming it as a view .Simply we can call as a sub query.
It is Oracle naming convention. From Inline View and Subquery:
An inline view is a SELECT statement in the FROM-clause of another SELECT statement. In-line views are commonly used to simplify complex queries by removing join operations and condensing several separate queries into a single query.
This feature is commonly referred to in the MSSQL community as a derived table, and in the Postgres community simply refers to it as a subselect (subselects are inline views + subqueries in Oracle nomenclature).
A subquery (sub-query) is a SELECT statement in the WHERE- or HAVING-clause of another SELECT statement.
So when you used it with FROM it is called inline view:
SELECT *
FROM ( SELECT deptno, count(*) emp_count
FROM emp
GROUP BY deptno ) emp,
dept
WHERE dept.deptno = emp.deptno;
And when you used it with WHERE/HAVING it is called subquery:
SELECT ename, deptno
FROM emp
WHERE deptno = (SELECT deptno
FROM emp
WHERE ename = 'TAYLOR');
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm trying to insert a date into oracle table using below
SQL> insert into temp (tst,thistime) values ('test3',TO_DATE('MM/DD/YYYY HH24:MI
:SS','01/01/2014 16:45:45') );
but its giving below error
ERROR at line 1:
ORA-01821: date format not recognized
Below is the description of table
SQL> describe temp;
Name Null? Type
----------------------------------------- -------- ---------------------------
TST VARCHAR2(10)
THISTIME DATE
Use the insert . . . select form of insert:
insert into temp (tst, thistime)
select 'test3', TO_DATE('01/01/2014 16:45:45', 'MM/DD/YYYY HH24:MI:SS')
from dual;
In addition to having the arguments backwards for to_date(), values doesn't evaluate expressions that belong in a select statement.