Add a string when the query returns all records

DB version: 11.2

create table t (empname varchar2 (25), salary number, varchar2 (20) months, number of over_time);

insert into values t ('JOHN', 2000, "NOVEMBER2014", 0);

insert into values t ('KATE', 2000, "NOVEMBER2014", 300);

insert into values t ('HANS', 5000, "NOVEMBER2014", 100);

insert into values t ("KRISHNA", 2500, "NOVEMBER2014", 0);

insert into values t ("SIEW", 3000, "NOVEMBER2014", 0);

commit;

SQL > select * from t;

EMPNAME MONTHS SALARY OVER_TIME

------------------------- ---------- -------------------- ----------

JOHN 2000 NOVEMBER2014 0

KATE 2000 NOVEMBER2014 300

HANS 5000 NOVEMBER2014 100

KRISHNA 2500 NOVEMBER2014 0

SIEW 3000 NOVEMBER2014 0

SQL > select * from t where MONTH = 'NOVEMBER2014' and OVER_TIME! = 0 ;

EMPNAME MONTHS SALARY OVER_TIME

------------------------- ---------- -------------------- ----------

KATE 2000 NOVEMBER2014 300

HANS 5000 NOVEMBER2014 100

What I need is:

If the query above returns at least one record, it should display the line ' Yes. We have one or more employees who worked overtime in November2014'

before the documents are printed

Thus, the expected production is

Yes. We have one or more employees who worked overtime at the November2014

EMPNAME MONTHS SALARY OVER_TIME

------------------------- ---------- -------------------- ----------

KATE 2000 NOVEMBER2014 300

HANS 5000 NOVEMBER2014 100

If the query returns no records then usual 'no rows selected' isn't enough

Lothar G.f. says:

In fact, sql * more is no good tool for use considered.

Really?  It may be a good reporting tool if you learn to use it as such...

for example

SQL > ttitle left 'Yes. We have one or more employees who worked overtime in November2014.
SQL > select * from emp where empno = 1234;

no selected line

SQL > select * from emp where empno = 7788;

Yes. We have one or more employees who worked overtime at the November2014
EMPNO, ENAME, JOB HIREDATE DEPTNO COMM SAL MGR
---------- ---------- --------- ---------- -------------------- ---------- ---------- ----------
7788, SCOTT, ANALYST, 7566 19 APRIL 1987 00:00:00 3000 20

This is just a basic example.  It is possible to get SQL * more to ask for the required criteria and that the title could adjust according to this criterion, as well as the query building on it also.

However, the OP did not specify SQL * as the reporting tool, so there is little interest providing a complete solution which, until they specify what user interface that they are actually using.

Tags: Database

