Trigger fails when variable used in WHERE statement

I have a trigger that works when the following statment is in it:
SELECT custcall.callrkey into v_callrkey from custcall where custcall.servno = 152345;
But the trigger fails when I attempt to use a variable in the where statement as follows.
SELECT custcall.callrkey into v_callrkey from custcall where custcall.servno = :new.servno ;
Even though I have verified that the value of :new.servno is set to 152345 by outputting the value . That is the only difference between the working version and the non-working version. By not working I mean that the email which is to be sent by the trigger is not received.
Can anyone give me any ideas of how I could troubleshoot this or what might me happening? I'm pretty new to this and
feel that I'm missing something very simple. My apologies in advance if this has been posted elsewhere. I did spend a lot of time searching the forum before posting.
This is Oracle 9i.
Thanks!
Full code probably not necessary but posted below just in case:
create or replace
TRIGGER EMAILNOTIFY_NEW_SR
AFTER INSERT ON CUSTPROB
FOR EACH ROW
DECLARE
--SMTP Variables
vreply utl_smtp.reply;
vreplies utl_smtp.replies;
mailCONN utl_smtp.connection;
mailHOST VARCHAR2(64) ;
--MESSAGE Variables
mailText VARCHAR2(64);
mailFROM VARCHAR2(64);
mailTO VARCHAR2(64);
mailDATE VARCHAR2(20);
v_servno number ;
v_callrkey number ;
--PROGRAM Variables
i number;
BEGIN
--get some values from the database  
--set values for variables...
mailHOST:= '10.35.173.15'; --this will always stay the same 
mailFROM := 'Facilities_Customer_Service_Center'; --this will always stay the same
mailTO := '[email protected]';
SELECT custcall.callrkey into v_callrkey from custcall where custcall.servno = :new.servno  ;
SELECT TO_CHAR(SYSDATE,'MM/DD/YYYY HH24:MI:SS') INTO mailDATE FROM dual;
dbms_output.put_line('open_connection');
dbms_output.put_line('---------------');
vreply := utl_smtp.open_connection(mailHOST, 25, mailCONN);
dbms_output.put_line('helo');
dbms_output.put_line('----');
vreply := utl_smtp.helo(mailCONN, mailHOST);
dbms_output.put_line( 'code = ' || vreply.code );
dbms_output.put_line( 'text = ' || vreply.text );
dbms_output.put_line('mail');
dbms_output.put_line('----');
vreply := utl_smtp.mail(mailCONN, mailFROM);
dbms_output.put_line( 'code = ' || vreply.code );
dbms_output.put_line( 'text = ' || vreply.text );
dbms_output.put_line('rcpt to');
dbms_output.put_line('----');
vreply := utl_smtp.rcpt(mailCONN, mailTO);
dbms_output.put_line( 'code = ' || vreply.code );
dbms_output.put_line( 'text = ' || vreply.text );
dbms_output.put_line('open_data');
dbms_output.put_line('---------');
vreply := utl_smtp.open_data(mailCONN);
dbms_output.put_line( 'code = ' || vreply.code );
dbms_output.put_line( 'text = ' || vreply.text );
--SMTP ENVELOPE STUFF (In case it is needed later).  
--utl_smtp.write_data(mailCONN, 'From:'  ||mailFROM     || chr(13));
-- utl_smtp.write_data(mailCONN, 'To: '||mailTo || chr(13));
--utl_smtp.write_data(mailCONN, 'CC:      '||mailFROM     || chr(13));
--utl_smtp.write_data(mailCONN, 'Date:    '||mailDATE     || chr(13));
--utl_smtp.write_data(mailCONN, 'BCC:     '||mailFROM     || chr(13));
--THE MESSAGE
utl_smtp.write_data(mailCONN, 'Subject: '||'Your Facilities Service Request ' ||'(SR '||v_servno||')'|| chr(13));
utl_smtp.write_data(mailCONN, '');
utl_smtp.write_data(mailCONN, '');
utl_smtp.write_data(mailCONN, 'Dear Customer ' || chr(13));
utl_smtp.write_data(mailCONN, '');
utl_smtp.write_data(mailCONN, 'This is to inform you of something.' || ' ' ||mailTO|| chr(13) );
utl_smtp.write_data(mailCONN, 'Please call us with any questions or concerns. ' || '' || chr(13));
--DEBUG
utl_smtp.write_data(mailCONN, 'DEBUG: ' || ''|| chr(13));
utl_smtp.write_data(mailCONN, 'v_Servno ' || v_servno || chr(13));
utl_smtp.write_data(mailCONN, 'v_callrkey ' || v_callrkey || chr(13));
--END THE MESSAGE
dbms_output.put_line('close_data');
dbms_output.put_line('----------');
vreply := utl_smtp.close_data(mailCONN);
dbms_output.put_line( 'code = ' || vreply.code );
dbms_output.put_line( 'text = ' || vreply.text );
dbms_output.put_line('quit');
dbms_output.put_line('----');
vreply := utl_smtp.quit(mailCONN);
dbms_output.put_line( 'code = ' || vreply.code );
dbms_output.put_line( 'text = ' || vreply.text );
END;

