Data format in a generic query

My boss had given me a tough task. the requirement he gave me is:
Lets say select tname from tab;
EMP
DEPT
EMPSAL
i want the table name and the number of records in the table as in one row
Emp Dept EmpSAl
100 5 100
The output should come as 1 row with its result as second row. Is there anyway i can implement this?
I appreciate your quick reply on this..
Thank you

boss is crazy and he wants this report anyhowI think you are allowed to let the database go crazy for the sake of the crazy boss.
Write the output into a file using utl_file.
SQL> DECLARE
  2      TYPE table_names_lt IS TABLE OF NUMBER INDEX BY VARCHAR2(30);
  3      tables table_names_lt;
  4      l_rec  LONG;
  5  BEGIN
  6      FOR rec IN (SELECT table_name FROM user_tables WHERE rownum < 5)
  7      LOOP
  8          EXECUTE IMMEDIATE 'select count(*) from ' || rec.table_name
  9              INTO tables(rec.table_name);
10      END LOOP;
11      l_rec := tables.FIRST;
12      WHILE l_rec IS NOT NULL
13      LOOP
14          dbms_output.put(rpad(l_rec, 31, ' '));
15          l_rec := tables.NEXT(l_rec);
16      END LOOP;
17      dbms_output.new_line;
18      l_rec := tables.FIRST;
19      WHILE l_rec IS NOT NULL
20      LOOP
21          dbms_output.put(rpad('-', 30, '-') || ' ');
22          l_rec := tables.NEXT(l_rec);
23      END LOOP;
24      dbms_output.new_line;
25      l_rec := tables.FIRST;
26      WHILE l_rec IS NOT NULL
27      LOOP
28          dbms_output.put(rpad(tables(l_rec), 30, ' ') || ' ');
29          l_rec := tables.NEXT(l_rec);
30      END LOOP;
31      dbms_output.new_line;
32  END;
33  /
A                              B                              C                              DEPT
1                              1                              0                              4
PL/SQL procedure successfully completed.
SQL>

