return the names of columns which line values are not null.

Hi I m a new db admin guy, and I need a sql script that should return the names of columns of the given table. and the returned column must be the value (fyi - if the column contains the value null column name would not come to the o/p of sql).
Exmple:
name of the table - A
fresh status s.no name brand
1 null aa 45P
paid 2 null bb 30
3 cc paid 35P

(FYI - 1) if I give the table name (A) and s. n. (2) o/p should be - name, mark.
(2) if I give the status of tablename (A) and s. n (1) the o/p should be - name, brand.

Thank you
Krishna.

Published by: user13294228 on June 14, 2010 22:54

BTW,
The previous solution is for all values of the column, if you want a specific line, you can add it in where clause.
I mean in your example, it you look like:

SET serveroutput on;

DECLARE
   l_cnt          NUMBER;
   l_str          VARCHAR2 (255) := '';
   l_table_name   VARCHAR2 (255) := 'YOUR_TABLE_NAME';
   l_col_cond     VARCHAR2 (255) := 'S_NO';
   l_val          NUMBER         := 1;

   CURSOR c_col
   IS
      SELECT column_name
        FROM user_tab_columns
       WHERE table_name = l_table_name;
BEGIN
   FOR i IN c_col
   LOOP
      EXECUTE IMMEDIATE    'SELECT COUNT ('
                        || i.column_name
                        || ') FROM '
                        || l_table_name
                        || ' WHERE '
                        || l_col_cond
                        || ' = '
                        || l_val
                   INTO l_cnt;

      l_str := l_str || CASE
                  WHEN l_cnt = 0
                     THEN ''
                  ELSE i.column_name
               END || ',';
   END LOOP;

   l_str := SUBSTR (l_str, 1, LENGTH (l_str) - 1);
   DBMS_OUTPUT.put_line (l_str);
END;

Saad,

Published by: S.Nayef on June 15, 2010 11:54

Tags: Database

