Find columns with only NULL values

I have a list of tables around 30 in number. Among them i need to generate a report with Table Name and Column Names, for which all values are NULL.
In other words, i need to find all the columns for which all the values are NULL.


I thought of dealing it with cursors, and comparing the total count with null count in each column. But i need to loop "Number of columns" times. Is there any better way to do this?

If your statistics are up to date, you can use the datadictionary:

select tab.table_name
,      tab.num_rows
,      col.column_name
,      case
         when tab.num_rows = col.num_nulls then '*100% NULL*'
         else to_char(col.num_nulls)
       end num_nulls
from   user_tab_columns col
,      user_tables tab
where  col.table_name = tab.table_name
and    tab.num_rows > 0
and    tab.table_name IN (YOUR_TABLE NAMES)
order by tab.table_name, column_id;

Set the query for your needs.

Tags: Database

Similar Questions

  • Indexes on columns with only "Y" and "n".

    Our transaction table has about 100 mn lines. Of these latter on 60 minutes the lines are not actively used.

    We have composite index on multiple columns, including dates, and these are used to regular queries.

    Will be adding a status = 'y' or ' don't column and the creation of an index on this column is useful to increase the performance of the query?

    For example, will add a condition like

    OÙ......... AND ACTIVE_FLAG = 'Y '.

    help increase the performance of queries?

    Creating such a column and adding a help index?
    What type of clue do you recommend?

    The alternative advocated by some members of the staff is the archiving of INACTIVE lines in a separate table. This will have a big impact on business processes. But we might be able to pull it off.

    Is there another solution.

    I am a beginner full performance although I am familiar with PL/SQL and queries.
    I'm on the constraints of very tight timetable for the first level of back. I'll have more time as soon as I know the direction in which to go.

    Forgive me if I broke a tag forum. I'm new on the forum too.

    Thanks for providing this information. This gives a much clearer picture of what you are facing.

    I will try to give you my answer your questions afterwards.

    You have indicated your data volumes have steadily increased and performance made that decline.
    Even if you do not say (I forgot to ask) but it may be that the number of users increases as and.
    so typical, many users use the system of the time.

    For me it's indicative of a systemic problem. In other words, the problem is not due to a
    a thing or a part of the system.

    There are two main components of a server: the instance and the database. This link sums up the difference
    between the two - http://www.adp-gmbh.ch/ora/misc/database_vs_instance.html and here is a link to recent forum
    for reference Re: difference between Oracle Instance and Database.

    To paraphrase, an instance includes background processes and structures of memory (SGA, PGA, etc.)
    Oracle uses.

    The symptoms you describe could mean that your instance is more configured size not set correctly
    for your current workload are originally strain throughout the system. Maybe the memory is too limited.
    Maybe your sorts are growing with addional data.

    I suggest that you start the new thread to ask for help in the evaluation and optimization of your instance. Use this
    as a starting point:
    >
    Question/title - how to evaluate the State of health / instance and tune

    Our facility has a problem of increasing return.

    How can we collect and provide assessment of workload and configuration information, so you can help determine
    possible solutions such as: memory sizing, temp and segment again sizing, sort the issue.

    Statement of the problem
    1 oracle Version is? ?. ?. ?

    2. gradually return was degrading with more and more data. The UI response suffers and
    batch processing is also in hours. We expect volumes to only continue to grow.

    3. the volumes have continued to increase over the years and gradually performance issues
    accumulate over the past 2 years. Data volumes began to increase faster
    last year 1 due to changes in the company.

    4. the data in OLTP system is a combination of assets of 40% and 60% relatively inactive (financial history).

    5. a complete system near-live replecation on several sites. In my opinion, using streams.

    6. notice of the tech team is a few tables have too many lines. We know that our demands can be suboptimal.

    >

    Now to your question:
    >
    1. I do not know the index on the existing columns are not fully exploited. In the meantime can but, we still get some benefits from adding
    a 'Y' and the null column? What will be improved?
    >

    It is unlikely the benefits you need. It's putting the cart before the horse. The first step is to identify a specific problem.
    Only then can examine you and evaluate solutions. for example by adding a new column or index.

    There are several reasons, this isn't the right solution; certainly not at the moment
    A. any new column and index, BY DEFINITION, maybe even this does not use except if one or more current
    queries are changed. This is obvious since no existing query could possibly refer to a column that does not exist.

    (B) to try to obtain the Oracle to use the new index column / single lease request must be changed.

    C. in my opinion, you should never modify a query of production without knowing which allows to obtain the amendment
    a well-defined objective. You must evaluate the current execution plan to identify what changes, IF ANY,
    can improve performance.

    D. it can be and given your systemic problem is likely to be, some ripe fruit on the performance. That
    is that there may be ways to tune the query to use existing indexes or add a new index on an existing column
    improve things.

    E. assuming that none of the above does the work adding a new column and an index to identify
    a 40/60 split (40% of assets) is unlikely to be used by Oracle (see response of Centinui).

    >
    2. notes that this calculation 'Y' is not negligible. I can easily reproduce this with a WHERE condition on the existing columns. We can have
    to run a batch on the weekend to check row groups and mark them as 'Y '. So it is not only the advantage of indexing on 'Y', but also some benefits of prior calculation.
    Given this info doing now more logic to have a 'Y' and the null column?
    >
    My answer is no – there is no sense to have a Y/N Y/NULL column.

    A. certainly not for reasons of performance - as noted above above it is unlikely help

    Certainly not for commercial reasons.
    The calculation of your "non-trivial" is to demonstrate a business rule: identify groups of lines that have earned.
    If you perform this calculation, the result must be saved significantly. One way is to create a new
    column called 'DATE_NETTED_OUT '. This column name have meanings, and can be used as a boolean DATE/NULL type. This
    It would be much better that Y/NULL which is not really enter the business sense of the value.

    >
    3 partitioning speed up queries on the minutes 40 active and slow queries on the full 100 minutes?
    >
    Probably not to have one influence on the other. Allocation decisions are usually made to ensure easier data management and often
    have little, if any, a performance impact. All existing applications are unlikely to accomplish the any
    differently just because the table is partitioned. There are exceptions of course. If you partition on DATE
    and an existing query has a DATE filter, but there is no index on the DATE column, it will do a full table scan
    of the whole picture. If the table is partitioned on this DATE column that oracle would probably make a partition full
    Scan just the 40% or 60% of the table according to the value DATE. It would be so much faster.

    But if there is already an index on the column DATE I do not expect the performance to change much. It comes
    just speculation since it is based on data, the factor of grouping the data, and the existing queries.

    >
    1. I still need to a particular column of partion, I do not?
    >
    Yes, you do. Unless you use HASH Partitioning that don't really benefit your use case. You too
    says that "...". staff advocate is the archiving of INACTIVE lines in a separate table "."
    Partitioning can be used as part of this strategy. Partition by MONTH or by QUARTER on your
    new column "DATE_NETTED_OUT." Keep 1 or 2 years of data online as you do now and when a partition
    becomes more than 2 years you can 'transport' it to your archiving system. This is part of the partition
    management, which I mentioned earlier. You can simply disconnect the oldest partition and copy it to archive.
    This will not affect your applications other than the data not being is not available.

    >
    2. "adds a column' or ' cut-and - paste lines of table created by copy" the worst idea?
    >
    I don't know what that means.

    SUMMARY

    It is premature to consider alternatives until you know what the problems are. Only then you can try to
    determine the applicable solutions.

    I do it in this order:

    1. upgrading to a newer version of Oracle you are on an older (you said 9i which is not
    longer supported)

    2 assess the health and configuration of your instance. You may be able to significantly improve things
    by adjusting the parameters of configuration and instance. Post a new question, as previously mentioned. I don't
    have the expertise to advise you in details on that and the gurus tuning of the Forum the Forum can
    not to notice this thread (indexes on columns with only 'Y' and 'n') than even know you need help.

    3. identify the ripe fruits for performance problems. Is this one of your batch process? An individual
    request? You mentioned UI soon - that could be a problem of front end, middle tier or application
    not a database one.

    4. don't it make changes architecture (add columns) until you have tried everything first.

  • Documentation about adding column with the DEFAULT value.

    Hello

    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/statements_3001.htm#i2198241

    < quote >
    If you add a column, then the initial value of each row in the new column is NULL unless you specify the DEFAULT clause. In this case, Oracle database updates each row in the new column with the value specified for the DEFAULT value. This update operation, in turn, triggers AFTER UPDATE triggers defined on the table.
    < quote >

    I am not able to understand the emphasis on the part AFTER UPDATE while the column with DEFAULT values addition triggers both BEFORE and AFTER triggers defined on UPDATE.

    According to the documents of 11 g

    http://download.Oracle.com/docs/CD/B28359_01/server.111/b28286/statements_3001.htm#i2133105

    n.m. (u) r only changes with the NON NULL columns, but focus on AFTER UPDATE is still there. No trigger defined on the fire of the update in this case.

    This insistence is intended? If not, IMO, it should be changed.

    Kind regards

    Hi Sissi. After further discussion, we have added some information about a change in behavior. Here is what says the next version of the doc:

    When you add a column, the initial value of each row in the new column is null.

    * If you specify the DEFAULT clause for a column NOT NULL, then the default value is stored as metadata, but the column itself is not populated with data. However, the following queries that specify the new column are rewritten so that the default value is returned in the result set.

    This optimized behavior differs from earlier versions, when as part of operation ALTER TABLE Oracle database updated every line in the newly created with the default column and then fired defined update triggers on the table. In this release, no trigger is triggered because the default value is stored only in the form of metadata.

    * If you specify the DEFAULT for a nullable column clause, then the default value is added to existing lines under this ALTER TABLE statement, and any update triggers defined on the table are activated. This behavior also means if you change a NOT NULL column with a default value to be nullable.

    Hope that helps to clarify the matter further.

    Kind regards
    Diana

  • I have a column with two values, separated by a space, in each line. How to create 2 new columns with the first value in a column, and the second value in another column?

    I have a column with two values, separated by a space, in each line. How do I create 2 new columns with the first value in one column and the second value in another column?

    Add two new columns after than the original with space separated values column.

    Select cell B1 and type (or copy and paste it here) the formula:

    = IF (Len (a1) > 0, LEFT (A1, FIND ("", A1) −1), ' ')

    shortcut for this is:

    B1 = if (Len (a1) > 0, LEFT (A1, FIND ("", A1) −1), ' ')

    C1 = if (Len (a1) > 0, Member SUBSTITUTE (A1, B1 & "", ""), "")

    or

    the formula of the C1 could also be:

    = IF (Len (a1) > 0, RIGHT (A1, LEN (A1) −FIND ("", A1)), "")

    Select cells B1 and C1, copy

    Select cells B1 at the end of the C column, paste

  • An update on an index column with the same value generates an index to the top

    An update on an index column with the same value generates an update of the index?


    Thank you

    In addition to my previous answer, see also

    http://orainternals.WordPress.com/2010/11/04/does-an-update-statement-modify-the-row-if-the-update-modifies-the-column-to-same-value/

    Riyaj Shamsudeen has this to say:
    "+ We have an index on this column v1 and we update this column indexed too." Oracle was updating the indexed column? N ° if the values match the level of the indexed column, then the code of RDBMS isn't up-to-date index, a feature for optimization again. Only the row of table is updated, and the index is not updated. + "

    Hemant K Collette

  • How to leave db field with a Null value if no value is entered in the form?

    I have a short form that has optional fields. If the optional fields are not filled in the form, I want to leave the field with a Null value in the SQL db. SQL columns allow Null, but whenever this code runs, it seems to insert a space rather than leave the field with a null value. I forget to do?

    Here is the solution...

  • Eloqua recommended way to identify records with a null value in a specific field?

    What is the recommended Eloqua the way to identify records with a null value in a specific field in a contact filter.  For example, in the segment 'lead State cleaning-11/21/12', I look for records with a value zero in LeadID and ContactID... How Eloqua recommends to do this?

    Replied to your message here: http://topliners.eloqua.com/message/19075#19075

  • Addition of constraint not Null to a column that contains null values

    All,

    Could you please suggest me how to add the constraint not null to an existing column that has null values?

    SQL > create table nn (number n, s varchar2 (10));

    Table created.

    SQL > insert into nn values (1, 'test');

    1 line of creation.

    SQL > insert into values nn (2 '');

    1 line of creation.

    SQL > commit;

    Validation complete.

    SQL > alter table nn edit n number not null;

    Modified table.

    SQL > nn desc;

    Name                                      Null?    Type

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

    N NUMBER NOT NULL

    S                                                          VARCHAR2(10)

    SQL > alter table nn edit n number null.

    Modified table.

    SQL > nn desc;

    Name                                      Null?    Type

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

    N                                                  NUMBER

    S                                                  VARCHAR2(10)

    SQL > alter table nn change s varchar2 (10) not null;

    ALTER table nn change s varchar2 (10) not null

    *

    ERROR on line 1:

    ORA-02296: impossible to activate (SCOTT) - found null values

    SQL >

    Thank you

    Use NOVALIDATE:

    SQL > alter table nn change s varchar2 (10) not null;
    ALTER table nn change s varchar2 (10) not null
    *
    ERROR on line 1:
    ORA-02296: impossible to activate (SCOTT) - found null values

    SQL >
    SQL > alter table nn change s varchar2 (10) not null NOVALIDATE;

    Modified table.

    SQL > insert into values nn (3, null);
    insert into nn values (3, null)
    *
    ERROR on line 1:
    ORA-01400: cannot insert NULL into ('SCOTT'. "' NN '. » S »)

    SQL > select * from nn;

    N S
    ---------- ----------
    1 test
    2

    SQL >

    SY.

  • The research of a column with comma separated values with ora-text

    I use the Oracle 11 g 2 XE and Oracle Text to a web search engine.

    I've now created and text indexed a CLOB keywords column that contains words separated by spaces. This allowed me to expand the search, as Oracle Text returns the rows that have one or more keywords that are stored in this column. The contents of the column are visible to the user and serves to 'expand' the search. This does not work as expected.

    But now I need support several words or even sentences. With the current configuration, Oracle Text will only search for each keyword. How should I store the phrases and configure Oracle text so that it will search entire sentences (exact match is better, but the partial match is fine too)?

    Example of content column of two lines (values separated semicolon):
    "Hello, Hello; y at - it anyone out there? Nope; »
    "the just; basic facts; »
    I found a similar question: looking for a column with values separated by commas, except that I need a solution for Oracle 11 g with it's freetext search.

    Possible solutions:
    1st solution: I thought to redraw the DB as follows. I would like to make a new array of keywords (pkID NUMBER, nonUniqueID NUMBER, singlePhrase VARCHAR2 (100 BYTE)). And I want to change the column previous keyword to KeywordNonUniqueID, holding the ID (instead of a list of values). At the time of the research I had INNER JOIN with the new keyword table. The problem with this solution is that I will get several lines containing the same data except for the sentence. I guess this will destroy the ranking?

    2nd solution: is it possible to store sentences as an XML in the column key of origin and somehow say Oracle text to search for in the XML?

    3rd solution: separate individual phrases with spaces, but replace the spaces in sentences with the underscore or something (making a single word). If a phrase "why Hello there, Johnny!" is saved as "Why_hello_there, _Johnny!

    4th solution?:

    Note that, generally, there is a lot of sentences (less than 100), nor that they will be long (one sentence will be up to 5 words).

    Also note that I am currently using CONTAINS, and needs some of its operators, to my full-text searches.

    When you talk about "phrase", do you mean "a list of words separated by a comma other sentences?

    Isn't that the definition of "sentence" used by Oracle Text, where it simply means "a list of words in the order defined."

    If I understand your requirement, you want to have data such as:

    "aa bb cc dd".
    "aa ee dd ff.

    and give priority to the first on the second if someone looking for "dd".

    First, to conduct research in the comma separated list, you should look for in a section. You can either explicitly define sections of field such as
    AA bb cc dd
    Or you can use the PHRASE special section and set the sentence delimiters correctly. This is done with the attribute BASIC_LEXER punctuation

    Then you have the number you want to find only words where they are the only words in the section. That's the same problem, I address in the last post of this forum entry:
    Contains: match exactly

    Our solution will be substantially the same, some surrounding text with special markers, and then prioritize a phrase search with these special markers each side of the word.
    We need to do a treatment some additional, although, as we need to surround each "sentence" (in your terminology) with special markers. I did it by surrounding the text with "XX1"... Condition2"then by replacing every comma with"Condition2, XX1"as part of a MULTI_COLUMN_DATASTORE:

    drop table names;
    create table names (id number primary key, text varchar2(50));
    
    insert into names values( 1, 'just and kind, kind and loving' );
    insert into names values( 2, 'just, kind' );
    
    exec ctx_ddl.drop_preference  ( 'mylex' )
    exec ctx_ddl.create_preference( 'mylex', 'BASIC_LEXER' )
    exec ctx_ddl.set_attribute    ( 'mylex', 'PUNCTUATIONS', ',' )
    
    exec ctx_ddl.drop_preference  ( 'mcds' )
    exec ctx_ddl.create_preference( 'mcds',  'MULTI_COLUMN_DATASTORE' )
    exec ctx_ddl.set_attribute    ( 'mcds', 'COLUMNS', '''XX1 ''||replace(text, '','',''XX2, XX1'')||'' XX2''' )
    
    exec ctx_ddl.drop_preference  ( 'mywl' )
    exec ctx_ddl.create_preference( 'mywl', 'BASIC_WORDLIST' )
    exec ctx_ddl.set_attribute    ( 'mywl', 'SUBSTRING_INDEX', 'YES' )
    
    create index namesindex on names(text)
    indextype is ctxsys.context
    parameters( 'datastore mcds wordlist mywl' )
    /
    
    select score(1),id,text from names where contains( text, '
    
      
        
           XX1 kind XX2 
           kind
        
      
    
    ', 1) > 0
    order by score(1) desc
    /
    

    Output of this is:

      SCORE(1)        ID TEXT
    ---------- ---------- --------------------------------------------------
         52         2 just, kind
          2         1 just and kind, kind and loving
    
  • Several lines in duplicate with the null value displayed in the combined analysis rpt

    Dear all,

    Our requirement is to display users open tasks (my open tasks) on the home page. So I created a report called open my tasks.

    The columns to display are subject, account name, due date, owner. If I use only the 'activities' notification area, and then I can not retrieve tasks that have NULL of the account name. SOD ignore and filter the tasks with the NULL account name if I display the name of the account.

    So I used a combined analysis of activity report activity with itself i.e. area statement. All columns except account name in one of them where I used "instead of the name of Account.Account.

    It now also displays tasks with NULL account name. But there is another question. These activities when there is an account name, display double - double rows - an account name and othet without account name (for example, NULL).

    Please can you help how to solve above or meet the requirement in an alternative way?

    Thank you
    Niraj

    VR;

    (1. any activity with account) + (2. All activities - 3. Activities with account)

    1 account name because it is
    2 maintain a column empty "
    3 write the instruction box and change the name of the account by white ")

    Dinesh

  • History of backfilling with non-null values

    Hi gurus,

    in Oracle 11 g, which would be the best way to update a null with the next available non-null value?

    For example: in the code below, I need to update the null in 20130201 record (key = 1) (key date) with a value of 100 available at the next available date IE 20130203.
    Same key = 3 value will be updated with key = 4 value i.e. 200.
    1,ABCD, 20130201, NULL
    2,ABCD,20130203, 100
    3,ABCD, 20130205, NULL
    4, ABCD,20130207, 200
    Thank you
    S
    with t as (
               select  tbl.*,
                       last_value(nvl2(c4,c1,null) ignore nulls) over(order by c1) prev_c1,
                       last_value(c4 ignore nulls) over(order by c1) prev_c4,
                       first_value(nvl2(c4,c1,null) ignore nulls) over(order by c1 rows between current row and unbounded following) next_c1,
                       first_value(c4 ignore nulls) over(order by c1 rows between current row and unbounded following) next_c4
                 from  tbl
              )
    select  c1,
            c2,
            c3,
            c4,
            case
              when c4 is not null then c4
              when c1 - prev_c1 < next_c1 - c1 then prev_c4
              else next_c4
            end new_c4
      from  t
    /
    
            C1 C2           C3         C4     NEW_C4
    ---------- ---- ---------- ---------- ----------
             1 ABCD   20130201                   100
             2 ABCD   20130203        100        100
             3 ABCD   20130205                   200
             4 ABCD   20130207        200        200
    
    SQL> 
    

    SY.

  • How can I replace the value of the column with a particular value in SQL

    Hi all

    Is someone can you please tell me how can I format my output with the replacement of a column value with a specific value that really depends on the current value of the column

    I am executing the following SQL statement

    Select state, count (id) from < table_name > where composite_dn = < composite_dn_name > Group by State;
    My current performance is:

    State Instance number
    1 3
    3 28

    I want to replace the value in the State column as follows

    No.OfInstances State
    3 filled
    28 faulted

    I want '1' to be reppaced of 'Done' and '3' is replaced by 'Faulted. '

    Is is possible with SQL or PL/SQL, if it is then how I can achieve this required. Help, please!

    Thanks in advance!

    Published by: Roshni Shankar on October 27, 2012 12:38 AM

    Hi Claude,.

    I guess this CASE clause can be simulated by a DECODE and also it is very easy to use.
    See - http://www.techonthenet.com/oracle/functions/decode.php

    select decode(t1.state,t2.state_id,t2.state_name), t1.count_id
    from  t2, (select state,count(id) count_id
     from 
     where composite_dn= 
    group by state) t1
    where t1.state = t2.state_id;
    

    HTH
    Vanessa B.

    Published by: Vanessa B on October 27, 2012 14:02
    -link added

    Published by: Vanessa B on October 27, 2012 14:19
    -added code sample

  • Need to add a column with a default value

    I need to add a column of type char (1) to a table and there should be a value default of'm '

    I want to check first if this column already exists in this table.
    If so, I still want to check if the default is am'

    How can I do this?

    I was able to all_tab_columns to query for the presence of column with the type of data and all, but not able to do the second part.

    Thanks in advance.

    The DATA_DEFAULT field in dba_tab_columns stores information.

  • Number of rows in each partition is displayed with a NULL value for a table partitioned in user_tab_partitions. Why?

    I created a table and partitioned on the date of the entry and added a local partitioned index.

    Now, I use a query to extract "num_rows" of user_tab_partitions to know the number of rows in each partition.

    Getting this value as null num_rows, wonder why?

    After looking to explain the Plan after interrogation ("select * from my_table1 where entry_date = 1 January 2015" ;))

    to find out if she actually partitioned table and its data in different partitions, I interpreted in effect because the query plan had a line like Partition_range (Single).

    My Question is:

    (a) is actually partitioned data (have I misinterpreted the Explain plan)

    (b) why is the num_rows null column in the query (Pasted below)

    (c) also in addition what difference it would have been if I had created a Global Index instead of the Local Index in my case?

    The following code Snippet:

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

    create the table my_table1
    (
    roll_no number constraint my_table1_pk primary key,
    date of entry_date
    )
    partition of range (entry_date)
    (
    PARTITION data_p1 VALUES LESS THAN (TO_DATE (December 31, 2014 ',' DD-MM-YYYY ""));
    PARTITION data_p2 VALUES LESS THAN (MAXVALUE)
    );


    create an index only my_table1_indx on my_table1 (entry_date) local;

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

    I now insert two lines:
    insert into my_table1 values (1, to_date ('01-01-2015', ' dd-mm-yyyy'));
    insert into my_table1 values (2, to_date('01-02-2015','dd-mm-yyyy'));

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

    These have been inserted successfully, now using the query below shows num_rows column as null. I don't know why?

    SELECT table_name, num_rows, high_value, nom_partition
    Of user_tab_partitions
    where table_name = 'MY_TABLE1 '.
    ORDER BY table_name, nom_partition;

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


    (a) is actually partitioned data (have I misinterpreted the Explain plan)

    Yes, it is partitioned. You can query this particular partition SELECT * FROM my_table1 (data_p1) PARTITION to check that.

    (b) why is the num_rows null column in the query (Pasted below)

    As already mentioned that you have not collected statistics.

    (c) also in addition what difference it would have been if I had created a Global Index instead of the Local Index in my case?

    In fact, you have created two types of indexes without knowing (can be)! One is not partitioned (although this column is not partition key) and another is partitioned (LOCAL). They are MY_TABLE1_PK and MY_TABLE1_INDX. You can check that USER_INDEXES.

    You can read this article to get an early jump on the partitioning of decision. Partition: Partition decisions

  • Complete with matching null values

    Hi all
    Take into consideration the following:

    create table X_T2
    (
      COL1 VARCHAR2(2),
      COL2 VARCHAR2(2)
    )
    insert into x_t2 (COL1, COL2)
    values ('1', 'A');
    
    insert into x_t2 (COL1, COL2)
    values ('2', '');
    
    insert into x_t2 (COL1, COL2)
    values ('3', '');
    
    insert into x_t2 (COL1, COL2)
    values ('4', '');
    
    insert into x_t2 (COL1, COL2)
    values ('5', '');
    
    insert into x_t2 (COL1, COL2)
    values ('6', '');
    
    insert into x_t2 (COL1, COL2)
    values ('7', 'B');
    
    insert into x_t2 (COL1, COL2)
    values ('8', '');
    
    insert into x_t2 (COL1, COL2)
    values ('9', '');
    
    insert into x_t2 (COL1, COL2)
    values ('10', '');
    
    insert into x_t2 (COL1, COL2)
    values ('11', '');
    
    insert into x_t2 (COL1, COL2)
    values ('12', 'C');
    
    insert into x_t2 (COL1, COL2)
    values ('13', '');
    
    insert into x_t2 (COL1, COL2)
    values ('14', '');
    
    insert into x_t2 (COL1, COL2)
    values ('15', '');
    
    insert into x_t2 (COL1, COL2)
    values ('16', '');
    
    insert into x_t2 (COL1, COL2)
    values ('17', 'D');
    
    insert into x_t2 (COL1, COL2)
    values ('18', '');
    
    insert into x_t2 (COL1, COL2)
    values ('19', '');
    
    insert into x_t2 (COL1, COL2)
    values ('20', '');
    Required result:
    1     A
    2     A
    3     A
    4     A
    5     A
    6     A
    7     B
    8     B
    9     B
    10     B
    11     B
    12     C
    13     C
    14     C
    15     C
    16     C
    17     D
    18     D
    19     D
    20     D
    Any ideas?

    Oracle 11g


    Thanks in advance,
    Alexander.

    Hello, Alexander.

    Here's one way:

    SELECT    col1
    ,       LAST_VALUE (col2 IGNORE NULLS)
               OVER (ORDER BY  LPAD (col1, 2))     AS c2
    FROM       x_t2
    ORDER BY  LPAD (col1, 2)
    ;
    

    a.Stoyanov wrote: Hi all,.
    Take into consideration the following:

    create table X_T2
    (
    COL1 VARCHAR2(2),
    COL2 VARCHAR2(2)
    )
    
    insert into x_t2 (COL1, COL2)
    values ('1', 'A');
    ...
    

    If you want to '2' and '3' in front of '10' and 11', then you might consider col1, a NUMBER, rather than a VARCHAR2, or add a constraint (and possibly a trigger) to make sure he always has 2 characters.

    Please include the information and sample version; It's very useful!
    You didn't say if you have Oracle 11.1 or 11.2. From 11.2, there is another way to specify IGNORE NULLS; but as noted above will work in both versions (or any version starting with Oracle 10.1).

Maybe you are looking for

  • Firefox.exe * 32 to 99% of the CPU is running and blocking WHY?

    so on two different PCs, we have problems with firefox as soon as launch you it, it goes back to 99% cpu ussage and freezes.I did a complete uninstall and reinstall as running revo and delete all entries from firefox on the registry. It does this eve

  • My new Imac 27 inch restarts on its own.

    My brand new 27-inch Imac 3000-buck restarts on its own. I'm under EL CAPITAN - sorry; my profile says Mavericks. Will change now. An article said that Spotlight is the culprit. In addition, two times I woke up to find my computer had just closed. Wh

  • Satellite P30 110: what power?

    I need to replace the power supply for my Satellite P30-110. The main web site search gives three options: PA3336E-1ACA, PA3381E-1ACA, and PA3290E-2ACA (e = 1 http://uk.computers.toshiba-europe.com/cgi-bin/ToshibaCSG/options_and_accessories_search_by

  • Backup will not perform, he's stuck at 49%

    Original title: used to backup complete! Bakup AM backup on CD, but he has been slain on 49% complete for the last 2 hours. Had problems all morning. Said that I was browsing with IE 8 when spose IE 7 (don't know how it happened?) set in a way everyt

  • HP ENVY M7 - K111DX NOTEBOOK PC: fastest shipping the laptop repaired

    My cell phone is being repaired by HP.  Who should I contact and extra to have it returned more quickly to me?