Crosstab query using  PL/SQL [HELP]

hi all,
i got this output after execute my query:
week no | department | item | budget
1 | 0901 | salary | 25000
1 | 0901 | stationery | 5000
1 | 5501 | salary | 45000
2 | 0901 | salary | 25000
2 | 5501 | salary | 25000
2 | 5501 | stationery | 100
i hope to get the output like below:
dept/week no 1 2 3
=========================================
0901 30,000 25,000 800 (A)
5501 45,000 25,100 100 (B)
variance 45,000 70,000 70,800 (C)
=========================================
Grand total - 75,000 - 50,100 - (D)
======================================
NOTE:
the week is from week 1 until week 52, is it advisable to use looping or??.
It is more than 2 departments and items as well. the user is allowed to passing in more than 1 selection of the items (salary,stationary,hardware and software, etc) to get this report.
I need to display the output on the screen/spool into file after the execution.
==========
Definition
===========
Grant total (D1) by week =(A1 + B1)
Variance (C1) for the 1st week of the year will always take the (B1) values as the based values for the next calculation. whereas (C2) = (C1) + (A2) and (C3) =(C2)+(A3) and the same formular apply up to week 52.
the pivot method not a suitable solution to produce this output.
anyone can suggest the shorter and more intelligent solution?
this is very urgent, pls help!! thank

You can get your basic data by,
SELECT department, week_no, sum(budget) AS budget
  FROM your_table
GROUP BY department, week_no;Then you'll just pivot the above data by week. Then you can use an analytic SUM() to get your weekly totals.
WITH your_table AS (
SELECT '0901' AS department, 1 AS week_no, 1000 AS budget FROM dual
UNION ALL
SELECT '1234' AS department, 1 AS week_no, 500 AS budget FROM dual)
SELECT v.*,
       SUM(budget) OVER (PARTITION BY week_no) AS week_total
  FROM (
SELECT department, week_no, sum(budget) AS budget
  FROM your_table
GROUP BY department, week_no
ORDER BY department, week_no
       )  v;I have to admit I'm a bit confused about your definition of variance.

