How to find Random Row using SQL
In Scott.emp table (oracle default) there are fourteen rows
I want to select employee with salary at second (eg if 2000, 3000, 5000, 2500 )
then second no salary is 3000.?
Re: how we select 3 rd max salary from given salaries
But.....
How the title is related to the topic ?
Similar Messages
-
How to find duplicate row in sql query?
Hi All,
Please solve my query, find duplicate row and how to count its. your suggestion would be greatly appreciated.You can use group by and having.
SQL> WITH t
2 AS (SELECT LEVEL id
3 FROM DUAL
4 CONNECT BY LEVEL <= 5
5 UNION ALL
6 SELECT LEVEL + 2
7 FROM DUAL
8 CONNECT BY LEVEL <= 3)
9 SELECT *
10 FROM t;
ID
1
2
3
4
5
3
4
5
8 rows selected.
SQL> WITH t
2 AS (SELECT LEVEL id
3 FROM DUAL
4 CONNECT BY LEVEL <= 5
5 UNION ALL
6 SELECT LEVEL + 2
7 FROM DUAL
8 CONNECT BY LEVEL <= 3)
9 SELECT id, COUNT (*)
10 FROM t
11 GROUP BY id
12 HAVING COUNT (*) > 1;
ID COUNT(*)
3 2
4 2
5 2
SQL> -
How to find rejected rows using External Table
Hi all,
I had written a stored procedure to read comma(,) separated flat file using External Tables in oracle 9i with Reject Limit "Unlimited" Option. Sometimes all rows are successfully loaded into external table and sometimes some rows are failed, I can find out those rows from logfile created by oracle. I want to inserted those rows key values into some other table. Can any body suggest/links how to write this.
Thanking you in advance"Is there a way to have the system truncate the log files besides some O/S utility that will scour the directory every night, week, etc.?"
You can use UTL_FILE.FREMOVE to delete the file, if you have sufficient privileges. You can schedule it using DBMS_JOB if you like or run it before you recreate the file, as demonstrated below. The pl/sql block to check whether the file exists is used for demonstration purposes only and is not necessary. This is just one method. There are various ways to delete or truncate a file. This just seems like the simplest.
scott@ORA92> CREATE OR REPLACE DIRECTORY mydir AS 'c:\oracle'
2 /
Directory created.
scott@ORA92> DECLARE
2 v_bfile BFILE := BFILENAME ('MY_DIR', 'test_tab.log');
3 BEGIN
4 IF DBMS_LOB.FILEEXISTS (v_bfile) = 1
5 THEN DBMS_OUTPUT.PUT_LINE ('test_tab.log exists');
6 ELSE DBMS_OUTPUT.PUT_line ('test_tab.log does not exist');
7 END IF;
8 END;
9 /
test_tab.log exists
PL/SQL procedure successfully completed.
scott@ORA92> EXECUTE UTL_FILE.FREMOVE ('MY_DIR', 'test_tab.log')
PL/SQL procedure successfully completed.
scott@ORA92> DECLARE
2 v_bfile BFILE := BFILENAME ('MY_DIR', 'test_tab.log');
3 BEGIN
4 IF DBMS_LOB.FILEEXISTS (v_bfile) = 1
5 THEN DBMS_OUTPUT.PUT_LINE ('test_tab.log exists');
6 ELSE DBMS_OUTPUT.PUT_line ('test_tab.log does not exist');
7 END IF;
8 END;
9 /
test_tab.log does not exist
PL/SQL procedure successfully completed.
scott@ORA92> CREATE TABLE test_tab
2 (col1 NUMBER,
3 col2 VARCHAR2(4))
4 ORGANIZATION external
5 (TYPE ORACLE_LOADER
6 DEFAULT DIRECTORY mydir
7 ACCESS PARAMETERS
8 (RECORDS DELIMITED BY NEWLINE
9 BADFILE 'MYDIR':'test_bad.bad'
10 LOGFILE 'MYDIR':'test_tab.log'
11 FIELDS TERMINATED BY ","
12 (col1,
13 col2))
14 LOCATION ('test.dat'))
15 REJECT LIMIT UNLIMITED
16 /
Table created.
scott@ORA92> SELECT * FROM test_tab
2 /
COL1 COL2
1 a
2 b
scott@ORA92> "Or is there a way to prevent the log from being written to every time it's accessed?"
You can use NOLOGFILE as an access parameter to prevent it from being written to, as shown below.
scott@ORA92> CREATE OR REPLACE DIRECTORY mydir AS 'c:\oracle'
2 /
Directory created.
scott@ORA92> CREATE TABLE test_tab
2 (col1 NUMBER,
3 col2 VARCHAR2(4))
4 ORGANIZATION external
5 (TYPE ORACLE_LOADER
6 DEFAULT DIRECTORY mydir
7 ACCESS PARAMETERS
8 (RECORDS DELIMITED BY NEWLINE
9 BADFILE 'MYDIR':'test_bad.bad'
10 NOLOGFILE
11 FIELDS TERMINATED BY ","
12 (col1,
13 col2))
14 LOCATION ('test.dat'))
15 REJECT LIMIT UNLIMITED
16 /
Table created.
scott@ORA92> SELECT * FROM test_tab
2 /
COL1 COL2
1 a
2 b
scott@ORA92> "Is there a way to have the log written only when an error occurs?"
Not that I know of, but that does not mean that somebody else doesn't know how or isn't able to figure out a way. If you do find a way, please post it for the benefit of the rest of us. -
How to hide repeated details using SQL Query?
How to hide repeated details using SQL Query?
For Ex:
------------------------+
DEPTNO| ENAME | JOB |
------|-------| --------|
10 | JAMES | MANAGER |
10 | BLAKE | CLERK |
10 | FORD | SALESMAN|
20 | SCOTT | MANAGER |
20 | ADAMS | CLERK |
20 | KING | SALESMAN|
------------------------+
How we can display the above details in the following way?
------------------------+
DEPTNO| ENAME | JOB |
------|-------| --------|
10 | JAMES | MANAGER |
| BLAKE | CLERK |
| FORD | SALESMAN|
20 | SCOTT | MANAGER |
| ADAMS | CLERK |
| KING | SALESMAN|
------------------------+
Thanks AdvanceHi,
you can use BREAK ON DEPTNO in SQL*Plus or use LAG.
SQL> ed
Wrote file afiedt.buf
1 select nullif(department_id
2 , lag(department_id) over (partition by department_id order by last_name)
3 ) dept_id
4 , last_name, job_id
5* from employees where department_id in (30,50) and rownum <=10
SQL> /
DEPT_ID LAST_NAME JOB_ID
30 Baida PU_CLERK
Colmenares PU_CLERK
Himuro PU_CLERK
Khoo PU_CLERK
Raphaely PU_MAN
Tobias PU_CLERK
50 Fripp ST_MAN
Kaufling ST_MAN
Vollman ST_MAN
Weiss ST_MAN
10 rows selected. -
Mutiple Rows from a Single Row using SQL
How can i get Multiple rows from a single row using sql ?
Example : one row contains the complete address separated by delimiter say comma (,) as address1,address2,city,state,zip,country
I want to split this row and get the output in multiple rows as address1 address2 city state zip country using sql query.
Thanks,Hi,
The solution above assumes that the |-delimited entries always contain at least one character. If you have a string like
1 Elm Street|||Sioux City|IA||it will think 'Siuox City' is address2.
If you have empty entries, like that, then you need something a little more complicated:
INSERT INTO table2
( address1
, address2
, address3
, city
, state
, postal
, country
SELECT SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 1), 2) -- address1
, SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 2), 2) -- address2
, SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 3), 2) -- address3
, SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 4), 2) -- city
, SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 5), 2) -- state
, SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 6), 2) -- postal
, SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 7), 2) -- country
FROM table1
; -
How to find Software version using a copy of software without installing
How to find Software version using a copy of software without installing
How to find Software version using a copy of software without installing
See answer given by Ahmed
Right click on setup file and select properties and then details tab.
http://social.msdn.microsoft.com/forums/sqlserver/en-US/c5424ffa-ce98-4899-ac0d-97cbcac10029/how-to-get-versionbuild-from-sql-install-media
You can also open Mediainfo.xml to see information from Installation file
Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it.
My TechNet Wiki Articles -
How to find the records using contains with the word like this 'some text-some text'?
Hi,
How to find the records using the full text contains keyword and that column contains ‘some text-some text’
In the above some text can be anything.
Does anybody know please let me know.
Thanks,Hello,
You can try to create a Full Text Index on the table and use CONTAINS() to get the record which contains the specify words.
For example:
SELECT * FROM TABLE WHERE CONTAINS(column_name, 'some text')
Reference:
Full-Text Search (SQL Server)
Creating Full Text Catalog and Full Text Search
Regards,
Fanny Liu
Fanny Liu
TechNet Community Support -
How to find process chain using background job in sm37
How to find process chain using background job in sm37
Better is to select the job.
Select (Define) Step (s) or F6.
Select the line and Menu Goto>Variant.
The variant contains the name of the CHAIN and its VARIANT.
Success
We faced an old job and via job monitoring we were informed about a cancelled job every 'interval'.
We noticed that the related chain was deleted but still the job was scheduled each interval again and was cancelled because an event was missing
We could not find the scheduled job via SM37.
Via view V_OP, view over tbtco abd tbtcp, we find the related entry.
We delete these entries via function BP_JOB_DELETE....
Edited by: Jack Otten on Jul 9, 2010 2:50 PM -
How to find leap year in sql query
How to find leap year in sql query
Select
CASE
WHEN result = 0 THEN 'Leap_Year'
WHEN result <> 0 THEN 'Not_A_Leap_Year'
END
From (Select mod((EXTRACT(YEAR FROM DATE '2013-08-24')), 4) result FROM DUAL); -
How to find report values using report writer
hi,
Please help me.
How to find report values using report writer
Regards,
RRK.
Edited by: Alvaro Tejada Galindo on Feb 6, 2008 12:01 PMThanks all for the reply.
I am trying to solve a problem where report parameter value that is set at Management Console is wiped out after calling replaceConnection.
databaseController.replaceConnection(oldConnectionInfo, newConnectionInfo,
null,DBOptions._doNotVerifyDB);
We have to support changing database connection from a java utility
class. But once replaceConnection is called all existing static parameter values are lost. To fix this issue we thought of getting parameters and values before calling replaceConnection and setting it after replaceConnection.
Version is CS2008 SP3 - version 12.3.0.601
If there is any other option of fixing the original wipe out issue?
ParameterValues.getValues() didn't return value. I will try ParameterValues.getCurrentCalues() but the document says ParameterValues.getValues() is equivalent to the IParameterField.getCurrentValues() method unless it is empty, in which case it is equivalent to the IParameterField.getDefaultValues() method.
So getCurrentValues() may not work. -
Hi every one
Can any one help me out, How to Update a Row using ADF.
Thanks in advanceIn addition to Clear to my question
By Using ADF BC How can I update a record in a database.
I have VO and EO associated with a table.
How can I update a record using ADF BC
Message was edited by:
user616296 -
How to get this output using sql query?
Hi,
How to get this output using sql query?
Sno Name Age ADD Result
1 Anil 23 delhi Pass
2 Shruti 25 bangalor Pass
3 Arun 21 delhi fail
4 Sonu 23 pune Pass
5 Roji 26 hydrabad fail
6 Anil 28 delhi pass
Output
Sno Name Age ADD Result
1 Anil 23 delhi pass
28 delhi passHi Vamshi,
Your query is not pretty clear.
write the select query using Name = 'ANIL' in where condition and display the ouput using Control-break statements.
Regards,
Kannan -
How to view alerlog contents using SQL?
How to view alertlog contents using SQL?
Hi,
Why don't you use the OEM Database Console ?? Now, in order to view the contents of the alert log file using a SELECT statement, you need to create a external table:
create or replace
directory background_dump_dest_dir
as '<your_oracle_home>/bdump';
CREATE table alert_log_external
(line varchar2(4000) )
ORGANIZATION EXTERNAL
(TYPE oracle_loader
DEFAULT DIRECTORY background_dump_dest_dir
ACCESS PARAMETERS (
RECORDS DELIMITED BY newline
nobadfile
nologfile
nodiscardfile
FIELDS TERMINATED BY '#$~=ui$X'
MISSING FIELD VALUES ARE NULL
(line)
LOCATION ('alert_<sid_of your_database>.log') )
REJECT LIMIT UNLIMITED;Cheers -
How do I use the find my phone app to find my phone?
what do i need to do? I have the app in my computer, but I don't know how to find it or use it.To use Find my iPhone on a PC or Mac, open http://www.icloud.com, login with your Apple ID and choose Find my iPhone. There isn't an app for Mac or PC
-
How to find Port numbers used by RMI application
Hi, hope u all find me a solution, how to find port numbers used in the RMI application, that is port number which the RMI application communicates between RMIserver and RMIclient. ur answers would b highly appreciated
Currently RMI transport layer does not directly expose any public methods to get the listening ports of the exported RMI objects, but the application can always export RMI server objects at certain designated ports instead of relying on the RMI runtime by specifying them to UnicastRemoteObjcect at the time of exporting.
RMI transport layer try to optimize the number of listeing sockets by exporting all RMI server objects on a single port if no explicit ports were chosen. If the application is really interested in knowing the listeing ports, it can always specify the client and server socket factories to be used for creating Socket and ServerSocket to the RMI runtime at the time of exporting. When a RMI server object is exported, but the listening socket is not yet created, RMI transport layer invokes the createServerSocket(host, port) of server socket factory by passing the host and port details. If no explicit port is specified, underlying socket implementation choses anonymous port. At this point of time application can log these listeing ports to some log file.
Similarly when the stub to the remote object is de-serialized in the client address space, it does also contain the client socket factory along with the end point details (host, port and server object ID). RMI runtime in the client address space needs to establish connection with the remote server object, it try to get the socket from client socket factory by invoking createSocket() on the client socket factory. Now the application can call getLocalPort() on the socket before returning it to the RMI transport layer.
There is a undocumented class RMIStat to dump RMI runtime state information. It provides a lot of static methods to dump RMI state information like object table, transports, threads etc. You can download the source code of this utility from RMI archives, but remember this is not a comman-line utility, you must invoke these static methods as part of the application code.
-- Srinath Mandalapu
Maybe you are looking for
-
Invoking a webservice from Oracle ODI 11.1
Hello there, new to this forum but I am having trouble invoking a webservice from a package within ODI. The error message I am recieving is as follows. com.sunopsis.wsinvocation.SnpsWSInvocationException: javax.xml.ws.WebServiceException: java.lang.E
-
Importing from Final Cut Pro-improving rendered quality
Is it possible to render an exported movie in FInal Cut so that it can be immediately written to the DVD rather than be rerendered/ compressed? FC allows you to create MPEG2, the same as iDVD or DVDs generally? Failing that. my guess is that the expo
-
Connecting LG home theatre system to xbox
"I'm looking at a blue ray home theater system (LG LHB953). I want to make sure there's a way to have my xbox play its sound through the blue ray speaker system. Here is a link to the picture of the back of the blue ray player (http://shopper.cnet.co
-
I have a green screen whenever I try to watch any video on my laptop. This just started within the last couple days. I tried right-clicking on "Settings" when in the video, but there's no place that allows me to enable "hardware acceleration". How ca
-
PyGTK GTK.Dialog doesn't disappear when destroyed
I'm creating a Python module for precanned GTK dialog boxes. The code to create the dialog box works fine - I get the return code, etc. I want - but when I try to destroy the dialog box, the box freezes until the interpreter exits. The function retur