Search for value otherwise select all... to decode?

Hi all

I am wanting to a reasonably simple (poll) result of a query: select data where a certain column is equal to a value, otherwise, I want to return all results.

Let me know if you need more details.

Thank you!

Hello

djston wrote:
Hi all

I am wanting to a reasonably simple (poll) result of a query: select data where a certain column is equal to a value, otherwise, I want to return all results.

Let me know if you need more details.

Whenever you have a problem, post a small example data (CREATE TABLE and only relevant columns, INSERT statements). You can skip this option if the problem is based on commonly available tables, like those of the scott schema.
Also post the results you want from this data, as well as an explanation of how you get these results from these data, with specific examples.
If the problem is with the parameters, give some examples of different parameters and the desired results of each.
Always tell what version of Oracle you are using.

For example:
"I use Oracle 10.2.0.3.0.
I want to find all the people in the table scott.emp employed given; But if no one has this post, so I choose everyone.
For example, if I give 'MANAGER' as a parameter, then I want to these results:
{code}
EMPLOYMENT ENAME
---------- ---------
MANAGER BLAKE
MANAGER OF CLARK
MANAGER OF JONES
{code}
because they are the only people at the table with use = "MANAGER".
However, if I give "DBA" as a parameter, then I want to see every 14 rows in the table, because there is no line where employment = "DBA". »

If this happens to be what you want, here's a way to do it:

VARIABLE     target_job     VARCHAR2 (10)

-- EXEC     :target_job := 'DBA';
-- EXEC     :target_job := 'PRESIDENT';
EXEC     :target_job := 'MANAGER';

SELECT       ename, job
FROM       scott.emp
WHERE       job          = :target_job
OR       NOT EXISTS     (
                       SELECT  1
                   FROM    scott.emp
                   WHERE   job     = :target_job
                   )
ORDER BY  ename
;

Notice that this query involves a rare request subsidiary non correlated EXISTS. (The less intentionally not correlated subqueries EXISTS are rare).

You can get the same results with DENSE_RANK and a CASE expression.

Tags: Database

