About Level Psuedo column

Hi all,
can any one explain the query how it is working internally.
I could not get the logic of it and i tried and surfed many sites, all the sites are giving the query but no one explained how it is working.
how will you get the nth highest salary ?
select * from emp where sal in (select max(sal) from emp where level = &level connect by prior sal > sal group by level);
Please help me.
Regards,
Sri Ram.

Hi,
Sri Ram wrote:
i want to know how the query is getting executed.If a row is in the result set because it meets the START WITH condition, then it has LEVEL = 1.
If a row is in the result set becuse it (together with some row that has LEVEL = N) meets the CONNECT BY condition, then the new row has LEVEL = N + 1.
If there is no START WITH clause, then every row in the table is counted as meeting the START WITH conditiion, and so every row in the table is in the result set once with LEVEL = 1.
Let's simplify the problem a little by including only deptno=20. That is, let's only work with the rows produced by:
CREATE OR REPLACE VIEW  emp_20  AS
SELECT       ename, sal
FROM       scott.emp
WHERE       deptno     = 20;so the data is:
ENAME             SAL
SMITH             800
ADAMS            1100
JONES            2975
FORD             3000
SCOTT            3000To understand any query, look at its sub-queries and make sure you understand them first. Run just the sub-query, simplified, if necessary, and showing any extra expressions that will help you understand it. In this case, the quesry contains the following sub-query:
     select        max(sal)
     from        emp_20
     where        level = &level_wanted
     connect by      prior sal > sal
     group by  level
)That's a lot to understand a once. Let's simplify it, by removing the GROUP BY. Of course, that means we won't be able to use aggregate functions like MAX, so let's display their arguments, instead. Also, let's start by not using a WHERE clause. Instead, let's display the expression used in the WHERE clause. When trying to understand a CONNECT BY query, it can be very helpful to include SYS_CONNECT_BY_PATH in the output.
So let's run just this query:
WITH     in_subquery     AS
     select        sal          -- originally was max (sal)
     ,       ename
     ,       LEVEL
     ,       SYS_CONNECT_BY_PATH (ename, ',')     AS path
     from        emp_20     -- originally was xcott.emp
--     where        level = &level_wanted
     connect by      prior sal > sal
--     group by  level
SELECT     *
FROM     in_subquery
;Output:
  SAL ENAME  LEVEL PATH
  800 SMITH      1 ,SMITH
2975 JONES      1 ,JONES
  800 SMITH      2 ,JONES,SMITH
1100 ADAMS      2 ,JONES,ADAMS
  800 SMITH      3 ,JONES,ADAMS,SMITH
3000 SCOTT      1 ,SCOTT
  800 SMITH      2 ,SCOTT,SMITH
2975 JONES      2 ,SCOTT,JONES
  800 SMITH      3 ,SCOTT,JONES,SMITH
1100 ADAMS      3 ,SCOTT,JONES,ADAMS
  800 SMITH      4 ,SCOTT,JONES,ADAMS,SMITH
1100 ADAMS      2 ,SCOTT,ADAMS
  800 SMITH      3 ,SCOTT,ADAMS,SMITH
1100 ADAMS      1 ,ADAMS
  800 SMITH      2 ,ADAMS,SMITH
3000 FORD       1 ,FORD
  800 SMITH      2 ,FORD,SMITH
2975 JONES      2 ,FORD,JONES
  800 SMITH      3 ,FORD,JONES,SMITH
1100 ADAMS      3 ,FORD,JONES,ADAMS
  800 SMITH      4 ,FORD,JONES,ADAMS,SMITH
1100 ADAMS      2 ,FORD,ADAMS
  800 SMITH      3 ,FORD,ADAMS,SMITHThere is no START WITH clause, so every employee appears once on LEVEL=1.
The CONNECT BY condition is "prior sal > sal", meaning that row p will be considered a parent of row c when p.sal > c.sal.
Let's look at the employee named JONES. the result set has the following rows with ename='JONES':
  SAL ENAME  LEVEL PATH
