Read file and count rows and columns

Can someone guide me on how can I accomplish the following
a) read what supposedly is a matrix from text file
b) make sure all the entries in input are integers
c) if not raise error, else
c) is the matrix a square matrix?
d) if not raise error if its not square matrix else
e) if it's a square matrix, print the matrix on the screen
please give me pointers.. some code snippet is ok. but would like to code to some degree myself. so i can grasp how java works.
thanks

javadonkey wrote:
how do I verify if all the lines consist of ints. Well, there are two parts here. One is to split the line into tokens, and the other is to try to parse each of those tokens as an int. There are two ways you could do this:
1) String.split() and Integer.parseInt(). See the javadocs for details of those methods.
2) Use java.util.Scanner. Again, see its javadocs, and you may also want to look at a java io tutorial, like this one: [http://java.sun.com/docs/books/tutorial/essential/io/]
and if its a square matrixCan you define in English what makes a square matrix?

Similar Messages

  • How do I read text from specific rows and columns in a tree structure?

    How do I read text from specific rows and columns in a tree structure? In a table you can specify the cell to read from but I have not been able to figure out how to do this with a tree structure.

    You need to set two properties to activate the correct cell and then you can read it's string property.
    The positioning properties are the "ActiveItemTag" and
    "ActiveColNum" properties. With them you select the tree item by it's tag and the active column. The string can then be read from the "Cell String" property.
    MTO

  • Downloading .xls file with multiple rows and Columns

    Hi ALL,
    I need to genarate .xls file with multiple rows and and Columns and sent as an email.Since our customer having Problem with .CSV files need to genarate .XLS file.
    Please do the needful.
    Thanks
    Madhu

    Hi Madhu,
    You might also consider using Excel Spreadsheet XML as the target structure (namespace is urn:schemas-microsoft-com:office:spreadsheet).  When you double-click the resulting xml on a PC it automatically opens with Excel. So, users don't see a difference.  It will open up a lot of options with formatting including creating multiple worksheets if you wanted to.  Best of all you can stick with XML.
    See my response in this thread:
    Re: Convert XML data into XLS 
    Thanks,
    -Russ

  • Need Tips to Customise Invoice with Logo and Adjust Rows and Values

    Need Tips to Customise Invoice with Logo and Adjust Rows and Values

    Hi rabisaha,
    Your logo is an image. Details on adding and working with images in Numbers can be found in Chapter 9 of the Numbers '09 User Guide.
    Rows are part of a Table. I'm not certain what you are referring to when you say "adjust rows," but the details regarding adding, removing and changing rows are in the "Working with Rows and Columns in Tables" section of Chapter 3, Using Tables in the Numbers '09 User Guide.
    Adjusting values is done by entering new values, or by revising the formulas that create values. This is also conered in the User Guide in Chapter 4, Working with Table Cells.
    The Numbers '09 User Guide is free, and may be downloaded via the Help menu in Numbers. If you intend to create Numbers tables (or to modify formulas), you may also want the iWork Formulas and Functions User Guide, available from th same location.
    For anyone new to Numbers (and for old hands as well), I recommend reading at least the first four chapters of the Numbers guide. The rest can be kept to use as a reference as needed.
    Regards,
    Barry

  • Transpose of columns to rows (unpivoting) and not rows to columns

    Hi,
    I am right now using oracle 10g. I HAVE the following specification. Here I specified only 5 columns.
    We have upto 200 columns.
    TRANS_ID      PORTFILIO_NUM     TICKER          PRICE     NUM_SHARES ........................................
    2     100     MO      25.00     100 ........................................
    3     100     MCD          31.50     100 ........................................
    I want the above to be transformed into the following output .
    TRANS_ID TYPE VALUE
    2 PORTFILIO_NUM 100
    2 TICKER MO
    2 PRICE 25.00
    2 NUM_SHARES 100.
    I don't want to use case/decode function by hard coding the 200 columns.
    Can anyone provide me a good way (mostly dynamic way) of doing this?
    I searched the whole forum and also other forums. Everywhere I could find
    rows to columns / columns to rows where the column names have been hardcoded.
    I want a dynamic way of doing it. Let me know if u need any other inputs.
    DDL :
    CREATE TABLE PORT_TRANS
    TRANS_ID VARCHAR2(100 BYTE),
    PORTFILIO_NUM VARCHAR2(100 BYTE),
    TICKER VARCHAR2(100 BYTE),
    PRICE VARCHAR2(100 BYTE),
    NUM_SHARES VARCHAR2(100 BYTE)
    INSERT INTO PORT_TRANS (TRANS_ID,PORTFILIO_NUM,TICKER,PRICE,NUM_SHARES)
    VALUES('2','100','MO','25.00','100');
    INSERT INTO PORT_TRANS (TRANS_ID,PORTFILIO_NUM,TICKER,PRICE,NUM_SHARES)
    VALUES('3,'100','MCD','31.50','100');
    COMMIT;
    Thanks,
    Priya.

    Hi,
    What you're trying to write is something like this:
    WITH     cntr     AS
         SELECT     LEVEL     AS n
         FROM     dual
         CONNECT BY     LEVEL     <= 4
    SELECT     p.trans_id
    ,     CASE
              WHEN  c.n     <= 2
              THEN
                   CASE     c.n
                        WHEN 1     THEN 'PORTFILIO_NUM'
                        WHEN 2     THEN 'TICKER'
                   END
              ELSE
                   CASE     c.n
                        WHEN 3     THEN 'PRICE'
                        WHEN 4     THEN 'NUM_SHARES'
                   END
         END     AS type
    ,     CASE
              WHEN  c.n     <= 2
              THEN
                   CASE     c.n
                        WHEN 1     THEN p.PORTFILIO_NUM
                        WHEN 2     THEN p.TICKER
                   END
              ELSE
                   CASE     c.n
                        WHEN 3     THEN p.PRICE
                        WHEN 4     THEN p.NUM_SHARES
                   END
         END     AS value
    FROM          port_trans     p
    CROSS JOIN     cntr          c
    ORDER BY     p.trans_id
    ,          c.n
    ;I wrote this as if CASE could only handle 2 choices, rather than 128, just to show how to nest CASE expressions.
    What you have to do is write the CASE expressions, based on the contents of all_tab_columns.
    In your sample data, all of the columns are VARCHAR2 (another design flaw). If you have any columns of other types, use TO_CHAR to convert them to VARCHAR2; that is, the final code to be run will have something like:
    ...                    WHEN 4     THEN TO_CHAR (p.NUM_SHARES)If I had to do this, I might run several queries on all_tab_columns, each producing one script, containing just a fragment of the query.
    To run the whole thing, I would hard-code a main query like this
    WITH     cntr     AS
         SELECT     LEVEL     AS n
         FROM     dual
         CONNECT BY     LEVEL     <=
                        @num_columns.sql
    SELECT     p.trans_id
    ,     CASE
              @type.sql
         END     AS type
    ,     CASE
              @value.sql
         END     AS value
    FROM          port_trans     p
    CROSS JOIN     cntr          c
    ORDER BY     p.trans_id
    ,          c.n
    ;As with any coidng, start small and take baby steps. Maybe the first step would just be to write num_columns.sql, which just contains the number 4. When you can do that, hard-code the CONNECT BY query, calling num_columns.sql.
    Good luck!

  • Dynamically creating table and inserting rows and columns using JSP

    Hi,
    I'm using mysql and JSP to create web interface for my forms/tables. I wanna create the table dynamically depending on the data in the table and for each particualar record. and these values shud be loaded on the form after loading from the databaes as soon as the form loads.
    also i want to have a button which shud add new rows dynamically. and same one for columns.
    how do i calculate the values across the rows on the forms
    I'm new to JSP. Please point me in the right direction...any tutorials or code will be helpful.
    Any help is appreciated.
    Thanks
    Ayesha

    u write the code in sequence:
    1 write jdbs to select count(* )from table
    2 put in array e.g. String doc_no=new String[count];
    3 write jdbs to select * from table with condition
    //for no. of records just write
    for(int j=0;j<(count);j++){
    <% while(rs4.next()){
         doc_no=rs4.getString(2);
                        date1[i]=rs4.getString(3);
         doc_type[i]=rs4.getString(4);
         location[i]=rs4.getString(5);
         cheque[i]=rs4.getString(6);
         rate[i]=rs4.getInt(7);
         deb_qty[i]=rs4.getInt(8);
         cre_qty[i]=rs4.getInt(9);
         deb_amt[i]=rs4.getInt(10);
         cre_amt[i]=rs4.getInt(11);
         i++;
         //rs4.close();
                   for(int j=0;j<(count);j++){
                   System.out.println("Data count= "+j);
                   %>
    <tr>
    <td width="15%"><font size="1"><%=doc_no[j] %></font></td>
    <td width="10%"><font size="1"><%=date1[j] %></font></td>
    <td width="12%"><font size="1"><%=doc_type[j] %></font></td>
    <td width="9%"><font size="1"><%=location[j] %></font></td>
    <td width="9%">
    <div align="left"><font size="1"><%=cheque[j] %></font></div>
    </td>
    <td width="8%">
    <div align="right"><font size="1"><%=deb_qty[j] %></font></div>
    </td>
    <td width="8%">
    <div align="right"><font size="1"><%=cre_qty[j] %></font></div>
    </td>
    <td width="9%">
    <div align="right"><font size="1"><%=deb_amt[j] %></font></div>
    </td>
    <td width="10%">
    <div align="right"><font size="1"><%=cre_amt[j] %></font></div>
    </td>
    </tr>
    write if there is any specific problem
    bye,
    Samir

  • Reading File in native format and attaching it.

    Hi all,
    I am reading file in native format(Without schema) and wish to attach it before sending it accross.
    I am assigning .csv instead of .html .
    I am getting the following error
    <mismatchedAssignmentFailure xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/"><part name="summary"><summary>Cannot assign a non-element value to a message part. (The value is of type java.lang.String.)</summary>
    </part></mismatchedAssignmentFailure>

    How do you read the fille ?
    - with a file adapter ?
    - with the BPEL Extension XPath function ora:read ?
    B.

  • Total count and count based on column value

    Primaryid  Id     Status
    1            50          1
    2            50          1
    3          50          1
    4            50          3
    5           50          2
    6            50          1
    7            51         1
    8            51         2Im looking for a query which returns total count of rows for id 50 and count of rows with status 1
    something like
    Id    count_total   count_total_status1
    50        6              4
    51        2              1Any suggestion ?

    SQL> select * from t4;
    PID ID STATUS
    1 50 1
    2 50 1
    3 50 1
    4 50 3
    5 50 2
    6 50 1
    7 51 1
    8 51 2
    已选择8行。
    SQL> select distinct id,count(id),sum(decode(status,1,1,0)) from t4 group by id;
    ID COUNT(ID) SUM(DECODE(STATUS,1,1,0))
    51 2 1
    50 6 4

  • How to add and remove rows and keep track of it

    hi all,
    i hv an issue
    im developing a page which will hv remove and add buttons for 3 categories
    on clicking it it should add r remove HTML table rows respective to which category button is pressed. and also i should track the number of rows added or deleted for a particular category.
    Is it possible with JSP
    a sample code wil also help me a lot
    thanks in advance

    i could not under how ur page structure is but i will try to tell what i used in such a situation where u have to add or remove some elements from the page based on wht the user chooses.
    I put buttons linking to the same page with a variable containing the row id in the url (http://something.com?id=10')
    while displaying the records i will be iterating througnh the data row by row and displaying the text in the table.
    but when i find a row id equal to the rowid passed i display it in another format with a form and text boxes to edit the data and a submit button to submit the data
    like...........
    while (rs.next())
         if(rs.getString("recid").trim().equalsIgnoreCase(request.getParameter("recid").trim()))
    %>
         <form name="form2" method="post" onsubmit="javascript:return ValidateForm(form2)" action="camp_update_msg_a.jsp">
         <tr class="colstyle3">
              <td width="5%" valign="middle"><%= rs.getString("questionno").trim() %></td><td><TEXTAREA NAME="question" COLS=35 ROWS=4 ><%= rs.getString("question").trim() %></TEXTAREA></td><td><TEXTAREA NAME="answer" COLS=15 ROWS=4 ><%= rs.getString("answerno").trim() %></TEXTAREA></td>
              <td><INPUT id="submit1" type="submit" value="Submit"></td><td><a href="camp_del_msg.jsp?campid=<%=request.getParameter(campid").trim() %">&recid=<%= rs.getString("recid") %>">Delete</a></td>
         </tr>
         </form>
    <%           }
    else
         { %>
         <tr class="colstyle3">
              <td width="5%" valign="middle"><%= rs.getString("questionno").trim() %></td><td><%= rs.getString("question").trim() %></td><td><%= rs.getString("answerno").trim() %></td>
              <td><a href="camp_edit_msg.jsp?campid=<%=request.getParameter("campid").trim() %>&recid=<%= rs.getString("recid") %>">Edit</a></td><td><a href="camp_del_msg.jsp?campid=<%=request.getParameter("campid").trim() %>&recid=<%= rs.getString("recid") %>">Delete</a></td>
         </tr>
    <%
    I think this information is helpful to u.......
    Good luck.............</a>

  • Stored procedure to count rows and columns- NEWB

    I have  the following table and I want to get a count of 'Enabled' in each column and output to a new table with the same column names with counts. Is this possible?
    AzureRMS    Office_PP   Lync        Office_Onli Sharepoint  Exchange    Visio       Project     ExchangeArc
    Disabled    Enabled     Disabled    Enabled     Enabled     Disabled    Disabled    Disabled    Disabled
    Disabled    Enabled     Disabled    Enabled     Enabled     Disabled    Disabled    Disabled    Disabled
    Disabled    Enabled     Disabled    Disabled    Disabled    Disabled    Disabled    Disabled    Disabled
    Disabled    Enabled     Disabled    Disabled    Disabled    Disabled    Disabled    Disabled    Disabled
    Disabled    Enabled     Disabled    Enabled     Enabled     Disabled    Disabled    Disabled    Disabled
    Disabled    Enabled     Disabled    Disabled    Disabled    Disabled    Disabled    Disabled    Disabled
    Disabled    Enabled     Disabled    Enabled     Enabled     Disabled    Disabled    Disabled    Disabled
    Disabled    Enabled     Disabled    Disabled    Disabled    Disabled    Disabled    Disabled    Disabled
    Disabled    Enabled     Disabled    Disabled    Disabled    Disabled    Disabled    Disabled    Disabled
    Disabled    Enabled     Disabled    Disabled    Disabled    Disabled    Disabled    Disabled    Disabled
    Disabled    Enabled     Disabled    Disabled    Disabled    Disabled    Disabled    Disabled    Disabled
    Disabled    Enabled     Disabled    Disabled    Disabled    Disabled    Disabled    Disabled    Disabled
    Disabled    Enabled     Disabled    Disabled    Disabled    Disabled    Disabled    Disabled    Disabled
    Disabled    Enabled     Disabled    Disabled    Disabled    Disabled    Disabled    Disabled    Disabled
    Disabled    Enabled     Disabled    Disabled    Disabled    Disabled    Disabled    Disabled    Disabled
    Disabled    Enabled     Disabled    Enabled     Enabled     Disabled    Disabled    Disabled    Disabled
    Disabled    Enabled     Disabled    Disabled    Disabled    Disabled    Disabled    Disabled    Disabled
    Disabled    Enabled     Disabled    Disabled    Disabled    Disabled    Disabled    Disabled    Disabled
    Dan

    Hello Dan,
    The base query is a conditional sum, like:
    SELECT
    SUM(CASE WHEN AzureRMS = 'Enabled' THEN 1 ELSE 0 END) AS CountAzureRMS
    ,SUM(CASE WHEN Office_PP = 'Enabled' THEN 1 ELSE 0 END) AS CountOffice_PP
    , -- and so on
    FROM yourTable
    just complete it for the other columns.
    Olaf Helper
    [ Blog] [ Xing] [ MVP]
    Thanks!  
    How do I write this a stored procedure using a tablename as a parameter?
    Dan
    Thats not recommended. Why do you want write a generic procedure for this passing tablename as a parameter??
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
    I am accessing the data via powershell/windows forms and I like to simplify the query.
    Dan

  • JQuery and the row selector column.

    I have a tabular form which i'm running some validation against.
    I'm using the row selector to indicate rows which are to be deleted.
    Now i've deleted rows using the method below, that's fine.
    DECLARE
    rows_int integer;
    Err_message varchar2(50);
    BEGIN
    FOR i IN 1..apex_application.g_f01.COUNT LOOP
    DELETE
    FROM com_transactions
    WHERE ID = apex_application.g_f02(NVL(apex_application.g_f01(i),0));
    END LOOP;
    END;
    However when i try to use JQUERY for the validation things go awry.
    $('input[name="f01"]').each(function(j)
    if($(this).val().length > 0)
    {   row_var = $(this).val();
    $('input[name=f06]:eq('+(row_var)+')').val(' DELETE ROW '+ row_var);
    Now there's a mis allignement on the returned values j = 0 returns the values in row 1 when using pl sql, but that's fine.
    The problem is that in the plsql block only the rows with a tick against them are returned but in the jquery every row is returned regardless of if it's been ticked or not.
    Any ideas please folks?
    Thankyou
    JH.

    Having done a bit more research i was accessing the item incorrectly and needed to use the following syntax.
    $('input[name=f01]:checked').each( function(){
    JH.

  • Counting rows and group by

    Hi
    in query below
    WITH AUX_CONSULTORA AS (SELECT T2.CD_CONSULTORA,
                                         T2.CD_TIPO_ESTRUTURA_COMERCIAL,
                                         T2.CD_ESTRUTURA_COMERCIAL,
                                         T2.NM_CICLO_INICIO,
                                         T2.DC_NOME_CONSULTORA
                                    FROM T_CONSULTORA_INDICADA T1,
                                         T_CONSULTORA          T2
                                   WHERE T1.CD_CONSULTORA_INDICADA =
                                         T2.CD_CONSULTORA
                                     AND T1.CD_CONSULTORA_INDICANTE =
                                        4701040 --- CONSULTORA INDICANTE
                                     AND T2.NM_CICLO_INICIO <=
                                        200802 --- CICLO ATUAL
                                     AND T2.NM_CICLO_INICIO >=
                                         200716 --- TRES CICLOS ANTERIORES
                                  )SELECT                                                       
                                 DC_NOME_CONSULTORA,
                                  W1.CD_CONSULTORA,
                               NM_CICLO_INICIO,
                               W2.NM_CICLO_OPERACIONAL,
                               w2.vl_indicador
                         FROM AUX_CONSULTORA           W1,
                               T_EC_PESSOA_PERFIL_CICLO W2
                        WHERE W1.CD_TIPO_ESTRUTURA_COMERCIAL =
                              W2.CD_TIPO_ESTRUTURA_COMERCIAL
                          AND W1.CD_ESTRUTURA_COMERCIAL =
                              W2.CD_ESTRUTURA_COMERCIAL
                          AND W2.CD_CONSULTORA = W1.CD_CONSULTORA
                          AND W2.CD_PERFIL = 1
                          AND W2.CD_INDICADOR = 2
                          AND W2.NM_CICLO_OPERACIONAL <=  200802
                          AND W2.NM_CICLO_OPERACIONAL >=  200716
                          AND W2.NM_CICLO_OPERACIONAL >=  W1.NM_CICLO_INICIO
                          AND W1.NM_CICLO_INICIO >200716
                        ORDER BY W1.DC_NOME_CONSULTORA ASC;
    DC_NOME_CONSULTORA                       CD_CONSULTORA NM_CICLO_INICIO NM_CICLO_OPERACIONAL      VL_INDICADOR
    CRISTIANE MARIA MARQUES SUCUPIRA              38178923          200802               200802              0.00
    ELIONITA DE MATOS COSTA                       39218910          200801               200801              0.00
    ELIONITA DE MATOS COSTA                       39218910          200801               200802              1.00
    IBRANDINA LOPO MONTALVAO                      38176661          200717               200717              0.00
    IBRANDINA LOPO MONTALVAO                      38176661          200717               200801              0.00
    IBRANDINA LOPO MONTALVAO                      38176661          200717               200802              0.00
    JANAINA NOBRE DE MENEZES JORDAO RAMOS         38072777          200801               200801              0.00
    JANAINA NOBRE DE MENEZES JORDAO RAMOS         38072777          200801               200802              0.00
    JOCINELIA DE SOUZA LEITE                      38518490          200717               200802              0.00
    JOCINELIA DE SOUZA LEITE                      38518490          200717               200801              1.00
    JOCINELIA DE SOUZA LEITE                      38518490          200717               200717              0.00
    WALLACE DE OLIVEIRA XIMENES                   41824407          200717               200717              0.00
    WALLACE DE OLIVEIRA XIMENES                   41824407          200717               200801              1.00
    WALLACE DE OLIVEIRA XIMENES                   41824407          200717               200802              2.00
    I must to count distinct CD_CONSULTORA , in example above there are 6
    I did SELECT COUNT(DISTINCT) work fine , but now I must to Count WHEN
    W1.NM_CICLO_INICIO = 200716 and W2.NM_CICLO_OPERACIONAL = 200717 and in this cycle (200717) w2.vl_indicador =0 or W2.NM_CICLO_OPERACIONAL = 200801 and w2.vl_indicador =0
    Some know how can to do it ?
    see result for W1.NM_CICLO_INICIO =200716
    WITH AUX_CONSULTORA AS (SELECT T2.CD_CONSULTORA,
                                         T2.CD_TIPO_ESTRUTURA_COMERCIAL,
                                         T2.CD_ESTRUTURA_COMERCIAL,
                                         T2.NM_CICLO_INICIO,
                                         T2.DC_NOME_CONSULTORA
                                    FROM T_CONSULTORA_INDICADA T1,
                                         T_CONSULTORA          T2
                                   WHERE T1.CD_CONSULTORA_INDICADA =
                                         T2.CD_CONSULTORA
                                     AND T1.CD_CONSULTORA_INDICANTE =
                                        4701040 --- CONSULTORA INDICANTE
                                     AND T2.NM_CICLO_INICIO <=
                                        200802 --- CICLO ATUAL
                                     AND T2.NM_CICLO_INICIO >=
                                         200716 --- TRES CICLOS ANTERIORES
                                  )SELECT                                                       
                                 DC_NOME_CONSULTORA,
                                  W1.CD_CONSULTORA,
                               NM_CICLO_INICIO,
                               W2.NM_CICLO_OPERACIONAL,
                               w2.vl_indicador
                         FROM AUX_CONSULTORA           W1,
                               T_EC_PESSOA_PERFIL_CICLO W2
                        WHERE W1.CD_TIPO_ESTRUTURA_COMERCIAL =
                              W2.CD_TIPO_ESTRUTURA_COMERCIAL
                          AND W1.CD_ESTRUTURA_COMERCIAL =
                              W2.CD_ESTRUTURA_COMERCIAL
                          AND W2.CD_CONSULTORA = W1.CD_CONSULTORA
                          AND W2.CD_PERFIL = 1
                          AND W2.CD_INDICADOR = 2
                          AND W2.NM_CICLO_OPERACIONAL <=  200802
                          AND W2.NM_CICLO_OPERACIONAL >=  200716
                          AND W2.NM_CICLO_OPERACIONAL >=  W1.NM_CICLO_INICIO
                          AND W1.NM_CICLO_INICIO =200716
                        ORDER BY W1.DC_NOME_CONSULTORA ASC;
    DC_NOME_CONSULTORA                       CD_CONSULTORA NM_CICLO_INICIO NM_CICLO_OPERACIONAL      VL_INDICADOR
    ANA GLORIA DIAS DE CARVALHO                   43048927          200716               200802              2.00
    ANA GLORIA DIAS DE CARVALHO                   43048927          200716               200801              1.00
    ANA GLORIA DIAS DE CARVALHO                   43048927          200716               200717              0.00
    ANA GLORIA DIAS DE CARVALHO                   43048927          200716               200716              0.00
    ELAINE MARIA DE SANT ANNA                     43985238          200716               200717              1.00
    ELAINE MARIA DE SANT ANNA                     43985238          200716               200801              2.00
    ELAINE MARIA DE SANT ANNA                     43985238          200716               200802              3.00
    ELAINE MARIA DE SANT ANNA                     43985238          200716               200716              0.00
    EURIDES DE BARROS SANTOS                      38146681          200716               200802              0.00
    EURIDES DE BARROS SANTOS                      38146681          200716               200801              0.00
    EURIDES DE BARROS SANTOS                      38146681          200716               200716              0.00
    EURIDES DE BARROS SANTOS                      38146681          200716               200717              0.00
    JOSEFA DA SILVA RIBEIRO DE AVILA              34589813          200716               200801              0.00
    JOSEFA DA SILVA RIBEIRO DE AVILA              34589813          200716               200717              1.00
    JOSEFA DA SILVA RIBEIRO DE AVILA              34589813          200716               200716              0.00
    JOSEFA DA SILVA RIBEIRO DE AVILA              34589813          200716               200802              1.00
    KARLA RESENDE MARANHAO                        42536502          200716               200801              0.00
    KARLA RESENDE MARANHAO                        42536502          200716               200802              0.00
    KARLA RESENDE MARANHAO                        42536502          200716               200717              1.00
    KARLA RESENDE MARANHAO                        42536502          200716               200716              0.00
    DC_NOME_CONSULTORA                       CD_CONSULTORA NM_CICLO_INICIO NM_CICLO_OPERACIONAL      VL_INDICADOR
    MARISTELA MATIAS DE ALIXANDRIA                 4488954          200716               200716              0.00
    MARISTELA MATIAS DE ALIXANDRIA                 4488954          200716               200717              1.00
    MARISTELA MATIAS DE ALIXANDRIA                 4488954          200716               200801              2.00
    MARISTELA MATIAS DE ALIXANDRIA                 4488954          200716               200802              0.00
    24 rows selectedthanks
    Message was edited by:
    muttleychess

    If I treat your question right (not sure) you want to have separate counts for some specific conditions within one group.
    Maybe CASE is that you need:
    SQL> select deptno, job from emp order by 1,2;
        DEPTNO JOB
            10 CLERK
            10 MANAGER
            10 PRESIDENT
            20 ANALYST
            20 ANALYST
            20 CLERK
            20 CLERK
            20 MANAGER
            30 CLERK
            30 MANAGER
            30 SALESMAN
            30 SALESMAN
            30 SALESMAN
            30 SALESMAN
    14 rows selected.
    SQL> select deptno, count(case job when 'CLERK' then 1 end) "clerks",
      2  count(case job when 'SALESMAN' then 1 end) "sales"
      3  from emp
      4  group by deptno;
        DEPTNO     clerks      sales
            30          1          4
            20          2          0
            10          1          0Rgds.

  • Reading file from ftp server and importing data into table

    Hi experts,
    Well basically i have text files with different layout that have been uploaded on an ftp server. Now i have to write a procedure to fetch those files, read them and insert data in a table... can that be done?
    your precious help would be greatly helpful.
    Thanks

    declare
    file1 UTL_FILE.FILE_TYPE;
    filename varchar2(1000) := 'GTECHFILES';
    str long;
    begin
    file1 := UTL_FILE.FOPEN (filename,'agent_dump_csv.rep','r',32767);
    loop
    UTL_FILE.GET_LINE ( file1, str );
    --dbms_output.put_line('Value is :'||to_char(str));
    end loop;
    UTL_FILE.FCLOSE( file1 );
    exception
    when no_data_found then
    dbms_output.put_line('END OF FILE');
    UTL_FILE.FCLOSE( file1 ) ;
    when others then
    UTL_FILE.FCLOSE( file1 ) ;
    dbms_output.put_line('ERROR: '||sqlcode||':'||sqlerrm) ;
    end;
    i have managed to write this piece of code and all lines are being read and now i need to insert data into my table and the fields are seperated by a `|` i am strill trying to figure how to do that now. help ...
    Edited by: Kevin CK on 17-Jan-2010 22:40

  • Reading files from different directories and exceuting them

    D:\>cd PROC_PKG_FUNC
    mkdir FUNCTIONS
    mkdir PACKAGES
    mkdir PACKAGES_BODY
    mkdir PROCEDURES
    mkdir TYPES
    mkdir TYPES_BODY
    SQL> create directory FUNCTIONS as 'D:\PROC_PKG_FUNC\FUNCTIONS';
    Directory created.
    SQL> create directory PACKAGES as 'D:\PROC_PKG_FUNC\PACKAGES';
    Directory created.
    SQL> create directory PROCEDURES as 'D:\PROC_PKG_FUNC\PROCEDURES';
    Directory created.
    SQL> create directory PACKAGES_BODY as 'D:\PROC_PKG_FUNC\PACKAGES_BODY';
    Directory created.
    SQL> create directory TYPES as 'D:\PROC_PKG_FUNC\TYPES';
    Directory created.
    SQL> create directory TYPES_BODY as 'D:\PROC_PKG_FUNC\TYPES_BODY';
    Directory created.
    suppose,
    there is a D:\PROC_PKG_FUNC directory in my local machine where the database server exists.
    And in that directory there are different directories like FUNCTIONS,PACKAGES,PACKAGES_BODY,PROCEDURES,TYPES,TYPES_BODY, now I've created all the remote schemas obejcts in these folders using utl_file, with the help of the following package
    SQL> CREATE OR REPLACE PROCEDURE Get_Db_Ddl_Scripts AS
    2 v_file Utl_File.FILE_TYPE;
    3 v_file_dir VARCHAR2(50);
    4 i_first_line NUMBER := 1;
    5 BEGIN
    6
    7 v_file_dir := 'PROC_PKG_FUNC';
    8
    9 FOR REC_OBJ IN
    10 (SELECT DISTINCT NAME,TYPE,DECODE(TYPE,'FUNCTION','FUNCTIONS','PACKAGE','PA
    CKAGES','PACKAGE BODY','PACKAGES_BODY','PROCEDURE','PROCEDURES','TYPE','TYPES','
    TYPE BODY','TYPES_BODY') v_file_dir
    11 FROM ALL_SOURCE@FRISKDEVI41B_ORCL WHERE OWNER='FRISKDEVI41B'
    12 AND TYPE IN ('FUNCTION, PROCEDURE','PACKAGE','PACKAGE BODY','TYPE'))
    13 LOOP
    14 v_file := Utl_File.FOPEN(location => REC_OBJ.v_file_dir,
    15 filename => REC_OBJ.NAME || '.sql',
    16 open_mode => 'w',
    17 max_linesize => 32767);
    18 i_first_line := 1;
    19 FOR REC IN (SELECT TEXT FROM ALL_SOURCE@FRISKDEVI41B_ORCL WHERE NAME = REC_
    OBJ.NAME AND TYPE=REC_OBJ.TYPE AND OWNER='FRISKDEVI41B' ORDER BY LINE)
    20 LOOP
    21 IF i_first_line = 1 THEN
    22 Utl_File.PUT_LINE(v_file,'CREATE OR REPLACE ' || REPLACE(REC.TEXT,CHR(10),N
    ULL));
    23 ELSE Utl_File.PUT_LINE(v_file, REPLACE(REC.TEXT,CHR(10),NULL));
    24 END IF;
    25 i_first_line := i_first_line + 1;
    26 END LOOP;
    27 Utl_File.FCLOSE(v_file);
    28
    29 END LOOP;
    30
    31 END;
    32 /
    Procedure created.
    SQL>exec Get_Db_Ddl_Scripts ;
    PL/SQL procedure successfully completed.
    Thus the files are created in the location.
    now what i want to do is i want to read each file and run in my current schema to create these objects in my local scehma ,is that possible? Help required._

    ORCHYP wrote:
    once these files are written in respective folders, you can open them with utl_file('read') in current schema and very well you can execute them.
    Try it onceTry it as many times as you like, you won't execute the files with utl_file, that's for sure. ?:|
    Using something like DBMS_SCHEDULER you could issue a one off job for each script, as that package can call o/s commands.
    However, what's the point?
    You may as well, in the code above, just build up your DDL commands or whatever inside your code and, rather than write them out to scripts, use the EXECUTE IMMEDIATE command to execute the DDL against the database.
    Of course may not be the best thing to be doing, but we have very little information about what it is that is trying to be achieved, and no reason given why all the functions, packages etc. aren't just put together in a single script that is executed from the command line in the first place. Why try and write PL/SQL to do it?

  • Easy join of 2 tables and count of specify column

    Hi,
    I have these two tables:
    servers, records (contains info about server's fixes)
    server has: id, description
    records has: id, server, action
    I would like to this view:
    NameOfServer | Number of all applied fixes
    serverA |120
    serverB |180
    I try this:
    select records.server, COUNT(server) as countt
    FROM records
    GROUP BY records.server
    HAVING COUNT(records.server) > 0
    ORDER BY COUNT(records.server) desc
    But first column had IdOfServer (as int), so I try JOIN:
    SELECT records.server, COUNT(records.server) as countt, servers.description, servers.description
    FROM records
    LEFT JOIN servers
    ON servers.id = records.server
    GROUP BY records.server
    HAVING COUNT(records.server) > 0
    ORDER BY COUNT(records.server) desc
    Bold text is problem: "servers.description" (which is varchar) had error message:
    ... is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
    Thx fo hint(s), Jerry

    If you do not need this column as per your post , just do not specify it in the SELECT statement , otherwiseuse Jay reply.SELECT records.server, COUNT(records.server) as counttFROM records
    LEFT JOIN servers
    ON servers.id = records.server
    GROUP BY records.server
    HAVING COUNT(records.server) > 0
    ORDER BY COUNT(records.server) desc
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

Maybe you are looking for