Similar Messages

  • Date format mask in Enter-Query mode

    Hi,
    I'm developing a Form which is able to query the masterblock from a detail-item.
    The queryable detail-item is a date field and has a datatype: DATETIME. When a new record is entered the values in the date field are stored in the database like "18-10-2002 15:04:02"
    When the form is in enter_query mode the user must be able to enter 18-10-2002 (DD-MM-YYYY format mask, so without time mask). When execute the query with this date format the query is not able to find data.
    I used a Key-Execute-Query on the detailblock like this:
    SELECT 1.COLUMN
    , 2.COLUMN
    INTO :1.COLUMN
    , :2.COLUMN
    FROM TABLE.1
    , TABLE.2
    WHERE 1.COLUMN = 2.COLUMN
    AND TO_CHAR(1.COLUMN,'dd-mm-yyyy') = to_date(:avg.datum,'dd-mm-yyyy');
    Can anyone please help me?
    Regards,
    Ronny.

    Hi Ronny,
    I'm not sure to have got exactly your issue (especially why you have to use that select in master-detail query), but I suggest you to substitute
    ...AND TO_CHAR(1.COLUMN,'dd-mm-yyyy') = to_date(:avg.datum,'dd-mm-yyyy');
    with
    ...TRUNC(1.COLUMN) = TO_DATE(:avg.datum,'dd-mm-yyyy');
    To be fair, I would use it in the where clause, even if you set it dinamically.
    Let us know,
    Marco

  • Date format conversion in BEX query level

    Hi ,
          We had a date field in the numeric format like 735.020 in the cube level, but when we execute the query the values for thsi date field is changed in to date format like 31.05.2013.
    we are not having any conversion routines and the date fields are used directly in the query .

    Hi,
    Try the below class file or may be create a method in your controller. It will resolve your problem.
    package com.XXX.DateFormatForSAP;
    import java.util.Date;
    import java.text.SimpleDateFormat;
    public class FormatSAPDate {
    public static String changeDateFormat(Date sapDate) {
    String formattedDate = null;
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    formattedDate = dateFormat.format(sapDate);
    return formattedDate;
    Try this code and let me know.
    Regards
    Mukesh

  • Date Format in Visual Studio Query Result Window

    Most vendor tools let you change the date format to show datetime in its query results window.
    But .NET does not have this.
    The ability to change this should be in located in Tools|Options but its not there.
    Can it be added in the next release?
    ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-RR HH:MI:SS' does not work. btw.
    .NET and/or ODT over-rides it.

    Why would you expect Microsoft to write stuff for an Oracle plugin?! Why on earth would you want to see anything other than the actual raw data that YOU requested in the results of a query? Surely formating/displaying a datetime is a presentation layer thing not a database layer thing! If you're really that bothered re-write your SQL till you get what you want.

  • Data format in Ad-hoc query

    Dear All,
    We had created query which join table as below
    Addit. structures
    T500L INNER JOIN INNER JOIN T500P INNER JOIN PA0001 INNER JOIN CSKS INNER JOIN PA0000 INNER JOIN PA0007 INNER JOIN CEPC INNER JOIN CEPCT INNER JOIN PA9315 INNER JOIN PA0105
    1 When we execute and transfer to local file with DAT data format,
    - Company code would auto become 401 instead of 0401.
    - Hours weekly appear as 40,00 but we want the hours weekly download as 40.00
    May i know how i could solve this as we need this downloaded file to be upload to legacy system ?
    Should i create custom field to solve it ?
    Thanks and regards,
    AO

    I would output to SAP directory and the legacy system would FTP to get the file from there.
    There's no chance to format manually. Is it possible put ABAP code in Field code (In QUERY) to hardcode the company code as Character, so when download to xls, it would not change to numeric ?
    May i know which ABAP expect could help on this ? I not good in ABAP code.

  • Date format for Task Predicate Query

    Does anyone know the correct format the task query is expecting when testing against flex field data e.g. dateAttribute1?
    I the following query ->
    <tas1:taskListRequest xmlns:com="http://xmlns.oracle.com/bpel/workflow/common" xmlns:tas="http://xmlns.oracle.com/bpel/workflow/taskQuery" xmlns:task="http://xmlns.oracle.com/bpel/workflow/task" xmlns:tas1="http://xmlns.oracle.com/bpel/workflow/taskQueryService">
        <tas:taskPredicateQuery startRow="0" endRow="200">
          <tas:displayColumnList>
            <tas:displayColumn>textAttribute1</tas:displayColumn>
            <tas:displayColumn>textAttribute2</tas:displayColumn>
            <tas:displayColumn>textAttribute3</tas:displayColumn>
            <tas:displayColumn>textAttribute4</tas:displayColumn>
            <tas:displayColumn>numberAttribute1</tas:displayColumn>
            <tas:displayColumn>dateAttribute1</tas:displayColumn>
          </tas:displayColumnList>
          <tas:optionalInfoList>
            <tas:taskOptionalInfo>Payload</tas:taskOptionalInfo>
          </tas:optionalInfoList>
          <tas:predicate>
            <tas:assignmentFilter>All</tas:assignmentFilter>
            <tas:clause joinOperator="AND" ignoreCase="true">
              <tas:column>STATE</tas:column>
              <tas:operator>EQ</tas:operator>
              <tas:value>ASSIGNED</tas:value>
            </tas:clause>
            <tas:clause joinOperator="AND">
              <tas:column>TITLE</tas:column>
              <tas:operator>EQ</tas:operator>
              <tas:value>Index Case</tas:value>
            </tas:clause>
            <tas:clause joinOperator="AND">
              <tas:column>dateAttribute1</tas:column>
              <tas:operator>BEFORE</tas:operator>
              <tas:value>2014-12-05T12:00:00</tas:value>
            </tas:clause>
          </tas:predicate>
        </tas:taskPredicateQuery>
      </tas1:taskListRequest>
    And get the following error ->
    <taskQueryServiceFaultResponse  xmlns="http://xmlns.oracle.com/bpel/workflow/taskQueryService">
          <message>
               ORA-30961:Invalid value specified in predicate clause.
              The value 2014-12-05T12:00:00 for column wfn.dateAttribute1 is invalid for the columns  data type.
              Specify a value that is of the correct type, or is another column with a matching  data type.
          </message>
    </taskQueryServiceFaultResponse>
    I have tried a number of formats and always get the same error!

    Of course you're right, thor_b. My point is that Oracle's "to_date" can convert a string to a date, but that's not how Access or SQL Server or any other RDBMS do it. They're all different. If you hardwire "to_date" into your SQL you'll have to rewrite the whole thing if you move from Oracle to SQL Server.
    I like the PreparedStatement because it takes care of all that for me.
    Performance penalty? Over Statement? I've read some stuff about that, but I find it hard to believe.
    Whenever you send SQL to a relational database it has to parse the SQL, determine if the tables and columns exist and have the right types, optimize the query, and then execute it. You have to do that whether you're using Statement or PreparedStatement. If PreparedStatement allows the RDBMS to do all that work once and then store it, I can't see how you'll do worse. - MOD

  • Date format with BW MDX Query driver

    Hi,
    I have a question regarding the BW MDX Query driver.
    I have updated the driver from BW Query to BW MDX Query on my crystal reports and all the Date fields have been converted to Strings. Has anyone experienced the same issue?
    Thanks,

    Hi Abhilash
    Thanks for the reply. We have two different environments and are using Crystal XI R2 and Crystal 11. We have installed SAP Integration toolkit XI R2 and SAP GUI 7.1 Patch 14. The date issue is appening in both environments.
    Does MDX supports Date fields/formats?
    Thanks,

  • Repcleanupu and date formats

    Post Author: Thang Nguyen
    CA Forum: Data Quality
    i've got SQL Server installed with a date format of YYYY-DD-MM.
    When I run repcleanupu it tries to execute a query with a date format of YYYY-MM-DD so results in an out of range problem when it does the date conversion.
    Does anyone know how to correct this?
    Thanks

    Post Author: amr_foci
    CA Forum: Data Quality
    im more related with oracle,,
    you can fix this by using th date format mask in ur query,,
    i think you will find the same in SQL Server Database
    try to check with format masks
    good luck
    Amr

  • Date Format issue while Connecting to Oracle8i and Oracle10g

    Hi All,
    While playing around with JDBC drivers, I came across this weird issue. I have a Local machine with Japanese Locale and I have 2 Database Servers that too with Japanese Locales and Oracle 8i and Oracle 10g each. Now, I connect to these database using JDBC drivers for 8i and perform "select sysdate from dual". Then, m getting dates with 2 different format. While 8i being returning Date with 'DD-MON-RRRR' format, 10g returns date with 'DD-MM_RR' format.
    Initially I thought it might be because of some VM Locale thing but when I connected to 10g DB from 8i Oracle client, this behaviour did not changed. Which mean in this case also the date format returned ny the query was different.
    Guys F1! F1! (Help! Help!) Appreciate your help to understand this process. Links and suggestions welcome... :)

    I guess u did not read the whole content. I mentioned this but the difference in behaviour with respect to JDBC drivers made me post this in Java forum.
    As I mentioned, it has something to do with the jdbc driver or oracle server itself. Agreed, but what that "something little to do" is the maiin question.
    I mentioned that I want to understand this process about how JDBC driver works with Client VM specific Locale settings while interacting with Oracle Database.
    Don't you think it could be interesting to know, what it is which brings this difference in results. Its all about clarifying the small bits & pieces which stays unanswered if one overlooks. Its own perception, I felt like asking question, no offense right!

  • PHP/MySQL Date Format problems

    Dear all,
    In the past I successfully formatted a date from a Unix date format to my own desired output by using a PHP command as such:
    echo date($row_rsGNresults['date'], "Y F j"); 
    For a reason unbeknown to me, this no longer works and no matter what I try, the page always returns the date results in yyyy-mm-dd format.
    I've even tried using date format in the SQL query:
    SELECT * DATE_FORMAT('date', '%Y %F %j') AS showdate FROM gemnews_tab WHERE language LIKE %s AND entry LIKE %s AND works LIKE %s AND category LIKE %s ORDER BY date ASC 
    I've even tried installing various Dreamweaver extensions for date server formats (like Kaosweaver's) to no avail.  I've checked MySQL and the field is definitely set to 'date' and the dates are in yyyy-mm-dd format.
    Does anyone have any suggestions?  Would it matter that the dates are from the 18th century?
    Many Thanks
    J
    Message was edited by: Günter Schenk. Reason: the "PHP command" code was invisible

    Try this:
    <?php echo Date("M d, Y",
    strtotime($row_Recordset1['review_date'])); ?>
    Ken Ford
    Adobe Community Expert
    Fordwebs, LLC
    http://www.fordwebs.com
    "newhorizonhosting.com" <[email protected]>
    wrote in message news:et7lf6$q8a$[email protected]..
    > Can someone help me out here. I am trying to format my
    date. My MySQL is a
    > "datetime". How ever I would like to display only the
    month, day, year like so
    > "Jan,15,2007"
    >
    > Here is my current code, what should I add to make it do
    what I want.
    >
    > <?php echo $row_Recordset1['review_date']; ?>
    >
    > Thanks
    >

  • BEX: Changing date format from 'mm/dd/yyyy' to 'mon/yyyy'

    Happy Friday! I need to change the date format in my BEX query from a regular date format (dd/mm/yyyy) to display as 'JUN/2008'. Please note that I dont want to modify the date field but just need to display it month and year format in the bex query. Would truly appreciate a complete answer.
    Thanks

    Hi
    Check the first thread
    Hope this will solve your problem.
    How to change Date format in Bex to DD/MM/YYYY
    Check ur Windows or Excel settings. Try changing it in Control Panel->Regional Options->Date->Short Date format.
    change it in Control Panel->Regional Options->Date->Short Date format.
    Changing Date format in BEx & Web Application
    I Need to change Date Format in BEx report
    Regards
    M.A
    Edited by: M.A on Jun 27, 2008 10:12 PM

  • Date Format IN BDC

    Hi,
    In One Interview I was asked that How can You Handle Data Format when Writing BDC ?

    Satya,
    The date format depends on User settings. Its different for different login ID's.
    It can be YYYY.MM.DD or MM.DD.YYYY or anything.
    To handle the date format, you need to query on table USR01 and fetch DATFM field that stores date format.
    Refer below piece of code
    */...Fetch the date format settings for the user
          SELECT SINGLE datfm
                   INTO gv_date_format
                   FROM usr01
                  WHERE bname = sy-uname.
      CASE gv_date_format.
        WHEN 1.     "DD.MM.YYYY
          CONCATENATE fv_impdate+6(2) '.'
                      fv_impdate+4(2) '.'
                      fv_impdate+0(4) INTO fv_expdate.
        WHEN 2.     "MM/DD/YYYY
          CONCATENATE fv_impdate+4(2) '/'
                      fv_impdate+6(2) '/'
                      fv_impdate+0(4) INTO fv_expdate.
        WHEN 3.     "MM-DD-YYYY
          CONCATENATE fv_impdate+4(2) '-'
                      fv_impdate+6(2) '-'
                      fv_impdate+0(4) INTO fv_expdate.
        WHEN 4.     "YYYY.MM.DD
          CONCATENATE fv_impdate+0(4) '.'
                      fv_impdate+4(2) '.'
                      fv_impdate+6(2) INTO fv_expdate.
        WHEN 5.     "YYYY/MM/DD
          CONCATENATE fv_impdate+0(4) '/'
                      fv_impdate+4(2) '/'
                      fv_impdate+6(2) INTO fv_expdate.
        WHEN 6.     "YYYY-MM-DD
          CONCATENATE fv_impdate+0(4) '-'
                      fv_impdate+4(2) '-'
                      fv_impdate+6(2) INTO fv_expdate.
      ENDCASE.
    This would convert the date into the format set for user.
    Hope this is helpful.
    Amogh

  • Date format in Query Result Window

    In recent versions on OSD (trying with V3.2.20.09 Build MAIN-09.87) I've been unable to change the date format for results shown in the query results window via the NLS settings in Preferences, it's the same for other users on v3 in my area. Can anyone advice on whether anything can be done to resolve this issue or is there a bug in recent additions of OSD
    Frustrating having a result show as 01-DEC-12 and I don't know whether it's 01-DEC-2012 or our default date of 01-DEC-4712 without having to hard code a to_char in my sql which I don't want to be doing all the time to analyse my results
    I have an old version 1.5.4 Build MAIN-5940 and changing the NLS settings in preferences refrects correctly in the query results window
    Any advice appreciated, Thanks

    Thanks, looks like it's permission, tried on a different database supposed to be the same and it works when I update the preferences or run the alter session statement. Call to my admins to get on the case
    Ta
    for anyone else having simular issues, help are the statements I've tried to confirm it's permissions
    alter session set NLS_DATE_FORMAT = 'DD-MON-RR HH24:MI:SS'; -- Original
    alter session set NLS_DATE_FORMAT = 'DD-MON-RRRR HH24:MI:SS';
    commit;
    SELECT *
    FROM nls_session_parameters
    Edited by: lakeuk on 14-Nov-2012 06:37

  • Date format in BI query

    Hi,
    We need to display a single date format independent of date format of SAP User settings. For ex: as below.
    In a current query the  date, depending on the user's configuration could appear as:
    dd.mm.yyyy (English format)         or        yyyy-mm-dd (Swedish format)        or        mm.dd.yyyy (American format)
    I need to change some of the queries date format as below.
    a) Change all dates in query outputs and parameters to the format YYYYMMDD
    b) Change all months in query outputs and parameters to the format YYYYMM
    c) Change all financial periods in query outputs and parameters to the format YYYYPPP
    Thanks,
    Jitu

    Hi
    I think u have to use the ABAP code at the query level.
    First take the date in one variable zdate_var  and then if u want the below , then
    data : zdate_var_year type d,
               zdate_var_mm type d,
              zdate_var_dd type d.
    zdate_var_year = zdate_var(4).
    zdate_var_mm = zdate + 4(2).
    zdate_var_dd = zdate + 6(2).
    YYYYMM = zdate_var_year , zdate_var_mm.
    LIke this u can have ur o/p as per ur wish,
    Hope u got it ,
    Thanx & Regards,
    RaviChandra

  • Wrong query results: due to date format?

    hello,
    I have oracle 11 and when I execute this query:
    select MYDATE from mytable order by MYDATE DESC;
    it get me a bad order:
    MYDATE
    25-MAR-09
    13-MAR-09
    10-MAR-10
    10-MAR-10
    31-JAN-10
    29-JAN-10
    28-JAN-10
    08-DEC-09
    07-DEC-09
    06-DEC-09
    05-DEC-09
    is it may due to a wrong date format?
    where have I to look out? init.ora?

    But, there is no problem at my end (Using Oracle 10.2.0.1 on win xp):
    SQL> create table t(mydate date);
    Table created.
    SQL> insert into t values(to_date('25-MAR-09','DD-MON-YY'));
    1 row created.
    SQL> insert into t values(to_date('13-MAR-09','DD-MON-YY'));
    1 row created.
    SQL> insert into t values(to_date('31-JAN-10','DD-MON-YY'));
    1 row created.
    SQL> insert into t values(to_date('07-DEC-09','DD-MON-YY'));
    1 row created.
    SQL> insert into t values(to_date('05-DEC-09','DD-MON-YY'));
    1 row created.
    SQL> insert into t values(to_date('06-DEC-09','DD-MON-YY'));
    1 row created.
    SQL> insert into t values(to_date('08-DEC-09','DD-MON-YY'));
    1 row created.
    SQL> insert into t values(to_date('10-MAR-09','DD-MON-YY'));
    1 row created.
    SQL> insert into t values(to_date('29-JAN-10','DD-MON-YY'));
    1 row created.
    SQL> insert into t values(to_date('10-MAR-10','DD-MON-YY'));
    1 row created.
    SQL> insert into t values(to_date('28-JAN-10','DD-MON-YY'));
    1 row created.
    SQL> select * from t;
    MYDATE
    25-MAR-09
    13-MAR-09
    31-JAN-10
    07-DEC-09
    05-DEC-09
    06-DEC-09
    08-DEC-09
    10-MAR-09
    29-JAN-10
    10-MAR-10
    28-JAN-10
    11 rows selected.
    SQL> SELECT MYDATE FROM T ORDER BY MYDATE DESC;
    MYDATE
    10-MAR-10
    31-JAN-10
    29-JAN-10
    28-JAN-10
    08-DEC-09
    07-DEC-09
    06-DEC-09
    05-DEC-09
    25-MAR-09
    13-MAR-09
    10-MAR-09
    11 rows selected.
    SQL> SHOW PARAMETER NLS_DATE;
    NAME                                 TYPE        VALUE
    nls_date_format                      string
    nls_date_language                    stringCan you show us the output of
    show parameter nls_date;
    Regards
    Girish Sharma