Similar Questions

  • Select from another table, when the query returns no result

    Hello

    I have a question where I'm supposed to retrieve the address of an account id-based billing. However, the table of billing may not have an address. There is a table of addresses that always has an address for an account. If the billing address exists, it should be used, so I can't use the address table. Is it possible in a select statement to query to the billing address and if it does not exist, use the address table.

    SELECT * FROM accounts a, b billings WHERE a.accountid = b.accountid

    Any help will be greatly appreciated.

    Thank you.

    user10407139 wrote:
    Hello

    I have a question where I'm supposed to retrieve the address of an account id-based billing. However, the table of billing may not have an address. There is a table of addresses that always has an address for an account. If the billing address exists, it should be used, so I can't use the address table. Is it possible in a select statement to query to the billing address and if it does not exist, use the address table.

    SELECT * FROM accounts a, b billings WHERE a.accountid = b.accountid

    Any help will be greatly appreciated.

    I think you need to explain more clearly if

    -you only have a couple of "billing" columns which is empty and in this case, you want to use the columns from the table 'accounts '.

    - or you have a join with another table that doesn't return data, for example a foreign key "address_id" "billing" is zero and therefore the join to other tables 'address' will return all the data

    In the first case, you have already been provided with some examples here, how to use NVL or similar functions to achieve, even if the first post first evaluates the information of 'accounts' and if it is white using information from "billing". According to your description you need the other way around. The second post a subquery recursive useless in my opinion.

    In the latter case, you should probably use an "outer" join so that the data in your table "bills" are returned, even if the join to another table is not at all the lines.

    SELECT
    NVL(AD1.ADDRESS_ATTR1, AD2.ADDRESS_ATTR1) as ADDRESS_ATTR1,
    NVL(AD1.ADDRESS_ATTR2, AD2.ADDRESS_ATTR2) as ADDRESS_ATTR2,
    NVL(AD1.ADDRESS_STREET, AD2.ADDRESS_STREET) as ADDRESS_STREET,
    ...
    FROM accounts a
    INNER JOIN billings b
    ON a.accountid = b.accountid
    LEFT OUTER JOIN address ad1
    ON b.address_id = ad1.address_id
    INNER JOIN address ad2
    ON a.address_id = ad2.address_id;
    

    In this way you pick up the address stored in the "invoices" table, if it existed, otherwise you pick up the address assigned to the "accounts" table I used an inner for the second address join join because you said that the account always has an assigned address.

    Kind regards
    Randolf

    Oracle related blog stuff:
    http://Oracle-Randolf.blogspot.com/

    SQLTools ++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676 /.
    http://sourceforge.NET/projects/SQLT-pp/

  • When the query returns no data, I get a strange behavior

    Hi all!

    I use jDev 11.1.2.1.0

    I've implemented a .jspx a read-only table with a query at the top. The user can press the 'new' button and a popup with an editable form appears in the order the user to insert a new record.
    The user can press "ok" in the dialog box and the record is validated, or press 'cancel' and the restore operation is executed. Which is more or less all the features of the form.

    I have the following problem.
    If I have a query in a way so that no record is returned (so read only table is empty) and press the 'new' button, the validation of the VO are enabled in the form (that is, all the required fields are red). If I press cancel, the restore operation is performed, but there is a blank line in the table ready only. The user does not see the postings at this time, neither the blank line. BTY, if I try to delete this empty line, I 25039-Houston: RowNotFoundException, which makes sense, since there is no current record should be deleted. On re - interview, he disappears.

    This problem occurs only when there is no trace at all in the table.

    I can't understand...
    Any suggestions? Any clue?

    Thank you very much
    ~ apostolos

    In the popupCanceledListener have you tried to do a PPR manually using (.addPartialTarget) AdfFacesContext.getCurrentInstance ()?

    Thank you
    TK

  • reload the page when SQL query returns a value

    Hello world

    the title of this discussion may seem strange, but I'll try to explain why I need this:

    A user has the ability to connect on my APEX application. There are several tabs in my application that are visible only if a certain SQL statement returns a value which is not the case by default. The user has also the ability to download a file that is transferred to an external system that analyzes the file and writes the data in the database. During this writing process - which may take several minutes - conditions for some of the tabs to show the will becomes real (-> the query will return a value). When the user refreshes the page manually, the tabs will be displayed. However, I want the tabs will appear automatically when the condition is met.

    Is it possible to refresh the page as soon as the query returns a value? It is perhaps possible to check it on the client side and trigger a refresh of the page when the condition is met. It would be even better if only the tabset has been updated, but refreshing the full page is fine as well.

    Thank you!

    Here is an overview of how it can be done

    This is possible thanks to a dynamic action being performed on a timer.

    View default tabs and dynamic action hide them on loading the page if they are not to be considered

    Create a dynamic action that will execute your query every 5 seconds or more

    If the query returns data, you can use the dynamic action to show your tabs using javascript

  • If I drag and drop an object in a box. When the timeline returns like that, I want the object to remain in the area and restores not where it was originally.

    Hi all, this is my first post here. Very happy to be here.

    I created an interaction by which objects can be dragged and got stuck in a box. Never, I solved the problem when the playhead returned items I looked where I had left. I did it with as2 and never solved the problem which I am sure is easy enough to solve. I remember someone saying something about levels.

    I need to create an interaction where objects are put in a box and they stay there until the interaction ends. Say that the objects are in a room where the user must visit several times in the interaction. There must be a certain number of objects in the room and drag them into a box to get a done message, I want the user to be able to move to another part of my interaction and come back and be able to complete the conclusion and place the objects in the box without reset everything to where they were first encountered user them.

    I have wi

    All advice, tips are greatly appreciated.

    Looks like you need to add programming that 1) stores the x / y locations of the objects since they change 2) uses this information in position to position objects whenever you enter the picture that they are in.

    You should be able to create variables to store the information that is on a layer that extends from the complete timeline so that the data is stored as it is updated and you move along the timeline.  When you move the object update you its position data. Then, in the context where you have objects use you a simple coding to place objects using this position info... something as simple as...

    Object1.x = object1X;

    Object1.y = object1Y;

    If you are still using AS1/2 you would use _x and FLF instead of x and y

  • How to add multiple lines when the button is clicked

    How to add multiple lines when the click on button now is just add a row .plz give me idea how... waiting for answer

    / public final class screen extends MyScreen
    {
    /**
    * Creates a new object of MyScreen
    */
    ObjectChoiceField obj1 obj2, obj3, obj4.
    Table of String() = {'101 ', ' 102'};
    String of shadow [] = {"Shade1", "Shade2"};
    Rolls of string [] = {'101 ', ' 102'};
    String cutting [] = {"100-150", "150-200"};
    Chain of selectedindex1, selectedindex2, selectedindex3, selectedindex4;
    LabelField lbl1 lbl2, lbl3, lbl4;
        
    GFM LinedGridFieldManager;
    HFM HorizontalFieldManager, hfm1, hfm2 hfm3;
    VerticalFieldManager vfmMain;
        
    public MyScreen()
    {
        
    Set the displayed title of the screen
    hfm1 = new HorizontalFieldManager (HorizontalFieldManager.NO_VERTICAL_SCROLL |) HorizontalFieldManager.NO_VERTICAL_SCROLLBAR);
    hfm2 = new HorizontalFieldManager (HorizontalFieldManager.NO_VERTICAL_SCROLL |) HorizontalFieldManager.NO_VERTICAL_SCROLLBAR);
    hfm3 = new HorizontalFieldManager (HorizontalFieldManager.NO_VERTICAL_SCROLL |) HorizontalFieldManager.NO_VERTICAL_SCROLLBAR);
    HFM = new HorizontalFieldManager (HorizontalFieldManager.FIELD_RIGHT);
    vfmMain = new VerticalFieldManager (Manager.NO_VERTICAL_SCROLL |) Manager.NO_HORIZONTAL_SCROLLBAR);
            
    obj1 = new ObjectChoiceField ("", graph, 0, FIELD_LEFT);
    obj2 = new ObjectChoiceField ("", blind, 0, FIELD_LEFT);
    Obj3 = new ObjectChoiceField ("", rolls, 0, FIELD_LEFT);
    Obj4 = new ObjectChoiceField ("", cuts, 0, FIELD_LEFT);
            
    LBL1 = new LabelField("");
    LBL2 = new LabelField("");
    lbl3 = new LabelField("");
    lbl4 = new LabelField("");
            
    ButtonField btnAdd = new ButtonField ("ADD", FIELD_RIGHT);
            
    GFM = new LinedGridFieldManager (4, LinedGridFieldManager.VERTICAL_SCROLL);
            
    hfm1.setMargin (20, 0, 10, 0);
    hfm1. Add (new LabelField ("Chart"));
    hfm1. Add (obj1);
    hfm1. Add (new LabelField ("Shade"));
    hfm1. Add (obj2);
            
    hfm2. Add (new LabelField ("Rolls"));
    hfm2. Add (Obj3);
    hfm2. Add (new LabelField ("Cuts"));
    hfm2. Add (Obj4);
    HFM. Add (btnAdd);
            
    GFM. Add (new LabelField ("Chart"));
    GFM. Add (new LabelField ("Shade"));
    GFM. Add (new LabelField ("Rolls"));
    GFM. Add (new LabelField ("Cuts"));
            
    vfmMain.add (hfm1);
    vfmMain.add (hfm2);
    vfmMain.add (hfm3);
    vfmMain.add (hfm);
    vfmMain.add (new SeparatorField());
    vfmMain.add (gfm);
    Add (vfmMain);
            
    btnAdd.setChangeListener (new FieldChangeListener()
    {
    ' Public Sub fieldChanged (field field, int context) {}
    TODO self-generating method stub
    selectedindex1 = chart [obj1.getSelectedIndex ()];
    selectedindex2 = shade [obj2.getSelectedIndex ()];
    selectedindex3 = rolls [obj3.getSelectedIndex ()];
    selectedindex4 = cuts [obj4.getSelectedIndex ()];
                    
    While (LBL1. GetText(). Equals("") | LBL2. GetText(). Equals("") | lbl3. GetText(). Equals("") | lbl4. GetText(). Equals(""))
    {
    LBL1. SetText (selectedindex1);
    LBL2. SetText (selectedindex2);
    lbl3. SetText (selectedindex3);
    lbl4. SetText (selectedindex4);
                    
    GFM. Add (LBL1);
    GFM. Add (LBL2);
    GFM. Add (lbl3);
    GFM. Add (lbl4);
                    
    }
    }
    });
    }
    }

    Hi Piya,

    I run your code, and according to your logic that it works correctly.

    It's adding that line only once because according to your logic that one line can be added to MDT, if you do not want to add line on each click on the button, follow these steps:

    selectedindex1 = chart [obj1.getSelectedIndex ()];
    selectedindex2 = shade [obj2.getSelectedIndex ()];
    selectedindex3 = rolls [obj3.getSelectedIndex ()];
    selectedindex4 = cuts [obj4.getSelectedIndex ()];

    Lbl1 LabelField = new LabelField("");
    Lbl2 LabelField = new LabelField("");
    LabelField lbl3 = new LabelField("");
    LabelField lbl4 = new LabelField("");
    If (LBL1. GetText(). Equals("") | LBL2. GetText(). Equals("") | lbl3. GetText(). Equals("") | lbl4. GetText(). Equals(""))
    {
    LBL1. SetText (selectedindex1);
    LBL2. SetText (selectedindex2);
    lbl3. SetText (selectedindex3);
    lbl4. SetText (selectedindex4);
                    
    GFM. Add (LBL1);
    GFM. Add (LBL2);
    GFM. Add (lbl3);
    GFM. Add (lbl4);
                    
    }

  • How to add two lines when the second row is not visible, but also gets the first data line too?

    Mr President

    Jdev worm is 12.2.1

    How to add two lines when the second row is not visible, but also gets the first data line too?

    I want to add two lines like below picture, but want the second to remain invisible.

    tworows.png

    I asked this question but my way of asking was wrong, that's why for me once again.

    Concerning

    Try to follow these steps:

    1. in the database table to add the new column "JOIN_COLUMN" and add the new sequence "JOIN_SEQ".

    2. Add this new column in the entity object. (You can add this in entity object by right clicking on the entity object and then select "Synchronize with database" then the new column and press on sync)

    3. in your bookmark create button to create only one line NOT 2 rows.

    4 - Open the object entity--> java--> java class--> on the entity object class generate and Tick tick on the accessors and methods of data manipulation

    5 - Open the generated class to EntityImpl and go to the doDML method and write this code

      protected void doDML(int operation, TransactionEvent e)
      {
        if(operation == DML_INSERT)
        {
          SequenceImpl seq = new SequenceImpl("JOIN_SEQ", getDBTransaction());
          oracle.jbo.domain.Number seqValue = seq.getSequenceNumber();
          setJoinColumn(seqValue);
          insertSecondRowInDatabase(getAttribute1(), getAttribute2(), getAttribute3(), getJoinColumn());
        }
    
        if(operation == DML_UPDATE)
        {
          updateSecondRowInDatabase(getAttribute1(), getAttribute2(), getAttribute3(), getJoinColumn());
        }
    
        super.doDML(operation, e);
      }
    
      private void insertSecondRowInDatabase(Object value1, Object value2, Object value3, Object joinColumn)
      {
        PreparedStatement stat = null;
        try
        {
          String sql = "Insert into table_name (COLUMN_1,COLUMN_2,COLUMN_3,JOIN_COLUMN, HIDDEN_COLUMN) values ('" + value1 + "','" + value2 + "','" + value3 + "','" + joinColumn + "', 1)";
          stat = getDBTransaction().createPreparedStatement(sql, 1);
          stat.executeUpdate();
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }
        finally
        {
          try
          {
            stat.close();
          }
          catch (Exception e)
          {
            e.printStackTrace();
          }
        }
      }
    
      private void updateSecondRowInDatabase(Object value1, Object value2, Object value3, Object joinColumn)
      {
        PreparedStatement stat = null;
        try
        {
          String sql = "update table_name set column_1='" + value1 + "', column_2='" + value2 + "', column_3='" + value3 + "' where JOIN_COLUMN='" + joinColumn + "'";
          stat = getDBTransaction().createPreparedStatement(sql, 1);
          stat.executeUpdate();
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }
        finally
        {
          try
          {
            stat.close();
          }
          catch (Exception e)
          {
            e.printStackTrace();
          }
        }
      }
    
  • How to add a string to the end TLFTextField without losing the current text format!

    • I have a TLFTextField which loads the text of the external text file.
    • Then a function changes the format of certain parts.
    • Then, as soon as I add a string to the end my TLFTextField, all previous formatting is lost!

    I use this code to add the string:

    • myTLF.text += ".";

    or

    • myTLFText.text = myTLFText.text.concat(".");

    Should I use another method?

    Sample.png


    pass again the text through your function put shaped, or try appendText:

    • myTLF.appendText(".");
  • Why I - Phone 4 always shows use of 2.6 GB mail when the total of all the mail is only 5 MB?

    Why my I-Phone 4 mail application always displays the use of 2.6 GB when the total of all messages is less than 5 KB?

    When in your Mail pass of mailboxes, and then select the account in your email. From there, see if you have other folders where the post goes as undesirable or sent, Deleted etc.

  • I'm unable to open Add/Remove programs in the Control Panel, all other bits in the control panel can be opened.

    Add/Remove programs. I'm unable to open Add/Remove programs in the Control Panel, all other bits in the control panel can be opened. Any ideas? Thank you.

    original title: Add/Remove programs.

    Hi, Tay 13,

    Open command prompt window

    type the following command

    SFC/scannow

    Press enter

    Note: There is a space between SFC and / scannow

    Once the scan is complete, look for the journal by clicking Start > run

    Type

    %windir%\Logs\CBS

    Search for repaired files or cannot repair file and note the name of any file not repaired.

    New attempt to open Control Panel Add/Remove section.

    Open the command prompt window

    Type the following command

    appwiz.cpl

    Press enter

    This will open Add/Remove programs

  • Is there a fix for when the reader changes all my program icons?

    Is there a fix for when the reader changes all my program icons?

    See http://helpx.adobe.com/acrobat/kb/application-file-icons-change-acrobat.html

  • Overview of the LR5 does not. Just updated iMac 2010 with ssd, 32 GB of ram and El captain and all imports new previews are gray. The images are there, can work on them and then they appear in the preview. All records older still work fine just new downlo

    Overview of the LR5 does not. Just updated iMac 2010 with ssd, 32 GB of ram and El captain and all imports new previews are gray. The images are there, can work on them and then they appear in the preview. All records older still work fine just new download does not work. Help, please!

    Please try and delete preview Cache.

    It is located in the same folder as the catalog in Lightroom. The name of the cache an extract ends with Previews.LRDATA and should be deleted. Not to be confused with *. LRCAT, which should not be deleted

    Default location should folder of the image.

    Kind regards

    ~ Mohit

  • Query based ViewObject does pull not all attributes, when the query has 'WITH' clause

    Hello

    12.1.2 and 12.1.3 JDeveloper

    When we try to create a custom query based ViewObject, and the query clause of "with."

    So not all the columns selected in the query are appearing as attributes of the View object in the wizard.

    This is the query. And it performs very well in Toad.

    WITH dept_count AS)

    SELECT department_id, COUNT (*) AS dept_count

    Employees

    GROUP BY department_id)

    SELECT e.first_name AS employee_name,

    DC1.dept_count AS emp_dept_count,

    m.first_name AS manager_name,

    DC2.dept_count AS mgr_dept_count

    E employees,

    dept_count dc1,

    m employees,

    dept_count dc2

    WHERE e.department_id = dc1.department_id

    AND e.manager_id = m.employee_id

    AND m.department_id = dc2.department_id;

    Only the EmployeeName attribute is extracted from the query. It does not show the rest of the attributes in the VO Wizard.

    VO.png

    (I also tried to create a VO from the EntityObject class and make it editable as false, even in this case all attributes are not displayed.)

    I was wondering if something changed in 12 c?

    It works in 11.1.1.7

    (A friend of mine just asked me this).

    Thanks for any help.

    Sameer

    Jdev dislikes the syntax

    You can rewrite as

    SELECT e.first_name AS employee_name,

    DC1.dept_count AS emp_dept_count,

    m.first_name AS manager_name,

    DC2.dept_count AS mgr_dept_count

    E employees,

    (

    SELECT department_id, COUNT (*) AS dept_count

    Employees

    GROUP BY department_id) dc1,.

    m employees,

    (

    SELECT department_id, COUNT (*) AS dept_count

    Employees

    GROUP BY department_id) dc2

    WHERE e.department_id = dc1.department_id

    AND e.manager_id = m.employee_id

    AND m.department_id = dc2.department_id

    who must work and give you the same result.

    Timo

  • 12.2.4 WebADI - Integrator custom fails to cleanup script is triggered when the import returns the error lines

    Hi, hoping for help because it is not very useful detailed documentation on this topic here.

    I built a custom WebADI that uses custom procedures to validate and download the date in a custom table.  I then called an importer script that checks the balance of files (and other things) and mark the lines that do not reach a State of error.  I also managed to get these errors to be selected by the definition of error line and message error search section and everything is right with the world.

    Except that when imported and reports to hide the sad faces appear in the worksheet, I expect the cleanup script then learn to delete the records so that when the errors are corrected in the spreadsheet we don't get the lines in double... and is not.  No amount of tweaking, etc. application errors will result in cleaning the fire.

    Can someone tell me what I need to import of PL/SQL program to do when it detects a mistake for execution of the cleaning procedure?

    Thanks in advance

    Mike

    IT FIXED myself.

    The downloaded must be a function and return an error message of VARCHAR2.  If you return NULL - then the cleaning is not called as expected. If you return to any string, then cleanup is called.

  • CFwheels WHEN the query

    I recently learn CFwheels. Am able to print all of my objects in a database in a loop with this command line to...

    <cfset queryall = model("equips").findAll(order="name")>
    

    But I want to do a query where it returns only the elements of this basis where status = 'In '.  I tried this...

    <cfset appequips = model("equips").findAll(WHERE "status=In")>  
    

    But I get an error "invalid construct.

    The documentation says to do-


    <!--- Including an association (which in this case needs to be setup as a `belongsTo` association to `author` on the `article` model first) --->
    <cfset articles = model("article").findAll(where="published=1", order="createdAt DESC", include="author")>

    I don't know what they mean with the association 'belongsTo '...

    My entire function in the "equiplist" controller (all exterior line with WHERE is for something else and works very well).

    < cffunction name = "equiplist" >

     <!---query everything--->
            <cfset queryall = model("equips").findAll(order="name")>
    <!---end main query--->
            
              <cfset appequips = model("equips").new>
              <cfset appequips = model("equips").findAll(WHERE "status=In")>
            
    <!---queries for adding new equipment--->    
            <cfset equip = model("equips").new()>
            <cfif isPost() and StructKeyExists(params, "equip")>
                <cfset equip = model("equips").new(params.equip)>
                <cfset equip.save()>
                <cfset redirectTo(action="equiplist")>
            </cfif>
    <!---end new equipment save--->
        </cffunction>
    

    And the view

    <!---Pending requests--->
    <span class="label label-default">Pending Requests</span>
        <table class="table table-bordered table-striped">
                <tr>
                <td><b>Verify</b></td>    
                <td><b>Name</b></td>
                <td><b>Serial #</b></td>
                <td><b>Date Out</b></td>
                <td><b>Return Date</b></td>
                <td><b>Status</b></td>
                </tr>
        <cfloop query = "appequips">
            <cfoutput>
                <tr>
                <td>
                    #startFormTag(action="pending")#
                    <button class="btn btn-warning"><span class="glyphicon glyphicon-hand-right"></span></button>
                    <input name="serial"type="text"style="display:none" value="#serial#"/>
                    #endFormTag()#
                </td>    
                <td>#name#</td>
                <td>#serial#</td>
                <td>#startdate#</td>
                <td>#enddate#</td>
                <td>#status#</td>
                </tr>
            </cfoutput>
    </cfloop>
    </table>
    

    Thank you

    I answer my own question...

    Fixa-

     

    TO

     

Maybe you are looking for