How To Display The Second MAX Value In A Table
Jul 31, 2007a sample query to display second MAX value from the oracle database
View 1 Repliesa sample query to display second MAX value from the oracle database
View 1 RepliesI have a following table,
create table test ( col1 date,col2 number);
Data:
col1 Col2
----------
NULL NULL
select * from test where col2=123 will give me null because It doesnt have any values, But can we display some harcoded value when I do not have anything ?
I am bit confused to display all the rows in a column using stored procedure like
In sqlserver:
create procedure test
as
begin
select * from table;
end
in sqlserver it is working perfectly.
In oracle:
create or replace procedure test
is
begin
select * from table;
end;
But in oracle i am getting an error like select * into something like that.I understand the error. i.e. i need to move the column values into variables.if it a single row then there will be no problem.i want to display all the rows in the table at one time.i can not use cursors.
how to display all the records in a table ,i am passing the table name as in param to the procedure/function suppose if i pass emp table name it will display 14 rec, if i pass dept it will display 4 records.
View 3 Replies View RelatedAs far as SQL is concerned, I am using oracle 9i and oracle sql *plus.
1.
This is a table 'spj'
SID PID JID QTY
---------- ---------- ---------- ----------
1 3 2 5
1 2 2 12
1 7 1 10
2 5 3 5
[code]...
I wish to count all the qty for each pid.This is what I have:
SQL> select pid,sum(qty) from spj group by pid;
PID SUM(QTY)
---------- ----------
1 5
2 12
3 29
4 10
5 5
6 6
7 10
and it seems to work fine. But I now I want to display another column in the table called 'pname' which is a primary key in another table 'p'. 'spj.pid' is the foreign key.
2. Another query I can't perform needs the table s
SID SNAME STATUS CITY
---------- -------------------- -------------------- -------------------
1 s1 y asansol
2 s2 y durgapur
3 s3 y durgapur
4 s4 y asansol
5 s5 y kolkata
6 s6 y asansol
7 s7 y tarakeshwar
the question says:
Quote: List supplier names(snames) who supply at least all parts supplied by supplier(sname) S2.
How may I achieve it.
how to display the dupicate record in table
View 1 Replies View Relatedhow to create a procedure to display all the rows in a table.
I wrote the below PL/SQL but im hitting as below.
DECLARE
howmany NUMBER;
some_full_name login_user.full_name%TYPE;
some_login_id login_user.login_id%TYPE;
some_users login_user%ROWTYPE;
[code]....
error :
Error report:
ORA-06550: line 3, column 19:
PLS-00225: subprogram or cursor 'LOGIN_USER' reference is out of scope
ORA-06550: line 3, column 19:
PL/SQL: Item ignored
ORA-06550: line 4, column 18:
[code]....
i want to display all the records of my database in a table with scrollingexample if i have 3records in my DB so a table must have 3records too !!!this is my code :
DECLARE
Cursor cur IS
SELECT numb_ph AS phone,
name_emp AS name
[code]...
but the problem 's all records of my DB are display in one record (to view another record i use the scrolling ..
in the below query
select
b.user_code
, b.user_name
, b.user_disabled
, b.user_email
, b.user_created_by
, b.user_created_date
, b.user_approved_by
, b.user_approved_date
, b.flag
, b.user_status
from mst_user_checker b, mst_user a
where a.user_code=b.user_code
and b.flag in ('I','P','R','F')
If the flag is 'F', then I need to display the data from the mst_user table. Where should i modify the above query ?
This is my first post in this portal. I want display the details of emp table.. for that I am using this SQL statement.
select * from emp where mgr=nvl(:mgr,mgr);
when I give the input as 7698 it is displaying the corresponding records... and also when I won't give any input then it isdisplaying all the records except the mgr with null values.
1)I want to display all the records when I won't give any input including nulls
2)I want to display all the records who's mgr is null
Is there any way to incorporate to include all these in a single query..
I would like to format my output for the select query.
Example:
SQL>select empno, ename from emp;
empnoename
1987766Jack Blake
187765Greg Ni
But I would like to get the output in the below format
EMPNO:.................1987766
ENAME:.................Jack Blake
EMPNO:.................187765
ENAME:.................Greg Ni
I will need printing the column name. I would like to know how do we address the column name to print.
How can we display the rows which are existed in T_SOURCE table and which doesn't existed in T_TARGET table using outer join.
My code is as follows.
CREATE TABLE T_SOURCE(sno NUMBER,sname VARCHAR2(20));
CREATE TABLE T_TARGET(sno NUMBER,sname VARCHAR2(20));
INSERT INTO T_SOURCE VALUES(1,'A');
INSERT INTO T_SOURCE VALUES(2,'B');
INSERT INTO T_SOURCE VALUES(3,'C');
INSERT INTO T_SOURCE VALUES(4,'D');
INSERT INTO T_SOURCE VALUES(4,'E');
INSERT INTO T_TARGET VALUES(1,'A');
INSERT INTO T_TARGET VALUES(2,'B');
I tried this but I am getteing all the rows.
select t_source.sno,t_source.sname
FROM t_target,t_source
WHERE t_target.sno(+)=t_source.sno
AND
t_target.sname(+)=t_source.sname
How to display table columns on oracle form?
View 7 Replies View RelatedI used Scott schema.I take 2 blocks ,one block having Deptno,Job and also 1st block is a non database block and Another Block Empno,ename,job,sal,deptno, is a database block,my question is when i enter Deptno,Job then Display Employees Details and also Department name
View 1 Replies View Relateddisplay the total number of employee working under president in emp table
View 5 Replies View RelatedI would like to have a table in HTML region and to display in the table some Page Items from the page.
I got the code like this:
{
<table>
<tr><td>&P1_ECEMEA_ASSISTANCE</td></tr>
<tr><td>&P1_ECEMEA_WIP</td></tr>
</table>
}
It shows the Page Item names as text, not the values. However this code without the table tags:
{
ECEMEA Request for CQT Assistance: &P1_ECEMEA_ASSISTANCE.
ECEMEA CQT Work in Progress: &P1_ECEMEA_WIP.
}
works and the Page Item values are displayed.
Is it possible to display the Page Item values in the HTML table at all or I have to use a different method of showing the values in a table? The above is only a snippet of the code. I need to display about 30 Page Items, formatted in a table with headings.
what kind of region is the best to be used or if I should only use some escape symbols in the table code.
This query
SELECT
SCRATTR_ATTR_CODE
from scrattr_TEST,scbcrse_TEST
where
SUBSTR(scbcrse_subj_code,1,3) = SUBSTR(scrattr_subj_code,1,3)
and SUBSTR(scbcrse_crse_numb,1,4) = SUBSTR(scrattr_crse_numb,1,4)Returns this
SCRATTR_ATTR_CODE
A
INS
MCSR
How I can make to return someting like A INS MCSR in one row there is a row for every code
hERE is some code to create the tables and insert the data
CREATE TABLE SCRATTR_test
(
SCRATTR_SUBJ_CODE VARCHAR2(4 CHAR) NOT NULL,
SCRATTR_CRSE_NUMB VARCHAR2(5 CHAR) NOT NULL,
SCRATTR_EFF_TERM VARCHAR2(6 CHAR) NOT NULL,
SCRATTR_ATTR_CODE VARCHAR2(4 CHAR)
[Code]....
I am doing a Gross Profit percentage. I want to display zero if the GP% is have negative value.
for example
If GP% shows -75 I want to display as 0.
trunc((sum(total)-(sum(DECODE(po_pur,'',0,PO_PUR))+sum(DECODE(pl_pur,'',0,PL_PUR))+SUM(parts))) / SUM(DECODE(TOTAL,0,1,TOTAL))*100,2) "GP%"
Below is returning rows in single column.I need to display in two different columns
SELECT * FROM TABLE(PLUSER.SPLIT('a,b,c'))
union all
SELECT * FROM TABLE(PLUSER.SPLIT('1,2,3'))
this returning result like
a
b
c
1
2
3
but need abc in one column and 1,2 3 in one column
a 1
b 2
c 3
i was tried like
select * from TABLE(PLUSER.SPLIT('1,2,3')),(select * from TABLE(PLUSER.SPLIT('a,b,c')));
but it's giving cartesion result like below
1a
1b
1c
2a
2b
2c
3a
3b
3c
I have a requirement where I want to display amount what I have billed to my client and then how I received my amounts from that Bill. For eg.lets say there is bill no 001 amounting 10000 and after some days I received a part payment cheque/cash from client worth 2000 then he gave second part 2000 and then finally I received 2000. Still 4000 is remaining to be received.So in tabular format I want to display data which will have 3 records of 2000 and one record of balance 4000.
In attached file i have given few examples, where highlighted area is what i want to derive. There are formula's in Collection date, delay by and Int calc. Basically highlighted lines are the ones which should be shown in query result. And data shown above that is what i have right now.
I have a procedure in this i want add a column to display my procedure is
set serveroutput on;
create or replace PROCEDURE IdentifySparesInDSIGNALTables
AS
V_SQL VARCHAR2(1024);
cnt1 number;
[code]...
i wnat to add dlstation in this procedure to display output...
I have a requirement where i need to display like
Consider EMPLOYEES table and If an employee 'A' joined in Jan month then he should come under JAN, if employee B and C joined in MARCH month than both has to come under MAR and so on..
OUTPUT:
JAN FEB MAR APR MAY JUNE JULY AUG SEP OCT NOV DEC
A B D E
C
is this possible.????
I want to display '18-MAR-13' as 20130318.
View 9 Replies View RelatedI need to return the stored result in a record by ref cursor. In the below code I am displaying the result through DBMS_OUTPUT.PUT_LINE but i need to do it through ref cursor to display the result.
declare
type r_cursor is REF CURSOR;
c_emp r_cursor;
type rec_emp is record
(
name varchar2(20),
sal number(6)
[code].....
How to display row value of each class as a column value
IDNAMECLASSHOURSSCHOOLNAME
1AllenMaths12school1
2SamMaths12school1
4PamMaths10school1
3SamComp10school1
9SmithComp15school1
7SmithPhy20school1
5PamPhy12school1
[code]....
I wanted output like below for School1
NamemathsCompPhyAccountsBusiness
Allen120000
Sam1210000
Pam10012150
Smith01520120
Adams000030
I wanted output like below for School2
NameCompAccountsBusiness
Anthony2000
Chris102020
I wanted output like below for School3
NamemathsAccounts
Angelo2015
Robert1515
how to write a single query, Also i may add /delete school/class anytime. Query should support mesans everything dynamically should get the data.Even stored procedure will work for me.
i have to display the 10 most costly missions. but if the 11th record has the same cost then it needs to display 11 records instead of 10. how can i do this?
View 5 Replies View Relatedi have a table displaying location, cost, inner_num and rownum ordered by the descending order of the cost.
the question is: display locations of the highest 10 costs. if the cost of 11th row is the same as 11th, then display 11 rows.
query in order to display a hierarchy list. Example:
Database has three tables
Heading --> id, status, order, title
Sub-heading --> id, status, order, title, heading_id
Item --> id, status, order, title, heading_id, sub-heading_id, actual_content
order = the sequence in which they are to be displayed a sub-heading's heading_id refers to the parent heading, likewise an item's sub-heading_id refers to the parent sub-heading.
I assumed there was no need to track child content.
Now, the output format should be something like this, where the sub-headings are not repeated, nor are the items. Sort of like chapters in a book, things in a catalogue, or even topics in a forum.
Heading 1
Sub-heading 1
Item 1
Item 2
Item 3
Sub-heading 2
Item 1
Item 2
Item 3
Heading 2
Sub-heading 1
Item 1
Item 2
Item 3
Heading 3
Sub-heading 1
Item 1
Item 2
Item 3
Sub-heading 2
Item 1
Item 2
Item 3
Sub-heading 3
Item 1
Item 2
Item 3
Where I'm getting hung up is how to query the data so it's quick, efficient, clean and easy to read and maintain. I've only gotten to listing the sub-headings and already the query looks convoluted. So, how should I approach this? Should it be done all in one query, and always checking against the results to know when to print a new heading or sub heading. Or should I run multiple queries and save the results to a variable, and then run sub-queries off that? Is there a better way to do this, am I going about it the hard way or am I in the right direction and just haven't gone far enough with it yet?
I've tried using Select * from ALL_TABLES but this does not return me the column info for each table.
How do I get an output of all tables in a database along with column (e.g datatypes etc)?
I'm using TOAD v8.6.1.
I have two columns which I need to add together then devide by 60 in order to display that time in minutes. the problem I am facing is that at times I get numbers above 60 and my client doesn't want to see numbers above 60.
i.e (col1 + col 2)/60 = 34.87
what I need to do is make sure that when the number reaches 60 it moves on to 35.