request for a row of each distinct column value
Let's say theres employee table with the columns name, id and title. How do you get a line for each separate title. What line is it of okay as long as your result set covers all the possible titles used. How can I do this? Thank youHello
I think that you may have about a Request of Top - N .
As you post a version of your table, I'll use scott.emp to illustrate.
The following query illustrates exactly one line of output for each separate work:
WITH got_r_num AS
(
SELECT empno, ename, job
, ROW_NUMBER () OVER ( PARTITION BY job
ORDER BY ename
) AS r_num
FROM scott.emp
)
SELECT empno, ename, job
FROM got_r_num
WHERE r_num = 1
;
Output:
` EMPNO ENAME JOB
---------- ---------- ---------
7902 FORD ANALYST
7876 ADAMS CLERK
7698 BLAKE MANAGER
7839 KING PRESIDENT
7499 ALLEN SALESMAN
The lines you see are actually the rows in the table, not aggregates. In other words, you can be sure that there is a line in the table with empno = 7902, ename = 'FORD' and employment = "ANALYST."
I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and also publish outcomes from these data.
If the expected results are not unique, in other words, if you want to be just as pleased at a number of games of different results, then after a few examples from the same data of the sample.
Tags: Database
Similar Questions
-
Single request for the display of all, but the values of 1 column for all tables
Hello
All tables have the column SYS_CREATION_DATE.
But I don't want to not display the value of this column
Can anyone suggest a way in which I could achieve this?
Oracle version: 11 GR 1 material
OS: SunOS
See you soon,.
Malika
Published by: user9131570 on July 6, 2010 19:57user9131570 wrote:
@TubbyI * table-wise display the values of all but 1 columns (SYS_CREATION_DATE) in my database.*
I need it to compare to another data base for all these values.
I would like to make a wild guess at what you are getting.
In view of these two tables
create table emp (empid number, empname varchar2(15), empaddr varchar2(15), sys_creation_date date); -- create table dept (deptid number, deptmgr varchar2(10), sys_creation_date date);
you want to combine somehow
select empid, empname, empaddr from emp;
with
select deptid, deptmgr from dept;
in a single sql statement?
-
[8i] way to add a specific number of rows based on a column value?
I know that the version of Oracle is old:
Oracle8i Enterprise Edition Release 8.1.7.2.0 - Production
PL/SQL Release 8.1.7.2.0 - Production
CORE 8.1.7.0.0-Production
AMT for HP - UX: 8.1.7.2.0 - Production Version
NLSRTL Version 3.4.1.0.0 - Production
I'm trying to get an old database data in a specific format, and this should be run several times during the next year, until we can phase out the old database. Unfortunately, it is not particularly useful for formatting the data after he is questioned, so if a SQL solution can be found, it would probably be best.
Some examples of data:
I want to get these results:CREATE TABLE testabc ( item CHAR(25) , qty NUMBER(13,4) ); INSERT INTO testabc VALUES ('Item1',1); INSERT INTO testabc VALUES ('Item2',3); INSERT INTO testabc VALUES ('Item3',1); INSERT INTO testabc VALUES ('Item4',2);
Either format would be acceptable. The key is to have the same number of rows for an article as its quantity.ITEM QTY ------------------------- --------------- Item1 1.000 Item2 3.000 --blank row --blank row Item3 1.000 Item4 2.000 --blank row OR ITEM QTY ------------------------- --------------- Item1 1.000 Item2 1.000 Item2 1.000 Item2 1.000 Item3 1.000 Item4 1.000 Item4 1.000
Any help on this would be appreciated. I wasn't sure if maybe that this would require a CONNECT BY statement. With my luck, it requires one of the functions which did not become available until 9i...
I tried this:
but he gave me a bunch of empty lines.SELECT CASE WHEN LAG(qty) OVER(PARTITION BY item ORDER BY item, qty DESC) = 1 THEN item END AS item , CASE WHEN LAG(qty) OVER(PARTITION BY item ORDER BY item, qty DESC) > 1 THEN LAG(qty) OVER(PARTITION BY item ORDER BY item, qty DESC) - 1 END AS qty FROM testabc ;
Thank you!Hello
Here's a way to do it in Oracle 8.1
SELECT CASE c.n WHEN 1 THEN t.item END AS item_col , CASE c.n WHEN 1 THEN t.qty END AS qty FROM testabc t , ( SELECT ROWNUM AS n FROM all_objects WHERE ROWNUM <= 10 -- If you know an upper bound ) c WHERE c.n <= t.qty ORDER BY t.item , c.n ;
This assumes that this quantity is never more than the number of lines in object (usually at least 5000). If you need more lines, you can cross join object to itself, with the result a limit of 25 million lines or more.
The WHERE clause in the subquery c is not absolutely necessary, but it will make things faster.Published by: Frank Kulash, December 19, 2011 15:33
The solution above is for the first set of results, with blank lines.
For the results of the second, with lines no NULL duplicate, just lose the CASE expressions in the FROM clause:SELECT t.item , t.qty FROM testabc t , ( SELECT ROWNUM AS n FROM all_objects WHERE ROWNUM <= 10 -- If you know an upper bound ) c WHERE c.n <= t.qty ORDER BY t.item , c.n ;
-
How to reset a number of rows based on a column value?
OracleBI Discoverer 10g (10.1.2.3)
Oracle Business Intelligence Discoverer Plus 10g (10.1.2.55.26)
I have a Scout more State showing point receipts, receipt of the dates, and if the reception has been inspected. I've got items that need to be inspected each 5th receipt. There must be a function of hand-dandy, that I can use to do that, right?
I'm looking to count receipts and reset the inspection counter = YItem Receipt Date Inspected Bracket 1/1/2009 Y Bracket 2/1/2009 N Bracket 3/1/2009 N Bracket 4/1/2009 Y <--let's assume someone didn't follow the instructions Bracket 5/1/2009 N Bracket 6/1/2009 N Bracket 7/1/2009 N Bracket 8/1/2009 N Bracket 9/1/2009
I'm open to other methods if the mine seems to be a failure.Item Receipt Date Inspected Inspect_Count Bracket 1/1/2009 Y 0 Bracket 2/1/2009 N 1 Bracket 3/1/2009 N 2 Bracket 4/1/2009 Y 0 Bracket 5/1/2009 N 1 Bracket 6/1/2009 N 2 Bracket 7/1/2009 N 3 Bracket 8/1/2009 N 4 Bracket 9/1/2009 5 <-- receiver should inspect on this receipt
-TracyHello
I don't think you can do it is Discoverer more only because you must divide twice once to get all inspected records and still counting the days between them.
What you can do is in Discoverer Admin add an element to the EUL calculated:
inspections = COUNT (DECODE (inspected, 'Y', 1)) OVER (ORDER BY reception Date)
In Discoverer, you can add a calculation:
Count (inspected) over (PARTITION BY ORDER BY Date of receipt) - 1
to produce the County to inspect.
Rod West
-
I created a table and partitioned on the date of the entry and added a local partitioned index.
Now, I use a query to extract "num_rows" of user_tab_partitions to know the number of rows in each partition.
Getting this value as null num_rows, wonder why?
After looking to explain the Plan after interrogation ("select * from my_table1 where entry_date = 1 January 2015" ;))
to find out if she actually partitioned table and its data in different partitions, I interpreted in effect because the query plan had a line like Partition_range (Single).
My Question is:
(a) is actually partitioned data (have I misinterpreted the Explain plan)
(b) why is the num_rows null column in the query (Pasted below)
(c) also in addition what difference it would have been if I had created a Global Index instead of the Local Index in my case?
The following code Snippet:
----------------------------------------------------------------------------------------------
create the table my_table1
(
roll_no number constraint my_table1_pk primary key,
date of entry_date
)
partition of range (entry_date)
(
PARTITION data_p1 VALUES LESS THAN (TO_DATE (December 31, 2014 ',' DD-MM-YYYY ""));
PARTITION data_p2 VALUES LESS THAN (MAXVALUE)
);
create an index only my_table1_indx on my_table1 (entry_date) local;----------------------------------------------------------------------------------------------
I now insert two lines:
insert into my_table1 values (1, to_date ('01-01-2015', ' dd-mm-yyyy'));
insert into my_table1 values (2, to_date('01-02-2015','dd-mm-yyyy'));----------------------------------------------------------------------------------------------
These have been inserted successfully, now using the query below shows num_rows column as null. I don't know why?
SELECT table_name, num_rows, high_value, nom_partition
Of user_tab_partitions
where table_name = 'MY_TABLE1 '.
ORDER BY table_name, nom_partition;----------------------------------------------------------------------------------------------
(a) is actually partitioned data (have I misinterpreted the Explain plan)
Yes, it is partitioned. You can query this particular partition SELECT * FROM my_table1 (data_p1) PARTITION to check that.
(b) why is the num_rows null column in the query (Pasted below)
As already mentioned that you have not collected statistics.
(c) also in addition what difference it would have been if I had created a Global Index instead of the Local Index in my case?
In fact, you have created two types of indexes without knowing (can be)! One is not partitioned (although this column is not partition key) and another is partitioned (LOCAL). They are MY_TABLE1_PK and MY_TABLE1_INDX. You can check that USER_INDEXES.
You can read this article to get an early jump on the partitioning of decision. Partition: Partition decisions
-
Request to remove row where the value of column contains alphabets
Hello
Could someone please help me to get this application working.
Request to remove row where the value of column contains alphabets.
DELETE FROM BIN_ITEM WHERE order_nmb LIKE '% [A - Z] % ' | LIKE '% [a - z] %'
Thank you and best regards,
Madam.
SELECT order_nmb FROM BIN_ITEM WHERE regexp_count(order_nmb,'[0-9]') = 0
----
Ramin Hashimzade
-
Hi all
I want a script, plsql for below now.
I will grab a table name
for example the EMP
for the Emp table
(1) I need to identify the columns of blank (empty).
(2) I need to enter the data based on the data type of the column
for example
If emp.empname is empty
then
If emp.empname is varchar2 and then update all the empname empty with NA_EMPNAME (NA_columname)
on the other
If emp.deptno is empty
then
If emp.deptno is the number then update all the deptno white with 1
This script is useful for all tables.
means, it checks all columns and all rows from some that it will update the table.
Ultimately we will see with on table any void for any row and column.
Please help me solve this problem.
Thank you
Krishna
E-mail: [email protected]CREATE OR REPLACE PROCEDURE count_chars AS TYPE strarray IS TABLE OF VARCHAR2(50); v_tabName STRARRAY ; v_colName STRARRAY ; v_DATA_TYPE STRARRAY ; v_stmt VARCHAR2(4000); v_stmt_update VARCHAR2(4000); v_count NUMBER; BEGIN --collect all the table names into v_tabname SELECT DISTINCT table_name BULK COLLECT INTO v_tabName FROM user_tab_columns WHERE (table_name not Like 'BIN%' and table_name not like 'TOAD%') ; --for every table, collect all the columns into v_colname FOR i IN v_tabName.FIRST .. v_tabName.LAST LOOP SELECT DISTINCT column_name ,DATA_TYPE BULK COLLECT INTO v_colName,v_DATA_TYPE FROM user_tab_columns WHERE table_name = v_tabName(i); --for each column in each table, check whether the apost exists FOR j IN v_colName.FIRST .. v_colName.LAST LOOP v_stmt := 'SELECT COUNT(*) FROM '|| v_tabname(i) || ' WHERE '|| v_colName(j) ||' IS NULL '; -- dbms_output.put_line (v_stmt); EXECUTE IMMEDIATE v_stmt INTO v_count; -- if exists print the tablename, columname and count IF v_count > 0 THEN dbms_output.put_line (v_tabName(i)||' '||v_colName(j)||'with '||v_DATA_TYPE(j) ); If ( v_DATA_TYPE(j) ='NUMBER') THEN v_stmt_update :=' UPDATE ' || v_tabName(i) || ' SET ' ||v_colName(j) ||' = 1 WHERE ' || v_colName(j) ||' IS NULL '; dbms_output.put_line ( v_stmt_update); EXECUTE IMMEDIATE v_stmt_update; else if ( v_DATA_TYPE(j) ='VARCHAR2') THEN v_stmt_update :=' UPDATE ' || v_tabName(i) || ' SET ' ||v_colName(j) ||' = ''NA'||v_colName(j) ||''' WHERE ' || v_colName(j) ||' IS NULL '; dbms_output.put_line ( v_stmt_update); EXECUTE IMMEDIATE v_stmt_update; END IF; END IF; END IF; END LOOP; END LOOP; END count_chars;
eexcute by
BEGIN COUNT_CHARS; COMMIT; END;
-
Compare the column values for multiple lines
I am new to oracle and I have a requirement to compare the values of column across multiple lines. If all column values are the same, I want to display that value, if the columns are not the same, I need to display 'no match' as value. I need id to group values and display a status value based on the above logic. Can anyone offer assistance with dispalying the result expected below?
Sample
Table
State ID
1 S
2 L
1 S
2 S
expected results
State ID
1 S
2 no match
Hello
That's what you asked for:
SELECT id
CASE
WHEN COUNT (DISTINCT status) > 1
THEN "no match."
For ANOTHER MIN (status)
The END as status
T
GROUP BY id
;
Want that if each State ID is NULL? The CASE expression above returns NULL in this situation.
-
Hello
I need a little faovour... I need search a pariticular table column value... !! Whenever my superiors asking
What table with that value... This value... etc... !!!
For this I need a solution... (select query). If I give the value name and the column of the table... I can't what column having this perticular value? is this possible? I have many tables and each table has many columns. It takes a lot of time to search for a value of column for each table and columns. Please give me a nice solution.
Thanks to the adv.
Concerning
Rekhafor number
SQL> select table_name, column_name 2 from (select rownum,table_name, column_name, 3 dbms_xmlgen.getxml('select 1 from "'||table_name||'" where "'||column_name||'" = &val') x 4 from user_tab_columns where data_type='NUMBER' 5 ) where length(x)!=0 6 / Enter value for val: 3000 old 3: dbms_xmlgen.getxml('select 1 from "'||table_name||'" where "'||column_name||'" =&val') x new 3: dbms_xmlgen.getxml('select 1 from "'||table_name||'" where "'||column_name||'" =3000') x TABLE_NAME COLUMN_NAME ------------------------------ ------------------------------ EMP SAL TID SAL 7 rows selected. SQL>
for varchar2
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options SQL> select table_name, column_name 2 from (select rownum,table_name, column_name, 3 dbms_xmlgen.getxml('select 1 from "'||table_name||'" where "'||column_name||'" = ''&val''') x 4 from user_tab_columns where data_type='VARCHAR2' 5 ) where length(x)!=0 6 / Enter value for val: OPERATIONS old 3: dbms_xmlgen.getxml('select 1 from "'||table_name||'" where "'||column_name||'" =''&val''') new 3: dbms_xmlgen.getxml('select 1 from "'||table_name||'" where "'||column_name||'" =''OPERATIO TABLE_NAME COLUMN_NAME ------------------------------ ------------------------------ DEPT DNAME SQL>
-
Hi all
We try to add new proposal for a salary of some employees from form August 1, 2015 (the Date of the beginning of employee)
There is no existing salary proposal doesn't exist for these employees.
We get below error.
ORA-01422: exact fetch returns more than the requested number of rows in the hr_maintain_proposal_swi procedure insert_salary_proposal package
Help, please.
Thank you
Tarun
Hi John,.
If it helps, take a look at the following note:
ORA-01422 exact Fetch returns more than number of lines requested in Hr_maintain_proposal_swi (Doc ID 1673527.1)
Kind regards
Rajen
-
How to write a query to return rows with the varchar column that contains even a single occurrence of the characters, such as Ÿ and
I have a table whose columns with values such as
MINNEAŸPOLIS and ¿VV ¿A
Only the characters that are allowed in this column are alphabets, numbers, spaces, points and supports.
Please help to write a SQL SELECT with Regexp_like query or any other option.
Thanks to you all! Under query worked for me. Thank you Frank to explain the concept of hooks inside regexp_like.
SELECT * FROM testspecial, WHERE REGEXP_LIKE (sampletext, "[^] ^ A - Z ^ a - z ^ 0-9 ^ [^.]") ^ {^} ^]') ;
-
The script generation is not supported for Table with XML or UDT column Types
I get this message trying to generate a script to create a table with an XMLTYPE column. We use the Oracle Developer Tools for Visual Studio to generate scripts as SQLDeveloper does still not support TFS integration. He was always pretty easy to generate scripts and maintain control of source code in this way (with the exception of materialized views). It was great, just right click and generate a script for the project and check it in. Unfortunately as the adoption of XML grows, we find passage to the SQL Developer more often to perform tasks not supported and then return to the VS IDE to manage source code control. Free of any chance that it will be supported in the future?
Yes, our plan is to support several types as time goes by.
You possibly can speed things along by voting or by filing a request for new feature here:
-
Should I me Integrator unique ID to multiple requests for payment service provider?
Hello-
My company manages the management of subscriptions for several digital content publishers. We are putting in place direct payment API signInWithCredentials, and. Al for a particular provider and I'm curious to know how extend us these same APIs to handle applications from different vendors?
Do I need an integrator ID from Adobe to the unique address for each provider, or are they assigned us to a unique ID? If a unique ID, how to direct calls to the database specific to the seller? How did Integrator ID related to the URL/Service Service Auth URL?
Thank you
William
N ° the API contains "appId" and "appVersion" on each method so that your application can detect which application requests information of law. Make sure that breast of the DPS App Builder, you check the box "Send AppId and AppVersion". There is no reason to ever do not select no not this box - even if at the end of the day, you choose to ignore the additional parameters.
While I'm on the subject... also ignore the dates of coverage and Don ' t bother sending ProductID in the body of the request for payment. This has caused a lot of confusion. If you really know what they are and why a digital system of their desire, then go ahead. But for 99% of the use cases, they are useless.
-
request for line lines - before using seq number
Hello
I have a table of records CatalogAuthor
long: id
varchar: author
long: seqnum
I made the table so that initially, if there are 10000 unique authors, then the lines will have numbers in sequence from 1 to 10000. When authors are added dynamically, they receive the sequence number of an existing line in the table, which is the nearest rank, which the author comes before the new author. Over time, there are more duplicates, and at some point, the table has all its sequence reassigned numbers to be monotonous increasing order of author name.
We want to use this table to generate a tree of about 10 knots by parent, which resulted in author names. So to expand the tree on the first level, we could divide 10000 by a power of 10 to get the number sequence groups. However, with double-seqnum, there may be 14365 lines so ideally, I'd sort of query to identify the record of 1436 in order sorted by sequence number of the record to 2872 by number of seq to overcome the problem of lumps, and so on.
What query would it? With the appropriate indices, it would still be slow? I do 10 of these requests to expand a node with 10 children? Is there a better design to achieve the same goal to explode a tree balanced by sort order of author name, which resulted in a map of a particular author?
AndyHi, Andy.
user9990110 wrote:
Hi Frank,.I thought more about my problem and I realize that my column seqnum does not help much. What I'm really after is, let's say I have the column gap seqnum. Instead, I do author name an index on the table. Is there a query for the nth element in a column as an author?
What version do you use? From Oracle 11.2, theres NTH_VALUE. I don't know how is it effective.
For example, if I was building my own binary tree, and wanted to get the nth element, then I would have all the nodes in the tree to hold the number of knots-front. Updates the tree would always be logN.
I'm not you. If you have added a new node, which happened to be the first in order by the author, wouldn't change the value of nodes_before to all other nodes?
Total_descendants of count may be more what you are looking for. Adding a node would change only the County total_descnedants of his ancestors, and this number is proportional to log(n). -
Update and request for insertion
I'm unable to write the query to update or insert or both the column of a table with the value on the other table once he finds an exact match
So here's the table data and sample to create.
I'm writing a query that would update the value of column - codedesc (currently Null) of the table1 table: after it is a string of column - table code1 codedesc.create table code1 ( codeid number, codedesc varchar2(60) ); Insert into code1 values ( 1,'R1 CONTRACTS'); Insert into code1 values ( 2,'R2 CONTRACTS'); Insert into code1 values ( 3,'R3 CONTRACTS'); Insert into code1 values ( 4,'R5 CONTRACTS'); Insert into code1 values ( 5,'R9 CONTRACTS'); Insert into code1 values ( 6,'R10 CONTRACTS'); Insert into code1 values ( 7,'R1'); Insert into code1 values ( 8,'R1 DEPT'); Insert into code1 values ( 9,'R1 SS'); create table table1 ( tablekey number, prefix varchar2(25), codedesc varchar2(60) ); Insert into table1(tablekey,prefix) values (1,'1001PAC'); Insert into table1(tablekey,prefix) values (2,'1001MXT'); Insert into table1(tablekey,prefix) values (3,'1002PAE'); Insert into table1(tablekey,prefix) values (4,'1003PCS'); Insert into table1(tablekey,prefix) values (5,'1004BDX'); Insert into table1(tablekey,prefix) values (6,'1005PAC'); Insert into table1(tablekey,prefix) values (7,'1006PAC'); Insert into table1(tablekey,prefix) values (8,'1007LDR'); Insert into table1(tablekey,prefix) values (9,'1009LCR'); Insert into table1(tablekey,prefix) values (10,'1010LBR'); Insert into table1(tablekey,prefix) values (11,'ABCDEF');
If it finds several match then it should update a line with the first matching string and insert the other row in double with the second matching string
The logic for the match is, - take - 2nd column of table-codedesc code value and get 2 characters. For example, when the string is - R1 CONTRACTS, the string will be 1. (Select substr ("R1 CONTRACTS, 2, 2) of the double). -Output will be 1.
Now,.
Look in table 1 for the 3rd position of the prefix that corresponds to the string returned by the query above. So, if the prefix is '1001PAC', it should look for 2 value of figures from the 3rd position. So, in this case it will be 01. Digitally 01 and 1 are equal, then the match is found for this line in the table1 table, so we will need to update the value of the column codedesc with the "contracts of R1.
Some time I have a similar scenario (update only and not insertion) and Frank's Script took care. So I was wondering if I could / Merge Into to achieve statement change.tablekey, prefix codedesc ---------- ------------------------------------------------------------ 1 1001PAC R1 CONTRACTS -- Needs to be update with this value. 2 1001PAC R1 -- This row needs to be inserted 3 1001PAC R1 DEPT -- This row needs to be inserted 4 1001PAC R1 SS -- This row needs to be inserted 5 1002PAE R2 CONTRACTS ... 11 ABCDEF --Null ( No Need to update when no match found).
MERGE INTO table1 dst USING ( SELECT LPAD ( RTRIM ( SUBSTR ( codedesc , 2 , 2 ) ) , 2 , '0' ) AS match_key , codedesc FROM code1 ) src ON (src.match_key = SUBSTR ( dst.prefix , 3 , 2 ) ) WHEN MATCHED THEN UPDATE SET dst.codedesc = src.codedesc ;
Appreciate your help.SQL> select * from v$version; BANNER ---------------------------------------------------------------- Oracle Database 10g Release 10.2.0.4.0 - 64bit Production PL/SQL Release 10.2.0.4.0 - Production CORE 10.2.0.4.0 Production TNS for Linux: Version 10.2.0.4.0 - Production NLSRTL Version 10.2.0.4.0 - Production
glad it worked for you
Sorry I did not respond as I left work just before responded you
Maybe you are looking for
-
Cannot import e-mail from Outlook 2007. Operating system is Windows 10.
I just tried to import messages from Outlook 2007 to Thunderbird 38.2.0 by using the import feature, but nothing seems to happen. Outlook is currently set as the default mail client, and I tried to do the import while Outlook is running and when it i
-
A small window with the error message appears whenever I want to open Firefox or if Firefox wants to open a window. I have to click the OK button and then open Firefox. It's embarrassing.
-
Satellite C850-19Z - display backlight problem
Hello I bought this laptop about a year ago and my laptop disappeared for about 2.5 months. The screen went black suddenly.We used an HDMI cable to connect our laptop with our TV screen, and then it worked perfectly. So we thought (while even shining
-
Lights on Compaq CQ61-415SA Blinkig
I have a Compaq CQ61-415SA and it seems to have stopped working. I turned it on and it worked very well, so I left it while doing something else for a few hours, it was not attached to the power supply and when I went to use the following happened. W
-
Hola! MI problema are el siguiente--> Tengo varios display of imagen y quiero that segun the seleccion me in pantalla muestre solo el display correpondiente an esa Selección. Creo that hace mediante a property node, pero the truth that no me entero c