Group by sql statement is not sorted.

execut sql statement include group by clause in a oci program, the result is not sorted.
I don't know why..
in SqlPlus, same sql statement return sorted data.
SELECT A.SHOP_ID,A.RESALE_TYPE,
SUM(A.DEAL_AMT,0) DEAL_AMT
FROM SHOP_ACC A, CD_TAB C
WHERE A.RESALE_TYPE = C.CD(+)
AND C.GB = 'AB'
AND A.ACC_M = :s_AccMonth
AND DEAL_GB='FOD'
GROUP BY A.SHOP_ID,A.RESALE_TYPE
But, RESALE_TYPE is outer join on CD_TAB..
if remove outer join between CD_TAB and SHOP_ACC,
sql statement is return sorted result.
and if modify the column RESALE_TYPE like
RESALE_TYPE||']' or NVL(RESALE_TYPE,'AAA')
return sorted result..
please help..
thanks for your kind.

thank you.. for reply..
I knew that order by clause make to sort.
but, using group by clause alone in SQL statement, that return sorted results too.
I was found a fault that outer join table CD_TAB column of one is not symbloc "(+)" in SQL statement
SELECT A.SHOP_ID,A.RESALE_TYPE,
SUM(A.DEAL_AMT,0) DEAL_AMT
FROM SHOP_ACC A, CD_TAB C
WHERE A.RESALE_TYPE = C.CD(+)
AND C.GB = 'AB' <----------- AND C.GB(+) = 'AB'
AND A.ACC_M = :s_AccMonth
AND DEAL_GB='FOD'
GROUP BY A.SHOP_ID,A.RESALE_TYPE
I want to know that why in other application - such as SqlPlus or SqlGate and ..etc. - this fault was ignore.. but OCI application such as my application programs is not ignore.. and is not sorted..
thank you..