Maybe you are looking for

  • Crystal Report for VS2010 show Login when deployed

    I am having a problem with my Windows Form project in VS2010 regarding the SAP Crystal Reports for VS2010. When I deploy my project on client's PC it shows a login dialog box. The client's PC is in XP. I already installed the correct runtime in their

  • Student Discount Question

    Hi everyone, I know this is unrelated, but I didn't know where else to post this and the iBook boards have helped me the most in my past questions so.... Anyway, I'm soon to purchase my first iPod and iBook G4 and I'm having a problem with my school.

  • 2011 imac vs 2015 mac mini

    Hi, I currently have low-end 2011 imac 21.5" and was thinking about getting cheapest 2015 mac mini and larger monitor to upgrade the screen without spending too much. But when I compared the specs. my imac says 2.5 Core i5 QuadCore, 8GB memory, AMD R

  • Burned dvd skips

    hi there - am waiting on final cut universal to arrive and am at the moment just needing to put a 5 min music video that a friend did from imovie onto DVD have managed to burn it fine but playing on a dvd player it skips like mad although it plays fi

  • ADA error 107

    Hi, I've a proble when i want to download the trial version of after effects CS5.5, just after i logged in it's written error 107. So i read some forums and you adviced to check http://kb2.adobe.com/cps/898/cpsid_89867.html , so i did it and did all