Justin,
Thanks for the reply. I'm away for a couple of days but when I get back to this I'm going to follow up on your suggestion about servno. I'm starting to think that the issue isn't with servno but rather that the select query doesn't return anything because the value I'm trying to get is in another table and is not being inserted in time for me to get them. This will be easiy enough to test. To be honest, I don't know very much about how things are being inserted.
I appreciate your and Tubby's (and Tom's) concerns. Maybe I'll go back to the drawing board next week. But note that I'm not inserting anything with this trigger--only sending an email based on the insert that is happening through an application. So unless I'm really missing it, my email is dependent on the insert but not vice versa. Since my email is absolutely critical but rather jus a courtesy thing, I was taking a pretty laid back attitude about it but it would be good for me to learn a better way.
Thanks again to all! I'll report back what I find/decide.

Similar Messages

  • How to create a Pooled VDI infrastructure using Win server 2012 as VM image?I have followed the "usual" way to build a pooled VDI desktop using Win7 or Win8 with success, but it fails when I use an image of Win Server 2012 as VM

    I have followed the "usual" way to build a pooled VDI desktop using Win7 or Win8 with success, but it fails when I use an image of Win Server 2012 as VM instead.
    Am I overlooking something?  Should I need to prepare the image in a different way? (Sysprep differently?)
    Thanks

    Hi,
    Thank you for your posting in Windows Server Forum.
    Can you specify the error which you are facing during VDI setup for server 2012?
    I might think that you need to check the memory setting for server 2012, as might happens that due to less memory you can’t setup the VDI setup properly. 
    Memory: If the Master VM is configured with static memory, it must have at least 1024 MB as startup RAM. If the Master VM is configured with dynamic memory, the maximum RAM must be at least 1024 MB.
    Please check beneath article for information.
    Windows
    Server 2012 2,500-user pooled VDI deployment guide (Doc)
    Single Image Management for Virtual Desktop Collections in Windows Server 2012
    Hope it helps!
    Thanks.
    Dharmesh Solanki

  • I have an sony vivaz, i want to upgrade the software. i had downloaded the upgradtion software. bUt it fails to upgrade, even it fails when i use phone repair in pc suit. What should i do?

    I have an sony vivaz, i want to upgrade the software. i had downloaded  the upgradtion software. bUt it fails to upgrade, even it fails when i  use phone repair in pc suit.
    What should i do?

    Hello @chavanjayesh2001... I wanted to give you some tips for when you can't update the software of your phone:
    -Make sure that the Internet connection is good. If the update process is interrupted it might be due to loss of Internet connection.
    -Try using another USB cable and usb port in your computer.
    -Try using another PC.
    -Temporary disable any firewalls and or antivirus software.
    -Start your PC in “Safe mode with networking” mode. This is done by pressing F8 during PC boot. When Windows is started in safe mode, try taking the update again.

  • Trigger function when variable a certain value?

    Hi
    I want a function to be triggered when a certain global var becomes true - I want to do this using an event listener.  I can do it as a one off using an if statement, but how do you set up a listener to trigger the function if the value becomes true at any time?
    Thanks guys
    Shaun

    Sorry kglad - I'm struggling to work this out.
    I've had a look at a few examples, but they don't make sense to me.
    I just want Flash to ....
    when globals.data.vari1 becomes true, gotoAndPlay(55);
    Could you please show me how this is done?
    Thanks in advance if you can help out.
    Cheers
    Shaun

  • Partition Pruning on Interval Range Partitioned Table not happening when SYSDATE used in Where Clause

    We have tables that are interval range partitioned on a DATE column, with a partition for each day - all very standard and straight out of Oracle doc.
    A 3rd party application queries the tables to find number of rows based on date range that is on the column used for the partition key.
    This application uses date range specified relative to current date - i.e. for last two days would be "..startdate > SYSDATE -2 " - but partition pruning does not take place and the explain plan shows that every partition is included.
    By presenting the query using the date in a variable partition pruning does table place, and query obviously performs much better.
    DB is 11.2.0.3 on RHEL6, and default parameters set - i.e. nothing changed that would influence optimizer behavior to something unusual.
    I can't work out why this would be so. It very easy to reproduce with simple test case below.
    I'd be very interested to hear any thoughts on why it is this way and whether anything can be done to permit the partition pruning to work with a query including SYSDATE as it would be difficult to get the application code changed.
    Furthermore to make a case to change the code I would need an explanation of why querying using SYSDATE is not good practice, and I don't know of any such information.
    1) Create simple partitioned table
    CREATETABLE part_test
       (id                      NUMBER NOT NULL,
        starttime               DATE NOT NULL,
        CONSTRAINT pk_part_test PRIMARY KEY (id))
    PARTITION BY RANGE (starttime) INTERVAL (NUMTODSINTERVAL(1,'day')) (PARTITION p0 VALUES LESS THAN (TO_DATE('01-01-2013','DD-MM-YYYY')));
    2) Populate table 1million rows spread between 10 partitions
    BEGIN
        FOR i IN 1..1000000
        LOOP
            INSERT INTO part_test (id, starttime) VALUES (i, SYSDATE - DBMS_RANDOM.value(low => 1, high => 10));
        END LOOP;
    END;
    EXEC dbms_stats.gather_table_stats('SUPER_CONF','PART_TEST');
    3) Query the Table for data from last 2 days using SYSDATE in clause
    EXPLAIN PLAN FOR
    SELECT  count(*)
    FROM    part_test
    WHERE   starttime >= SYSDATE - 2;
    | Id  | Operation                 | Name      | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT          |           |     1 |     8 |  7895  (1)| 00:00:01 |       |       |
    |   1 |  SORT AGGREGATE           |           |     1 |     8 |            |          |       |       |
    |   2 |   PARTITION RANGE ITERATOR|           |   111K|   867K|  7895   (1)| 00:00:01 |   KEY |1048575|
    |*  3 |    TABLE ACCESS FULL      | PART_TEST |   111K|   867K|  7895   (1)| 00:00:01 |   KEY |1048575|
    Predicate Information (identified by operation id):
       3 - filter("STARTTIME">=SYSDATE@!-2)
    4) Now do the same query but with SYSDATE - 2 presented as a literal value.
    This query returns the same answer but very different cost.
    EXPLAIN PLAN FOR
    SELECT count(*)
    FROM part_test
    WHERE starttime >= (to_date('23122013:0950','DDMMYYYY:HH24MI'))-2;
    | Id  | Operation                 | Name      | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT          |           |     1 |     8 |   131  (0)| 00:00:01 |       |       |
    |   1 |  SORT AGGREGATE           |           |     1 |     8 |            |          |       |       |
    |   2 |   PARTITION RANGE ITERATOR|           |   111K|   867K|   131   (0)| 00:00:01 |   356 |1048575|
    |*  3 |    TABLE ACCESS FULL      | PART_TEST |   111K|   867K|   131   (0)| 00:00:01 |   356 |1048575|
    Predicate Information (identified by operation id):
       3 - filter("STARTTIME">=TO_DATE(' 2013-12-21 09:50:00', 'syyyy-mm-dd hh24:mi:ss'))
    thanks in anticipation
    Jim

    As Jonathan has already pointed out there are situations where the CBO knows that partition pruning will occur but is unable to identify those partitions at parse time. The CBO will then use a dynamic pruning which means determine the partitions to eliminate dynamically at run time. This is why you see the KEY information instead of a known partition number. This is to occur mainly when you compare a function to your partition key i.e. where partition_key = function. And SYSDATE is a function. For the other bizarre PSTOP number (1048575) see this blog
    http://hourim.wordpress.com/2013/11/08/interval-partitioning-and-pstop-in-execution-plan/
    Best regards
    Mohamed Houri

  • Offline backup failing when scheduled using DB13

    Hi,
               We have done our backup schedule of our BI 7 system running on AIX 5.3 and Oracle 10.2 using DB13.The activities like online backup and datbase check is executing correctly but offline backup is failing with status unknown.
    If i check in sm37 for the DBA job offline backup is showing status completed successfully but in brbackup logs there is no log for the offline backup activity.
    Kindly provide your suggestion on how i can resolve this issue.

    Hi Ammey,
                   Thanks for your reply.
    When I trigger the backup directly from brtools offline backup is happening successfully.The issue is happening only for the db13 scheduled offline backup.The same thing happened for Update statistics but check db is executed.
    So what has to be checked in backint settings pls provide you suggestion.
    rgds,
    vinayak

  • I was wondering how come my Acrobat 6.0 Professional Standard before I had no problem now when I use it it states the program has compatibility issues, I have windows 7 what can I do..it was working before

    I am looking for help in correcting this issue... I had no problem before using my Acrobat 6.0 professional to create word documents to pdf...now when I go to use it there seems to be a problem
    it states that the program has compatibility issues with window 7
    can anyone help please.

    To expand on this, the PDF creation aspect of Acrobat  had to be updated to deal with changes in the Windows spooling system (for the Adobe PDF PostScript printer driver instance) as well as to support 64-bit versions of Windows.
              - Dov

  • Failed when add using ldapadd command

    Hi
    I have two directory server located at UAT and development
    when i run "ldapadd -D "cn=Directory Manager" -w password -f somefile.ldif " on my DEVELOPMENT Server
    it ran through and records get added to the directory server
    However when i run the same command on mu UAT server pointing to directory server sitting on that server it always gives me
    "Invalid Format : ldapadd"
    After further checking i found that some attribute value are null example as below
    dn: uid=lala,o=us.com
    mail: [email protected]
    address:Because of address attribute is null the directory server in uat always complaining that i cannot add this entry
    the confusing part is it ran successfully in my development
    i checked both directory server and both are having schema checking disabled mode?
    Is there any particular configuration that specify the attribute value cannot be null or something?
    Thanks

    what do u meant by that?
    but i can still run ldapadd in my UAT Server box and the Solaris OS does not complain
    I tested using ldapmodify -a it still gives me something like below
    ldapmodify: invalid format (line 3 of entry: uid=leerongl1, ou=Users, o=yes.com.sg)
    ldapmodify: invalid format (line 3 of entry: uid=teokailo1, ou=Users, o=yes.com.sg)After i checked the entry in my ldif file. it appears some attribute have some null value for example
    dn: uid=yennyng1, ou=Users, o=yes.com.sg
    roomNumber: h
    givenName: Yenny Ng
    mobile: 93475786
    objectClass: top
    objectClass: person
    objectClass: organizationalPerson
    objectClass: inetOrgPerson
    objectClass: users
    facsimileTelephoneNumber:78964
    ou: Sales Admin
    uid: yennyng1
    mail:
    cn: user
    groups: SYS ADMIN
    telephoneNumber: 8
    pager: 8765
    o: TPC
    sn: Ng
    warehouseid: 111
    warehouseid: 144
    warehouseid: 145
    warehouseid: 147
    warehouseid: 153
    warehouseid: 188
    warehouseid: 191
    personalTitle: Ms
    title: Admin Assistant
    userPassword: {SHA}jhnnaUUCK2fR/e8HvQKVxUaTDyY=As you can see mail attribute have some null value..
    After i enter/fill in that attribute and i run it again. it ran okay.
    So i was wondering if there is any constraint on attribute when we import to directory server and how to disable them?
    Thanks

  • Find the views where is used a "WHERE" statement

    Hello,
    I know that it is possible to search in a view with CTRL+F but is there also an option to search in al the views from a database for a statement in 1 step (not open each view)
    It will save a lot of time in my case
    Thanks
    for a reply

    Can you try this
    SELECT sm.object_id, OBJECT_NAME(sm.object_id) AS object_name, o.type, o.type_desc, sm.definition
    FROM sys.sql_modules AS sm
    JOIN sys.objects AS o ON sm.object_id = o.object_id
    where type='V' and definition like '%where%'
    ORDER BY o.type;
    --Prashanth

  • Scp works when logging with my user id but fails when using another one

    Hello all:
    I wrote a script that uses scp to transfer specific local files to a server. The script takes the user id and password and pass them as scp's parameters for authentication.
    Everything works fine when I uses my own user id to test the script but it fails when I used another id (with ligitimate password) to do the same thing.
    I suspect it's a privilege issue. Both ids belong to the same group. Where should I look to fingure this out?
    Thanks,
    John

    SCP is part of SSH. SSH requires the exchange of authorization keys to prevent man-in-the-middle attacks.
    When you log in the first time you may see a prompt like:
    RSA key fingerprint is 98:2e:d7:e0:de:9f:ac:67:28:d2:42:2e:37:16:58:45.
    Are you sure you want to continue connecting (yes/no)?
    This might be where your script fails. Since it prompts only the first time, you may just have to do one interactive SSH login to create an entry in ~/.ssh/known_hosts
    Or setup User equivalence to omit the exchange of passwords.
    You may find the following interesting:
    Oracle Linux 5 Howto: Installing and using cURL with support for SCP and SFTP
    OL5 Howto: Installing and using cURL with support for SCP and SFTP
    see 3) Set up SSH user equivalence for SCP and SFTP

  • Not right data when row_number used in inner-view sql query...

    Hi ,
    I use the below sql statement which displays the right data
    select CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE , SUM_POSOTITA , row_number() over(partition by code_farmakou order by sum_posotita desc) from
      (SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES ,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_AT_SINT_CLINIC A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
      UNION ALL
      SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_AT_SINT_EX_IATR A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
      UNION ALL
      SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_AT_SINT_FOREON_MS A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
      UNION ALL
      SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_GEN_SINT_KLIN A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
      UNION ALL
      SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_GEN_SINT_EX_IATR A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS)The data are:
    CODE_FARMAKOU                            EMP_NAME                                                                         PACKTYPE                     PACKSIZE                  SUM_POSOTITA ROW_NUMBER()OVER(PARTITIONBYCO
    0000002419                               FACTREL INJECTION                                                                VIAL                         2 ML                                 5                              1
    0000014071                               DOPAMINE HYDROCHLORIDE                                                           VIAL                         5 ML X 25                           30                              1
    0000086289                               DETUSSIN EXPECTORANT                                                             BOT                          120 ML                               3                              1
    1000000760                               DEPON                                                                            BT                           20(BLIST2X10)                        2                              1
    1000000760                               DEPON                                                                            BT                           20(BLIST2X10)                        1                              2
    1000003279                               MOXACEF                                                                          BT                           40(BLIST10X4)                       45                              1
    1000003279                               MOXACEF                                                                          BT                           40(BLIST10X4)                        1                              2
    1000003279                               MOXACEF                                                                          BT                           40(BLIST10X4)                        1                              3
    1000014127                               DEPON VIT. C                                                                     BT                           2TUBX10                              6                              1
    1000014127                               DEPON VIT. C                                                                     BT                           2TUBX10                              2                              2
    1000016655                               KABIVEN                                                                          BT                           50ÖÕÓ.×1,7ML                        21                              1
    1000016655                               KABIVEN                                                                          BT                           50ÖÕÓ.×1,7ML                         2                              2However , when i use the below statement , in order not to display the row_number (so i use row_number function in inner-view) the data are different--in different order... why is that????
    select CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE , SUM_POSOTITA from
    select CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE , SUM_POSOTITA , row_number() over(partition by code_farmakou order by sum_posotita desc) from
      (SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES ,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_AT_SINT_CLINIC A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
      UNION ALL
      SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_AT_SINT_EX_IATR A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
      UNION ALL
      SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_AT_SINT_FOREON_MS A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
      UNION ALL
      SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_GEN_SINT_KLIN A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
      UNION ALL
      SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_GEN_SINT_EX_IATR A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS)
      )and its data are:
    CODE_FARMAKOU                            EMP_NAME                                                                         PACKTYPE                     PACKSIZE                  SUM_POSOTITA
    1000016655                               KABIVEN                                                                          BT                           50ΦΥΣ.Χ1,7ML                        21
    1000016655                               KABIVEN                                                                          BT                           50ΦΥΣ.Χ1,7ML                         2
    1000000760                               DEPON                                                                            BT                           20(BLIST2X10)                        2
    1000014127                               DEPON VIT. C                                                                     BT                           2TUBX10                              2
    1000003279                               MOXACEF                                                                          BT                           40(BLIST10X4)                       45
    0000014071                               DOPAMINE HYDROCHLORIDE                                                           VIAL                         5 ML X 25                           30
    0000086289                               DETUSSIN EXPECTORANT                                                             BOT                          120 ML                               3
    1000014127                               DEPON VIT. C                                                                     BT                           2TUBX10                              6
    1000003279                               MOXACEF                                                                          BT                           40(BLIST10X4)                        1
    1000003279                               MOXACEF                                                                          BT                           40(BLIST10X4)                        1
    0000002419                               FACTREL INJECTION                                                                VIAL                         2 ML                                 5
    1000000760                               DEPON                                                                            BT                           20(BLIST2X10)                        1NOTE :Sorry, I tried to pose some sample data using the "with" statement but i couldn't...the error ORA-32035 : unreferenced query name defined in WITH clause was displayed..
    Regards,
    Simon

    The optimizer has, well, optimized out the row_number because you never refer to its value in the outermost query.
    sql>select deptno, cnt, row_number() over (order by cnt desc) rn
      2    from (select deptno, count(*) cnt
      3            from emp
      4           group by deptno);
       DEPTNO       CNT        RN
           30         6         1
           20         5         2
           10         3         3
    3 rows selected.
    -- here because we include rn in the outermost query,
    -- the results are still ordered based on the analytical function result
    sql>select deptno, cnt, rn
      2    from (select deptno, cnt, row_number() over (order by cnt desc) rn
      3            from (select deptno, count(*) cnt
      4                    from emp
      5                   group by deptno));
       DEPTNO       CNT        RN
           30         6         1
           20         5         2
           10         3         3
    3 rows selected.
    -- but if we don't include rn in the outermost query,
    -- the optimizer leaves out the window sort and the results are in a different order
    sql>select deptno, cnt
      2    from (select deptno, cnt, row_number() over (order by cnt desc) rn
      3            from (select deptno, count(*) cnt
      4                    from emp
      5                   group by deptno));
       DEPTNO       CNT
           10         3
           20         5
           30         6
    3 rows selected.This just reinforces the point that if you want your results in a particular order, you need to provide an ORDER BY clause - don't rely on execution plans to do your sorting for you.

  • How to use a select statement with chinese characters?

    I am currently developing a java servlet<using tomcat 4.x> which allows me to use select statement to retrieve results from the Microsoft SQL Server 2000 database. I am using a simple form to get the parameter for querying. The main problem i'm facing is that there are chinese information in the SQL database, but i can't retrieve it through the sql statement with the chinese characters input<thru the form with the help of NJ STAR>in the WHERE condition. When i execute the statement, it returns me no results even though the rows are present in the database.
    Does anyone have the solution to using chinese words in the WHERE clause of the select statement to retrieve results with columns which contains chinese characters? Please help me. Thanks everyone. :)
    PS: when i cut and paste those characters in the sql database and paste onto java.. it is ??? in questionmarks.. but when i paste them into excel 2000.. its shown as chinese chars again..
    please heelppp~~

    Greetings,
    PS: when i cut and paste those characters in thesql
    database and paste onto java.. it is ??? in
    questionmarks.. but when i paste them into excelThis is why the SELECT is not returning any results.
    You need to set the character encoding set on your
    statement and parameters for the characters to be
    properly translated. Refer to the charsetName
    parameter in the String class constructor in your API
    docs and also to
    $JDK_DOCS/guide/intl/encoding.doc.html in your JDK
    documentation.
    2000.. its shown as chinese chars again..Because Office programs are performing the same kind
    of character translation with the appropriate MS APIs.
    please heelppp~~Regards,
    Tony "Vee Schade" Cookis it possible for you to show me some coding examples? i don't really understand what is to be done in order to set the char set and what does it really do.. tried reading up but still dun understand.. :(
    pardon my shallow knowledge of java..
    ok..
    The thing is when i used an insert statement with chinese characters of GBK format hardcoded into the java servlet and then i use the insert statement to insert the chars into the database, it cannot be seen as a chinese word when i off the NJStar. and then it can be searched out with my current form of servlet.. below is my coding of the servlet..
    note: i've set my html file to charset = GBK
    //prototype of Search engine...
    //workable for GBK input and output...
    import java.io.*;
    import java.io.OutputStream;
    import java.io.IOException;
    import javax.servlet.http.*;
    import javax.servlet.ServletException;
    import java.util.*;
    import java.sql.*;
    import java.nio.charset.Charset;
    public class SearchBeta extends HttpServlet {
         private Vector musicDetails = new Vector();
         private String query = "";
         public void service (HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException, UnsupportedEncodingException {
              query = req.getParameter ("T1");
              System.out.println("before:"+query);
              String type = req.getParameter ("D1");//type
              query = req.getParameter ("T1");
              //query = "������";
              System.out.println("after:"+query);
              getResults(type,query);
              System.out.println("locale = :"+req.getLocale());
              res.setContentType ("text/html;charset=GBK");
              PrintWriter out = res.getWriter();
              out.println("<html>");
              out.println("<head>");
              out.println("<body bgcolor = \"black\">");
              out.println("<font face = \"comic sans ms\" color=\"Cornsilk\">");
              if (query.length()==0)
                   out.println ("Please key in your search query.");
              else if (musicDetails.size()==0)
                   out.println ("Sorry, no results matching your search can be found.");
              else {
                   out.println("<center>");
                   out.println("<table cellspacing = \"50\">");
                   int i = 0;
                   //Display the details of the music
                   while (i<musicDetails.size()) {
                        Results details = (Results)musicDetails.get(i);
                        String dbArtist = "";
                        String dbAlbum = "";
                        String dbTitle = "";
                        String dbCompany = "";
                        dbAlbum = details.getAlbum();
                        dbTitle = details.getTitle();
                        dbCompany = details.getCompany();
                        dbArtist = details.getArtist();
                        try{
                             dbAlbum = new String(dbAlbum.getBytes("ISO-8859-1"),"GBK");
                             dbTitle = new String(dbTitle.getBytes("ISO-8859-1"),"GBK");
                             dbCompany = new String(dbCompany.getBytes("ISO-8859-1"),"GBK");
                             dbArtist = new String(dbArtist.getBytes("ISO-8859-1"),"GBK");//correct translation.
                        catch(UnsupportedEncodingException e){
                             System.out.print(e);
                             e.printStackTrace();
                        String dbImage_loc = details.getImage();
                        out.println("<tr>");
                             out.println("<td><table>");
                                  out.println("<img src=C:\\Program Files\\Apache Group\\Tomcat 4.1\\webapps\\examples\\ThumbNails\\"+dbImage_loc+">");
                             out.println("<tr>");
                                  out.println("<th><font color=\"violet\"> Artist: </font></th>");
                                  out.println("<td><font color=\"Cornsilk\">"+dbArtist+"</font></td>");
                             out.println("</tr>");
                             out.println("<tr>");
                                  out.println("<th><font color=\"violet\"> Title: </font></th>");
                                  out.println("<td><font color=\"Cornsilk\">"+dbTitle+"</font></td>");
                             out.println("</tr>");
                             out.println("<tr>");
                                  out.println("<th><font color=\"violet\"> Company: </font></th>");
                                  out.println("<td><font color=\"Cornsilk\">"+dbCompany+"</font></td>");
                             out.println("</tr>");
                             System.out.println("album: "+ dbAlbum);
                             out.println("<tr>");
                                  out.println("<th><font color=\"violet\"> Album: </font></th>");
                                  out.println("<td><font color=\"Cornsilk\">"+dbAlbum+"</font></td>");
                             out.println("</tr>");
                             System.out.println("company: "+ dbCompany);
                             out.println("</table></td>");
                        out.println("</tr>");
                        i++;
                   out.println("</table>");
                   out.println("</center>");
              out.println("</font>");
              out.println("</body>");
              out.println("</head>");
              out.println("</html>");
              out.close();
              //to remove all the elements from the Vector
              musicDetails.removeAllElements();
         //get Searched Music Details and store in Results object which is stored in musicDetails vector
         public void getResults (String type, String searchQuery) {
              try {
                   Class.forName ("com.microsoft.jdbc.sqlserver.SQLServerDriver");
                   Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=music","sa","kokkeng");
                   Statement stmt = con.createStatement();
                   String query = "SELECT * FROM MusicDetails WHERE "+type+" = '"+searchQuery+"'";
                   ResultSet rs = stmt.executeQuery(query);
                   while (rs.next()) {
                        String artist = rs.getString("Artist");
                        String title = rs.getString("Song");
                        String company = rs.getString("Company");
                        String album = rs.getString("Album");
                        String image_loc = rs.getString("Image");
                        Results details = new Results (artist,title,company,album,image_loc);
                        musicDetails.add(details);
                   stmt.close();
                   con.close();
              catch (Exception e) {
                   System.out.println(e.getMessage());
                   e.printStackTrace();
    with the above servlet i created, i can search out the data in the database which i've inserted through the insert statement. I still can't search for things i've keyed into the database directly using NJStar..
    thank you so much for helping.. really hope any one else who knows the answer to this will reply too... thank you all so much...
    -KK

  • EOFException when deserializing object in if statement

    Hi,
    I'm a java newbie and I've got a program in which I've got an method to open a serialized file.
    I am running into problems when determining the class of the object to be deserialized.
    When the code is as such everything works fine:
        ObjectInputStream ois;
        protected void open() {
            int returnVal = fc.showOpenDialog(this);
         if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                try {
                 ois = new ObjectInputStream(new FileInputStream(file));     
              frameSeqA72 = (SeqA72) ois.readObject();
              getContentPane().add(frameSeqA72);
              frameSeqA72.setVisible(true);
              ois.close();                                                                                                           
             catch (IOException ioe) {ioe.printStackTrace();}
             catch (ClassNotFoundException cnfe) {}     
        }For some reason I don't understand everything changes when I use an if statement in the code as follows:
        ObjectInputStream ois;
        protected void open() {
            int returnVal = fc.showOpenDialog(this);
         if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                try {
                 ois = new ObjectInputStream(new FileInputStream(file));     
              if (ois.readObject() instanceof SeqA72) {
                  frameSeqA72 = (SeqA72) ois.readObject();
                  getContentPane().add(frameSeqA72);
                  frameSeqA72.setVisible(true);
                  ois.close();                                                    
             catch (IOException ioe) {ioe.printStackTrace();}
             catch (ClassNotFoundException cnfe) {}     
        }An EOFException is thrown when this method is called -
    "EOFException at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1267)..."
    My serialized objects are of different classes so I want to determine the class before casting...so Im using "if (ois.readObject() instanceof SeqA72)".
    Why would the first version work and the second throw an exception?
    Am I going about this in a bad way?
    Casey

    You're calling readObject twice, so it's trying to read two objects.
    Read it once and save a reference in a variable. Use that variable, instead of calling readObject again.

  • Project wont run when I use nextInt()

    Has anyone had the problem where when they use nextInt() where the project never runs? I run the project without the nextInt() statements and it builds then runs fine. However when I put in the nextInt() the project just shows that it is building, and never runs. Anyone know whats up?

    The exact code runs fine in jGrasp. When I try to run it in JSE this is what i get....
    init:
    deps-jar:
    compile:
    run:
    and at the bottom it says building Wages(run)...
    import java.util.Scanner;
    import java.text.NumberFormat;
    public class Wages {
        /** Creates a new instance of Wages */
        public Wages() {
        public static void main(String[]args){
            final double RATE = 8.25;
            final int STANDARD =40;
            Scanner scan = new Scanner (System.in);
            double pay = 0.0;
            System.out.print ("Enter the number of hours worked: ");
            int hours = scan.nextInt();
            System.out.println();
                if(hours>STANDARD)
                pay= STANDARD*RATE + (hours-STANDARD) * (RATE*1.5);
                else
                pay = hours * RATE;
                NumberFormat fmt = NumberFormat.getCurrencyInstance();
                System.out.println("Gross earnings: "+fmt.format(pay));
                }

  • Trigger failed ?

    I wrote a trigger on "Logon on database" to call a procedure on every login/session is changed. Its working when i login with DBA. But trigger failed when i change session to SCOTT or other users who has no DBA role.
    My trigger code is:
    SQL> create or replace trigger logtrig after logon on database
              call myproc(parameters)
    SQL>connect  sys/xxxxxxxx            ---- its ok
    SQL>connect  myora/xxxxxxxxx      ----- its ok  (myora is dba)
    but when i connect to :
    SQL> conn scott/tiger
    ERROR:
    ORA-04098: trigger 'SYS.LOGONTRIG' is invalid and failed re-validation
    Warning: You are no longer connected to ORACLE. ---What is the reason?

    Until the trigger either compiles successfully or is dropped, users without the DBA role will not be able to logon to the database.
    By default, only the SYS and SYSTEM users are granted the DBA role.

Maybe you are looking for

  • Need to add text to a field in ALV_GRID

    Hi guys, I am working on a ALV_GRID report where I have a requirement...I have one field which is for debit and credit indicator, so what I have to do is ..if field has got 'A' in it then I need to print 'Yes' in this particular filed in the output a

  • Opening PDF in Preview

    Hi, In pages, when you open the print dialogue there is a PDF button. The top item on the list is: Open PDF in Preview. Clicking this used to do just that, open the document in preview. After updating to Snow Leopard, it now opens in Adobe Acrobat. I

  • I wan to restore my phone, will all my photos and music be lost how do i save it

    If i restore my phone will all my photos and music be lost, how do I back it up?

  • Min with group by

    i want to find the min(date) on a table using a select query that uses a group by, but i want to find the min(date) on the table and not the values grouped by. example col1 col2 1 10/04/07 2 11/04/07 1 09/04/07 4 04/04/06 want something like this sel

  • E-mail event generator errors

    We've done many different channels and not had many problems however, we've been experiencing problems when creating Email event generators that publish on a message broker channel and there's not a decent example in the documentation. The errors are