Need Help UTF8, Special Characters Conversion/Translate

Hi All,
I have requirement to cleanup special character of field.
The data which is retrieved from the field and written to text file.
So Here
HÃ-re - I need value Hire(actual value) from the filed.
Ã- this has written into file instead of i
In database i have
NLS_NCHAR_CHARACTERSET - AL16UTF16
NLS_CHARACTERSET - UTF8
I tried
select convert('HÃ-re','UTF8') from dual
Output: H??re
Can any one please provide me a solution.
Thanks,
Edited by: user8822881 on Nov 3, 2010 6:33 PM

user8822881 wrote:
Hi All,
I have requirement to cleanup special character of field.
The data which is retrieved from the field and written to text file.
So Here
HÃ-re - I need value Hire(actual value) from the filed.
Ã- this has written into file instead of i
In database i have
NLS_NCHAR_CHARACTERSET - AL16UTF16
NLS_CHARACTERSET - UTF8
I tried
select convert('HÃ-re','UTF8') from dual
Output: H??re
Can any one please provide me a solution.
Thanks,
Edited by: user8822881 on Nov 3, 2010 6:33 PMUse TRANSLATE() or REPLACE()?

Similar Messages

  • Need to add special characters in sap scripts

    Hi All,
       I need to add special characters in sap script.
    I have used them as it is my script,but in the print preview i am able to see '#' instead of those special characters.Can anybody please tell me the way in which we can add special characters in the scripts.
    eg. 'Shlesha' i.e. name in inverted colons.
    Thanks

    Hi
    If # is coming means, that is the problem with the printer. I think u might have used your local printer to see the print preview.
    Don't use LOCL or LP01. Our local printer won't recognize those characters.
    Just change the printer name to client printer name. It will work.

  • US7ASCII Characterset - Need to support Special Characters & Symbols

    Dear All,
    My database characterset is 'US7ASCII'
    Some of Special Characters / Symbols are not supported by 'US7ASCII'. But those symbols need to be supported by 'US7ASCII'.
    Do we have any option to make 'US7ASCII' Characterset to support such Symbols.
    Details given below.
    Database - Oracle 10g
    NLS_CHARACTERSET - US7ASCII
    Column - Description Varchar2(50)
    Symbols - ↓ β α ↑ З Њ Є € £ ± ¥ © ® ∞ etc......( Greek and Captic, European etc......Symbols stored as ������ )
    My requirement is the above symbols need to be properly stored in the database as it is.
    Kindly help / Guide me on this.

    Hi,
    Database - Oracle 10g
    NLS_CHARACTERSET - US7ASCII
    Column - Description Varchar2(50)
    Symbols - ↓ β α ↑ З Њ Є € £ ± ¥ © ® ∞ etc......( Greek and Captic, European etc......Symbols stored as ������ ) " Euro symbol is neither in US7ASCII nor WE8ISO8859P1 character set.
    You have to use WE8ISO8859P15, WE8MSWIN1252, UTF8..."
    Read Tom [Differrent Character set and NLS|http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1224836384599]
    Twinkle

  • Need Help with data type conversion

    Hello People,
    I am new to java, i need some help with data type conversion:
    I have variable(string) storing IP Address
    IPAddr="10.10.103.10"
    I have to call a library function which passes IP Address and does something and returns me a value.
    The problem I have is that external function call in this library excepts IP Address in form of a byte array.
    Here is the syntax for the function I am calling through my program
    int createDevice (byte[] ipAddress).
    now my problem is I don't know how to convert the string  IPAddr variable into a byte[] ipAddress to pass it through method.

    Class InetAddress has a method
    byte[]      getAddress() You can create an instance using the static method getByName() providing the IP address string as argument.

  • Need to remove special characters

    Hello All
        Some input is comming from source field, if any special characters comming from source field, I need remove special characters and send data source to target field. please suggest me how will i do .
    Thanks&Regards,
    Venkat

    Hi Venkat,
    check this thread.
    Handling Special Characters
    check the document :
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/502991a2-45d9-2910-d99f-8aba5d79fb42
    Depends upon encoding methods handling will differ,
    you can use ISO-8859-1 or ISO-8859-2 instead of UTF-8 for some special characters.
    check this blog:
    /people/ulrich.brink/blog/2005/08/18/unicode-file-handling-in-abap
    cheers
    Sunil

  • TCS 3.0: Anchored Frames contain callouts with german special characters Conversion to RH nok

    Hi all,
    I have Frame documents, which contain anchored frames with callouts. The callouts are created with Frame and contain german special characters like ä,ö,ü. These characters are not converted correctly.
    Thanks for help.
    Regards,
    Rainer

  • Help with Special Characters

    Am trying to read in a url that has special characters:
    http://intranet.xxx.org/Policies/!SSL!/RoboInfo_Output/Patient_Care_&_Services__(PCS)/Clin ical_Alarms_5-19-04_Final.htm
    I'm using ReadURL and have never had any issues before.
    When the page is published, the URL stops at the ampersand
    and says page cannot be found.
    I tried URL Encode and URLDecode with no success.
    Any ideas?
    Thanks!
    Kristin Hill

    If you run URLEncode on that URL, what is the result?
    If you copy (or type) that result into a browser address
    field, does it
    work?
    Erik
    kristinhill wrote:
    > Yes - totally an accident. Not a joke - although kind of
    funny once I tried the
    > link myself :)
    > The URL is actually on our intranet, which wouldn't have
    shown anyway - but
    > since it's internal healthcare policy, didn't want to
    take the chance so I
    > blanked out the actual address for the forum.
    >
    > Any ideas on my code?
    >
    Erik Lord
    http://www.capemedia.net
    Adobe Community Expert - Authorware
    http://www.adobe.com/communities/experts/
    http://www.awaretips.net -
    samples, tips, products, faqs, and links!
    *Search the A'ware newsgroup archives*
    http://groups.google.com/group/macromedia.authorware

  • Need help on content server conversioning formats

    Hi,
    I need a help on content server. My requirement is to convert PDF to HTML how can i achieve that wether by using IBR or by Dynamic converter and explain how to do this ?
    Srinath am fallowing you in the forum hope you can help in this...
    Thanks,
    DSV

    Hi
    Dynamic converter is the component that will be used to do the conversion from any format to HTML . So you will have to install the following to get this working :
    1. UCM Core Update patchset 6907073 which is build 74 (latest to be released)
    2. Dynamic Converter version 8.2.0.862 - This will be available in the above patchset .
    3. ContentAccess specific to your OS . This is from patchset 6899823 .
    After installing the above 3 component , restarting UCM should get the DC up and working . Then you would need to set pdf as a format to be converted to HTML (from configuration for DC admin) and it should start working fine .
    Hope it helps .
    Thanks
    Srinath

  • Need help in file content conversion complex structure

    Hi Guys ,
    Iam new to this file content conversion , Please let me know whether below requirement is possible .if yes than how ?
    Inbound XML file from Proxy
    <Data>
      <keyfield1>0011</keyfield1>
      <keyfield2>0012</keyfield2>
      <Keyfield3>0013</Keyfield3>
      <field1>Test1</field1>
      <field2>testfield1</field2>
      <field3>0001</field3>
    <Data>
      <keyfield1>0021</keyfield1>
      <keyfield2>0022</keyfield2>
      <Keyfield3>0023</Keyfield3>
      <field1>Test2</field1>
      <field2>testfield2</field2>
      <field3>0002</field3>
    output pgp flat file .
    pgp file format should be as below after file content conversion
      0011|0012|0013|Test1||||||
      0011|0012|0013|Testfield1||||||
      0011|0012|0013|0001||||||
      0021|0022|0023|Test2||||||
      0011|0012|0013|Testfield2||||||
      0011|0012|0013|0002||||||
    thanks a lot .
    Regards
    Prabhu

    Hi.
    Try this.
    First you need to use a message mapping  and create a target structure to convert a similar output  structure that do you want.  like this
    <Target>
    --  Field1
    --  Field2
    --  Field3
    --  Field4
    --  Field5
    --  Field6
    --  Field7
    --  Field8
    --  Field9
    </Target>.
    Then map
    keyfield1-> Field 1 ,keyfield2-> Field 2 , keyfield 3---> Field 3
    map  field1-> field4 .. for the others fields duplicate the Target node (right click)  and  map map  field2-> field5 ..etc.
    For the field 5 until field 9 map with constant ("'')
    Then in you receiver comunication channel put simple parameters. 
    Target.fieldSeparator = |
    Target.endSeparator = 'nl'
    Regards.

  • Need help about tags being automatically translated by BC

    One of our biggest client operates in Brazil. Unfortunately BC currently has no Portuguese version and some tags within BC are automatically translated by the engine as for example the {module_webformresults}. We have no choice but to select Spanish as the default language for the site and you can see the results here: http://prntscr.com/113rw7 We know that one option is to use custom fields instead of the email, address, etc fields provide by BC, but this not a good choice because we still have some texts being automatically translated in spanish by BC. Furthermore, if a customer fills wrongly a field, the pop up warning window show the text in Spanish too and we are not able to translate to Portuguese.
    Someone have a good advice, besides to tell BC to built a Portuguese version? (which we already offer to them to translate the dictionaries but they didn´t accept it.)

    WELL. Finally, we got an answer from BC:
    Mihai Tica (Adobe Business Catalyst Support)
    Apr 26 16:39 (EEST)
    I am afraid adding a new culture in the system is not an easy task, and it's not on our near term roadmap.
    As a workaround you can use the steps described in this article - http://forums.adobe.com/docs/DOC-2363 (scroll down to "Redirecting the Web Form confirmation page") to redirect the user to a custom webpage you can style according to your needs (customize the message displayed).
    Regarding the alert messages displayed by the webform validation script those are even easier to customize. Simply open up the page the form is inserted to and translate the error messages.
    The output of the {module_webformresults} module can also be customized using javascript. This way you can basically change any text into any placeholder on the site's front-end.
    Using this method is really simple, take a look at this tutorial - http://www.w3schools.com/jquery/html_text.asp
    And here is a more detailed description of how to change text strings using jQuery - http://api.jquery.com/text/
    The only thing that cannoe be translated is the email the customer receives by email, the strings there cannot be altered unfortunately using the method described above.
    I have also forwarded this as an enhancement request to the product management team. They will ***** its priority and decide when this feature will be implemented in one of the future releases.
    Kind regards,
    Mihai Tica.

  • Need help with converting characters to ASCII code

    Hey. Im trying to write a program to make Caesar Ciphers by random numbers. This cipher must also wrap from front to end of ASCII code, so that if, for example, the character being ciphered is Z and its being modified by +3, the result ciphered character is not "]", but "c".
    Im planning on reading the text that the user inputs (using ConsoleIO) into a string and then seperating each character into a character[]. Then, i would like to find the ASCII code of each character and print out the ASCII code character of the old ASCII code + the modifier.
    So far, this is what i have (sorry for the length, i like to space things out so that its easier on the eyes and more organized... X-( ... ):
    public class EvanFinalB {
         static ConsoleIO kbd = new ConsoleIO();
         static String enteredPhrase;
         static int phraseLength;
         public static void main(String[] args)
              System.out.println("Enter a phrase and this program will cipher it into a secret message.");
              System.out.println("/nEnter your phrase here:");
              //read phrase
              enteredPhrase = kbd.toString();
              //find length of entered text
              phraseLength = enteredPhrase.length();
              //declare arrays for the individual characters of the entered text and the ciphered characters
              char[] enteredChar = new char[phraseLength + 1];
              char[] cipheredChar = new char[phraseLength + 1];
              //loop converting of entered text into seperate characters
              for(int x = 1; x <= phraseLength; x++)
                   enteredChar[x] = enteredPhrase.charAt(x);
                   cipheredChar[x] = cipher(enteredChar[x]);//call cipher() method to find new ciphered character
         //wrap from front to end of ASCII code
         static char cipher(char enteredChar)
              //choose random number to cipher message by
              int modifier = (int)(Math.random() * 26) + 1;
              if(enteredChar + modifier > 90)//90 is the ASCII code for "Z" which is the last capital letter
                   cipheredChar = (97 + (modifier - (90 - enteredChar)));//97 is the ASCII code for "a" which is the first lower case letter
              return cipheredChar[1];
    }The program is obviously in its early stages but (i started creating it today actually), if there is a simple method or anything that i can use to find the ASCII value of a character in order to use enteredChar so that 'enteredChar' is equal to the ASCII code of the new ciphered character, please help me out...Thanks
    P.S. If there's an easier way to go about creating a program for Caesar Ciphers, let me know.

    The following code is from my Java textbook Big Java by Cay Horstmann. It is not my code and it's just to guide you in your own cipher.
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.io.IOException;
       This class encrypts files using the Caesar cipher.
       For decryption, use an encryptor whose key is the
       negative of the encryption key.
    public class CaesarCipher
          Constructs a cipher object with a given key.
          @param aKey the encryption key
       public CaesarCipher(int aKey)
          key = aKey;
          Encrypts the contents of a stream.
          @param in the input stream
          @param out the output stream
       public void encryptStream(InputStream in, OutputStream out)
             throws IOException
          boolean done = false;
          while (!done)
             int next = in.read();
             if (next == -1) done = true;
             else
                byte b = (byte) next;
                byte c = encrypt(b);
                out.write(c);
          Encrypts a byte.
          @param b the byte to encrypt
          @return the encrypted byte
       public byte encrypt(byte b)
          return (byte) (b + key);
       private int key;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    import java.util.Scanner;
       This program encrypts a file, using the Caesar cipher.
    public class CaesarEncryptor
       public static void main(String[] args)
          Scanner in = new Scanner(System.in);
          try
             System.out.print("Input file: ");
             String inFile = in.next();
             System.out.print("Output file: ");
             String outFile = in.next();
             System.out.print("Encryption key: ");
             int key = in.nextInt();
             InputStream inStream = new FileInputStream(inFile);
             OutputStream outStream = new FileOutputStream(outFile);
             CaesarCipher cipher = new CaesarCipher(key);
             cipher.encryptStream(inStream, outStream);
             inStream.close();
             outStream.close();
          catch (IOException exception)
             System.out.println("Error processing file: " + exception);
    }

  • Need Help with simple date conversion

    Hi all,
    I have been creating integrations from custom Oracle tables to my Hyperion Planning application. I have most of them working, but am having issues loading dates to the application.
    The dates in the source are formatted as M/DD/YY.
    Hyperion can only recieve the dates if they are in MM-DD-YYY format. (atleast that is the error I receive when I load the interface)
    Could someone please help me build an ODI expression that will convert/format the date? My SQL is pretty weak.
    Thanks,
    Nick

    Thanks for the reply. I guess one of my issues is I am trying to do this conversion in my Sunopsis Memory Staging Area. So I guess I should be using SQL to convert the date, but I am still having issues.
    Here is the error from my log file when I attempt a straight mapping of the date...
    B9708547A,Plan1,2001-08-27,OrganizationNone,Project Type None,BegBalance,FY11,RateNone,Working,Final,Cannot load dimension member, error message is: com.hyperion.planning.HspRuntimeException: Date is incorrectly formatted, expecting "MM-DD-YYYY" format.
    Here is the SQL statement from the operator when I attempt (poor attempt) at converting the date....
    sql= """select C2_MT_PROJECTID "Project",'Plan1' "Data Load Cube Name",CONVERT(C1_MT_PROJ_START_DT,Date('MM-DD-YYYY')) "StartDate",'OrganizationNone' + ',' + 'Project Type None' + ',' + 'BegBalance' + ',' + 'FY11' + ',' + 'RateNone' + ',' + 'Working' + ',' + 'Final' "Point-of-View" from "C$_0Project" where      (1=1) """
    Here is the error from the operator get...
    org.apache.bsf.BSFException: exception from Jython:
    Traceback (innermost last):
    File "<string>", line 20, in ?
    java.sql.SQLException: Unexpected token in statement [select   C2_MT_PROJECTID    "Project",'Plan1'    "Data Load Cube Name",CONVERT(C1_MT_PROJ_START_DT,Date(]
         at org.hsqldb.jdbc.jdbcUtil.sqlException(jdbcUtil.java:67)
         at org.hsqldb.jdbc.jdbcStatement.fetchResult(jdbcStatement.java:1598)
         at org.hsqldb.jdbc.jdbcStatement.executeQuery(jdbcStatement.java:194)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java)
         at org.python.core.PyMethod.__call__(PyMethod.java)
         at org.python.core.PyObject.__call__(PyObject.java)
         at org.python.core.PyInstance.invoke(PyInstance.java)
         at org.python.pycode._pyx14.f$0(<string>:20)
         at org.python.pycode._pyx14.call_function(<string>)
         at org.python.core.PyTableCode.call(PyTableCode.java)
         at org.python.core.PyCode.call(PyCode.java)
         at org.python.core.Py.runCode(Py.java)
         at org.python.core.Py.exec(Py.java)
         at org.python.util.PythonInterpreter.exec(PythonInterpreter.java)
         at org.apache.bsf.engines.jython.JythonEngine.exec(JythonEngine.java:144)
         at com.sunopsis.dwg.codeinterpretor.k.a(k.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.scripting(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execScriptingOrders(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execScriptingOrders(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTaskTrt(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSqlI.treatTaskTrt(SnpSessTaskSqlI.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java)
         at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java)
         at com.sunopsis.dwg.cmd.DwgCommandSession.treatCommand(DwgCommandSession.java)
         at com.sunopsis.dwg.cmd.DwgCommandBase.execute(DwgCommandBase.java)
         at com.sunopsis.dwg.cmd.e.i(e.java)
         at com.sunopsis.dwg.cmd.h.y(h.java)
         at com.sunopsis.dwg.cmd.e.run(e.java)
         at java.lang.Thread.run(Unknown Source)
    java.sql.SQLException: java.sql.SQLException: Unexpected token in statement [select   C2_MT_PROJECTID    "Project",'Plan1'    "Data Load Cube Name",CONVERT(C1_MT_PROJ_START_DT,Date(]
         at org.apache.bsf.engines.jython.JythonEngine.exec(JythonEngine.java:146)
         at com.sunopsis.dwg.codeinterpretor.k.a(k.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.scripting(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execScriptingOrders(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execScriptingOrders(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTaskTrt(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSqlI.treatTaskTrt(SnpSessTaskSqlI.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java)
         at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java)
         at com.sunopsis.dwg.cmd.DwgCommandSession.treatCommand(DwgCommandSession.java)
         at com.sunopsis.dwg.cmd.DwgCommandBase.execute(DwgCommandBase.java)
         at com.sunopsis.dwg.cmd.e.i(e.java)
         at com.sunopsis.dwg.cmd.h.y(h.java)
         at com.sunopsis.dwg.cmd.e.run(e.java)
         at java.lang.Thread.run(Unknown Source)

  • Need help with special logic...

    Hi,
    i have a query which selects all status changes for tasks. For every NEW status a record is inserted where the new status TYPE and ENTRY_DATE are stored.
    A task can have several statuses based on this information (unlimited number of status changes is allowed):
    1.) Open (the last inserted status record has type: 'Open')
    2.) Closed (the last inserted status record has type 'Closed')
    I need to get the following result:
    TASK_ID     START_TIME        STOP_TIME          
    333450      09-01-09 10:00     09-01-09 11:00    
    333450      12-01-09 10:00     12-01-09 15:00    
    333450      12-01-09 16:00     12-01-09 16:00    
    333450      12-01-09 16:00     CURRENT_DATE    
    Scenarios:
    - Multiple 'Close' records after each other: The START_TIME in the 3d tuple should be copied from the STOP_TIME in the real data.
    - No 'Close' record: The STOP_TIME in the 4th tuple should be the CURRENT_DATE.
    - Multiple 'Open' records after each other: The STOP_TIME of the previous 'Open' record in the realdata should be the ENTRY_DATE of the 'current' record in the realdata. (THIS ONE ISN'T PRESENT IN THE DATA EXAMPLE!!!)
    From this data:
    with REALDATA as (
    select 104993 PLAN_ID, to_date('09-01-09 10:00','dd-MM-yy HH24:MI') ENTRY_DATE, 'Open' STATUS_DESCRIPTION, 'Open' STATUS_TYPE, 333450 TASK_ID, 'Assembly' TASK_DESCRIPTION from dual
    union
    select 104993, to_date('09-01-09 11:00','dd-MM-yy HH24:MI'), 'Completed', 'Closed', 333450, 'Assembly' from dual
    union
    select 104993, to_date('12-01-09 10:00','dd-MM-yy HH24:MI'), 'Open', 'Open', 333450, 'Assembly' from dual
    union
    select 104993, to_date('12-01-09 15:00','dd-MM-yy HH24:MI'), 'Completed', 'Closed', 333450, 'Assembly' from dual
    union
    select 104993, to_date('12-01-09 16:00','dd-MM-yy HH24:MI'), 'Completed', 'Closed', 333450, 'Assembly' from dual
    union
    select 104993, to_date('13-01-09 15:00','dd-MM-yy HH24:MI'), 'Open', 'Open', 333450, 'Assembly' from dual
    select TASK_ID, TO_CHAR(ENTRY_DATE,'dd-MM-yy HH24:MI'), STATUS_DESCRIPTION, STATUS_TYPE, TASK_DESCRIPTION from realdata order by ENTRY_DATE
    Extra abstraction:_
    So the data should be sorted by ENTRY_DATE:
    then it should be 'grouped' like this (very abstract: tuples split by comma, between (brackets) is which ENTRY_DATE the data should come from)):
    - normal pair
    OPEN, CLOSED
    result: START_TIME (OPEN) | STOP_TIME (CLOSED)
    - multiple open records
    OPEN, OPEN, OPEN, CLOSED
    result: START_TIME (OPEN) | STOP_TIME (next OPEN), START_TIME (OPEN) | STOP_TIME (next OPEN), START_TIME (OPEN) | STOP_TIME (CLOSED)
    - multiple closed records
    OPEN, CLOSED, CLOSED
    result: START_TIME (OPEN) | STOP_TIME (CLOSED), START_TIME (CLOSED) | STOP_TIME (CLOSED)
    - no open record
    CLOSED[,CLOSED]
    result: START_TIME (CLOSED) | STOP_TIME (CLOSED)[,START_TIME (CLOSED) | STOP_TIME (CLOSED)]
    - no closed record
    OPEN
    result: START_TIME (OPEN) | STOP_TIME (CURRENT_DATE)
    - no closed record with multiple open records
    OPEN, OPEN
    result: START_TIME (OPEN) | STOP_TIME (next OPEN), START_TIME (OPEN) | STOP_TIME (CURRENT_DATE)Edited by: user574699 on Jan 14, 2009 5:09 AM
    Edited by: user574699 on Jan 14, 2009 5:30 AM - Extra abstraction at the bottom!

    Based on your original data, I'd go with something like:
    with REALDATA as (select 104993 PLAN_ID, to_date('09-01-09 10:00','dd-MM-yy HH24:MI') ENTRY_DATE, 'Open' STATUS_DESCRIPTION, 'Open' STATUS_TYPE, 333450 TASK_ID, 'Assembly' TASK_DESCRIPTION from dual
                      union all
                      select 104993, to_date('09-01-09 11:00','dd-MM-yy HH24:MI'), 'Completed', 'Closed', 333450, 'Assembly' from dual
                      union all
                      select 104993, to_date('12-01-09 10:00','dd-MM-yy HH24:MI'), 'Open', 'Open', 333450, 'Assembly' from dual
                      union all
                      select 104993, to_date('12-01-09 15:00','dd-MM-yy HH24:MI'), 'Completed', 'Closed', 333450, 'Assembly' from dual
                      union all
                      select 104993, to_date('12-01-09 16:00','dd-MM-yy HH24:MI'), 'Completed', 'Closed', 333450, 'Assembly' from dual
                      union all
                      select 104993, to_date('13-01-09 15:00','dd-MM-yy HH24:MI'), 'Open', 'Open', 333450, 'Assembly' from dual),
       trans_data as (select task_id,
                             task_description,
                             plan_id,
                             entry_date,
                             nvl(lead(entry_date) over (partition by task_id, task_description, plan_id
                                                        order by entry_date), sysdate) stop_date,
                             status_type status,
                             lag(status_type) over (partition by task_id, task_description, plan_id
                                                    order by entry_date) prev_status,
                             lead(status_type) over (partition by task_id, task_description, plan_id
                                                     order by entry_date) next_status
                      from   realdata)
    select task_id,
           task_description,
           plan_id,
           entry_date,
           case when status = 'Closed' and next_status != 'Closed' then
                     entry_date
                else stop_date
           end
    from   trans_data
    where  case when status = 'Closed' and prev_status = 'Open' then
                     1
                else 0
           end != 1But it looks like your actual data is more complicated than the original set of data (extra statuses for one). Also, you haven't said what should happen (I don't think) in the case of "Open, Close, Open Close" - I've taken it that the 2nd Open should have a start time of the 2nd Open, rather than the stop time of the 1st close.

  • Need help with special select case

    Oracle DB 12c, I think 12.1.2
    drop table person_tests;
    create table person_tests (
    person_id number,
    test_type_id varchar2(1),
    test_date date
    insert into person_tests (person_id,test_type_id,test_date) values (1,'A',to_date('01012000','MMDDYYYY'));
    insert into person_tests (person_id,test_type_id,test_date) values (1,'A',to_date('01022000','MMDDYYYY'));
    insert into person_tests (person_id,test_type_id,test_date) values (1,'B',to_date('01032000','MMDDYYYY'));
    insert into person_tests (person_id,test_type_id,test_date) values (1,'B',to_date('01042000','MMDDYYYY'));
    insert into person_tests (person_id,test_type_id,test_date) values (1,'C',to_date('01052000','MMDDYYYY'));
    insert into person_tests (person_id,test_type_id,test_date) values (2,'C',to_date('01062000','MMDDYYYY'));
    insert into person_tests (person_id,test_type_id,test_date) values (3,'A',to_date('01072001','MMDDYYYY'));
    insert into person_tests (person_id,test_type_id,test_date) values (3,'A',to_date('01082000','MMDDYYYY'));
    insert into person_tests (person_id,test_type_id,test_date) values (3,'B',to_date('01092000','MMDDYYYY'));
    insert into person_tests (person_id,test_type_id,test_date) values (3,'B',to_date('01102000','MMDDYYYY'));
    insert into person_tests (person_id,test_type_id,test_date) values (3,'C',to_date('01102000','MMDDYYYY'));
    Persons as participating in certain tests: A, B and C where each test is tagged with a date when done.
    I need to output only people that completed 2 tests of type A, 2 tests of type B and 1 test of type C. I have to display the test type and the date of the most recent of those tests. In the example above, desired output would be
    1 C            05-JAN-00
    3 A            07-JAN-01
    Hope this problem definition makes sense

    Hi,
    Sorry, I missed the requirement about showing the most recent test_type_id.
    Assuming the date to be shown is the date the minimum requirements were fulfilled (whether of not gratutitous tests came afterwrds), you can do something like this:
    WITH    got_r_num    AS
        SELECT  person_id, test_type_id, test_date
        ,       ROW_NUMBER () OVER ( PARTITION BY  person_id, test_type_id
                                     ORDER BY      test_date
                                   )   AS r_num
        FROM    person_tests
        WHERE   test_type_id  IN ('A', 'B', 'C')
    SELECT    person_id
    ,         MIN (test_type_id) KEEP (DENSE_RANK LAST ORDER BY  test_date)  AS last_test_type
    ,         MAX (test_date)                                                AS last_test_date
    FROM      got_r_num
    WHERE     r_num  <= CASE  test_type_id
                            WHEN  'A'  THEN  2
                            WHEN  'B'  THEN  2
                            WHEN  'C'  THEN  1
                        END
    GROUP BY  person_id
    HAVING    COUNT (*)  = 5  -- 2 'A's  +  2 'B's  +  1 'C'
    What test_type_id would you want to display in case of a tie for the latest test?
    I just saw your post saying that a person with 3 or more type 'A' tests should be excluded.  In that case, my original solution (with = in the main WHERE clause) is what you want; only used LAST to get the latest test_type_id.  The solution in this message is for the situation where you don't care if someone had 3 or more 'A's, but you want to ignore all but the first 2.

  • Need help on ANSI sql conversion

    Existing Query:
    select (list of columns from list of tables) from EMPANS A,EMPANS_MEMO M,QSTLINK L,QSTN Q
    WHERE A.FLDCOMMENT =M.FLDREC_NUM(+) AND L.FLDFORM = ? AND L.FLDQUESTION = A.FLDQUESTION AND L.FLDROLLOVER = 'y' AND Q.FLDCODE = L.FLDQUESTION AND
    (Q.FLDINACTIVE IS NULL OR Q.FLDINACTIVE <> 'y')
    Ansi Converted:
    select (list of columns from list of tables) from EMPANS A LEFT OUTER JOIN EMPANS_MEMO M ON (A.FLDCOMMENT =M.FLDREC_NUM)
    INNER JOIN QSTLINK L ON ( A.FLDQUESTION =L.FLDQUESTION )
    INNER JOIN QSTN Q ON (L.FLDQUESTION = Q.FLDCODE )
    WHERE L.FLDFORM = ? AND L.FLDROLLOVER = 'y' AND
    (Q.FLDINACTIVE IS NULL OR Q.FLDINACTIVE <> 'y')
    could any body let me know , is this correct.
    thanks for your support.

    Hello, this is the ANSI equivalent:
    SELECT...
    FROM EMPANS A
      JOIN QSTLINK L ON ( L.FLDQUESTION = A.FLDQUESTION)
      JOIN QSTN Q ON (Q.FLDCODE = L.FLDQUESTION)
      LEFT JOIN EMPANS_MEMO M ON (A.FLDCOMMENT =M.FLDREC_NUM)
    WHERE L.FLDFORM = ?
        AND L.FLDROLLOVER = 'y'
        AND (Q.FLDINACTIVE IS NULL OR Q.FLDINACTIVE 'y')

Maybe you are looking for