2975 JONES      1 ,JONES
2975 JONES      2 ,SCOTT,JONES
2975 JONES      2 ,FORD,JONESWe see that JONES is in the result set once with LEVEL=1(becuase there is no START WITH clause). JONES also appears as the child of SCOTT (because SCOTT has a higher sal than JONES) and again as a child of FORD (for the same reason). FORD was in the result set with LEVEL=1, and a row for JONES joined the result set at then next highest LEVEL, becuase that row met the CONNECT BY condition: FORD's sal (3000) was higher than JONES's sal (2975). Looking at this output, we can see that there is a chain of employees, each with a sal greater than the next employee. JONES appears in such a chain with LEVEL=2, so JONES has the 2nd highest sal in that chain, or JONES's sal (2975) is the 2nd highest sal in that chain.
Look at another employee, say ADAMS. Do you understand why all the rows with ename='ADAMS' are there, and what all the columns in the output mean on those rows?
When you understand this sub-query, let's modify it, making it a little more like the original. Let's restore the WHERE clause, so the query is now:
WITH     in_subquery     AS
     select        sal          -- originally was max (sal)
     ,       ename
     ,       LEVEL
     ,       SYS_CONNECT_BY_PATH (ename, ',')     AS path
     from        emp_20     -- originally was xcott.emp
     where        level = &level_wanted
     connect by      prior sal > sal
--     group by  level
SELECT     *
FROM     in_subquery
;and the output for any given value of &level_wanted will be something like:
  SAL ENAME  LEVEL PATH
  800 SMITH      2 ,JONES,SMITH
1100 ADAMS      2 ,JONES,ADAMS
  800 SMITH      2 ,SCOTT,SMITH
2975 JONES      2 ,SCOTT,JONES
1100 ADAMS      2 ,SCOTT,ADAMS
  800 SMITH      2 ,ADAMS,SMITH
  800 SMITH      2 ,FORD,SMITH
2975 JONES      2 ,FORD,JONES
1100 ADAMS      2 ,FORD,ADAMSAgain, study the output, and make sure you understand it.
Do you see jow each sal shown is the 2nd highest in some parent-child chain?
Do you see how heach sal shown might possibly be the 2nd highest sal?
When you do uderstand that query, make it still more like the original. Restore the GROUP BY clause and the MAX function. Actually, all you need is the MAX function. Since the WHERE clause guarantees that all rows in the ungrouped result set have the save LEVEL, then saying "GROUP BY LEVEL" isn't doing anything, and it doesn't make any sense. As Whitehat pointed out, the whole approach doesn't make any sense. This is a complicated and inefficient way to get the results you want. Whitehat showed a much better way, however, that solution was for the N-th highest paid employee. When there are ties (mutliple employees with the same sal), this will not be the same as the employee(s) who have the N-th highest sal, which is what the query you posted shows. Here's a better way to do what your query is doing:
WITH     got_r_num     AS
     SELECT     emp.*
     ,     DENSE_RANK () OVER (ORDER BY  sal   DESC)     AS r_num
     FROM     scott.emp
SELECT     ename, sal     -- list all columns wanted
FROM     got_r_num
WHERE     r_num     = &level_wanted
;