Similar Messages

  • The SQL statement is not valid - when importing data from SQL Server using a query

    Hi there,
    I am trying to import data from SQL to Power Pivot using a SQL query like below:
    SELECT Score.FieldCount, Score.Record.GetAt(0), Score.Record.GetAt(1),  Score.Record.GetAt(2),  Score.Record.GetAt(3),  Score.Record.GetAt(4)
    FROM 
    SELECT * FROM dbo.CLR1(
    dbo.CLR2('c:\FILES\Test.xml'), 
    'SELECT * FROM [dbo].[CXCustomer_Small]') Input
    ) Score
    And when I tried to validate it, it returns
    The SQL statement is not valid. A column name cannot be blank.
    I ran the above SQL statement in Management Studio and it works without problem. Any idea?
    Thanks!
    Chu
    -- Predict everything. http://www.predixionsoftware.com

    Never mind, I figured out - I need to give each column a name.
    -- Predict everything. http://www.predixionsoftware.com

  • Executing the SQL statement is not allowed - Error

    I am getting "Executing the SQL statement is not allowed" for an INSERT cfquery that I'm running.  I checked the usual suspects:
    - DSN allows INSERT
    - I've seen reports online where certain field names or values are considered key words, so for protection CF blocks the query in this way (it would be nice if there was a different error message when it gets blocked this way vs. the DSN doesn't allow INSERT error message).  The field names and values were all benign strings, so it didn't seem like that.
    I took the same string for the query and ran it on another page and it ran fine (same DSN, too).

    SOLVED: I decided to enter this in here, just to get it into web searches for others since I couldn't find anything.
    - I was calling a function for one of the values in the query:  get_db_status_code("initialize")  Apparently CF parses the query to see if it's allowed BEFORE it runs the CFML in it, so something in that function name, or the parameter "initialize" was a key word that CF doesn't allow.  I moved the function call outside of the query and loaded a temp variable for use in the query and it then worked.

  • SQL statement is not performing

    Hi community,
    I've a problem with a SQL statement.
    First of all here's the statement and the explain plan for it:
    select PPRJPOI.BBASE , PPRJPOI.CONTROLLINGAREA, PPRJPOI.COSTOBJTYPE , PPRJPOI.COSTOBJMAINPATH , PPRJPOI.COSTOBJSUBPATH ,
    PPRJPOI.PPOSNUM , PPRJPOI.PPOSTXT , PPRJPOI.PPOSBTG , PPRJPOI.PDCWABL , PPRJPOI.PDCWNUM , PPRJPOI.PDCWBUD , PPRJPOI.PKTOORI ,
    PPRJPOI.REFKEY1 , PPRJ.COSTCENTER , PPRJ.PATHELEM1 , PPRJSUB.PTPRTXT , LSUPPLIER.AADDRLINE1
    from PPRJPOI
    inner join PPRJ on PPRJ.BBASE = PPRJPOI.BBASE and PPRJ.CONTROLLINGAREA = PPRJPOI.CONTROLLINGAREA
    and PPRJ.COSTOBJTYPE = PPRJPOI.COSTOBJTYPE and PPRJ.COSTOBJMAINPATH = PPRJPOI.COSTOBJMAINPATH
    and PPRJ.COORGPATHELEM1 = ? and PPRJ.COORGPATHELEM2 = ? and PPRJ.COORGPATHELEM3 = ?
    and PPRJ.COORGPATHELEM4 = ? and PPRJ.COORGPATHELEM5 = ?
    inner join PPRJSUB on PPRJSUB.BBASE = PPRJPOI.BBASE and PPRJSUB.CONTROLLINGAREA = PPRJPOI.CONTROLLINGAREA
    and PPRJSUB.COSTOBJTYPE = PPRJPOI.COSTOBJTYPE and PPRJSUB.COSTOBJMAINPATH = PPRJPOI.COSTOBJMAINPATH
    and PPRJSUB.COSTOBJSUBPATH = PPRJPOI.COSTOBJSUBPATH
    left outer join LSUPPLIER on LSUPPLIER.BBASE = PPRJPOI.BBASE and LSUPPLIER.LSUPPLIERNUM = PPRJPOI.PLFTNUM
    where PPRJPOI.BBASE = ? and PPRJPOI.CONTROLLINGAREA = ? and PPRJPOI.COSTOBJTYPE = ?
    and PPRJPOI.SUMSTS = ? and (PPRJPOI.MOVCOSTOBJMAINPATH is null or PPRJPOI.CLEAREDITEM = ?)
    and (PPRJPOI.CLEAREDITEM ? or PPRJPOI.CLEAREDITEM is null)
    and PPRJPOI.COYEARID = ? and (PPRJPOI.COPERIODNUM between ? and ? )
    and PPRJPOI.BTS_CREATE <= TO_TIMESTAMP('27.10.2008 17:00:00')
    and PPRJPOI.PATHELEM2 = ? and PPRJPOI.PATHELEM3 = ?
    order by PPRJPOI.BBASE, PPRJPOI.CONTROLLINGAREA, PPRJPOI.COSTOBJTYPE,
    PPRJPOI.COSTOBJMAINPATH, PPRJPOI.COSTOBJSUBPATH
    | Id  | Operation                        | Name         | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                 |              |     1 |   489 |    40   (5)| 00:00:01 |
    |   1 |  SORT ORDER BY                   |              |     1 |   489 |    40   (5)| 00:00:01 |
    |*  2 |   FILTER                         |              |       |       |            |          |
    |   3 |    NESTED LOOPS OUTER            |              |     1 |   489 |    39   (3)| 00:00:01 |
    |   4 |     NESTED LOOPS                 |              |     1 |   439 |    38   (3)| 00:00:01 |
    |*  5 |      HASH JOIN                   |              |     1 |   262 |    37   (3)| 00:00:01 |
    |   6 |       TABLE ACCESS BY INDEX ROWID| PPRJ         |     1 |    95 |     1   (0)| 00:00:01 |
    |*  7 |        INDEX RANGE SCAN          | PPRJ_ORA4    |     1 |       |     1   (0)| 00:00:01 |
    |*  8 |       TABLE ACCESS BY INDEX ROWID| PPRJPOI      |    41 |  6847 |    36   (3)| 00:00:01 |
    |*  9 |        INDEX SKIP SCAN           | PPRJPOI_ORA3 |    83 |       |    26   (0)| 00:00:01 |
    |  10 |      TABLE ACCESS BY INDEX ROWID | PPRJSUB      |     1 |   177 |     1   (0)| 00:00:01 |
    |* 11 |       INDEX UNIQUE SCAN          | PK_233       |     1 |       |     1   (0)| 00:00:01 |
    |  12 |     TABLE ACCESS BY INDEX ROWID  | LSUPPLIER    |     1 |    50 |     1   (0)| 00:00:01 |
    |* 13 |      INDEX UNIQUE SCAN           | PK_177597    |     1 |       |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - filter(:13<=:14)
       5 - access("PPRJ"."BBASE"="PPRJPOI"."BBASE" AND
                  "PPRJ"."CONTROLLINGAREA"="PPRJPOI"."CONTROLLINGAREA" AND
                  "PPRJ"."COSTOBJTYPE"="PPRJPOI"."COSTOBJTYPE" AND
                  "PPRJ"."COSTOBJMAINPATH"="PPRJPOI"."COSTOBJMAINPATH")
       7 - access("PPRJ"."BBASE"=:6 AND "PPRJ"."CONTROLLINGAREA"=:7 AND
                  "PPRJ"."COSTOBJTYPE"=:8 AND "PPRJ"."COORGPATHELEM1"=:1 AND "PPRJ"."COORGPATHELEM2"=:2
                  AND "PPRJ"."COORGPATHELEM3"=:3 AND "PPRJ"."COORGPATHELEM4"=:4 AND
                  "PPRJ"."COORGPATHELEM5"=:5)
       8 - filter("PPRJPOI"."SUMSTS"=:9 AND ("PPRJPOI"."MOVCOSTOBJMAINPATH" IS NULL OR
                  "PPRJPOI"."CLEAREDITEM"=:10) AND ("PPRJPOI"."CLEAREDITEM" IS NULL OR
                  "PPRJPOI"."CLEAREDITEM"<>:11) AND "PPRJPOI"."BTS_CREATE"<=TO_TIMESTAMP('27.10.2008
                  17:00:00'))
       9 - access("PPRJPOI"."BBASE"=:6 AND "PPRJPOI"."CONTROLLINGAREA"=:7 AND
                  "PPRJPOI"."COSTOBJTYPE"=:8 AND "PPRJPOI"."COYEARID"=:12 AND "PPRJPOI"."COPERIODNUM">=:13
                  AND "PPRJPOI"."PATHELEM2"=:15 AND "PPRJPOI"."PATHELEM3"=:16 AND
                  "PPRJPOI"."COPERIODNUM"<=:14)
           filter("PPRJPOI"."PATHELEM3"=:16 AND "PPRJPOI"."PATHELEM2"=:15)
      11 - access("PPRJSUB"."BBASE"=:6 AND "PPRJSUB"."CONTROLLINGAREA"=:7 AND
                  "PPRJSUB"."COSTOBJTYPE"=:8 AND "PPRJSUB"."COSTOBJMAINPATH"="PPRJPOI"."COSTOBJMAINPATH"
                  AND "PPRJSUB"."COSTOBJSUBPATH"="PPRJPOI"."COSTOBJSUBPATH")
      13 - access("LSUPPLIER"."BBASE"(+)=:6 AND "LSUPPLIER"."LSUPPLIERNUM"(+)="PPRJPOI"."PLFT
                  NUM")Additional infos:
    Tablesize:
    PPRJPOI - 44.500.000 rows
    PPRJ - 7.013 rows
    PPRJSUB - 1.150.000 rows
    LSUPPLIER - 115.000 rows
    Used indexes:
    PPRJ_ORA4: index on PPRJ(BBASE, CONTROLLINGAREA, COSTOBJTYPE, COORGPATHELEM1, COORGPATHELEM2, COORGPATHELEM3 ,COORGPATHELEM4 , COORGPATHELEM5 , COORGPATHELEM6, COORGPATHELEM7, COORGPATHELEM8);
    PPRJPOI_ORA3: index on PPRJPOI(BBASE, CONTROLLINGAREA, COSTOBJTYPE, COYEARID, COPERIODNUM, PATHELEM2, PATHELEM3, PATHELEM4, PATHELEM5, PATHELEM6, PATHELEM7, PATHELEM8);
    PK_233: index on PPRJSUB(BBASE, CONTROLLINGAREA, COSTOBJTYPE, COSTOBJMAINPATH, COSTOBJSUBPATH);
    PK_177597: index on LSUPPLIER(BBASE, LSUPPLIERNUM);
    If I execute this statement I recieve a resultset which returns 5800 rows and takes about 70 seconds. Executing the same statement on DB2 returns the same number of rows but lasts only 15 seconds.
    I would really appreciate, if anybody can help me optimizing this statement so that the execution time will be equal to the DB2..
    Thanks in advance,
    Tobias Schmidt
    Edited by: tobiwan on Oct 31, 2008 1:01 PM

    tobiwan wrote:
    The statement we use is a prepared statement and the "?" are standing for the binding variables.
    I generated the explain plan by adding the prefix "explain plan for" to the statement and fetching the result by executing the statement "SELECT * FROM TABLE(dbms_xplan.display)". The plan table was created with the Oracle script ($ORACLE_HOME\RDBMS\ADMIN\utlxplan.sql).The cardinality estimates of the plan posted seem to be way off if you say that the statement returns 5,800 records, but since you're using bind variables the optimizer in the case of an "EXPLAIN PLAN" just applies default selectivities, like 1% for an equal comparison 5% for a range comparison etc.
    Note that you're using (a lot of) bind variables and therefore the output of EXPLAIN PLAN is only of limited help, because it doesn't/can't use the "bind variable peeking" that happens when the statement is actually executed.
    So you need to find out the actual execution plan(s) used at run time. You can use the convenient DBMS_XPLAN.DISPLAY_CURSOR function in 10g to obtain that information. You just need to find out the SQL_ID of your statement if it is cached in the Shared Pool, e.g. by searching the V$SQL* views available, or you can check V$SESSION if you know that the statement is currently being executed.
    You should check if you've histograms in place on the columns used with the bind variables, in a different thread I've provided already this useful blog note by the Pythian Group about this issue.
    http://www.pythian.com/blogs/867/stabilize-oracle-10gs-bind-peeking-behaviour-by-cutting-histograms
    Once you've obtained the actual execution plan(s, it could be multiple if you have histograms in place), post them here to find out if the cardinality estimates are still way off or what else could be the reason for the unexpected long execution time.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • TestStand Open SQL Statement does not support SQL's ORDER BY clause???

    TestStand 1.0.3
    Windows 2000 SP1
    SQL Server 2000 Personal
    You've got to be kidding me...
    It appears that the built-in TestStand Open SQL Step does NOT support the
    "ORDER BY" clause in the SELECT statement, even though the documentation
    says it does. Is this true?
    I have an Open SQL Statement query:
    "SELECT * FROM [MyTable] WHERE ([Batch ID]=1234)"
    it works fine, returning a correct record count 120 records. If I change
    the Open SQL Statement query simply by adding an ORDER BY clause, such as:
    "SELECT * FROM [MyTable] WHERE ([Batch ID]=1234) ORDER BY [MyField] ASC"
    it returns a record count of zero. I know that "MyField" exists in the
    MyTable table and contains valid data. The
    second query works fine in SQL
    Server Enterprise Manager.
    Am I missing something? Is it true that the TestStand Open SQL Step does
    NOT support the "ORDER BY" clause? If not, what &#$!ing good is it and why
    does the manual state it is supported? Is there any other way using just
    the TestStand steps to order a database recordset on one or more fields?
    Any help would be appreciated.
    Grrrrr....
    Bob Rafuse
    Etec Inc.

    > Bob -
    > The database step types do not do anything special to the SQL command
    > that you give it. The step just passes the command to the ADO
    > provider. I tried a simple query using the step types with the
    > following command,
    >
    > "SELECT UUT_RESULT.* FROM UUT_RESULT WHERE ([UUT_SERIAL_NUMBER] =
    > 12345) ORDER BY [EXECUTION_TIME] ASC"
    >
    > and this return the expected results and the record count parameter
    > was as expected. I tried this on TS 1.0.2 and TS 2.0 with MS Access
    > 2000 and MS SQL Server 7.0. I do not have MS SQL Server 2000 at this
    > time.
    >
    > It would be surprised if the step types are messing something up.
    I've been doing some experimenting over the past couple of days. Simple,
    one-table queries seem to handle the ORDER BY clause fine. Th
    ings seem to
    get messed up when I try multi-table queries with ORDER BY clause with the
    TestStand database steps. I get no errors but the returned record counts
    are always 0 with the ORDER BY and positive without the ORDER BY. The exact
    same queries work fine in Visual Basic/ADO and the SQL Server Query
    Analyzer.
    > Questions:
    > 1. Have you verified whether the data is actually returned even though
    > the record count is zero?
    Hmmm... yes data IS getting returned (at least on the two instances I just
    checked), but the record count is always zero. I was not proceeding with
    processing if the record count was 0.
    Still... I don't know how to loop through the recordset without knowing how
    many records there are an not eventually generate an error by passing EOF.
    Is there another way using the TestStand database steps to determine a) the
    number of records in the recordset or b) when I'm at EOF?
    > 2. Are you using any advanced options on the Opend SQL Statement step
    > type, specifically
    the cursor type set to forward only? Forward only
    > cursors do not allow for record counts.
    Everything on the Advanced tab of the Open SQL Statement step is set to "Use
    Default".
    Bob.

  • INSERT Script stored as "SQL Statement Script" not firing on Oracle Alert

    We are using Alert Manager to run Alerts based on absence information in EBS R12.1.3 HR tables.
    Application: Human Resources
    Period/Event: Periodic
    Frequency: Every Day
    The Alert has 2 actions.
    One is to email a supervisor based on the Alert SQL finding staff who have had x number of absences over a set period of time.
    That is working fine.
    The other action is defined as an "SQL Statement Script".
    The SQL script inserts the variables defined in the SQL from the main Alert definition SQL, into a custom table.
    When the Alert fires, we are getting the email generated, but the INSERT statement isn't firing.
    However, when we look at the result of the Alert when it has run, and look at the steps which were fired, we can see the email step and the SQL step. When we look at the SQL in the SQL step which was generated, we can copy and paste it direct into TOAD and it works fine.
    We have tried a simple SQL INSERT statement which even just does:
    INSERT INTO xx_tmp (VALUE1_DATE, VALUE2) VALUES (SYSDATE, 'this');
    But even that does not work.
    We wonder if the issue is that we cannot do a direct INSERT from an alert type of "SQL Statement Script"?
    We have found another Alert which does a direct UPDATE on a table, but the SQL Statement Script definition has "Purchasing" as the Application, because it's updating a PO table.
    In our case, we're trying to insert into a custom table held in our in-house XX schema.
    Could the problem be that we don't have the "Application" set? If that's the case, we don't have a corresponding application anyway.
    Or can we not do a direct INSERT like this - do we need to use a package instead, and call that?
    Any advice much appreciated.
    Thanks

    Hi Brian,
    Alert issue - Custom SQL fix
    1. Define actions via "Actions" button on Alert Definition
    2. Create an action for e.g. "Send Message to Supervisor"
       Action type: message
       Action - sends email to people
    3. Create another action called e.g. "Insert Record"
       Action type: SQL Statement Script
       Fill in SQL in the "Text" section, no need to add a begin or end bit, just a simple INSERT INTO X etc ending with a semi colon
    4. Back on the main alert definition window, go to "Action Sets" button
       Here, need one SEQ for the Message / Email (e.g. Seq 1), and then click on "Action Set Details" and click on "Members" tab and select the "Send Message to Supervisor" Action
       Then close the "Action Set Details" window, and return to the "Action Sets" window
       click into 2nd line, add e.g. Seq 2, and call it e.g. "Insert Record", click on "Action Set Details" > Members tab and select the "Insert Record" The problem was that in the first instance, we had a single Action Set, and under "Members" had selected the "Send Message to Supervisor" and "Insert Record" at the same time.
    Short answer: each Action needs to be defined as a separate line in the Action Sets definition.
    I can send screenshots if you need them, and don't mind putting your email address on this forum.
    You can always edit the thread after I've emailed you, to remove your email address.

  • In audit few statemntns SQL statements is not populating

    Hi,
    I enable audit,for few (SELECT,CREATE TABLE)statements audit not populating sqltext in sys.aud$.But i can see few more SELECT&CREATE TABLE activityit populates SQLTEXT.
    if it not populates sql text ,what ll be the reason behind this?

    Thank you for quick reply, Joe!
    Yes, I meant the second option with '%' symbols but still I get incorrect results. Seems that OpenSQL layer ignores the 'NOT LIKE' criterias. Any other ideas?
    I'm pasting you the log I have with the JPQL and the prepared SQL queries
    <query jpql="select distinct e, e.time.srvrStrInitTime from SlAutoGeneral e where e.status not like :status order by e.time.srvrStrInitTime desc ">
        <executeQuery>
            <prepare sql="SELECT DISTINCT E.ID E_ID_id,E.STATUS E_STATUS_status,E.SYNTH_SUBJECT E_SYNTH_SUBJECT_synthSubject,
              ALIAS_1.SRVR_STR_INIT_TIME DISPLAY_2
              FROM SL_AUTO_TIME ALIAS_1, SL_AUTO_GENERAL E WHERE ALIAS_1.ID = E.ID AND E.STATUS NOT LIKE ? ORDER BY DISPLAY_2 DESC"/>
    Best regards,
    Martin

  • Iif() sql statement is not working please help. An expression of non boolean type specified the context

    the following sql is not working . If  sum(salary) = null   should be displayed  1 or 0
    select empname,iif((isnull(sum(salary),0)),1,0) from salary group by empname
    regards
    Pol
    polachan

    I think what you're looking at is this
    select e.empname,
    COALESCE(s.totalsal,0) as salary
    from employee e
    left join (select empname,sum(salary) as totalsal
    from salary
    group by empname
    )s
    on s.empname = e.empname
    where employee represents your master table containing employee information
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Auditing: Flushing SGA to ensure SQL statement is not cached

    Currently I'm experimenting with Oracle auditing and have noticed that when I audit an object, like a table (AUDIT SELECT ON MY_TABLE), the select on the table is audited only once per session. I.e. When a user connects, and does:
    SQL> select * from my_table;
    SQL> ..
    SQL> ..
    SQL> select * from my_table;
    SQL> ..
    SQL> ..
    .. only the first select statement is audited. I have to reconnect each time for the statement to be audited.
    Is this how auditing works? I was thinking that it could be that the statement is held in memory and when a user does another subsequent select statement, the statement is cached and thus not audited. Could this be the case? I flushed the SGA and I still got the same results above...
    I'd like to hear your opinions about this.

    Raj has provided the solution but I would like to point out that auditing selects by access can generate an alful lot of audit records very quickly. The sys.aud$ table and its index may grow very, very large and fill the system tablespace if you are not careful. Also the updates to sys.aud$ are logged so you will also be generating a lot of extra redo if you make this type of auditing widespread.
    IMHO -- Mark D Powell --

  • 'lag' works in normal SQL statement, but not when in a view (resolved)

    hi,
    got a problem when using 'lag' in a view.
    if i set up a select statement using 'lag' and execute it, all the results are correct.
    when i stick the exact same select into a view, then the results for the 'lag' entries are not correct any more.
    has anyone experienced this ?
    any hints would be good.
    thanks
    Martin
    using Oracle 10g Express
    version 10.2.0.1.0
    can not download the patch because i can not log into metalink - no CSI
    setting to resolved.
    Message was edited by:
    user614086

    Hi again,
    I think the problem is more with your expectation of what LAG should be doing than with LAG itself.
    LAG must calculate based on the result set, in your stand alone query that means what's left after the WHERE clause is applied.
    In the view that means across all rows the view produces. THEN you apply the where clause to the calculated values. You can see this in the example below.
    So what you'd need to do is define this view in a manner in which the WHERE clause won't make a difference to the logical window produced.
    That would mean using some columns in the partition by clause and order by clause, or leaving the lag function outside the view.
    create table test_lag (column1 number, column2 varchar2(10), column3 date);
    insert into test_lag values (1, 'ONE', trunc(sysdate,'DD') - 1);
    insert into test_lag values (2, 'TWO' trunc(sysdate,'DD') );
    insert into test_lag values (3, 'THREE', trunc(sysdate,'DD') + 1);
    insert into test_lag values (4, 'FOUR', trunc(sysdate,'DD') + 2);
    commit;
    create or replace view test_lag_v
    as
    select column1, column2, lag(column2, 1) over (order by column1 asc) AS laggery, lag(column1) over (order by column3 desc) as laggery_2
    from test_lag;
    ME_XE?select *
      2  from test_lag_v
      3  where column1 <> 3;
               COLUMN1 COLUMN2                        LAGGERY                                 LAGGERY_2
                     4 FOUR                           THREE
                     1 ONE                                                                            3
    2 rows selected.
    Elapsed: 00:00:00.50
    ME_XE?
    ME_XE?select *
      2  from test_lag_v;
               COLUMN1 COLUMN2                        LAGGERY                                 LAGGERY_2
                     4 FOUR                           THREE
                     3 THREE                          ONE                                             4
                     1 ONE                                                                            3
    3 rows selected.
    Elapsed: 00:00:00.68

  • I need some help about Group by sql statement.

    Thank you for reading my post
    I am learning more sql and i have a question which is about HR schem.
    how i can show Departments.department_name in the following sql query?
    I want query to show department names along with department IDs.
    SELECT department_id dept_id, job_id, SUM(salary)
    FROM employees
    GROUP BY department_id, job_id ;thanks

    hi
    like this
    SQL> ed
    Wrote file afiedt.buf
      1  select d.department_id dept_id, d.department_name, e.job_id, sum(e.salary)
      2  from employees e, departments d
      3  where e.department_id = d.department_id
      4* group by d.department_id, d.department_name, e.job_id
    SQL> /
       DEPT_ID DEPARTMENT_NAME                JOB_ID     SUM(E.SALARY)
            10 Administration                 AD_ASST             4400
            20 Marketing                      MK_MAN             13000
            20 Marketing                      MK_REP              6000
            30 Purchasing                     PU_MAN             11000
            30 Purchasing                     PU_CLERK           13900
            40 Human Resources                HR_REP              6500
            50 Shipping                       ST_MAN             36400
            50 Shipping                       SH_CLERK           64300
            50 Shipping                       ST_CLERK           55700
            60 IT                             IT_PROG            28800
            70 Public Relations               PR_REP             10000
       DEPT_ID DEPARTMENT_NAME                JOB_ID     SUM(E.SALARY)
            80 Sales                          SA_MAN             61000
            80 Sales                          SA_REP            243500
            90 Executive                      AD_VP              34000
            90 Executive                      AD_PRES            24000
           100 Finance                        FI_MGR             12000
           100 Finance                        FI_ACCOUNT         39600
           110 Accounting                     AC_MGR             12000
           110 Accounting                     AC_ACCOUNT          8300
    19 rows selected.
    SQL>hope this helps
    Taj

  • User can Execute SQL Statement but not Stored Procedure

    I have a function in Access that calls a stored procedure to update a table. When I run it, it works fine but when the users try to run it, they get an error.
    If I change it run the actual SQL syntax that is in the stored procedure then the users can run it and update the table without any problems, which makes no sense to me. It's doing the same exact thing as the stored procedure. I'd much rather have them be
    able to run the procedures then writing the SQL in VBA modules because that's going to end up being a lot of code.
    Any idea on why it's like this and how to correct it? Any assistance would be appreciated.

    Hello,
    When you give a user permission to run a stored procedure, everything on that procedure but Dynamic SQL will be executed
    without evaluating user permissions on the objects the stored procedure deals with.
    On the link I provided above, you will see how to provide permissions to stored procedures. Try creating database roles, add user to database roles, then assign permissions to database roles.
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • Fetching SQL statements is not supported for this report.

    Post Author: Adam20002
    CA Forum: .NET
    I am using the following code to try and get the SQL string of a report in code. This works for all our reports apart from one which gives us the above error message. The code we are using is as follows:-
    rptDoc.ReportClientDocument.RowsetController.GetSQLStatement(Nothing)
    Can anyone give me any clues as to why this works for all the other reports and what i might need to check for this one particular report. There is noting special about the report it just gets detials from a few tables, no supreports, fancy formulas or anything.

    Post Author: Adam20002
    CA Forum: .NET
    I am using the following code to try and get the SQL string of a report in code. This works for all our reports apart from one which gives us the above error message. The code we are using is as follows:-
    rptDoc.ReportClientDocument.RowsetController.GetSQLStatement(Nothing)
    Can anyone give me any clues as to why this works for all the other reports and what i might need to check for this one particular report. There is noting special about the report it just gets detials from a few tables, no supreports, fancy formulas or anything.

  • Sql statement does not give require output

    Hi Guys,
    i have created two tables, tables data and required output are given below: any help would be highly appretiated:
    {code}
    create table tt (keyword varchar2(250))
    insert into tt ('Smith')
    insert into tt ('Walker')
    create table a (name_a varchar2(250), name_b varchar2(250))
    insert into a ('Smith Walker','Walker Smith');
    insert into a ('Adam Webster','Steve David');
    insert into a ('SmiGavin Walker'  ,'James Smith');
    insert into a ('Trever Michael ','Andy Walker');
    insert into a ('James Walton' ','Smith Thomas');
    select * from a, tt b where instr(a.name_a, b.keyword)=0 and instr(a.name_b,b.keyword)>0
    Trever Michael Andy Walker Walker
    Gavin Walker James Smith Smith
    James Walton Smith Thomas Smith
    Required output
    I want output where all name_a column should not have keyword, on the other hand, all name_b should have keyword
    Trever Michael Andy Walker Walker
    James Walton Smith Thomas Smith
    *************"Gavin Walker James Smith Smith" this one should not come as it has Walker in NAme_a which is forbidden, please can anyone help how to fix this issue.
    {/code}
    Best Regards,
    Zaid

    Try this
    SELECT KEYWORD, NAME_A, NAME_B FROM TT, A
    WHERE INSTR (NAME_A, KEYWORD) =0 AND INSTR (NAME_B, KEYWORD)>0
    AND NAME_A NOT IN (SELECT NAME_A FROM TT, A
    WHERE INSTR (NAME_A, KEYWORD) >0)

  • Using 'NOT IN' Within a SQL Statement

    Does anyone know why the following SQL statement does not return any values? The problem is with the SELECT statement within the 'NOT IN' clause. When explicitly typing in the part_ids returned from the select statement, everything works as expected.
    Thanks for any help.
    SELECT Distinct Part_Id, Trans_Date
         FROM Invctrl
         WHERE Trans_Type = 0
         AND Trans_Date BETWEEN To_Date( '1-Mar-2006 00:00:00', 'dd-mon-yyyy hh24:mi:ss' )
         AND To_Date( '31-Jan-2007 23:59:59', 'dd-mon-yyyy hh24:mi:ss' )               
         AND Part_Id NOT IN (SELECT part_Id From InvCtrl WHERE Trans_Date < To_Date( '1-Mar-2006 00:00:00', 'dd-mon-yyyy hh24:mi:ss'))

    'NOT IN' should be avoided where ever we can.
    Change your query to 'IN' clause as below and it should work.
    SELECT DISTINCT part_id, trans_date
               FROM invctrl
              WHERE trans_type = 0
                AND trans_date BETWEEN TO_DATE ('1-Mar-2006 00:00:00',
                                                'dd-mon-yyyy hh24:mi:ss'
                                   AND TO_DATE ('31-Jan-2007 23:59:59',
                                                'dd-mon-yyyy hh24:mi:ss'
                AND part_id IN (
                       SELECT part_id
                         FROM invctrl
                        WHERE trans_date BETWEEN TO_DATE ('1-Mar-2006 00:00:00',
                                                          'dd-mon-yyyy hh24:mi:ss'
                                             AND TO_DATE ('31-Jan-2007 23:59:59',
                                                          'dd-mon-yyyy hh24:mi:ss'
                       MINUS
                       SELECT part_id
                         FROM invctrl
                        WHERE trans_date <
                                 TO_DATE ('1-Mar-2006 00:00:00',
                                          'dd-mon-yyyy hh24:mi:ss'
    [pre]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Maybe you are looking for

  • Conky config question - running in multiple columns?

    Is it possible to display conky's output in rows rather than in columns? Example: I want to more or less cut my config in 1/2 and have the temps+ everything under them appear to the right of the CPU usage bit. # Swap Usage:$color $swapperc%${color li

  • When downloading itunes 11.1.4 I get a runtime error

    When downloading itunes 11.1.4 I get a runtime error and the program will not load. Has anyone had this problem?

  • Driver upda

    Can someone tell me what and where I can get an updated driver for my Sound Blaster card, I ran a trail program RadarSync. and it told me that I needed to update the driver for my Creative Audigy Audio Processor. I'm not sure what model # I have, onl

  • Call a VI whith the Run-Time Engine in TestStand

    Hi, I'm using TestStand 4.2.1. On the same PC I've installed LabVIEW Run-Time Engine 2009 (9), 2010, ... On another PC I developped a series of VI with LabVIEW 2010. My client want VI in the 2009 version, that's why I use a Run-Time Engine. I placed

  • ResultSet won't update

    I'm busy trying to write a database app (first time using java.sql). I use the jdbc:odbc bridge to connect to an Access 97 database (not my choice). Problem is I have written few thousand lines and have dialogs that can DISPLAY the data, but when I t