Similar Questions

  • Test whether the object is Assigned() which means... not null

    In Delphi using the Windows SDK, I can use the Assigned() function to determine if an object has been instantiated... IOW, not null.  How this is done in ActionScript?  I've been going around in circles in the documentation.  I can find every keyword and the operator, but I can't find how to test a null object variable.

    If (MyDataGrid.selectedItem is not null) {.. my... code...}

    Thanks in advance.

    If (MyDataGrid.selectedItem! = null) {.. my... code...}

    or

    If (!.) MyDataGrid.selectedItem) {.. my... code...}

  • change the names of columns in the automatic process line fetch, edit the code

    Hello

    I created the master detailed form of two tables, and then I changed one of the names of columns in the table which is the detail.

    of course the extraction process could not recognize the name of this column (as it is no longer exist), so I need to change the column name in the query of in the current name.

    Ditto for line process transformation, to insert a new line.

    I guess it's easy, but I don't know where to find the ASR process query request,
    suggestions please!

    Kind regards.

    Published by: user8784111 on September 14, 2009 12:53 AM

    Hello:

    The detail rows are rendered in tabular form. This tabular presentation is implemented in a region of "report". You can change the query for the report region explain the column names.

    CITY

  • display the name of column in exported .xls

    Hello

    I found the following code which works perfectly to export data from forms in .xls.
    procedure ExportToExcel is
    
    APPLICATION OLE2.OBJ_TYPE;
    WORKBOOKS OLE2.OBJ_TYPE;
    WORKBOOK OLE2.OBJ_TYPE;
    WORKSHEETS OLE2.OBJ_TYPE;
    WORKSHEET OLE2.OBJ_TYPE;
    ARGS OLE2.LIST_TYPE;
    CELL OLE2.OBJ_TYPE;
    J INTEGER;
    K INTEGER;
    file_name_cl VARCHAR2(32767);
    user_cancel EXCEPTION;
     
     
    BEGIN
     
    file_name_cl := CLIENT_GET_FILE_NAME('C:\rep2excel', 'MyExport.xls', 'XLS Files (.xls)|*.xls|', NULL, SAVE_FILE, TRUE);
    file_name_cl := SUBSTR(file_name_cl,1,LENGTH(file_name_cl));
    --
    IF file_name_cl IS NULL THEN
    MESSAGE('INSIDE EXCEPTION STATEMENT');
    RAISE user_cancel;
    END IF;
     
    --MESSAGE('STARTING TRIGGER');
     
     
    APPLICATION := OLE2.CREATE_OBJ('Excel.Application');
    OLE2.SET_PROPERTY(APPLICATION,'Visible',True);
     
    WORKBOOKS := OLE2.GET_OBJ_PROPERTY(APPLICATION, 'WORKBOOKS');
    WORKBOOK := OLE2.INVOKE_OBJ(WORKBOOKS, 'ADD');
    WORKSHEETS := OLE2.GET_OBJ_PROPERTY(WORKBOOK, 'WORKSHEETS');
    WORKSHEET := OLE2.INVOKE_OBJ(WORKSHEETS, 'ADD');
     
    GO_BLOCK('ELEVI');
     
    FIRST_RECORD;
     
    J:=1;
     
    K:=1;
     
    WHILE :SYSTEM.LAST_RECORD = 'FALSE'
     
    LOOP
     
    FOR K IN 1..9 --form has 9 columns
     
    LOOP
     
     
    If not name_in(:system.cursor_item) is NULL Then
     
    args:=OLE2.create_arglist;
     
    OLE2.add_arg(args, j);
     
    OLE2.add_arg(args, k);
     
    cell:=OLE2.get_obj_property(worksheet, 'Cells', args);
     
    OLE2.destroy_arglist(args);
     
    OLE2.set_property(cell, 'Value', name_in(:system.cursor_item));
     
    OLE2.release_obj(cell);
     
     
    End If;
     
    NEXT_ITEM;
     
    END LOOP;
     
     
    J:=J+1;
     
    NEXT_RECORD;
     
    END LOOP;
     
     
    -- for the last record
     
    for k in 1..9
     
    loop
     
    If not name_in(:system.cursor_item) is NULL Then
     
    args:=OLE2.create_arglist;
     
    OLE2.add_arg(args, j);
     
    OLE2.add_arg(args, k);
     
    cell:=OLE2.get_obj_property(worksheet, 'Cells', args);
     
    OLE2.destroy_arglist(args);
     
    OLE2.set_property(cell, 'Value', name_in(:system.cursor_item));
     
    OLE2.release_obj(cell);
     
    End If;
     
    next_item;
     
    end loop;
     
    OLE2.Release_Obj(worksheet);
     
    OLE2.Release_Obj(worksheets);
     
    -- Save the Excel file created
     
    args := OLE2.Create_Arglist;
     
    OLE2.Add_Arg(args,'c:\temp\test.xls');
     
    OLE2.Invoke(workbook, 'SaveAs', args);
     
    OLE2.Destroy_Arglist(args);
     
    -- release workbook
     
    OLE2.Release_Obj(workbook);
     
    OLE2.Release_Obj(workbooks);
     
    OLE2.Release_Obj(application);
     
    MESSAGE('RIGHT BEFORE END');
    END;
    But the cells are filled with data from the 1st line. In Excel, on the 1st line, with bold, I want the name of the columns. How can I do? If the recordings should start from the 2nd line.
    Any ideas?

    Thank you!

    Rogerrrrrrrrrr...
    because there was a pause stmt. in the code... as a stmt message... remove a friend!
    you don't need this funtion now that you need display all visible items in the block...

    PROCEDURE l_call_Excel(p_block varchar2 ) is
    
    APPLICATION OLE2.OBJ_TYPE;
    WORKBOOKS OLE2.OBJ_TYPE;
    WORKBOOK OLE2.OBJ_TYPE;
    WORKSHEETS OLE2.OBJ_TYPE;
    WORKSHEET OLE2.OBJ_TYPE;
    Arglist OLE2.LIST_TYPE;
    CELL OLE2.OBJ_TYPE;
    J INTEGER;
    K INTEGER;
    file_name_cl VARCHAR2(32767);
    user_cancel EXCEPTION;
    Workfont OLE2.OBJ_TYPE;
    WorkInterior OLE2.OBJ_TYPE;
    m_item varchar2(40);
    m_tot_columns number := 0;
    --Inner Proc.
    Procedure put_cell (Row_num number,
                        Col_num number,
                        put_value varchar2,
                        font_name varchar2 default null,
                        font_size binary_integer default null,
                        font_style varchar2 default null,/*here you can pass BOLD for bold, ITALIC for italic etc*/
                        font_color binary_integer default null) is
    Begin
            Arglist := OLE2.create_arglist;
            OLE2.add_arg(Arglist,row_num);
            OLE2.add_arg(Arglist,col_num);
                   cell := OLE2.get_obj_property(Worksheet,'Cells',Arglist);
            OLE2.destroy_arglist(Arglist);
            OLE2.set_property(cell,'Value',put_value);
    
            Workfont := OLE2.get_obj_property(cell,'Font');
            WorkInterior := OLE2.get_obj_property(cell,'Interior');
            If font_name is not null then
                   OLE2.set_property(Workfont,'Name',font_name);
            End if;
            If font_size is not null then
                   OLE2.set_property(Workfont,'Size',font_size);
            End if;
            If font_style is not null then
                   OLE2.set_property(Workfont,font_style,1);
            End if;
            If font_color is not null then
                   OLE2.set_property(Workfont,'ColorIndex',font_color);
            End if;
    OLE2.release_obj(workfont);
    OLE2.release_obj(workinterior);
    OLE2.release_obj(cell);
    End;
    
    BEGIN
    
      file_name_cl := CLIENT_GET_FILE_NAME('C:\rep2excel', 'MyExport.xls', 'XLS Files (.xls)|*.xls|', NULL, SAVE_FILE, TRUE);
      file_name_cl := SUBSTR(file_name_cl,1,LENGTH(file_name_cl));
      --
      IF file_name_cl IS NULL THEN
         MESSAGE('INSIDE EXCEPTION STATEMENT');
         RAISE user_cancel;
      END IF;
      --MESSAGE('STARTING TRIGGER');
    
      APPLICATION := OLE2.CREATE_OBJ('Excel.Application');
      OLE2.SET_PROPERTY(APPLICATION,'Visible',True);
    
      WORKBOOKS := OLE2.GET_OBJ_PROPERTY(APPLICATION, 'WORKBOOKS');
      WORKBOOK := OLE2.INVOKE_OBJ(WORKBOOKS, 'ADD');
      WORKSHEETS := OLE2.GET_OBJ_PROPERTY(WORKBOOK, 'WORKSHEETS');
      WORKSHEET := OLE2.INVOKE_OBJ(WORKSHEETS, 'ADD');
      OLE2.set_property(Worksheet,'Name','this is my sheet, named by me');
    
      GO_BLOCK(p_block);
      FIRST_RECORD;
     /*as your data should print from second row*/
      J:=2;
      K:=1;
      LOOP
        m_item := get_block_property(p_block,first_item);
        K:=1;
        Loop
         exit when M_ITEM IS NULL ;
          If not id_null(find_item(p_block||'.'||m_item))  then
               If get_item_property(p_block||'.'||m_item,item_type)IN ( 'TEXT ITEM' ,'DISPLAY ITEM','LIST','CHECKBOX')
                     and get_item_property(p_block||'.'||m_item,visible) ='TRUE'   then
                    If j=2 then
                    put_cell(1,k,get_item_property(p_block||'.'||m_item,column_name));
                  end if;
                  If not name_in(p_block||'.'||m_item) is NULL Then
                    put_cell(j,k,name_in(p_block||'.'||m_item));
                  End If;
                  K:=k+1;
                 end if;
           end if;
         m_item := get_item_property(p_block||'.'||m_item,NEXTITEM );
         END LOOP;
         J:=J+1; 
    
       exit when :system.last_record = 'TRUE';
       NEXT_RECORD;
       END LOOP;
      OLE2.Release_Obj(worksheet);
      OLE2.Release_Obj(worksheets);
      -- Save the Excel file created
      Arglist := OLE2.Create_Arglist;
      OLE2.Add_Arg(Arglist,'c:\temp\test.xls');
      OLE2.Invoke(workbook, 'SaveAs', Arglist);
      OLE2.Destroy_Arglist(Arglist);
      -- release workbook
      OLE2.Release_Obj(workbook);
      OLE2.Release_Obj(workbooks);
      OLE2.Release_Obj(application);
      MESSAGE('RIGHT BEFORE END');
    END;
    
  • How to query the name summary of custom line of Section header information

    I need a query which can help me to retrieve the contents of a header line custom section information name.  We have a couple of tables Denorm when data are denormalized, the field row_name is only show the name of alias denormalized.  We would like to be able to draw the contents of the line header information section name?  How can we use the alias denorm name and join another table to find the associated summary name?

    The following query returns the name of the line as well as the line name denorm, for a custom section, where we specify the section custom denorm table. Deserve you this to do otherwise, it depends on how you want to retrieve information. Is that what you are looking for?

    SELECT ml. Name [rowName], ml.langID, dr.NAME [denormRowName], Dr. FKROWTEMPLATE, dt. GENERATED_TABLE_NAME

    OF DENORM_CS_ROW dr

    DENORM_CS_TABLE dt on Dr. FK_DENORM_TABLE_ID = dt.ID inner join

    commonextendedattributeml ml on Dr. FKROWTEMPLATE = ml.fkOwner inner join

    where dt.NAME = 'myDenormTableName. '

  • Return the name of parnt in CS3

    var myDoc = app.activeDocument;
    var imageBox = myDoc.layoutWindows [0].activePage.place ("C:/Documents and Settings/lw/Desktop/Workflow_1/Artfiles/blo26940_ch10/blo26940_1002.eps");

    Alert (ImageBox.parent)

    It's my script here I placed the image file (blo26940_1002.eps) translate. In Indesig 2. It returns the Name (imageBox.parent) is Rectangle.

    But when I run this code in CS3 it not return the parent name wht is the problem

    Is that what you found for InDesign CS3 object model viewer? It is under the Help menu of ESTK.

    You use the method instead of a page, so let's get that:


    Page.place (filename: file, placePoint:Array of the number destinationLayer: layer, showingOptions:boolean, autoflowing:boolean, withProperties:Object): table of each
    Place the file.
    file name: Data type: file
    The file to put
    included: Data type: array of numbers
    The point on which you want to place (in option)
    destinationLayer: Data type: layer
    The layer on which you want to place (in option)
    showingOptions (optional): Data type: boolean, default value: false
    Whether to display the dialog box (optional) import options
    autoflowing (optional): Data type: boolean, default value: false
    Whether placed autoflow text (optional)
    withProperties: Data type: object
    Initial values for the properties of the new Page (optionally)

    I grant you it's a little difficult to read for a newcomer, but looking at your code, there are two points that you seem to be missing (according to what is written here):

    1. you pass a file as a string path to the place rather than a file object method.

    2. the method returns an array (is that the ': table of each ' at the end of this first string "BOLD").

    I have not checked, but your use of a chain can actually work, but I would always use a file reference myself. It is trivially easy to do.

    With respect to the returned array, it is because in theory, the place method to place several items, the parent you want is so the first (and in this case, only) member of the array.

    So, on that basis and assuming that the path to the file is correct, try this:

    var myDoc = app.activeDocument;
    var imageBox = myDoc.layoutWindows [0].activePage.place (file ("C:/Documents and Settings/lw/Desktop/Workflow_1/Artfiles/blo26940_ch10/blo26940_1002.eps"));

    Alert(ImageBox[0].parent);

    That should do the trick, although I'd probably write it like this:

    var myDoc = app.activeDocument;
    var myFile = file ("C:/Documents and Settings/lw/Desktop/Workflow_1/Artfiles/blo26940_ch10/blo26940_1002.eps");

    If {(myFile.exists)

    imageBox = myDoc.layoutWindows [0].activePage.place (myFile) [0];

    Alert (ImageBox.parent)

    } else {}

    Alert ("file does not exist")

    }

    Note that I moved the [0] at the end of the statement of the place so that the name of the variable imageBox corresponds to what it really is.

    Dave

  • Place SelectedPlace name attribute selector control does not always return the name as the url of the map

    Hello.

    When I search for and select a place from the UI of the PlacePicker, then function name() the class' SelectedPlace returns the name of the place. But this name isn't blue, when I show on a text box so that when its clicked it opens the card upward and show this place. But when I select the location by clicking the default button "my position", it shows my position as ' 446, Philip St, Warloo, ON, Canada,"which is blue color when displayed in the TextArea component. How can I also do the name formatted as it is formatted when chosed through the option 'my location '?

    Also my site is not canada. It is Bangladesh. So why it shows canada?

    My implementation is

    placePicker = new PlacePicker(locationRuleAddPageContainer);
        selectedPlace = placePicker->show();
        if (selectedPlace != NULL)
        {
          // Extract details from SelectedPlace object.
            locationText->setText(selectedPlace->name().append("\nLatitude: ").append(QString::number(selectedPlace->latitude())).append("\nLongitude: ").append(QString::number(selectedPlace->longitude())));
            qDebug()<<"Selected Location: "<description()();
            chooseActions->setEnabled(true);
        }
        else
        {
          // Either the user has canceled the operation or the location capability is not enabled.
        }
    

    Thank you.

    Just need to change the

    selectedPlace->name()
    

    TO

    selectedPlace->addressLabel()
    
  • How to dynamically change the names of columns LOV

    Hello

    I use JDeveloper 11.1.1.4

    I have only one requirement, while I need to change the names of columns in the list of values dynamically.

    How can I achieve it.

    Please help me.

    Kind regards

    John.

    Hello

    > But I want to change the column names 'ID' and 'Name' dynamically.

    Based on what? Condition? If Yes, have you tried to set the text for the label as an expression? If not based on the condition, you can also expose the VO to Java Impl and need a way to get the attribute and change its label.

    Arun-

  • ORE: the names of columns not valid cost.matrix

    I'm trying to use the method odmDT with application costs customized as follows:

    > dt.mod = ore.odmDT (default ~.,credit_train,max.depth=20,cost.matrix=matrix(c(0,1,4,0),nrow=2)

    but I get the error:

    Error in ore.odmDT (default ~., credit_train, max.depth = 20, cost.matrix = error_cost):

    ORE: the names of columns not valid cost.matrix

    I can't find any documentation anywhere on how exactly this cost matrix must be specified.

    Any help would be appreciated

    The value for cost.matrix currently requires a data structure object. The following examples using the NARROW data successfully pass a frame of data for the value of cost.matrix:

    R > NARROW.costs.gender<- data.frame(actual_target_value="">

    PREDICTED_TARGET_VALUE = c("M","M","F","F"),

    COST = c (0.25, 0.75, 0.0, 0.0))

    R > NARROW.costs.class<- data.frame(actual_target_value="">

    PREDICTED_TARGET_VALUE = c (0,0,1,1),

    COST = c (0.25, 0.75, 0.0, 0.0))

    R > dt.mod1<- ore.odmdt(gender="" ~="" .,="" narrow,="" cost.matrix="">

    Summary (DT. MOD1)

    R > dt.mod2<- ore.odmdt(class="" ~="" .,="" narrow,="" cost.matrix="">

    Summary (DT. MOD2)

    I filed a bug so this behavior can be evaluated for a future release of Oracle Enterprise R.

  • Formula of mounting: replace the names of parameters by actual values

    Hello

    After finding the values of the parameters in the formula of editing, I need to replace the names of parameters by actual values found by the algorithm of editing.

    For example in the screenshot below, I need to replace a, b, c by actual values (e.g. 2.346878,-12.4589 8.0012) in order to use this formula to solve a nonlinear equation.

    Transform the string to byte array formula seems to be quite dufficult because replacements have different sizes (e.g. an having to be replaced by 2.346878).

    Is there a smart solution to such a problem.

    Thank you

    Or better yet... the list of parameter names can also be extracted:

  • PowerShell - returns the name of the model of a virtual computer running

    Anyone know / got the (powershell) command to return the name of the model of a virtual machine?

    Sorry, I couldn't make it work. In the near future, we'll miss vW 8.6, I'll try again then.

    For now I fixed it with the HyperV 2012 R2 cmdlets

    $VMTemplate = ((get-VM-nom $VM).) ID | Get - VHD). ParentPath

    I've split and convert the correct model name.

  • How to extract the names of columns in dynamic SQL

    Hi all

    Is it possible to extract all the names of columns in a dynamic query?

    In my case according to the user selections that my query will get changed (number of the column, column name and tables that everything can vary).

    So now, is it possible to retrieve all the column names of the dynamic query generated?

    I am using Oracle 11g (11.2.0.4)

    Thank you

    Shaz

    Re: Dynamic Extraction on dynamic Sql

  • How to write information to complete file including the names of columns in the ftp adapter using the Ombudsman?

    Hi all

    I have a requirement like the reading of the data from the DB table and put it in a location of ftp server using mediator.also file in the ftp location must be in .csv format.

    I am able to get the data from the file in .csv format.

    But here, my requirement is I want the data from the file with the names of columns (i.e. header information).

    Can someone help me in this problem.

    Thanks in advance,

    Divya.

    Hello

    I am able to get the information to complete file with column names.

    I added a code in the ftpadapter xsd file.

    nxsd:version = "NXSD".

    nxsd:stream = "chars".

    nxsd: encoding = "US-ASCII".

    nxsd:hasHeader = 'true '.

    nxsd:headerLines = "1".

    nxsd:headerLinesTerminatedBy = "${eol}.

    nxsd:outboundHeader = "empno, ename, sal, location, status ${eol} '"

    By adding the code above, I'm able to get the full file header information.

    Thank you

  • getUserRoles() in SecurityContext returns the names of LDAP groups

    Hello

    getUserRoles() in SecurityContext returns the names of LDAP groups as well as the role of the user's request. Should it? If not, what could be the possible problem.

    I have OVDLDAP configured on the weblogic server.

    Thank you.

    Hello

    Yes, what is expected. OPSS API expose application roles and user roles. For the distinction between the two, I would recommend a names like app-role naming convention to identify application roles

    Frank

  • Regular expression TO validate the name of column

    Hi all

    I want to write a regular expression to validate the name of column names.i.e enterted must follow the convention of valid column name
    contain only A - Z, a-z, 0-9, _, $, and #.

    Please someone help me to do this.
    Padma

    Hey padma.

    Regular expression TO validate the name of column

    to set jaspx for example in the Validation number:

    **

    If your use na na... chain mention you model as etc. from A to z...

    otherwise if the two method nt answer using java Scrpit na... it's better ground for you.

    If however hepatitis is any querys na msg me... If possible I try best,.

    Thnks,
    Suresh V

    Published by: V Suresh on April 2, 2012 16:55

Maybe you are looking for