Similar Messages

  • Using Page Level Summary Column in Report 6i

    Hi Folks,
    I'm trying to create a report in which I want a Page level Summary column i.e., the Summary column should reset at each page and should display the sum of a particular field on each page depending upon how many records are displayed on each page. But whenever I choose the Reset Property to Page the following error is displayed" Page level summaries are not supported in the defaulting" and in certain case the summary column displays the sum only on the last page of the report and the rest of the pages do not display the summary column. The database has three tables i.e., master-detail-detail.
    Do I need to make some changes in the Data Model or what?
    TIA
    Hassan

    Hi Hassan,
    it only works onceWell, this is definitely not expected. Maybe you can try to see after running the report once whether all the values you set in your report (from my last post) remain the the same, or somehow they revert back to their default values.
    if I do some formatting of the report... summary also disapperasYou could try placing the page level summary in another frame, below your group repeating frame, with enough gap between them. Also, try setting the value for "max no of records" to some lower value, which makes sure there is space for the summary column on every page.
    Another idea for making a page level summary is - you can place the summary BEFORE your group repeating frame, which means the summary will print on top of every page. In this case, you won't even have to worry about setting "max no of records per page" to some particular value. See if this suits your needs.
    Navneet.

  • Unable to create cross tab report with multiple level dynamic columns

    Hi Gurus,
    We are trying to develope group above cross tab report with BI Publisher.
    i am unable to achieve multiple level columns dynamically.Using cross tab wizard i can achieve single level measure column ,but not the second level column.
    Output should look like this:
    Country1
    Region1 Region2 Region3 --(level1 column)
    d1 d2 d3 d1 d2 d3 d1 d2 d3 -- (level2 column)
    Row1 10 20 30 70 80 90 40 70 90 --data
    Row2 21 24 54 65 23 64 64 76 87
    Here regions and d1 d2 d3 may vary based on xml data.Also we have page break on country.
    Thanks,
    Mahesh

    Hi kavipriya,
    Any update on this.I have set the rtf and xml to ur gmail id.
    Thanks,
    mahesh

  • About place holder columns in reports

    hi gurus,
    i want to know about
    place holder columns,
    lexical parameters,
    matrix reports
    in reports with some common examples
    can any one guide me to do this..
    any help is highly appreciated..
    please reply...

    hi
    this is forms forum plz post your thread on Report forum. hope you will get prompt answer...
    sarah

  • What is connect by and level pseudo column? how it works?

    what is connect by and level pseudo column? how it works?
    Please explain this concept by giving an example..
    Thanks
    Prashant

    Read the following documents with examples :
    http://psoug.org/reference/connectby.html
    http://www.sqlsnippets.com/en/topic-11821.html
    http://docs.oracle.com/cd/B19306_01/server.102/b14200/queries003.htm

  • Using LEVEL Pseudo column to format repeating frame

    I am trying to display a hierarchy in Reports. I use the 'Connect By' Clause in SQL and gather the hierarchical data, and want to display the results in a tree fashion. How can I do it?
    I only come up with one answer, to use the LEVEL PSEUDO-Column and indent the repeating frame based on the value for LEVEL. I want to know how I can set the X and Y co-ordinates of the repeating frame dynamically?
    Please help me with this if you have other ideas?
    Thanks.
    -Shan

    Unfortunately, you can't programmatically set the geometry (x,y, width, height) values of any objects in the reports output.
    The best you can do is have another object (or number of objects) that are turned on/off and then use collapsing anchors and format triggers to move the repeating frame to the left. If you only have one object, you can set it's horizontal expansion to variable and then fill it with a number of characters to get the desired "indent".

  • Question about Unique Table Columns - How to Handle Alerts

    I have a table with a unique column, and I want to provide an error alert when a user tries to insert a record in which there is another record that already has the same value for that column.
    I tried just relying on the table constraint in the DB, but I just get a "cannot insert record" message on the form run-time.
    I put a query in the PRE-INSERT trigger to query and see if that value exists in another record and display the alert there, but my concern is that a record could be inserted by another user after my check query runs. In that case, I will still just get the "cannot insert record" message.
    What is a good way that I can give an error alert AND assure that another record is not being inserted in the mean time?
    Thanks,
    Kurz

    There is NO way you can absolutely trap all situations by checking in the when-validate triggers.
    Your user could even try to insert the same duplicate value in two rows at the same time.
    Or another user could commit at the same time as the first.
    The ONLY way to handle those errors is to trap for the error in the On-Error trigger, which fires
    when Forms returns the FRM-40508 or FRM-40509 code. Here is the standard code we have settled on here:
    -- On-Error form-level trigger                                       --*
    DECLARE
      Err_Code NUMBER(5)     := ERROR_CODE;
      Msg      VARCHAR2(150)
              := SUBSTR('   '||ERROR_TYPE||'-'||TO_CHAR(ERR_Code)||': '
                                         ||ERROR_TEXT,1,150);
      DBMS_TXT VARCHAR2(200);
    BEGIN
      -- 40508=Unable to insert rec.  40509=Unable to update rec.
      IF Err_Code IN(40508,40509) THEN
        DBMS_TXT := SUBSTR(DBMS_ERROR_TEXT,1,200);
        IF  DBMS_TXT like '%unique constraint%'
        AND DBMS_TXT like '%I_PK_ASGTABLE%'  THEN
          U73_ERR_TIMER('ASG.RESIDENCE_CODE');
          Message('   5011  DUPLICATE RESIDENCE CODE FOUND');
          Raise Form_trigger_failure;
        END IF;
      END IF;
      -- This handles all other on-error messages:
      Message(Msg);
      Raise Form_trigger_failure;
    END;U73_ERR_TIMER just assures that focus gets placed on the correct item, and sets its color red.

  • Table Rendering - Row level vs Column level

    Normally renderers are specified for a given class of data or column of data.
    So, how would you handle rendering requirements that are row or table dependent? For example, how do I:
    a) color alternate lines in a table
    b) change the border of the selected cell
    Traditional Approach
    Most answers in the forum would be something like "use a custom render". Sounds great, but what does it really mean? If all your data is displayed as a String then it really isn't too difficult to create a single renderer with the required logic and add it to the table as the default renderer.
    However, what if you table contains, String's, Dates, Integer's, Double's and Boolean's and you want your cell to retain the default formatting of each data type in addition to the above requirement? Now you have two options:
    a) render by class (multiple renderers). Each renderer would need to implement the default "formatting" of the data (dates: dd-MMM-yyy, numbers: right justified, etc) in addition to the "row/table" rendering requirements. So the answer really becomes "use five custom renderers". Now the "row/table" rendering code is found in 5 classes. Of course you could always move the "row/table" rendering code up to a common base class.
    b) render by table (single renderer). A single custom renderer would be created and would need to implement the default "formatting" for all data types in the table, in addition to the "row/table" rendering. The benefit is that all the rendering code is in one class. An example solution is include for this approach.
    Alternative Approach
    I recently came across an approach where the "formatting" of the data is still done by the default renderers and the "row/table" rendering is done at the table level by overriding the prepareRenderer() method. This approach is much simpler, but the rendering is done in two different places. Is this a problem?
    So, my question is which approach do you prefer:
    a) Traditional Approach - multiple renderers
    b) Triditional Approach - single renderer
    c) Alternative Approach
    Me, I like the alternative approach, but I'm more of a problem solver than I am a designer, so I don't know how the solution fits in a large scale application.
    Hopefully your response will consider:
    a) OO design principles
    b) class reusability
    c) class maintenance
    d) anything else you can think of
    import java.awt.*;
    import java.text.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.table.*;
    public class TableRowRendering extends JFrame
        JTable table;
        Border selected = new LineBorder(Color.GREEN);
        public TableRowRendering()
            //  Model used by both tables
            Object[] columnNames = {"Type", "Date", "Company", "Shares", "Price"};
            Object[][] data =
                {"Buy", new Date(), "IBM", new Integer(1000), new Double(80.50)},
                {"Sell",new Date(), "MicroSoft", new Integer(2000), new Double(6.25)},
                {"Sell",new Date(), "Apple", new Integer(3000), new Double(7.35)},
                {"Buy", new Date(), "Nortel", new Integer(4000), new Double(20.00)}
            DefaultTableModel model = new DefaultTableModel(data, columnNames)
                public Class getColumnClass(int column)
                    return getValueAt(0, column).getClass();
            //  Traditional Approach
            table = new JTable( model );
            table.setPreferredScrollableViewportSize(table.getPreferredSize());
            getContentPane().add(new JScrollPane( table ), BorderLayout.WEST);
            TableCellRenderer custom = new CustomRenderer();
            table.setDefaultRenderer(Object.class, custom);
            table.setDefaultRenderer(String.class, custom);
            table.setDefaultRenderer(Date.class, custom);
            table.setDefaultRenderer(Number.class, custom);
            table.setDefaultRenderer(Double.class, custom);
            //  Alternative Approach
            table = new JTable( model )
                public Component prepareRenderer(
                    TableCellRenderer renderer, int row, int column)
                    Component c = super.prepareRenderer(renderer, row, column);
                    if (!isRowSelected(row))
                        String type = (String)getModel().getValueAt(row, 0);
                        c.setBackground(row % 2 == 0 ? null : Color.LIGHT_GRAY );
                    if (isRowSelected(row) && isColumnSelected(column))
                        ((JComponent)c).setBorder(selected);
                    return c;
            table.setPreferredScrollableViewportSize(table.getPreferredSize());
            getContentPane().add(new JScrollPane( table ), BorderLayout.EAST);
        //  Custom renderer used by Traditional approach
        class CustomRenderer extends DefaultTableCellRenderer
            DateFormat dateFormatter = SimpleDateFormat.getDateInstance(DateFormat.MEDIUM);
            NumberFormat numberFormatter = NumberFormat.getInstance();
            public Component getTableCellRendererComponent(
                JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column)
                super.getTableCellRendererComponent(
                    table, value, isSelected, hasFocus, row, column);
                //  Code for data formatting
                setHorizontalAlignment(SwingConstants.LEFT);
                if ( value instanceof Date)
                    setText(dateFormatter.format((Date)value));
                if (value instanceof Number)
                    setHorizontalAlignment(SwingConstants.RIGHT);
                    if (value instanceof Double)
                        setText(numberFormatter.format(((Number) value).floatValue()));
                //  Code for highlighting
                if (!isSelected)
                    String type = (String)table.getModel().getValueAt(row, 0);
                    setBackground(row % 2 == 0 ? null : Color.LIGHT_GRAY );
                if (table.isRowSelected(row) && table.isColumnSelected(column))
                    setBorder(selected);
                return this;
        public static void main(String[] args)
            TableRowRendering frame = new TableRowRendering();
            frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
            frame.pack();
            frame.setLocationRelativeTo( null );
            frame.setVisible(true);
    }Before you make your final decision. What changes would be required for each solution in the following "what if " scenarios:
    a) what if, you added a Boolean column to the table
    b) what if, you added a second Double column to the table which should be formatted as a currency (ie. 1,234.5 --> $1,234.50).
    Here is an example of a currency renderer:
    class CurrencyRenderer extends DefaultTableCellRenderer
         private NumberFormat formatter;
         public CurrencyRenderer()
              super();
              formatter = NumberFormat.getCurrencyInstance();
              setHorizontalAlignment( SwingConstants.RIGHT );
         public void setValue(Object value)
              if ((value != null) && (value instanceof Number))
                   value = formatter.format(value);
              super.setValue(value);
    }

    Well, here's a partila solution using technique from a link you cited in another thread.
    import tests.basic.tables.ColorProvider;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.*;
    import java.text.NumberFormat;
    public class DecoratedTablePrepareRenderer extends JFrame {
        JTable table;
        private DefaultTableModel model;
        public DecoratedTablePrepareRenderer() {
            Object[] columnNames = {"Type", "Company", "Price", "Shares", "Closed"};
            Object[][] data =
                        {"Buy", "IBM", new Double(80.50), new Double(1000), Boolean.TRUE},
                        {"Sell", "MicroSoft", new Double(6.25), new Double(2000), Boolean.FALSE},
                        {"Sell", "Apple", new Double(7.35), new Double(3000), Boolean.TRUE},
                        {"Buy", "Nortel", new Double(20.00), new Double(4000), Boolean.FALSE}
            model = new DefaultTableModel(data, columnNames);
            table = new JTable(model) {
                //  Returning the Class of each column will allow different
                //  renderers to be used based on Class
                public Class getColumnClass(int column) {
                    return getValueAt(0, column).getClass();
                public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
                    Component c = super.prepareRenderer(renderer, row, column);
                    if (isRowSelected(row))
                        c.setFont(c.getFont().deriveFont(Font.BOLD));
                    return c;
            ColorProvider prov = new TransactionColorProvider();
            ColorTableCellRenderer renderer = new ColorTableCellRenderer(table.getDefaultRenderer(Object.class),prov);
            ColorTableCellRenderer boolrenderer = new ColorTableCellRenderer(table.getDefaultRenderer(Boolean.class),prov);
            ColorTableCellRenderer doublerenderer = new ColorTableCellRenderer(table.getDefaultRenderer(Double.class),prov);
                    int priceIndex = model.findColumn("Price");
              table.getColumnModel().getColumn(priceIndex).setCellRenderer( new EtchedBorderTableCellRenderer(new ColorTableCellRenderer(new CurrencyRenderer(),prov) ));
            table.setDefaultRenderer(Object.class,new EtchedBorderTableCellRenderer(renderer));
            table.setDefaultRenderer(Double.class,new EtchedBorderTableCellRenderer(doublerenderer));
            table.setDefaultRenderer(Boolean.class, new EtchedBorderTableCellRenderer(boolrenderer));
            JScrollPane scrollPane = new JScrollPane(table);
            getContentPane().add(scrollPane);
        class CurrencyRenderer extends DefaultTableCellRenderer {
            private NumberFormat formatter;
            public CurrencyRenderer() {
                super();
                formatter = NumberFormat.getCurrencyInstance();
                setHorizontalAlignment(SwingConstants.RIGHT);
            public void setValue(Object value) {
                if ((value != null) && (value instanceof Number)) {
                    value = formatter.format(value);
                super.setValue(value);
        public static void main(String[] args) {
            DecoratedTablePrepareRenderer frame = new DecoratedTablePrepareRenderer();
            frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        class ColorTableCellRenderer implements TableCellRenderer{
            protected TableCellRenderer delegate;
            protected ColorProvider provider;
            public ColorTableCellRenderer(TableCellRenderer delegate, ColorProvider provider) {
                this.delegate = delegate;
                this.provider = provider;
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                Component c = delegate.getTableCellRendererComponent(table, value,isSelected,hasFocus,row, column);
                  c.setBackground(provider.getBackgroundColor(row, column));
                return c;
          class EtchedBorderTableCellRenderer implements TableCellRenderer{
            protected TableCellRenderer delegate;
            public EtchedBorderTableCellRenderer(TableCellRenderer delegate) {
                this.delegate = delegate;
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                JComponent c = (JComponent)delegate.getTableCellRendererComponent(table, value,isSelected,hasFocus,row, column);
                  JPanel panel = new JPanel(new GridLayout(0,1));
                  panel.add(c);
                  panel.setBorder(BorderFactory.createEtchedBorder());
                return panel;
        class TransactionColorProvider implements ColorProvider {
            private int keyIndex = 0;
            private Color sellColor = Color.yellow;
            private Color buyColor = Color.green;
            public TransactionColorProvider() {
                keyIndex = model.findColumn("Type");
            public Color getBackgroundColor(int row, int column) {
                 if( model.getValueAt(row,keyIndex).equals("Sell")){
                     return sellColor;
                else {
                     return buyColor;
            public Color getForegroundColor(int row, int column) {
                return Color.black;
    }Boolean values are problematical since JCheckBox does seem to like borders, using a panel as I did in the Etched renderer seems to work. This solution need a little more work, this is submitted as a prototype
    Cheers
    DB

  • Doubt about UPDATE STAT COLUMN

    Hi,
    I have a doubt of when to execute update stat:
    i create this SQL to generate an SQL script to generate update stat for all my tables:
    select 'UPDATE STAT ' || schemaname || '.' || tablename || ' ESTIMATE SAMPLE 20 PERCENT' from tables where schemaname = 'DBUSER' and not tablename like 'JDBC%' AND type = 'TABLE'
    and created this SQL to generate an SQL script for update stat for all columns.
    select 'UPDATE STAT COLUMN(*) FOR ' || schemaname || '.' || tablename || ' ESTIMATE SAMPLE 20 PERCENT' from tables where schemaname = 'DBUSER' and not tablename like 'JDBC%' AND type = 'TABLE'
    my doubt is i really need run that second script? or the UPDATE STAT for table dont UPDATE STAT for all columns?
    thanks for any insight
    Clóvis

    > my doubt is i really need run that second script? or the UPDATE STAT for table dont UPDATE STAT for all columns?
    Hi Clovis,
    hmm... good question.
    There are a few things to know about the UPDATE STAT command here.
    1) It will always generate statistics for key or indexed columns.
    2) The optimizer won't be able to generate a better plan when there are column statistics for non-indexed columns present.
    3) The command will also collect column statistics for all columns that already have statistics.
    The direct effect of 3) is that by running your second command just once - all column statistics will always be collected.
    Since you can easily change the default sample size for your tables via
    ALTER TABLE SAMPLE SIZE 20 PERCENT
    I would say: drop your script and just use
    UPDATE STAT DBUSER.* ESTIMATE
    This single command would lead to the same statistics as your script does.
    And if you really, really want to leave out the JDBC tables - then just set their default sample size to 0 and they will be ignored by the UPDATE STAT command.
    regards,
    Lars

  • About the last_call_et column in v$session

    Hello,
    Can someone help me about a behaviour that is very strange ...
    We have connection about SAS on a database which manipulate Oracle table and others SAS Structure.
    The query is a "join" about that table and a "SAS Table" between million of lines in the Oracle table one ....
    It last a long time ....
    During the query, we have time to see at the v$session table...
    At any time (it lasts 3h), we saw that the column 'last_call_et' of the v$session never change : it continuesly stay at 0.
    What does it mean ? it means that SAS send a query every second ? Or this column shows the last "internal call"?
    If this is the right reason, i would'nt understand why, when i take the same query( launched by SAS) in TOAD, there is no the same behaviour and this behaviuor is in that case the right behaviour : the session is ACTIVE but the last_call_et respresents really the time since i launched the query... So why when SAS do it, the last_call_et stay at 0 ? it works like SAS launch every second this query !!!!
    Can someone help me ?
    Thanks ...

    Jonathan Lewis wrote:
    user12046632 wrote:
    When you say :
    A FETCH is a database call :
    That means that it must affect the value of 'last_call_et' or not ?"A Fetch is a database call"
    "last_call_et" -- certainly sounds like that could be something to do with database calls, perhaps End Time of LAST database CALL.
    A parse is also a database call, as is an execute ... I feel that perhaps I was a little too concise with my description. You asked why SAS could be doing lots of calls (although that wasn't exactly how you put the question) and I replied that calls could include fetches. And yes, the last_call_et is reset on every fetch (amongst other things - and ignoring the special behaviour of background processes).Ok
    >
    (accordint to me, only to user's activity do so and not to "database internal callsl") ! isn't it ?You don't want to believe everything you read on the internet - even if it did come from the online manuals. But a "fetch" is not a "database internal call" anyway, it's a call from a client to the server.Be sure that i don't do so.
    But the explanation of Oracle of the term 'cal' is not so precise at all ...
    >
    Your follonwing explanations seems to answers contrarily ....
    But the question is there : what sort of call affetcs the value of "last_call_et"All database calls - which you should read as "all calls from the client to the server".Ok
    >
    >>
    >>
    When you say
    all_rows plan => parse call, execute call ..... with very long call time, lots of fetch calls
    first_rows_n plan => parse call, execute call ... with very short call time, lots of fetch calls
    In the first case you would see last_call_et constantly growing until the fetches started
    In the second case last_call_et would keep resetting to zero so fast you probably wouldn't see it as a non-zero value.
    I don't understand : ok for the conséquences on the timing ... but if there are a lot of fetch call in both cases : the behaviour on the 'last_call_et' has to be equal ?True - but in one case I've included an execute call that is active for a very long time, and in the other I've proposed an execute call that is active for a very short time. (And execute calls are calls, and I did ask you about the exact details of your observations.)Ok
    If we consider that every call reset to 0 the value of 'last_call_et',
    why, in the case of launching the same request by TOAD, shouldn't i see the reset to 0 when the fetches works (because in TOAD during the whole query, which means since the click on "launching query" to the retrieving of data, the value did not reset to 0) ?
    >
    >>
    When you say
    Having said that, I've just run a quick test in SQL*Plus on 11.1.0.6 and 10.2.0.3 to demonstrate this point, and 11g is behaving differently from 10g - in the case where the last_call_et should be growing it stays at zero.
    "in the case" : in the case of the v11 or the v10 ?11g
    In my case : i'am on a v10.2.0.3 ::: Is there a bug ?Not that I know of.ok. So it is in V11 that you have an incorrect behaviour ....
    >>
    >
    Regards
    Jonathan LewisLAST NEWS : we have relaunched the query in SAS and observed that we have the same context of plan in both cases (by SAS en y TOAD) : ALL_ROWS.
    Very strange ...
    Last question :
    Just to be sure : When you talk about "First Rows plan" : it means that the retrieve data are restricted to the first rows encountered
    or
    it is just the plan of the query which is in "that context" which means that the engine works so although the whole data are retrieved ....
    thanks for your return

  • About selecting single column in a alv table.........

    Hi Experts,
    I need single column to be selected from a ALV table...selected in da sense to be highlighted....as it happens..by default for a row.....
    I hope u understood my query...
    Please help me out in this..
    I know u all will surely help me...
    Thks and Regards,
    Runali.

    Hi Runali,
    Get the reference to the column settings of your ALV Model. Then you can get the reference of each column by passing the column ID. There is a method set_selected_state in the column class, but that does not highlight the column as it does for a row. So what you can use is a cell design for a column that will highlight the column with a color or whatever.
    lr_column = lr_column_settings->get_column( ID = id ).
    lr_column->set_cell_design( preferred design ).
    Hope this helps. Please award points if it solves your purpose.
    Regards,
    Nithya

  • Datagrid: Can I set a tranparency level for column background color?

    Hi all,
    I have a datagrid with background colors set using triggers. This works. I would like to set a column background color but I don't want to make the color solid because it will block the row color. Is there a way to set the column background color transparency
    to 50% (or less) so that I can still see (or blend) with the row background color? I can set the "background" property of the column to a value of "transparent" but this makes no sense without a color.
    Thanks
    <DataGrid.RowStyle>
    <Style TargetType="DataGridRow">
    <Style.Triggers>
    <DataTrigger Binding="{Binding col_oPutorCall}" Value="call">
    <Setter Property="Background" Value="Cornsilk"/>
    </DataTrigger>
    <DataTrigger Binding="{Binding col_oPutorCall}" Value="put">
    <Setter Property="Background" Value="BlanchedAlmond"/>
    </DataTrigger>
    <DataTrigger Binding="{Binding col_rowColor}" Value="false">
    <Setter Property="Background" Value="LightGreen"/>
    </DataTrigger>
    </Style.Triggers>
    </Style>
    </DataGrid.RowStyle>
    <DataGridTextColumn Binding="{Binding col_oBid, StringFormat=F2}" FontFamily="Arial" FontWeight="Bold" FontSize="12" Header="oB" >
    <DataGridTextColumn.CellStyle>
    <Style TargetType="DataGridCell">
    <Setter Property="Background" Value= "Transparent" />
    <Setter Property="Background" Value= "AliceBlue" />
    </Style>
    </DataGridTextColumn.CellStyle>
    </DataGridTextColumn>

    Background is a brush.
    You can define a brush with an opacity in a resourcedictionary merged in app.xaml or in your window.resources ( etc ).
    <Grid.Resources>
    <SolidColorBrush x:Key="TransparentIshBrush" Color="Red" Opacity=".3" />
    </Grid.Resources>
    I should think you can then do:
    <DataGridTextColumn Binding="{Binding col_oBid, StringFormat=F2}" FontFamily="Arial" FontWeight="Bold" FontSize="12" Header="oB" >
    <DataGridTextColumn.CellStyle>
    <Style TargetType="DataGridCell">
    <Setter Property="Background" Value="{StaticResource TransparentIshBrush}" />
    </Style>
    </DataGridTextColumn.CellStyle>
    </DataGridTextColumn>
    The problem with your former piece of code is that setting an opacity on a datagridcell gets everything in it. You would have to do
    <Setter Property="(BackGround.Opacity)"
    And I'm rather doubtful that would work anyhow.
    Please don't forget to upvote posts which you like and mark those which answer your question.
    My latest Technet article - Dynamic XAML

  • Question about suming two columns from different tables in Subquery?

    Hello everyone,
    I have a subquery that works great for getting the total SUM of a Billing table, but I also need to add to that SUM the total surcharges or additional charges from a separate table.  I tried this by doing something like so:
    (SELECT SUM(SUM(Amount) FROM Billing WHERE Billing.JobID = Jobs.ID AND Billing.BillingType = 'Invoice' AND Billing.InvoiceCanceled = 'No', SUM(Payment) FROM Payments WHERE Payments.JobID = Jobs.ID AND Payments.Type = 'Bill')) as [Amount],
    But it doesn't work as there is an incorrect syntax near 'FROM'.  I'm assuming this is because of the two FROM's in the Subquery?  But I am not sure how else I would be able to do this then?  
    Any help would be greatly appreciated.  I just noticed this bug and am hoping to get a fix out as quickly as possible.
    Thanks Again,

    Hi, sorry for taking so long to get back to this post. 
    I tried this example like so:
    (SELECT SUM(A1) AS Total1, SUM(A2) AS Total2
    FROM
    (SELECT
    (SELECT SUM(Amount) FROM Billing WHERE Billing.JobID = Jobs.ID AND Billing.BillingType = 'Invoice' AND Billing.InvoiceCanceled = 'No') AS A1,
    (SELECT SUM(Payment) FROM Payments WHERE Payments.JobID = Jobs.ID AND Payments.Type = 'Bill') AS A2),
    However, get an error that an Incorrect Syntax exists near the ','.  I remove the comma (Which I think should be there), and I get an error that an Incorrect Syntax exists near the '.'...
    I also tried doing it like this (Based on other suggestions I've found online:
    (SELECT SUM(SELECT SUM(Amount) FROM Billing WHERE Billing.JobID = Jobs.ID AND Billing.BillingType = 'Invoice' AND Billing.InvoiceCanceled = 'No') as [Amount],
    (SELECT SUM(Payment) FROM Payments WHERE Payments.JobID = Jobs.ID AND Payments.Type = 'Bill') as [Additional]),
    And I get an error that an Incorrect Syntax exists near 'SELECT'...
    I also tried doing something like this with the SQL I already had...
    (SELECT SUM(Amount) FROM Billing WHERE Billing.JobID = Jobs.ID AND Billing.BillingType = 'Invoice' AND Billing.InvoiceCanceled = 'No') as [BilledAmount],
    (SELECT SUM(Payment) FROM Payments WHERE Payments.JobID = Jobs.ID AND Payments.Type = 'Bill') as [Additional],
    SUM(BilledAmount + Additional) AS [TotalBilled],
    But I get an error that the alias' are Invalid Column Names...  I have used Alias' before so I'm not sure why this would be an issue here...
    As you can see, I've been trying to figure this issue out, but haven't had much luck...  :(

  • Question about Level Meter Plug in

    I know how to change the channel meter between pre/post fader metering is there a way to do this with Logic's Level Meter plug in and with Inspector?

    Plugins are always pre-fader, as the audio path hits the plugins and then goes into the fader.
    What you'd have to do is route your audio through a fader (eg aux channel) to control the level, and then leave the fader on your output set to 0dB and meter in your plugins on that.

  • Tab level and column level security

    Hi
    Can anyone suggest a high level view of implementing a tab level security based on the user logged on? I have a form that has multiple tabs and within each of these tabs there are multiple fields displayed (in a multi record block). Based on the user, the relevant canvas tabs should be enabled and only those fields within each of these tabs to which the user is authorized to view should be displayed. I am looking for an approach methodology that can be implemented dynamically. There could be another form to maintain the user, roles and accessibility options.
    Any suggestions are welcome.
    Thanks

    When the form loads, capture the username (network login ID).
    Based on this username, in you when-new-form-instance trigger or when timer expired trigger(you have to create a timer for this), set the property that certain tabs/fields must be enabled/disabled depending on the user.
    Say, you have two groups of users, admins and non-admins..
    when the form loads, capture the username
    compare this username with the tabular data to determine if that user is an admin or non-admin (you can do this using a select query)..
    and using when-no-data-found exception you may set the appropriate previleges using set_tab_property('tab_name',ENABLED,property_true) and hence forth
    hope this helps

Maybe you are looking for