Query strange behaviour...please help...

Dear All,
I do have one query having two where conditions and group by and an order by ..
The problem is i run with particular combition of column values in where...oracle is exiting from sqlplus..(i.e disconnected)..
if i change where cluase combition which working fine...the problem is only for particular combination of where clause columns..(which more than 2 million records)..
Even i tested saperately the groupby and order by..it is working fine..
I am using 10g..really dont understand this oracle behaviour..
Please suggest...
Thanks
Onenessboy

It 's like - you have given all the ingredients and follow the exact process to cook a special item - but forget to open the fire.
Where is your code? How do we investigate your problem?
Please post your table's DDL and some test data in form of DML and also post your exact DB version with proper format.
Got me?
Regards.
Satyaki De.

Similar Messages

  • I can't watch Dailymotion videos on my iPad but can do so on my iPhone and PC. Very strange. Please help !

    I can't watch Dailymotion videos on my iPad but can do so on my iPhone and PC. Very strange. Please help !

    Take it to an Apple store genius bar to have the techs see what your options are for repair/replacement.  An out-of-warranty replacement is $149 in the US for the iPhone 4.

  • URGENT: Strange behaviour! Help!

    Hi All.
    When I run the enclosed program I am getting some strange behaviour. For instance, when I click on the EDIT button nothing happens, but when I click on the DELETE button everything is fine!
    And I can also not run the code in edit() directly after add(). Nothing happens. PLEASE HELP ME. I am going mad because I cannot see what is wrong!
    I want to run the code associated with the buttons to update my JTable. Please tell me if there is something wrong in the code.
    As I say - it works fine when I click the DELETE button, but on the others it doesn't work.
    Please tell me if you need more information!
    HOPE TO HEAR FROM SOMEONE BEFORE I KILL MYSELF OUT OF FRUSTRATION!!!!
    C
    // The "Main" class.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    import javax.swing.JPanel;
    import javax.swing.JTable;
    import javax.swing.table.AbstractTableModel;
    import javax.swing.JScrollPane;
    import javax.swing.JFrame;
    import javax.swing.SwingUtilities;
    import javax.swing.JOptionPane;
    public class Team
        extends JFrame
        implements ActionListener {
      JLabel LTeamSetup = new JLabel();
      JButton Edit = new JButton();
      Font customFont1 = new Font("SansSerif", Font.BOLD, 18);
      Font customFont2 = new Font("SansSerif", Font.PLAIN, 12);
      JButton Delete = new JButton();
      JButton Close = new JButton();
      JButton Add = new JButton();
      Border border1;
      TitledBorder titledBorder1;
      TeamDataModel myModel = new TeamDataModel();
      JTable Table = new JTable(myModel);
      JScrollPane scrollPane = new JScrollPane(Table);
      public Team() {
        super("Add Team Window");
        setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        setSize(790, 560);
        setLocation(3,5);
        setVisible(true);
        try {
          new DBTeam();
          jbInit();
        catch (Exception e) {
          e.printStackTrace();
      public void actionPerformed(ActionEvent event) {
        if (event.getActionCommand() == "CLOSE") {
          close();
        if (event.getActionCommand() == "ADD") {
          add();
        if (event.getActionCommand() == "DELETE") {
          delete();
        if (event.getActionCommand() == "EDIT") {
          edit();
      public void close() {
        this.dispose();
      public void add() {
        new TeamAdd();
      public void delete() {
        DBTeam.numRows();
        DBTeam.rows();
        Table.tableChanged(new TableModelEvent(myModel));
        Table.repaint();
      public void edit() {
        DBTeam.numRows();
        DBTeam.rows();
        Table.tableChanged(new TableModelEvent(myModel));
        Table.repaint();
      ///////////////////////////SETUP SWING FRAME////////////////////////
      private void jbInit() throws Exception {
        border1 = BorderFactory.createCompoundBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED,Color.white,Color.white,new Color(124, 124, 124),new Color(178, 178, 178)),BorderFactory.createEmptyBorder(1,1,1,1));
        this.getContentPane().setLayout(null);
        LTeamSetup.setBounds(new Rectangle(23, 4, 203, 50));
        LTeamSetup.setEnabled(true);
        LTeamSetup.setFont(new java.awt.Font("SansSerif", 1, 36));
        LTeamSetup.setForeground(Color.black);
        LTeamSetup.setText("Team Setup");
        LTeamSetup.setBounds(new Rectangle(41, 13, 390, 50));
        Edit.setText("EDIT");
        Edit.setBounds(new Rectangle(647, 157, 94, 45));
        Edit.setActionCommand("EDIT");
        this.setResizable(false);
        this.setTitle("Team Setup");
        Delete.addActionListener(this);
        Delete.setBounds(new Rectangle(647, 214, 94, 45));
        Delete.setText("DELETE");
        Close.setText("CLOSE");
        Close.setBounds(new Rectangle(641, 480, 105, 26));
        Close.addActionListener(this);
        Add.setText("ADD");
        Add.setBounds(new Rectangle(647, 99, 94, 45));
        Add.addActionListener(this);
        scrollPane.setBounds(new Rectangle(40, 96, 567, 412));
        this.getContentPane().add(LTeamSetup, null);
        this.getContentPane().add(Delete, null);
        this.getContentPane().add(Close, null);
        this.getContentPane().add(Add, null);
        this.getContentPane().add(Edit, null);
        this.getContentPane().add(LTeamSetup, null);
        this.getContentPane().add(scrollPane, null);
        scrollPane.getViewport().add(Table, null);
        repaint();
    }

    if (event.getActionCommand() == "CLOSE") {
    if (event.getActionCommand() == "ADD") {
    if (event.getActionCommand() == "DELETE") {
    if (event.getActionCommand() == "EDIT") {And these look highly dubious, too. Shouldn't you be doing
    event.getActionCommand().equals("CLOSE")
    etc.?

  • How to know the most queried item? (please help me)

    I'm doing a library's bookkeeping.
    In a report I wanna know what's the book more queried or the most looked. But I dont know how to put the query in SQL.
    can you please tell me?
    the columns in the table are:
    books varchar2(30)
    author varchar2 (30)
    (THERE's NOT any Book_id) or something.
    please help me.

    That's not a Forms question. Please direct your question to the appropriate forum.
    However, using those columns, there is no way to tell the book most queried, unless you store that information yourself, or use some sort of auditing in the database.
    Regards,
    Robin Zimmermann
    Forms Product Management

  • Query Using Joins.Please Help

    Hi,
    A Query please
    I have a Customer table and an Order Table
    The customer can place multiple orders
    Create Table Customers
    (Cust_id      number(2),
    cust_name    varchar2(15),
    constraint   pk_custid PRIMARY KEY(Cust_id)
    Create Table Orders
    (Order_no    number(2),
    Cust_id     number(2),
    order_status varchar2(1),
    constraint  pk_orderno PRIMARY KEY(order_no),
    constraint  fk_custid  FOREIGN KEY(cust_id)
    REFERENCES  Customers(cust_id)
    )Now,the Customer table has a single record
    whereas the Order Table has multiple records
    for the same customer.
    SQL> Select * from Orders
    ORDER_NO   CUST_ID ORDER_STATUS
            1         1 P
            2         1 PI'd like to view the different orders for that same customer
    Using a simple Join DOES NOT give the right output:
    SQL> Select C.cust_id,C.cust_name,
      2  O.order_no,O.order_status
      3  From Customers C,Orders O
      4  where C.cust_id = O.order_no;
      CUST_ID CUST_NAME        ORDER_NO O
            1 ABCD              1       PThere are 2 records in the Orders Table?
    How to view both the records from Orders Table?
    Do I need to use the EXISTS clause?
    Can someone please help?

    Well, I would have thought that you would join C.cust_id with the O.cust_id (and not O.order_no)???
    SQL> Select C.cust_id,C.cust_name,
      2  O.order_no,O.order_status
      3  From Customers C,Orders O
      4  where C.cust_id = O.order_no;

  • Computer is acting very strange. Please help.

    My computer has starter acting very strange. It has start to take ages to boot up, and it runs a progress bar on the grey apple screen (as if its was booting in safe mode, but its not). I cant seem to save any files with any Apps. When I try to save documents in office it tells me ether the file name or path doesn't exist, it is open by another program, or its read only. Office also keeps coming up with errors saying im out of memory. Other apps just come up with errors when I try and save files.
    The last thing I did before my computer started acting up, was to increase the size of a Windows partition. Using Winclone I copied my Windows OS, then added the partition back to my mac, and re-partitioned it to a larger size. I formatted it into NTFS using Tuxera, and then used Winclone to put Windows back on. Everything seemed to go smoothly, and the Windows OS is fine.
    Please Help!

    Yes, iRadu is correct.
    If Disk Utility can't fix it, you'll need a more robust utility for the repair. I would recommend DiskWarrior. It is the best at directory repairs. It rebuilds then actually replaces your old directory. I feel every Mac owner should have a copy.
    Make sure you get the disk so you can boot up on it to run repairs. You can also install it on another drive and run it from there to repair this one. DW works faster that way.
    I use DW once a month to try and catch errors in my system from getting too far out of hand.
    DW is the only utility I would recommend to repair +Keys out of order+. It's a pretty serious error.
    Do you have a good backup...one with no issues?
     DALE
    p.s. Here's a rewiew of DiskWarrior 4.

  • Baffled by a strange bug - please help!!!

    Hi all,
    I am baffled by a bug in a program I am working on that I just
    can't understand. Here is the code that causes a SIGSEGV crash:
    268      int k = wfall_pixbuf.rowstride;
    269      pix[0] = pix[ -k ];
    270      pix[0] = pix[ -wfall_pixbuf.rowstride ];
    Output of gdb:
    Program received signal SIGSEGV, Segmentation fault.
    0x00000000004152b2 in Display_Waterfall () at display.c:270
    270          pix[0] = pix[ -wfall_pixbuf.rowstride];
    wfall_pixbuf is a struct that encapsulates a GdkPixbuf together
    with some variables that hold the values of some properties like
    rowstride above.
    I added lines 268 and 269 in despair and the program
    works well if I comment out line 270, which does (I think)
    the same job as 269. I can't see how wfall_pixbuf.rowstride
    can change value from line 268 to 270???
    Please help!!!

    danielsoft wrote:
    hello,
    I think it's a type issue: what type is wfall_pixbuf.rowstride ?
    in the case
    int k = wfall_pixbuf.rowstride;
    pix[0] = pix[ -k ];
    you are making a negative value out of type "int" - precisely signed int
    when wfall_pixbuf.rowstride is unsigned, the result is undefined...
    what does
    pix[0] = pix[ -(int)wfall_pixbuf.rowstride ];
    do? should work the same as lines 268 and 269
    Ahh, thank you very much! rowstride is of type guint, which is
    a GTK2 type definition, essentially I think it boils down to
    unsigned int. So that was the issue :-)
    I am surprised that I didn't make a mistake of this sort till now
    but its never too late.... ;-)

  • HT5636 I was typing in a word for Mac document and I hit the apple key and the numeral 8 at the same time now all of my documents have these strange symbols please help

    I was typing in a word for Mac document and I hit the apple key and the numeral 8 at the same time now all of my documents have these strange symbols please help

    Simply type command 8 again. That toggles the "show paragraphs" function.

  • HT5636 I hit the apple key and the numeral 8 at the same time now all of my documents have these strange symbols please help

    I hit the apple key and the numeral 8 at the same time now all of my documents have these strange symbols please help

    Simply type command 8 again. That toggles the "show paragraphs" function.

  • Iclod Id Strange Problem Please Help

    I have iPhone 4 i Used my icloud ID On It After Some Time i erased My Id From iPhone 4 And Used Same Id On My New Purchased iPhone 4s
    After That i Update my iPhone 4 to 7.0.4 IOS After Update again iphone 4 wants my iclod id for activation witch i already erased from it and using on new 4s
    so i remove id from 4s and gives my id and pass in iphone 4 to activate but reply come This Iclod ID Not sign with this iPhone even my id name Like abc....[email protected] is showing me on icloud login stage now i m not able to login my own icloud id on iPhone 4 & not able to activate even i alredy erased before update to 7.0.4 and using on new 4s same id. Please help me my id pass is working i checked 3 time with icloud.com and also find my iPhone off but i m still not able to login or activate my own id witch appear on login screen

    As i said on activation lock iphone shows my own id but when i put id & pass reply comes not sign with this iphone hows that possible activation lock screen display my own id and not accept ?
    even i erase my id from this device becuse i m using on now iphone 4s and when i restore my iphone 4 device again ask me for my id pass witch i already erased before using on new 4s why ?
    i never change my is or pass then why not accepting ? activation lock screen ghul....[email protected] apear my own ID and now said not sign with this id is this happen coz i m using it now 4s ?
    or what ? why asking me again i already erased this id from iphone 4 before using on 4s this is not good i need solution i can provide all details of my id if any apple support team member wants they can check this id locked on my iphone 4 then ehy not accept now

  • Very strange boot/device behaviour- please help!

    hello!
    i was quite happy with my macbook pro, when it one day did not boot anymore. i just saw the black screen and no startup sound was heard. i tried several times to restart, but no result. i gave up for some hours and when i came back it worked again.
    i thought it might have been the humidity as sunnier days came their way and my macbook worked without any problem.
    however, one month later i´m confronted again with this boot issue. so after the mbp has been turned off, i have to wait 30 minutes in order to be able to restart. if not, it gets stuck with the black screen.
    i went trough the troubleshooting tips (SMC reset, PRam reset) and even made an archive and install. unfortunately without any result.
    to make things worse my audio stopped to work also. first it did not even show up the devices -" no input/output devices found", after the archive and install the devices were found, but still no sound (except the startupsound)...
    ...i really do not have any clue what might be the problem, but as i am currently far from home and far from any apple support center, i would very much appreciate every hint or solution.
    tnx
    dawandeh
    macbook pro 2,33 GHz Mac OS X (10.4.9)

    hello again!
    it's very strange indeed. my macbook was working without any problems again for 2 days. then i was playing music on itunes when the screen went black(please restart), i could hear some scratchy noises before. again i could not restart. after 30 attempts the computer booted and everything worked except the audio, it said "no output devices found". i noticed that after some hours of rest my computer returns to full funcionality. as i said, i have no means to bring my computer to an apple store. maybe someone can give me an indication of what might be wrong. here is the panic.log:
    panic(cpu 0 caller 0x00136744): stack_alloc: kernelmemoryallocate
    Backtrace, Format - Frame : Return Address (4 potential args on stack)
    0x2cb63eb8 : 0x128d08 (0x3c9afc 0x2cb63edc 0x131de5 0x0)
    0x2cb63ef8 : 0x136744 (0x3ca48c 0x2cb63f2c 0x4000 0x7fff)
    0x2cb63f38 : 0x13b9a8 (0x491d8b0 0x1 0x4af85c 0x4b8070)
    0x2cb63f68 : 0x13b9fb (0x13d8d5 0x0 0x5e 0x2cb63f8c)
    0x2cb63f98 : 0x13d0b1 (0x13d8d5 0x0 0x5e 0x2cb63fbc)
    0x2cb63fc8 : 0x19a77c (0x0 0x0 0x19d0b5 0x491e2dc) Backtrace terminated-invalid frame pointer 0x0
    Kernel version:
    Darwin Kernel Version 8.8.2: Thu Sep 28 20:43:26 PDT 2006; root:xnu-792.14.14.obj~1/RELEASE_I386
    Model: MacBookPro2,2, BootROM MBP22.00A5.B01, 2 processors, Intel Core 2 Duo, 2.33 GHz, 2 GB
    Graphics: ATI Radeon X1600, ATY,RadeonX1600, PCIe, 256 MB
    Memory Module: BANK 0/DIMM0, 1 GB, DDR2 SDRAM, 667 MHz
    Memory Module: BANK 1/DIMM1, 1 GB, DDR2 SDRAM, 667 MHz
    AirPort: AirPort Extreme, 1.0.27p3
    Bluetooth: Version 1.7.11f14, 2 service, 0 devices, 1 incoming serial ports
    Serial ATA Device: Hitachi HTS541616J9SA00, 149.05 GB
    Parallel ATA Device: MATSHITADVD-R UJ-857D
    USB Device: Built-in iSight, Micron, Up to 480 Mb/sec, 500 mA
    USB Device: Apple Internal Keyboard / Trackpad, Apple Computer, Up to 12 Mb/sec, 500 mA
    USB Device: Bluetooth HCI, Up to 12 Mb/sec, 500 mA
    USB Device: IR Receiver, Apple Computer, Inc., Up to 12 Mb/sec, 500 mA
    tnx
    dawandeh

  • Very strange itunes behaviour: please help!

    OK. So I downloaded uniblue's 'speed up my PC' software which is highly unadvisable because quite apart from it having little noticeable effect, it appears to have really screwed up my itunes, albeit more in an annoying way than a disastrous way.
    On attempting to open itunes I am presented with a small box (Windows Xp SP3 by the way.) which says "Importing 'iTunes Music Library.xml'..." This takes about 3-4 minutes. Then the box changes to "Organizing Files" and appears to scan through my music very quickly - about 5-10 seconds.
    Then I get an error message reading: "The file 'iTunes Library.itl' does not appear to be a valid iTunes library file. iTunes has attempted to recover your itunes library and renamed this file to 'iTunes Library (Damaged).itl'
    So I press 'OK' (the only option) and itunes opens, and begins "creating artwork thumbnails" and "Determining gapless playback information" each of which takes aprox. 5 minutes.
    While this is going on another error message appears: "The itunes library file cannot be saved. An unknown error occurred (-1450)." Again 'OK' is the only option. This message sometimes appears multiple times.
    At this point I closed down itunes, uninstalled it, defragged my hard drive, deleted the itunes file and replaced it with a backup I keep on my external hard drive, then reinstalled it.
    Hallelujah! It worked fine again, opening without any problems, with all my playlist and playcount data safe. I thought I had solved my problem. However, after the third reboot itunes reverted to its old behaviour (starting from paragraph two) again. I have now been through this entire cycle about three times and am getting very fed up.
    If anyone could explain to me why this is happening and how to fix it - I wouldn't be able to thankyou enough.

    Praise be to Lord above! I have fixed it! And because I'm a nice guy and wouldn't want anyone else to go through the same frustration - I'm going to tell you how...
    It was a problem with the registry that was causing the issue and funny old thing - uniblue's 'Registry Booster' solved the issue. It's ironic that software from the same company was used to solve the problem I know...I had almost decided to uninstall all uniblue products, but decided to run one last scan with registry booster to see what happened....So just to sum up, this is how to solve the above issue:
    1. Re-create/rebuild your library as detailed in this article: http://support.apple.com/kb/HT1451 or replace itunes folder with backup. Delete any corrupted/damaged files.
    This alone should solve many issues but if you keep getting repeated corruption problems like I did then the problem seems to be within the REGISTRY.
    2. To solve the registry error - I ran uniblue's 'Registry Booster' programme. I have no idea how to fix the registry manually. Sorry.
    Message was edited by: andy525

  • How to write this query.. Please Help

    Hello Guys,
    I have a table that contains all possible leave types, it is a look up table. Table name is Att_Leave_Types and data in the table is:
    Leavetype_ID Leavetype_Desc
    1 Annaul
    2 Sick
    3 Casual
    4 Long
    5 Maternity
    Now, another table Att_Emp_Leaves Contains leaves of an employee
    Columns and values are
    Emp_ID leave_date levetype_id
    14210 28-AUG-06 2
    14210 30-AUG-06 3
    14210 12-JUL-06 1
    14210 13-JUL-06 1
    14210 14-JUL-06 1
    6902 27-AUG-06 2
    6902 30-AUG-06 3
    Now i want to get the following result from the query:
    Group by month and year
    list all leavetypes and leaves employee have availved, if no leavetype availved then the result must show 0 for the leavetype. calculate leaves for a month based on leavetype ID.
    This result will help you clear what i result i want by my query.
    MON_YYYY employee_id leavetype_id number_of_leaves
    JUL-2006 14210 1 3
    JUL-2006 14210 2 0
    JUL-2006 14210 3 0
    JUL-2006 14210 4 0
    JU:-2006 14210 5 0
    AUG-2006 14210 1 0
    AUG-2006 14210 2 1
    AUG-2006 14210 3 1
    AUG-2006 14210 4 0
    AUG-2006 14210 5 0
    AUG-2006 6902 1 0
    AUG-2006 6902 2 1
    AUG-2006 6902 3 1
    AUG-2006 6902 4 0
    AUG-2006 6902 5 0
    Please guide me and help me, its very urgent.
    I will be thankful to you.
    Regards,
    Imran Baig

    Here we are:
    DROP TABLE Att_Leave_Types;
    CREATE TABLE Att_Leave_Types
               Leavetype_ID NUMBER
              ,Leavetype_Desc VARCHAR2(30)
    INSERT INTO Att_Leave_Types VALUES(1, 'Annual');
    INSERT INTO Att_Leave_Types VALUES(2, 'Sick');
    INSERT INTO Att_Leave_Types VALUES(3, 'Casual');
    INSERT INTO Att_Leave_Types VALUES(4, 'Long');
    INSERT INTO Att_Leave_Types VALUES(5, 'Maternity');
    DROP TABLE Att_Emp_Leaves;
    CREATE TABLE Att_Emp_Leaves
               Emp_ID NUMBER
              ,leave_date DATE
              ,leavetype_id NUMBER
    INSERT INTO Att_Emp_Leaves VALUES (14210, TO_DATE('01-JUL-2006', 'DD-MON-YYYY'), 1);
    INSERT INTO Att_Emp_Leaves VALUES (14210, TO_DATE('10-JUL-2006', 'DD-MON-YYYY'), 1);
    INSERT INTO Att_Emp_Leaves VALUES (14210, TO_DATE('15-JUL-2006', 'DD-MON-YYYY'), 1);
    INSERT INTO Att_Emp_Leaves VALUES (14210, TO_DATE('15-AUG-2006', 'DD-MON-YYYY'), 2);
    INSERT INTO Att_Emp_Leaves VALUES (14210, TO_DATE('25-AUG-2006', 'DD-MON-YYYY'), 3);
    INSERT INTO Att_Emp_Leaves VALUES (6902, TO_DATE('15-AUG-2006', 'DD-MON-YYYY'), 2);
    INSERT INTO Att_Emp_Leaves VALUES (6902, TO_DATE('25-AUG-2006', 'DD-MON-YYYY'), 3);
    SELECT
              LP.*
              ,EL.Leave_date
    COLUMN Emp_ID FOR 999999
    COLUMN Leave_Month FOR A8
    COLUMN Leavetype_ID FOR 999
    COLUMN Leavetype_desc FOR A10
    COLUMN Leave_Count FOR 999
    SELECT
               LP.Emp_ID
              ,TO_CHAR(LP.Leave_Month, 'MON-YYYY') Leave_Month
              ,LP.Leavetype_ID
              ,LP.Leavetype_desc
              ,COUNT(EL.Emp_ID) Leave_Count
         FROM
              SELECT *
                   FROM
                        SELECT
                                   Emp_ID
                                  ,ADD_MONTHS(Min_Leave_month, RN - 1) Leave_Month
                                  ,Max_Leave_month
                             FROM
                                  SELECT ROWNUM RN FROM
                                       USER_OBJECTS
                                       WHERE ROWNUM <= 100
                                  SELECT
                                             Emp_ID
                                            ,TRUNC(MIN(Leave_date), 'MM') Min_Leave_month
                                            ,TRUNC(MAX(Leave_date), 'MM') Max_Leave_month
                                       FROM Att_Emp_Leaves
                                       GROUP BY Emp_ID
                             WHERE ADD_MONTHS(Min_Leave_month, RN - 1) <= Max_Leave_month
                        ,Att_Leave_Types
                   -- ORDER BY Emp_ID, Leave_Month, Leavetype_ID
              ) LP -- Leave periods
              ,Att_Emp_Leaves EL -- Employee leaves
         WHERE EL.Emp_ID(+) = LP.Emp_ID
              AND EL.Leavetype_ID(+) = LP.Leavetype_ID
              AND EL.Leave_date(+) >= LP.Leave_Month
              AND EL.Leave_date(+) < ADD_MONTHS(LP.Leave_Month, 1)
         GROUP BY
               LP.Emp_ID
              ,LP.Leave_Month
              ,LP.Leavetype_ID
              ,LP.Leavetype_desc
         ORDER BY
               LP.Emp_ID
              ,LP.Leave_Month
              ,LP.Leavetype_ID
    EMP_ID LEAVE_MO LEAVETYPE_ID LEAVETYPE_ LEAVE_COUNT
      6902 AUG-2006            1 Annual               0
      6902 AUG-2006            2 Sick                 1
      6902 AUG-2006            3 Casual               1
      6902 AUG-2006            4 Long                 0
      6902 AUG-2006            5 Maternity            0
    14210 JUL-2006            1 Annual               3
    14210 JUL-2006            2 Sick                 0
    14210 JUL-2006            3 Casual               0
    14210 JUL-2006            4 Long                 0
    14210 JUL-2006            5 Maternity            0
    14210 AUG-2006            1 Annual               0
    14210 AUG-2006            2 Sick                 1
    14210 AUG-2006            3 Casual               1
    14210 AUG-2006            4 Long                 0
    14210 AUG-2006            5 Maternity            0
         BW

  • Need SQL query using View - Please help

    Hi,
    I have similar requirement like below.
    I have two tables DEPT and EMP and some departments may not have employees. I have created below view, which displays all DEPT records, even though there are no emplyees.
    CREATE OR REPLACE VIEW dept_emp_vw AS
    SELECT deptno, empid, 0 AS selected
    FROM dept d, emp e
    WHERE d.deptno = e.deptnno (+);
    Ex.
    DEPTNO         EMPID        SELECTED
    10 101 0
    10 102 0
    20 103 0
    30 103 0
    40 104 0
    50 <null> 0
    Application will pass "empid" to the view (for ex. empid = 103) and I want result like below.
    Ex.
    DEPTNO         EMPID        SELECTED
    10 101 0
    10 102 0
    20 103 1
    30 103 1
    40 104 0
    50 <null> 0
    Can you please let me know the query using "dept_emp_vw" view. We have Oracle 11g Release 2.
    Thanks a lot for the help.

    Not possible using normal SQL - as SQL is not a procedure language and does not support variable declaration and use (e.g. passing empid as a variable and using it both as a predicate and as a condition in the SQL projection).
    That said - SQL can be "+parameterised+". An approach that is ugly and contrary to the basic design and use of SQL. But it can support the (very weird) view definition of yours.
    E.g.
    SQL> create or replace procedure SetVariable( name varchar2, value varchar2 ) is
      2  begin
      3          DBMS_SESSION.set_context( 'MyVariables', name, value );
      4  end;
      5  /
    Procedure created.
    SQL>
    SQL>
    SQL> create or replace context MyVariables using SetVariable;
    Context created.
    SQL>
    SQL> create or replace view my_funky_weird_view as
      2  select
      3          e.empno,
      4          e.ename,
      5          e.job,
      6          case e.empno
      7                  when to_number(sys_context( 'MyVariables', 'empid' )) then
      8                          0
      9                  else
    10                          1
    11          end     as "SELECTED"
    12  from       emp e
    13  /
    View created.
    SQL>
    SQL> exec SetVariable( 'empid', 7499 )
    PL/SQL procedure successfully completed.
    SQL>
    SQL> select * from session_context where namespace = 'MYVARIABLES';
    NAMESPACE            ATTRIBUTE            VALUE
    MYVARIABLES          EMPID                7499
    SQL>
    SQL> select * from my_funky_weird_view order by selected;
         EMPNO ENAME      JOB               SELECTED
          7499 ALLEN      SALESMAN                 0
          7521 WARD       SALESMAN                 1
          7566 JONES      MANAGER                  1
          7654 MARTIN     SALESMAN                 1
          7698 BLAKE      MANAGER                  1
          7934 MILLER     CLERK                    1
          7788 SCOTT      ANALYST                  1
          7839 KING       PRESIDENT                1
          7844 TURNER     SALESMAN                 1
          7876 ADAMS      CLERK                    1
          7900 JAMES      CLERK                    1
          7902 FORD       ANALYST                  1
          7369 SMITH      CLERK                    1
          7782 CLARK      MANAGER                  1
    14 rows selected.
    SQL>But I will N\OT recommend doing it this way. It is not natural SQL as PL/SQL is needed to "+inject+" name-value pairs into the context for the SQL view to use. It is ugly. It is not standard. It cannot scale. It is complex to use. Etc.
    Yes, there are instances when this approach is exactly what one needs - when for example dealing with a trusted context and using the contents for implementing a security layer. But in the above case - I would rather want to see the actual business requirement first, as I think you're barking up the wrong tree with the view solution you have imagined.

  • Urgent query on joins --Please Help!!

    Hi Experts,
    We have two table T1 and T2 with A three columns in T1 as A(uniquie constraint and not null )and in table T2 as X.
    We need to find rows in T1 for which no value of A exists in X of T2.Please provide your suggestion on the query we can frame for this requirement.
    Thanks and Regards
    Debashis
    Edited by: user13267825 on Aug 27, 2010 3:08 AM

    Maybe something like this then:
    SELECT a FROM t1 WHERE b = :something
    MINUS
    SELECT x FROM t2
    / This is a case where it is always helpful to provide the following:
    1. Oracle version (SELECT * FROM V$VERSION)
    2. Sample data in the form of CREATE / INSERT statements.
    3. Expected output
    4. Explanation of expected output (A.K.A. "business logic")
    5. Use \ tags for #2 and #3. See FAQ (Link on top right side) for details.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Maybe you are looking for