Similar Messages

  • Crosstab query using pure SQL only

    Hi all,
    Found a lot of threads on crosstab, but none seems to address what I need. I need to perform crosstab query using pure SQL only & the number of columns are dynamic. From a query, I obtained the below table:
    Name Date Amount
    Alex 2005-06-10 1000
    Alex 2005-06-20 1000
    Alex 2005-07-10 1000
    Alex 2005-07-20 1000
    Alex 2005-08-10 1000
    Alex 2005-08-20 1000
    John 2005-06-10 2000
    John 2005-06-20 2000
    John 2005-07-10 2000
    John 2005-07-20 2000
    John 2005-08-10 2000
    John 2005-08-20 2000
    And I need to transform it into:
    Name 06-2005 07-2005 08-2005
    Alex 2000 2000 2000
    John 4000 4000 4000
    Reason for the columns being dynamic is because they'll be a limit on the date ranges to select the data from. I'd have a lower & upper bound date say June-2005 to August-2005, which explains how I got the data from the above table.
    Please advise.
    Thanks!

    Hi,
    I couldn't resist the intellectual challenge of a pure SQL solution for a pivot table with a dynamic number of columns. As Laurent pointed out, a SQL query can only have a fixed number of columns. You can fake a dynamic number of columns, though, by selecting a single column containing data at fixed positions.
    <br>
    <br>
    If it were me, I'd use a PL/SQL solution, but if you must have a pure SQL solution, here is an admittedly gruesome one. It shows the sum of all EMP salaries per department over a date range defined by start and end date parameters (which I've hardcoded for simplicity). Perhaps some of the techniques demonstrated may help you in your situation.
    <br>
    <br>
    set echo off
    set heading on
    set linesize 100
    <br>
    select version from v$instance ;
    <br>
    set heading off
    <br>
    column sort_order noprint
    column sal_sums format a80
    <br>
    select -- header row
      1        as sort_order,
      'DEPTNO' as DEPTNO ,
      sys_connect_by_path
        ( rpad
            ( to_char(month_column),
              10
          ' | '
        ) as sal_sums
    from
        select
          add_months( first_month, level - 1 ) as month_column
        from
          ( select
              date '1981-01-01' as first_month,
              date '1981-03-01' as last_month,
              months_between( date '1981-03-01', date '1981-01-01' ) + 1 total_months
            from dual
        connect by level < total_months + 1
      ) months
    where
      connect_by_isleaf = 1
    connect by
      month_column = add_months( prior month_column, 1 )
    start with
      month_column = date '1981-01-01'
    union all
    select -- data rows
      2 as sort_order,
      deptno,
      sys_connect_by_path( sum_sal, ' | ' ) sal_sums
    from
      select
        dept_months.deptno,
        dept_months.month_column,
        rpad( to_char( nvl( sum( emp.sal ), 0 ) ), 10 ) sum_sal
      from
          select
            dept.deptno,
            reporting_months.month_column
          from
            dept,
            ( select
                add_months( first_month, level - 1 ) as month_column
              from
                ( select
                    date '1981-01-01' as first_month,
                    date '1981-03-01' as last_month,
                    months_between( date '1981-03-01', date '1981-01-01' ) + 1 total_months
                  from
                    dual
              connect by level < total_months + 1
            ) reporting_months
        ) dept_months,
        emp
      where
        dept_months.deptno = emp.deptno (+) and
        dept_months.month_column = trunc( emp.hiredate (+), 'MONTH' )
      group by
        dept_months.deptno,
        dept_months.month_column
    ) dept_months_sal
    where
      month_column = date '1981-03-01'
    connect by
      deptno = prior deptno and
      month_column = add_months( prior month_column, 1 )
    start with
      month_column = date '1981-01-01'
    order by
      1, 2
    <br>
    VERSION
    10.1.0.3.0
    <br>
    DEPTNO      | 81-01-01   | 81-02-01   | 81-03-01
    10          | 0          | 0          | 0
    20          | 0          | 0          | 0
    30          | 0          | 2850       | 0
    40          | 0          | 0          | 0
    <br>
    Now, if we substitute '1981-03-01' with '1981-06-01', we see 7 columns instead of 4
    <br>
    DEPTNO      | 81-01-01   | 81-02-01   | 81-03-01   | 81-04-01   | 81-05-01   | 81-06-01
    10          | 0          | 0          | 0          | 0          | 0          | 2450
    20          | 0          | 0          | 0          | 2975       | 0          | 0
    30          | 0          | 2850       | 0          | 0          | 2850       | 0
    40          | 0          | 0          | 0          | 0          | 0          | 0
    <br>To understand the solution, start by running the innermost subquery by itself and then work your way outward.

  • Need SQL query using View - Please help

    Hi,
    I have similar requirement like below.
    I have two tables DEPT and EMP and some departments may not have employees. I have created below view, which displays all DEPT records, even though there are no emplyees.
    CREATE OR REPLACE VIEW dept_emp_vw AS
    SELECT deptno, empid, 0 AS selected
    FROM dept d, emp e
    WHERE d.deptno = e.deptnno (+);
    Ex.
    DEPTNO         EMPID        SELECTED
    10 101 0
    10 102 0
    20 103 0
    30 103 0
    40 104 0
    50 <null> 0
    Application will pass "empid" to the view (for ex. empid = 103) and I want result like below.
    Ex.
    DEPTNO         EMPID        SELECTED
    10 101 0
    10 102 0
    20 103 1
    30 103 1
    40 104 0
    50 <null> 0
    Can you please let me know the query using "dept_emp_vw" view. We have Oracle 11g Release 2.
    Thanks a lot for the help.

    Not possible using normal SQL - as SQL is not a procedure language and does not support variable declaration and use (e.g. passing empid as a variable and using it both as a predicate and as a condition in the SQL projection).
    That said - SQL can be "+parameterised+". An approach that is ugly and contrary to the basic design and use of SQL. But it can support the (very weird) view definition of yours.
    E.g.
    SQL> create or replace procedure SetVariable( name varchar2, value varchar2 ) is
      2  begin
      3          DBMS_SESSION.set_context( 'MyVariables', name, value );
      4  end;
      5  /
    Procedure created.
    SQL>
    SQL>
    SQL> create or replace context MyVariables using SetVariable;
    Context created.
    SQL>
    SQL> create or replace view my_funky_weird_view as
      2  select
      3          e.empno,
      4          e.ename,
      5          e.job,
      6          case e.empno
      7                  when to_number(sys_context( 'MyVariables', 'empid' )) then
      8                          0
      9                  else
    10                          1
    11          end     as "SELECTED"
    12  from       emp e
    13  /
    View created.
    SQL>
    SQL> exec SetVariable( 'empid', 7499 )
    PL/SQL procedure successfully completed.
    SQL>
    SQL> select * from session_context where namespace = 'MYVARIABLES';
    NAMESPACE            ATTRIBUTE            VALUE
    MYVARIABLES          EMPID                7499
    SQL>
    SQL> select * from my_funky_weird_view order by selected;
         EMPNO ENAME      JOB               SELECTED
          7499 ALLEN      SALESMAN                 0
          7521 WARD       SALESMAN                 1
          7566 JONES      MANAGER                  1
          7654 MARTIN     SALESMAN                 1
          7698 BLAKE      MANAGER                  1
          7934 MILLER     CLERK                    1
          7788 SCOTT      ANALYST                  1
          7839 KING       PRESIDENT                1
          7844 TURNER     SALESMAN                 1
          7876 ADAMS      CLERK                    1
          7900 JAMES      CLERK                    1
          7902 FORD       ANALYST                  1
          7369 SMITH      CLERK                    1
          7782 CLARK      MANAGER                  1
    14 rows selected.
    SQL>But I will N\OT recommend doing it this way. It is not natural SQL as PL/SQL is needed to "+inject+" name-value pairs into the context for the SQL view to use. It is ugly. It is not standard. It cannot scale. It is complex to use. Etc.
    Yes, there are instances when this approach is exactly what one needs - when for example dealing with a trusted context and using the contents for implementing a security layer. But in the above case - I would rather want to see the actual business requirement first, as I think you're barking up the wrong tree with the view solution you have imagined.

  • Parameter passing to custom SQL query using PL/SQL FUNCTION

    Hi
    In order to pass a parameter to the query in custom folder of a business area I created a function and mapped it to the Custome query using Discoverer Desktop. There is no error in mapping as the system does not throw any error. When I am inputting the Parameter for the input values everytime the query doesnot return any rows.
    Can anybody help in this regard

    Hi,
    I need to take the request Id as input from the user and then fetch only the data pertaining to that requet Id. As a lot of complex joins are involved I need to pass request id as parameter to the custome folder.
    The package i greated:
    CREATE OR REPLACE PACKAGE SETPARAM
    AS
    param1 varchar2(25);
    param2 varchar2(25);
    FUNCTION SET_PARAM1(p1 IN varchar2) RETURN NUMBER ;
    FUNCTION GET_PARAM1 RETURN varchar2;
    END SETPARAM;
    CREATE OR REPLACE PACKAGE BODY SETPARAM AS
    FUNCTION SET_PARAM1(p1 IN varchar2) RETURN NUMBER IS
    BEGIN
    fnd_client_info.set_org_context('138');
    param1 := p1;
    dbms_output.put_line(param1);
    RETURN 1;
    END;
    FUNCTION GET_PARAM1 RETURN varchar2 AS
    BEGIN
    RETURN param1;
    END;
    END SETPARAM;
    I registered the set_param1 function as a pl/sql function in discoverer admin.
    This function is called on the condition associated with the parameter in Discoverer Desktop when i run the report.
    In the custom folder query i have this piece in the where clause
    WHERE tnfo.request_id = NVL(APPS.SETPARAM.GET_PARAM1,7383588)
    And everytime i get the data pertaining to request id =7383588,
    Please suggest where i went wrong
    thanks
    Ashwini

  • Query in PL/SQL Help

    Hi All!
    I want to write following type of query in PL/SQL
    How can I write one which will work.
    SELECT count(1) INTO v_count2 from TRJ_TRAN_REJ_T a and PEU_PUR_ENRL_UNT_T b
    where a.TRJ_CVRG_PER_DATE IN (b.PEU_EFF_DATE AND b.PEU_END_DATE) AND
    a.purik = b.purik AND a.peuik = b.peuik
    Above query is not working correctly. Any changes?? DATE stored in database is like 01/01/2001
    v_count2 is NUMBER variable declared in PL?SQL.
    SA

    I'd also watch out for the TIME part of the date matching, best to do a TRUNC on them, but make sure also [purik] and [peuik] are indexed. This is the format I use for a select. Some parts were removed but you get the idea.
    --[START]
    --[SELECT]
    SELECT
    --/*+ choose */
    /*+ RULE */
    --/*+ first_rows */
    --/*+ all_rows */
    count(1)          --[C1]
    --[INTO]
    INTO
    v_count2          --[V1]
    --[FROM]
    FROM
    trj_tran_rej_t T1,
    peu_pur_enrl_unt_t T2
    --[WHERE]
    WHERE
    TRUNC(T1.trj_cvrg_per_date) = TRUNC(T2.peu_eff_date)
    OR
    TRUNC(T1.trj_cvrg_per_date) = TRUNC(T2.peu_end_date)
    AND
    T1.purik = T2.purik
    AND
    T1.peuik = T2.peuik
    --[ABORT]
    AND 1=1;
    --[END]
    Tyler Durden

  • Optimizing an SQL Query using Oracle SQL Developer

    Hi ,
    Currently i am using Oracle SQL Developer as my Database IDE .
    Is it possible to use Orqcles SQLDeveloper for the purpose of Optimizing an SQL Query ??
    For example assume i am having a query as :
    Select from Tranac_Master where CUST_STATAUS='Y' and JCC_REPORT='N'*
    Could anybody please tell me how can i use Oracle SQL Developer to optimize this query or any other SQL queries ??
    Please share your ideas , thanks in advance .

    1. Your query looks very simplistic as it is, so I fail to see how you can better optimise it (unless 'Tranac_Master' is a view, in which case I'd need to see the view details).
    2. No tool can automagically optimise your SQL to any degree of practical use. Very minor adjustments may be possible automatically, but really it is a question of you knowing your data & database design accurately, and then you applying your expert knowledge to tune it.

  • Query used by SQL Server Management Pack for monitoring database backups

    I use SCOM 2012 R2 and the SQL Server Management Pack to monitor SQL Server database backups. I believe I am getting false positives. SCOM reports database are not backuped, while in fact they are. So I need to troubleshoot this. I suspect SCOM is querying
    the backup history in the msdb database. I want to know which query SCOM uses.
    I have tried looking in the monitor's definition but I suspect the query is embedded in the management pack files which are binary. I have also tried running a trace using the SQL Server Profiler on my test environment and overriding the interval to 60 seconds,
    but I don't see a relevant query being executed. I also don't see the alert reappear so I suspect SCOM does not honor the interval in a way I would expect.
    What query, or other method, does SCOM use to check database backups?
    Thanks in advance.

    Thank you both Ivan and Michael,
    I only saw your messages by email and didn't see your screen shot before I extracted the query myself. In my own queries I calculate the backup age in hours instead of days because of daily full backups. Perhaps It will be a good idea to create my own monitors
    from scratch like I used to do with Nagios.
    I will study the vbscripts and might create my own version which allows the query to be entered as an parameter and move all code to a .Net class which can be called from vbscript as an COM object. This way I hope to reduce the vbscript code to an minimum
    while keeping the flexibility of the SCOM Operations Console and the robustness of .Net. I suspect I want to make more non standard monitors in the future.
    Regards,
    Arjen

  • Querying using Native SQL

    Hi Pals,
    I have a requirement which I would like to brief.
    I have an internal table with columns FIELD1 and FIELD2. For all the values in FIELD1 I have to query a table MSI(which does not form a part of the R/3 framework) through Native SQL statement and get the corresponding values for FIELD2.
    Could anybody suggest how I must proceed writing my statements between EXEC and ENDEXEC.
    Do I have to query the database table for each entry in my internal table or is it possible to use for all entries in my SQL statemnt.
    Your inputs would be highly appreciated.
    Thank You in advance.
    Regards,
    Gayathri N.

    Hai Gayathri
    check this document
    EXEC SQL.
    Addition
    ... PERFORMING form
    Effect
    Executes the Native SQL command enclosed by the statements EXEC SQL and ENDEXEC . In contrast to Open SQL , addressed database tables do not have to be known to the ABAP/4 Dictionary and the ABAP/4 program does not have to contain appropriate TABLES statements.
    Example
    Create the table AVERI_CLNT :
    EXEC SQL.
      CREATE TABLE AVERI_CLNT (
             CLIENT   CHAR(3)  NOT NULL,
             ARG1     CHAR(3)  NOT NULL,
             ARG2     CHAR(3)  NOT NULL,
             FUNCTION CHAR(10) NOT NULL,
             PRIMARY KEY (CLIENT, ARG1, ARG2)
    ENDEXEC.
    With Native SQL commands, passing data between an ABAP/4 program and the database is achieved using host variables . A host variable is an ABAP/4 variable prefixed by a "*" in the Native SQL statement.
    Example
    Display a section of the table AVERI_CLNT :
    DATA: F1(3), F2(3), F3(3).
    F3 = ' 1 '
    EXEC SQL.
      SELECT CLIENT, ARG1 INTO :F1, :F2 FROM AVERI_CLNT
             WHERE ARG2 = :F3
    ENDEXEC.
    WRITE: / F1, F2.
    To simplify the spelling of INTO lists in the SELECT command, you can specify a single structure as the target area as in Open SQL .
    Example
    Display a section of the table AVERI_CLNT :
    DATA: BEGIN OF WA,
            CLIENT(3), ARG1(3), ARG2(3),
          END OF WA.
    DATA  F3(3).
    F3 = ' 1 '
    EXEC SQL.
      SELECT CLIENT, ARG1 INTO :WA FROM AVERI_CLNT
             WHERE ARG2 = :F3
    ENDEXEC.
    WRITE: / WA-CLIENT, WA-ARG1.
    Notes
    In contrast to Open SQL , a client field in Native SQL is a field like any other and must be specified explicitly in calls.
    Authorization checks cannot be properly realized in EXEC SQL . You should perform these in the program.
    When you start the R/3 System, a CONNECT to the current database is executed automatically. An explicit CONNECT is unnecessary.
    A Native SQL command can (but does not have to) end with a ";". Under no circumstances should it end with a ".".
    Some database systems allow upper and lower case in table names and field names. If you want to take advantage of this, you must ensure that the spelling of names is correct. To enable entry of lower case letters in names in the ABAP/4 editor, you must set the attribute for upper/lower case in the report.
    Since there are no arrays in ABAP/4 , array operations are not possible in Native SQL . If the result of a SELECT command is a table, you can read this table line by line either with the Native SQL command FETCH or with the addition ... PERFORMING form .
    Unlike in ABAP/4 programs, the character " in a Native SQL statement does not introduce a comment until the end of the editor line.
    Addition
    ... PERFORMING form
    Effect
    If the result of a SELECT command is a table, you can read this table line by line in a processing loop. The subroutine form is called once for each line. In this subroutine, you can leave the loop by using EXIT FROM SQL . If the result of the selection is a single record, the subroutine is called only once.
    Example
    Display a section of the table AVERI_CLNT :
    DATA: F1(3), F2(3), F3(3).
    F3 = ' 1 '
    EXEC SQL PERFORMING WRITE_AVERI_CLNT.
      SELECT CLIENT, ARG1 INTO :F1, :F2 FROM AVERI_CLNT
             WHERE ARG2 = :F3
    ENDEXEC.
    FORM WRITE_AVERI_CLNT.
      WRITE: / F1, F2.
    ENDFORM.
    Note
    This addition is allowed only with a SELECT command.
    Related SELECT , INSERT , UPDATE , MODIFY , DELETE , OPEN CURSOR , FETCH , CLOSE CURSOR, COMMIT WORK and ROLLBACK WORK .
    go to se38
    type 'EXEC' and put cursor on 'EXEC' press f1-function key
    then you get help for EXEC
    Thanks & regards
    Sreenivasulu P
    Message was edited by: Sreenivasulu Ponnadi

  • Query Using Joins.Please Help

    Hi,
    A Query please
    I have a Customer table and an Order Table
    The customer can place multiple orders
    Create Table Customers
    (Cust_id      number(2),
    cust_name    varchar2(15),
    constraint   pk_custid PRIMARY KEY(Cust_id)
    Create Table Orders
    (Order_no    number(2),
    Cust_id     number(2),
    order_status varchar2(1),
    constraint  pk_orderno PRIMARY KEY(order_no),
    constraint  fk_custid  FOREIGN KEY(cust_id)
    REFERENCES  Customers(cust_id)
    )Now,the Customer table has a single record
    whereas the Order Table has multiple records
    for the same customer.
    SQL> Select * from Orders
    ORDER_NO   CUST_ID ORDER_STATUS
            1         1 P
            2         1 PI'd like to view the different orders for that same customer
    Using a simple Join DOES NOT give the right output:
    SQL> Select C.cust_id,C.cust_name,
      2  O.order_no,O.order_status
      3  From Customers C,Orders O
      4  where C.cust_id = O.order_no;
      CUST_ID CUST_NAME        ORDER_NO O
            1 ABCD              1       PThere are 2 records in the Orders Table?
    How to view both the records from Orders Table?
    Do I need to use the EXISTS clause?
    Can someone please help?

    Well, I would have thought that you would join C.cust_id with the O.cust_id (and not O.order_no)???
    SQL> Select C.cust_id,C.cust_name,
      2  O.order_no,O.order_status
      3  From Customers C,Orders O
      4  where C.cust_id = O.order_no;

  • Query using the SQL 'go' command  on a JAVA code

    Hi,
    I am trying to create a new database on MS SQL and at the same time verify whether the data base exist already and then add a new table. The query statement works well on the query windows on MS SQL, but when the query is place using a JAVA code it gives the following error:
    java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'go'.
    java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'go'.
         at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
         at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
         at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)
         at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)
         at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(Unknown Source)
         at DataBaseCreator.main(DataBaseCreator.java:30)
    I have to add that if I only query: "CREATE DATABASE NameOfDatabase" the new data base is created without a problem using JAVA, but when I try to use the following query, I got the error message.
    "USE Master "
                        + "IF EXISTS (SELECT * FROM SysDatabases WHERE NAME='DatesTemps') "
                        + " DROP DATABASE DatesTemps"
                        + " go "
                        + " CREATE DATABASE DatesTemps22 "
                        + " go"
                        + " USE DatesTemps "
                        + " CREATE TABLE Fable ( "
                        + " FableID INT NOT NULL CONSTRAINT FablePK PRIMARY KEY NONCLUSTERED, "
                        + " Title VARCHAR(50) NOT NULL, "
                        + " Moral VARCHAR(100) NOT NULL, "
                        + " FableText VARCHAR(1536) NOT NULL, "
                        + " BlobType CHAR(3) NULL DEFAULT 'doc', "
                        + " Blob IMAGE NULL DEFAULT NULL )"
    If it is useful my complete code is the following, I appreciate in advance your comments.
    import java.sql.Connection;
    import java.sql.Statement;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.*;
    import java.util.Calendar;
    import java.util.GregorianCalendar;
    public class DataBaseCreator {
         public static void main (String[] args)
              Connection Time =null;
              Statement stmt = null;
              String data = "jdbc:odbc:DataBaseCreation";
              try
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   Time= DriverManager.getConnection(data,"","");
                   stmt = Time.createStatement();
                   //String query;
                   //java.sql.Timestamp ts1 = new java.sql.Timestamp(((3*60)+58)*60*1000);
              // System.out.println(ts1 + " This is a Time Stamp");
              ResultSet rec = stmt.executeQuery(
                        "USE Master "
                        + "IF EXISTS (SELECT * FROM SysDatabases WHERE NAME='DatesTemps') "
                        + " DROP DATABASE DatesTemps"
                        + " go "
                        + " CREATE DATABASE DatesTemps22 "
                        + " go"
                        + " USE DatesTemps "
                        + " CREATE TABLE Fable ( "
                        + " FableID INT NOT NULL CONSTRAINT FablePK PRIMARY KEY NONCLUSTERED, "
                        + " Title VARCHAR(50) NOT NULL, "
                        + " Moral VARCHAR(100) NOT NULL, "
                        + " FableText VARCHAR(1536) NOT NULL, "
                        + " BlobType CHAR(3) NULL DEFAULT 'doc', "
                        + " Blob IMAGE NULL DEFAULT NULL )"
              catch( Exception e )
                        System.err.println( e );
                        e.printStackTrace();
              finally
                        try
                             stmt.close();
                             Time.close();
              catch( Exception e )
                        System.err.println( e );
    }

    Ok, first of all thanks for your answer, now what I want to do is the following:
    1) I need to input ((retrieve) every minute some data (Date and Temperature), that I will get from and external device, this is not part of this code.
    2) I want to store that data (Date and Temp) on a data base, here where I need the command to create the data base and to verify whether that data base already exists. In case it has already been created then create new table(s) on it. If it doesn't exist then create and then create new tables.
    3) Each Day (at yyyy mm dd 00:00:00:000 will create a new table, and the name of this table will be yyyymmdd.
    4) Then every minute the java code will retrieve the data and add it to the table in the data base.
    5) That will be a close loop that will be running until the user interrupt it.
    I haven't make the communication code yet, in order to test my code I was thinking to retrieve the data from another data base. This would be just to verify that the JAVA sequence is able to retrieve the data every minute and create new data base and tables.
    For the record I am able to send the queries and retrieve information from SQL running the code in eclipse, that will cover your first observation.
    I am quite new in the forum I am sorry I didn't get the use of code tags.
    Sorry again as I said I am quite new on this, what's a DDL statement.
    Thanks.

  • JDBC Query using PL/SQL

    I have gotten this to work in my Reports class but can not get this to work at my company. Basically I'm trying to use the JDBC query in Report Builder.
    Here is my Ref Cursor Code:
    CREATE OR REPLACE PACKAGE SCOTT.types is
    type sqlcur is REF cursor;
    end;
    Here is my Pl/SQL function:
    CREATE OR REPLACE FUNCTION SCOTT.test return Scott.types.sqlcur is
    c1 Scott.types.sqlcur;
    begin
    open c1 for select * from scott.emp;
    return c1;
    end;
    I can get this to work in SQL Plus by doing the following:
    var r refcursor
    exec :r := test;
    print r When I go into Reports Builder->JDBC query I connect to the SCOTT db using tiger as the password. I type in the function name TEST and get the error "wrong number or types of arguments in call TEST". I have tried "call TEST" but that doesnt work either. If I use "call TEST" I get an error saying it expected characters ":=(@" etc....
    I know my connection works because I can do a "select * from emp" and get results. Can anyone get this to work?
    I'm running Report Builder 9.0.2.0.3
    I have done multiple searches on this issue and most responses point someone to links that dont work or documentation. I have read them and my code above should work but doesnt........Please put some real examples or code that works with the "Scott" schema.
    Thanks

    hi Shawn
    When running jdbc quesry based on SP with Oracle DB, the first parameter of the store procedure should be of ref cursor type and it shall be a OUT parameter.
    For example:
    CREATE OR REPLACE PACKAGE jdbcpdspkg AS
    TYPE Empcur IS ref cursor ;
    procedure proc_with_param      (p_emp_cv out jdbcpdspkg .empcur, p1 in number, p2 in number , p3 in number, p4 in number , p5 in number) ;
    Thanks
    Rohit

  • Tree query using XML SQL

    Hi,
    Any ideas or code samples of how we could use the XML SQL Utility
    to do a tree structure, like the following:
    <GROUP id="grp1">
    <ITEM> item 1 </ITEM>
    <ITEM> item 2 </ITEM>
    <GROUP id="grp2">
    <ITEM> item 3 </ITEM>
    <ITEM> item 4 </ITEM>
    </GROUP>
    <ITEM> item 5 </ITEM>
    </GROUP>
    Thanks,
    Cyril.
    null

    Hi Mark,
    To a certain extent one can modify the xml generated by
    manipulating the query and by using some of the tag name
    customizations which the XSU allows. Unfortunately, what you
    want to create will take more than that; you will have to use
    XSLT - xml transformation language, part of XSL. You will find
    and XSL processor packaged with the oracle xml parser v2 (see
    oraxsl). You can find more info on XSLT at www.w3c.org
    Mark Fortner (guest) wrote:
    : I have an example similar to his:
    : Given a resultset in the form:
    : Company Department User
    : Oracle XML Dev John Smith
    : Oracle XML Dev Jane Smith
    : Oracle Mgmt Larry Ellison
    : Sun Project X Jane Doe
    : Sun Mgmt Scott McNealy
    : which usually results in XML like this
    : <rowset>
    : <row id=1>
    : <Company>Oracle</Company>
    : <Department>XML Dev</Department>
    : <User>John Smith</User>
    : </row>
    : </rowset>
    : how do I get it to look like this?
    : <JTree>
    : <Oracle>
    : <XML Dev>
    : <Jane Smith/>
    : <John Smith/>
    : </XML Dev>
    : <Mgmt>
    : <Larry Ellison/>
    : </Mgmt>
    : </Oracle>
    : <Sun>
    : <Project X>
    : <Jane Doe/>
    : </Project X>
    : <Mgmt>
    : <Scott McNealy/>
    : </Mgmt>
    : </Sun>
    : </JTree>
    : Oracle XML Team wrote:
    : : Hi Cyril,
    : : Your question is a bit vague. Do you have a table which
    you
    : : are trying to query and get the result in the following
    : format?
    : : If these is the case please give me the description of the
    : table
    : : or the view.
    : : The other thing to keep in mind is that even if the XSU
    : can't
    : : give you the XML data in the exactly the format you want, you
    : can
    : : always use XSLT to transform the XML doc generated by the XSU
    : to
    : : the desired XML doc.
    : : Cyril Dunnion (guest) wrote:
    : : : Hi,
    : : : Any ideas or code samples of how we could use the XML SQL
    : : Utility
    : : : to do a tree structure, like the following:
    : : : <GROUP id="grp1">
    : : : <ITEM> item 1 </ITEM>
    : : : <ITEM> item 2 </ITEM>
    : : : <GROUP id="grp2">
    : : : <ITEM> item 3 </ITEM>
    : : : <ITEM> item 4 </ITEM>
    : : : </GROUP>
    : : : <ITEM> item 5 </ITEM>
    : : : </GROUP>
    : : : Thanks,
    : : : Cyril.
    : : Oracle Technology Network
    : : http://technet.oracle.com
    Oracle Technology Network
    http://technet.oracle.com
    null

  • Linked server query using Dynamic SQL

    I have a Linked server query that takes forever to run. WHen I hardcode the acct# it runs fast. However I want these acct numbers int he where clause to be generated dynamically. For eg: below is what I need:
    --Get the 11 Loans from this Table A From the FIRST QUERY
    --- Plug those loans numbers in the second query  In the WHERE Clause eg should looks like  where  ACCT in (1,2,3,5)
    DECLARE
    @sSQL varChar(MAX)
    SET @sSQL
    =
    ' SELECT
    [Loan] FROM TableA D
    EXECUTE(@sSQL)
    --2ND QUERY 
    DECLARE
    @sSQL1 varChar(MAX)
    SET @sSQL1
    ='
    SELECT Field1, 
    Field2,
    Field3,
    Field4,
    Field5
       FROM LinkedServer.Dbaname.dbo.TableB a
    where ACCT in ''('''
    +(@sSQL)
    +
    ''')'''--- This needs to look like  where  ACCT in (1,2,3,5)
    select
    @sSQL1

    Ok, so use this.. instead of your first statement.
    DECLARE @sSQL NvarChar(MAX), @output NVARCHAR(100), @ParmDefinition nvarchar(500);
    SET @ParmDefinition = N'@sqlout NVARCHAR(100) OUTPUT'
    SET @sSQL = N'SELECT DISTINCT @sqlout = STUFF((SELECT '',''+CAST(S2.loan AS VARCHAR(100))
    FROM tableA S2
    FOR XML PATH('''')), 1, 1, '''')
    FROM tableA S1'
    EXECUTE sp_executesql @sSQL, @parmdefinition, @sqlout = @output OUTPUT
    and use @output instead of @sSQL in the second statement.
    You can read about STUFF command @
    http://sqlsaga.com/sql-server/how-to-concatenate-rows-into-one-row-using-stuff/.
    Good Luck :)
    Visit www.sqlsaga.com for more t-sql code snippets or BI related how to's.

  • Query using Group by - help needed

    I am having a query as follows:
    select id_nbr, stop_nbr, street || city || state, count(sub_stop_nbr)
    from details where created_date = ' 22-Jul-08';
    As group by clause is missing it is giving errors.
    But when I add group by to this query, I have to add all selected values.
    How can I add the concatenatd values here.
    Is there any other way rather than writing as :
    (select id_nbr, stop_nbr, street || city || state, count(sub_stop_nbr)
    from details where created_date = ' 22-Jul-08'
    group by id_nbr, stop_nbr, street || city || state)

    so where is the problem in writing:
    select id_nbr, stop_nbr, street || city || state, count(sub_stop_nbr)
    from details
    where created_date = ' 22-Jul-08'
    group by id_nbr, stop_nbr, street || city || state
    ????

  • Using Native SQL in ABAP for DB2 database

    Dear Friends,
           I have 500K records in ITAB(Internal table) which needs to insert in 'Z' transparent table. Currently it is taking hours of time for insertion and commit. 
    Does using Native SQL helps in performance or any suggestions? If so please send the code. Our database is DB2.
    Your immediate reply is appreciated. Thanks in advance.

    Hi Rama,
    Using array inserts and commit after each Insert, set up your array size as a parameter and try  different array sizes.
    I would start with 2000 and increment by 1000 or 2000 and see what the optimal array size is.
    I would think more commits are desirable, as the array gets bigger it takes longer for the system to prepare in the event of a rollback.
    Just remember to commit after each insert. And are you enqueueing the table first?
    Hope this helps.
    Filler

Maybe you are looking for

  • In list view, duplicating a file causes the finder to jump to the top

    I'm working on an iMac with Lion, connected to files on a Mac server and working in list view with a number of sub-folders expanded. When I duplicate a file, the list view jumps all the way to the top of the first folder. I then have to scroll back d

  • What generation do I have?

    Hello everyone. I recently purchased a used MBA on eBay and want to verify which generation it is. The system profiler says MacBook Air 1,1. Is this first-generation, early 2008? The other technical specs seem to indicate this. Is there any other way

  • Shuffle issues in playlist

    how do i make it so my playlist will play continuously when i have shuffle turned on?

  • Reg date difference ?

    hi friends.. in my program i want to find the difference between two dates for that i try with following FM ISHMED_CALC_DATE_TIME_DIFF FI_PSO_DAYS_MONTHS_YEARS_GET HR_99S_INTERVAL_BETWEEN_DATES FIMA_DAYS_AND_MONTHS_AND_YEARS all these FM are work pro

  • Alternate layout question

    I have finished the vertical layout of my entire issue and want to know complete the horizontal part of the issue.  I went up to alternate layout and the horizontal design showed up and i edited it and saved file.  I updated the article in my folio b