Similar Questions

  • How to search for a keyword in all views in a database?

    Hi all:

    I'm trying to search for a keyword in all views in a database. Can someone share me a query that I can reuse?

    Kind regards

    BMP

    Published by: BMP on January 8, 2010 14:55

    Select owner, name from dba_dependencies where referenced_link_name = 'XXX ';

    Or something like: -.

    Select view_name, dba_views text where text like 'XXX % ';

  • The search for values in a group

    WITH x AS (SELECT 1 2 attribute_id meter_id, to_date('01012015','MMDDYYYY') read_date, 3 double type_id

    UNION ALL

    SELECT 2 attribute_id, to_date('01012015','MMDDYYYY') read_date, 1 meter_id, 4 double type_id

    UNION ALL

    SELECT 2 attribute_id, to_date('01012015','MMDDYYYY') read_date, 1 meter_id, 3 double type_id

    UNION ALL

    SELECT 2 attribute_id, to_date('01012015','MMDDYYYY') read_derfate, 2 meter_id, 1 double type_id

    UNION ALL

    SELECT 2 attribute_id, to_date('01012015','MMDDYYYY') read_date, 2 meter_id, 2 double type_id)

    SELECT x.*, '?' result_id x;

    METER_ID ATTRIBUTE_ID READ_DATE Type_id RESULT_ID
    12JANUARY 1, 153?
    12JANUARY 1, 154?
    12JANUARY 1, 153?
    22JANUARY 1, 151?
    22JANUARY 1, 152?

    What I need is for each METER_ID ATTRIBUTE_ID, combination of READ_DATE to check if ALL the values TYPE_ID is 3.  If Yes, then all of the RESULT_ID values should be 3 for the group, otherwise, RESULT_ID will be equal to TYPE_ID so that the results look like this:

    METER_ID ATTRIBUTE_ID READ_DATE Type_id RESULT_ID
    12JANUARY 1, 1533
    12JANUARY 1, 1543
    12JANUARY 1, 1533
    22JANUARY 1, 1511
    22JANUARY 1, 1522

    Is it possible to do this without a SELF JOIN?

    Yes, you could do with the analytical functions. For example

    Select x.*,

    case

    When count (case type_id when 3 then 1 end) over (partition by attribute_id, meter_id, read_date) > 0

    then 3

    type_id else

    end up like result_id

    x

    ;

    Kind regards

    Bob

  • How to create a value to select all the dashboard command prompt values

    Dear Sir/Madam,
    OBIEE version is 10g.
    I create a dashboard promt to act as a filter option. It includes all the values in the target column. I wonder how to add value to this prompt to select all of the values in this column?

    For example:
    Table has a column 'product '. Total of 3 values in this column: "product produced b","", "product c '. When I create a dashboard command prompt to include all the choice of 'product '.
    Show sql result: I press "select A product".
    Ok. This message now includes "product produced b","", "product c ' fall down meun. But the problem also. If the user wants to choose all the values in this column? How he/she can do that? I would also add a value 'All products' to include ' product produced b "," "," product c "drop menu drop-down. If the user choose this option. Displays all the results of the product?
    Thank you.

    June wrote:
    I'm sorry that I have no idea about this idea.
    Do you mean the dash prompt has a functional to the list of the values of all options as check boxes? Please would you give me a simple example if you are convenient?
    Thanks anyway.

    When you create the dashboard, as David T say, simply leave the values at all rather than send the SQL query. This will give you the list of all values for the prompt. When the user wants to run the report with all values, it will need check all the boxes in the list, to get the report with all products.

    Kind regards
    -Laurence.

  • Search for a word in all my files on the mac HD

    Is there a function in the application of SEARCH to the search for a word or phrase in all my files to my Mac Book Pro HD?

    Have you tried spotlight and searched on "content?  See this discussion.

  • Under XP I could search for a string in all the files on my computer. I can't find this search function of SMEs on Windows 7. Anyone?

    On Windows XP, there is a search function to search for a string in any kind of files on your computer. You are looking for a specific name was easy, if you fogort what kind of file, this name occurred in or what it was named.

    On Windows 7 it only allows searching for a name of a file.  How to search for strings in file names?  29/12/12 Paul Figueroa

    Oh, what you want is the content property.

    content: ~ = Figueroa

    [Update: apparently special search symbols such as ~ = do not work with the content when property indexed research places, but work during the search in unindexed locations.]

    I should mention that Windows 7 Search is not case sensitive, so it makes no difference to try to find upper or lower case letters.  In addition, Windows 7 Search is not able to search the contents of files that have no file extension.  There is also a weird question having to watch in Indexing Options to determine which file extensions are defined for content, research, where you have a type of unusual file that is not defined for the content of the search.

  • Search for value in the subset of data and returns a single line.

    Hello

    I wonder if you can help me with a query.

    I want to return a single line of data below

    where the Rno = 1 but also include a column to indicate a code of T555 tran was found in the subset (based on customer no)

    I used an analytic function (row_number) to enter the data in the following order and wonder if there is something similar for helping me understand the transaction code.

    Customer without Tran Code TranDate NWR

    1 T345 01/01/2001 1

    1 B455 01/01/1999 2

    1 T555 01/01/1998 3

    1 R433 01/01/1997 4

    1 "T543" 01/01/1996 5

    Thank you


    SQL> with t
      2  as
      3  (
      4  select 1 client_no, 'T345' tran_code, to_date('01/01/2001', 'dd/mm/yyyy') trandate, 1 rno
      5    from dual union all
      6  select 1 client_no, 'B455' tran_code, to_date('01/01/1999', 'dd/mm/yyyy') trandate, 2 rno
      7    from dual union all
      8  select 1 client_no, 'T555' tran_code, to_date('01/01/1998', 'dd/mm/yyyy') trandate, 3 rno
      9    from dual union all
     10  select 1 client_no, 'R433' tran_code, to_date('01/01/1997', 'dd/mm/yyyy') trandate, 4 rno
     11    from dual union all
     12  select 1 client_no, 'T543' tran_code, to_date('01/01/1996', 'dd/mm/yyyy') trandate, 5 rno
     13    from dual
     14  )
     15  select client_no
     16       , tran_code
     17       , trandate
     18       , rno
     19       , case when t555_cnt > 0 then 'YES' else 'NO' end t555
     20    from (
     21            select t.*
     22                 , count(decode(tran_code, 'T555', 1)) over() t555_cnt
     23              from t
     24             where client_no = 1
     25         )
     26   where rno = 1;
    
     CLIENT_NO TRAN TRANDATE         RNO T55
    ---------- ---- --------- ---------- ---
             1 T345 01-JAN-01          1 YES
    
    SQL>
    
  • Search for ISO files in all data stores NFS bypassing the folders .snapshot

    Hello

    Someone has a tip on how to find all preparations of NFS data for an ISO files bypassing the folders ".snapshot."

    What I tried:

    "dir-Recurse vmstores: \-inclure *.iso | Select name, length folderpath, lastwritetime | out-gridview.

    But the line above is not ignoring the snapshot files and it takes forever to analyze because of the snapshot files.

    Any suggestions would be widely accepted.

    BR

    There was a "Select - first 1' in there to test, I have removed that.»

    You can try again now?

  • Search for Safari crashes on all devices

    I have a question very bizzare. I am unable to use Safari with success on my iPad, iPhone and the iMac. They all run the latest versions of El Capitan & iOS respectively.

    On the iMac - safari takes over, but the search bar does not work - no search is possible (you can type, but does not appear or anything occurs when you press on enter), only by entering the URL manually. On iOS, the Safari app closes as soon as you touch the search bar. Typing a bookmark works well.

    Any thoughts? It feels as if something in iCloud is perhaps corrupt Safari on all fronts.

    Try the following steps:

    A possible solution to the problem of address bar: disable the Safari Suggestions

  • Search for forums work at all?

    I have the Forum through the request for help from Adobe.  When I do specific searches of the Illustrator forum, even choose search terms that appear in the list of the opening of the latest discussions, I get NO search results.

    I have extended the deadline and expanded forums and discussions - nothing new.

    It present some glitch coming to it from a Mac?  Very very confused.

    Bob,

    Unfortunately, the search function is a malfunction to search most of the time, and many complanits were made on this subject here, in the Forum comments forum:

    http://forums.Adobe.com/community/General/forum_comments

    This is one of the threads:

    http://forums.Adobe.com/thread/823088?TSTART=0

  • Easy way to display the value of the search for value vs reference foreign key itself

    I understood how to do this for a form

    http://www.DBA-Oracle.com/HTMLDB/t_lov_list_values_master_parent_child.htm

    .. .but not for a report which lists the data line by line.

    Center table with the following columns:

    ID
    Name
    Department_id

    and service table with the following columns:

    ID
    Name


    When the report runs on the Center table, it queries simply department_id, name and the ID of the database and then displays each column as it is.

    Instead of display the Center table department_id (which is a number and not very informative), how can I do to display the name of the department table?

    I have many other similar areas that should be displayed in this way, so I hope that there is not a ton of configuration/coding I have to do.

    Hello

    Try the report query

    SELECT a.id,
      a.name,
      b.name dept_name
    FROM centre a,
      department b
    WHERE a.department_id = b.id
    

    BR, Jari

  • Months of searching for numbers on the sheet

    Hello all and thanks in advance.

    I have tabs at the top. DATA (sheet 1), JAN (sheet 2), FEB (record 3), etc. until the end of the year.

    Data sheet will be the months on the left now I want care to go to the form to correct month and takes the total of the column relative to the other leaves and place in the correct cell line. (I've been copy paste, but I know there is an easier way to do this, so I turn to the people who know the numbers unlike my lack of knowledge.)

    On the leaves of the month, I would also like to highlight the line that are sat and Sun.

    Thanks again everyone for their help.

    Rich

    In the material master

    Hi, NN,.

    You will have a Table for each month. Each Table must have a different name. Your summary table lists more than 12 months, then I would say the table name from each month is named with the name of the month AND the year.

    The monthly tables may appear on separate sheets, or the same sheet. The key, as far as the formulae are concerned, is that each Table can be identified by its name.

    The following example includes only the table for April 2016, named "APR 2016", I assumed that the total line will be row 33 on each table of data collection, but wrote the formula to allow the placement of the line totals in other places. The lines for most of the actual days have been hidden and has not been designated, as these labels have no role in the operation of the formula.

    The TOTALS is defined as a footer line. The formula, in the columns showing a value is SUM (a) where 'a' is the letter of the column to be added. (The two values of zero have been entered manually for example).

    The table has a unique formula, entered in cell B3 and filled with right and until the last line for which there is a Table whose name corresponds to the label in column A. For example, the formula has been met only 3 online.

    B3: = INDEX (APRIL 2016: $A$ 1: $ 33, MATCH $N ("TOTALS", APRIL 2016: $A, 0), GAME ($ 1 B, APRIL 2016: $1: $1.0),)

    Syntax:

    INSTRUCTION (range,-l'index of the line, column-index, index of the surface)

    range: all of the cells in the source table

    the index of the line: the number of the start line to get the value. This is provided by the first statement of the GAME.

    the index of the column: the number of the column from which to get the value. This is provided by the second statement to MATCH.

    the index of the surface: omis. By default, 1. There is only 1 area of application of this INDEX, all of the source table.

    MATCH (image search-search for, - where - method)

    EQUIV function returns the position in the list of the search for value.

    First case:

    search for: TOTALS text

    search - where: column A of table source

    method): 0 means finding the exact value.

    Second case:

    search for: the text contained in the cell of line 1 of the specified column. That form is completed on the right, the increments of the column by one for each stage.

    search - where: line 1 of table source

    method): 0 means finding the exact value.

    The formula should be changed for each new line. Three references to "APR 2016" should be changed to match the name of the table to collect this row grand totals. Once edited in column A, the formula can be filled right and automatically adapts to his new position.

    Note: The duration value in column F of the table of the month wouldn't transfer and keep the same formula in column C of the summary table. Any attempt to restore the format to match your example resulted in a triangle of error.

    Kind regards

    Barry

  • Install the HP software for the 5500 series all-in-one Macintosh

    I reinstalled the software all-in-one HP 5500 on Mac OS 10.6 running, and now I can't print.   I uninstalled the software from the CD and re-installed but not luck.

    The printer was working before, but I have reinstalled the software because the ferry did not work when scanning documents.

    When I try to print nothing happens and when I go to print queue shows the document and status is listed as "error" with no further details.

    I can print a test page.  When I try to scan (from the all-in-one), I can see the scan on my screen but cannot open the document (pdf) and it is said that something is wrong with the scanned document and that some software is missing for the printer.

    Download and install this: support.apple.com/kb/DL907

    Reset the printing system:

    -Go to System Preferences > print & Scan
    -Right (or control) click in the rectangle listing your printers and select Reset Printing System.
    WARNING - This will remove ALL your printers!
    -Select the sign more to add a printer. Select the default tab on the top of the window. Search for the printer, select it, and wait until the button 'Add' becomes available. Until it clicks.

  • File directory cannot search for Smartphones blackBerry after new entry

    I recorded a new record on my phone book, and I use the search icon-online-online Select All keyword-online search.  I could find that record of my directory.

    And I double check a few times in the phone book file is prevailing.  Do not know why.

    (I tried the two first, last, first + last name) still does not work.

    All the old records seem to work OK with the search except this new record feature.  I deleted that record and recreated again again do not help.  Help, please.

    I tried it and I'm able to find Contacts using the search. I found that I have to enter the name of contacts in the field 'Name' rather than the 'Text' field so he can find it. I have never search for the one that long before that. I always go into the address book and type the first few letters of their name and he will find them.

  • Impossible to search for songs on iPhone using iTunes search box

    I have an iPhone running iOS 9.3 6, and my work PC was recently swapped for a newer model. The new PC running iTunes 12.3. Until the computer has been swapped, to search for a song on all my iPhone, that I had to connect my iPhone to the computer, click on "Music" in the column of playlist on the left side to see all the songs on my iPhone and type the name of a song (or any other relevant information) in the search box. Now, when I type the name of a song I want on my phone, I get a message "No results of library." In order to search for a song on my iPhone, I have to click the icon of the device (iPhone) on iTunes, scroll down to the "On My Device" section, click music and then type in my search term in the search box.

    Any ideas how I can just return to search on the old way instead of having to do additional steps?

    Click on the magnifying glass in the search box, and uncheck the box search entire library.

    TT2

Maybe you are looking for

  • Real-time backup question

    Real-time running Apple Time Machine backup airport Time Capsule?

  • Connect my e-mail yahoo for Outlook Express for Windows XP

    I followed the instructions in the wizard, but when I start Outlook, it evokes a box that says: "enter network password". In this box, it lists my server as being: pop.mail.yahoo.com. It then lists my user name (which is OK for yahoo), then he asks f

  • Trend titanium stop Defender?

    I thought that I had the two running before my machine being debugged trend last week. Defender and titanium will work together?

  • 4620 installation printer MUST have access to the network?

    I want to connect a printer to 4620 all-in-One for a Dell 4400 DIM, which is running win XP SP3.  I did not need the fax or Scan functions or by mail and all I want to do is print the documents I compose on MS Office.  However, connect this printer o

  • Problem with user API 5.0 interface components

    Hello! I have a problem with the user interface components. My application needs of the analogues of the toolbar and PaneManager (as in api 6 and higher) in BB API 5, but I have no idea how to make them. Please, need help