Trying to get a date value from a string

Hi All,
I'm not sure I am doing this right, so I figured I would ask the experts...
I have built a file upload page that is working the way I need it, but I have found that I need to determine the date from the uploaded file name. I tried to create a PL/SQL computation and do some substr / instr to the filename, but I'm not getting it as I get "ORA-01843: not a valid month" error. Here is the code I'm trying:
declare
  v_underscore  integer;
  v_date            varchar2(15);  --have also tried using date datatype...
begin
  v_underscore := INSTR(:P20_EXPRESS,'_',1,1);
  v_date := to_date(substr(:P20_EXPRESS,v_underscore + 1,6),'YYMMDD');
  return v_date;
end;And here is a sample filename:
F15047/proc_10607161001.csv
Is this the best way to achive what I'm trying to do?
Thanks,
Corey

Hi,
v_underscore := INSTR(:P20_EXPRESS,'_',1,1);
v_date := to_date(substr(:P20_EXPRESS,v_underscore + 1,6),'YYMMDD');What this is saying is:
Get the position of the "_" character
Move to the next character to the right (which is a "1" in your case)
Get 6 characters (106071) from the string value
Convert them to a date using the format 'YYMMDD'
This results in:
Year: 10
Month: 60
Day: 71
Which of course is not valid.
For example:
select
  substr('F15047/proc_10607161001.csv', instr('F15047/proc_10607161001.csv', '_', 1, 1) + 1, 6)
from
  dual;
SUBSTR
106071It looks like you want to move two positions to the right rather than a single position:
select
  substr('F15047/proc_10607161001.csv', instr('F15047/proc_10607161001.csv', '_', 1, 1) + 2, 6)
from
  dual;
SUBSTR
060716Hope that helps a bit,
Mark

Similar Messages

  • How to get shared date value from subreport to main report

    Hi,
    I need your help in passing the value of a running total that is located in the subreport to the main report. The running total in the subreport is getting the maximum of the Effective Date (which it is type in the database is date) for each group and it is value will change on the change of the sequence no. group. I am printing the value at the group footer which displayed correctly. Now my issue is that how to pass the value from the subreport to the main report as a date. I have created a formula that it is having the code:
    shared datevar ddd := date(0,0,0);
    ddd:={RTotl0}
    The above formula is not compiled and it is first giving me an error at line 1 that date(0,0,0) is not accepted. Then when I removed it, it gave me an error that ddd:= can't have a running total to a datevar.
    So can you please help in getting the value from the subreport and then to pass it to the main report as a formula as I need to include it in other formulas which it compares the dates.
    Thanks

    Hi Mohammed,
    Are you displaying the shared variable on the Main Report's group footer as well?
    Try changing the code to:
    shared datevar ddd := cdate(0,0,0);
    ddd:= date({RTotl0});
    -Abhilash

  • How to get the Date value from DB

    Hi All,
    I give one string parameter (25-Jan-07). My database table stored in some dates and values. How i'll get the all date value(25-Jan-07) and the correspong values?
    Thanks!

    SELECT *
    FROM your_table
    WHERE date_column = to_date('25-Jan-07', 'dd-Mon-yy')Why oh why oh why are you using dates with two-digits representing the year? In my opinion, this is bad and wrong. Be explicit; use 4 digits. is your "07" representing 1907? 2007? 2107?

  • Trying to get a return value from a Stored Procedure

    Hi folks,
    I have been tasked with something I thought was simple, but apparently its not that simple.  I am trying to call a Stored Procedure in UCCX that will do some calculations and returns back an integer value.  The stored procedure call I have is:
    DECLARE @return_status int
    EXEC @return_status = dbo.CTTLoginPhone @CTTId = $EmployeeID , @PIN = $EmployeePIN , @PhoneNumber = $CallingPhoneNumber ;SELECT 'Return_Status' = @return_status
    When I run this in this the editor, I get back one row.  If I run this in the debugger, I do not get any errors back and the stored procedure runs fine, however the Return_Status is not set either.  What am I doing wrong?
    I have defined Return_Status with intial value of 0 and the stored proc should be returning back 1 or 2, but the Return_Status remains as 0
    Can someone please let me know if I need a DB GET after a DB READ or can I just use the DB READ standalone when calling stored procedure.
    All help will be really appreciated.
    Thank you.

    I am having the same issue here... any help would be greatly appreciated. I am on UCCX 8
    I am getting 1 row returned when I click "TEST" in the READ step but the DB GET step is going into the SQL Error branch.
    Here are some details and I have attached screen shots of my script DB steps.....
    I have a Stored Procedure that is very simple...
    CREATE PROCEDURE sp_test AS
    Select 'N';
    GO
    Ive created a dummy table with 1 field..
    TABLE: testTable
    FIELD: code
    Let me know if there are any more details I can provide....

  • I am reading from an instrument a 1D string array of numbers in ascii. I want to be extract the actual data values from the string. How do I do that?

    labview 6i. Using sr785 instrument.

    Two ways. Use Fract/Exp to Number function on the Strin>Strin Number Conversion palette. It accepts both individual or strin array inputs. Wire your string array in an get an array of doubles out. You can also use Scan From String on the String palette inside of a for loop. The for loop will autoindex the string array in and autoindex an array of doubles out.
    Attachments:
    string_to_double.jpg ‏10 KB

  • Getting char values from a string problem

    Hi,
    Here's an example of what I'm trying to do:
    boolean loopSwitch = true;
    while (loopSwitch)
         String orderDecider = JOptionPane.showInputDialog (null, "Would you like your numbers to be ordered in   ascending or descending order(A/D)",      "Order decision", JOptionPane.QUESTION_MESSAGE);
         if (orderDecider == A)
         loopSwitch = false;
         }I basically want the user to input either a/A/d/D and to get the char values from the string so I can use them in an if statement.
    Basically, I wanna parse the string into a char.
    Is this possible?
    Thanks.
    Edited by: xcd on Oct 16, 2009 8:38 AM

    Why not just use the String.equals() method to compare a String to a String?
    But if you must, you can use the String.charAt() method to return a char at a particular location in the String.
    Note: char literals need to be surrounded by single quotes ('A') and String literals need to be surrounded by double quotes ("A").

  • How to get edited row values from ADF table?

    JDev 11.
    I have a table which is populated with data from Bean.
    I need to save changes after user make changes in any table cell. InputText is defined for table column component.
    I have defined ValueChangeListener for inputText field and AutoSubmit=true. So when user change value in inputText field, method is called:
    public void SaveMaterial(ValueChangeEvent valueChangeEvent) {
    getSelectedRow();
    SaveMaterial(material);
    This method should call getSelectedRow which take values from selected table row and save them into object:
    private Row getSelectedRow(){
    RichTable table = this.getMaterialTable();
    Iterator selection = table.getSelectedRowKeys().iterator();
    while (selection.hasNext())
    Object key = selection.next();
    table.setRowKey(key);
    Object o = table.getRowData();
    material = (MATERIAL) o;
    System.out.println("Selected Material Desc = "+material.getEnumb());
    return null;
    Problem is that getSelectedRow method doesnt get new (edited) values, old values are still used.
    I have tried to use ActiveButton with same method and it works fine in that case. New values are selected from active row and inserted into object.
    JSF:
    <af:table var="row" rowSelection="single" columnSelection="single"
    value="#{ManageWO.material}" binding="#{ManageWO.materialTable}">
    <af:column sortable="false" headerText="E-number">
    <af:inputText value="#{row.enumb}" valueChangeListener="#{ManageWO.SaveMaterial}" autoSubmit="true"/>
    </af:column>
    <af:column sortable="false" headerText="Description">
    <af:inputText value="#{row.desc}" valueChangeListener="#{ManageWO.SaveMaterial}" autoSubmit="true"/>
    </af:column>
    </af:table>
    <af:activeCommandToolbarButton text="Save" action="#{ManageWO.EditData}"/>
    What is a correct place from where save method should be called to get new (edited) values from ADF table?
    Thanks.

    Did you look into the valueChangeEvent?
    It has oldValue and newValue attributes.
    public void SaveMaterial(ValueChangeEvent valueChangeEvent) {
    Object oldVal = valueChangeEvent.getOldValue();
    Object newVal = valueChangeEvent.getNewValue();
    // check if you see what you are looking for.....
    getSelectedRow();
    SaveMaterial(material);
    }Timo

  • Get all the values from a multiple select in a multipart form

    Hi there!
    I am using a form with enctype="multipart/form-data" in order to upload files from the form.
    I have read this page: http://commons.apache.org/fileupload/using.html and everything works well for my form.
    The only problem is that I can't get all the values from a "multiple select" html object. I get only one value.
    Using servlets I have used this method:
    public java.lang.String[] getParameterValues(java.lang.String name) But now I have enctype="multipart/form-data" in my form and I can't use this way...
    Is there a way to get all the values of a multi-valued parameter?
    Thanks a lot!
    Stefano

    Hi
    I have got solution for this problem so, I am listing here logic
    assume tag name of html
    <select name="moption" multiple="multiple">
    iterate it in as
    String moption="";
    boolean cnt=true;
    while(itr.hasNext())
    FileItem fi=(FileItem)itr.next();
    if(fi.isFormField())
    if(fi.getFieldName().equals("moption"))
    if(cnt==true)
    moption=fi.getString();
    cnt=false;
    else
    moption=moption+","+fi.getString();
    If wants more help then mail me your problem
    at [email protected]
    Thanks!
    Anand Shankar
    Edited by: AnandShankar on 6 Nov, 2009 12:54 PM

  • How to get all the values from the dropdown menu

    How to get all the values from the dropdown menu
    I need to be able to extract all values from the dropdown menu; I know how to get all those values as a string, but I need to be able to access each item; (the value in a dropdown menu will change dynamically)
    How do I get number of item is selection dropdown?
    How do I extract a ?name? for each value, one by one?
    How do I change a selection by referring to particular index of the item in a dropdown menu?
    Here is the Path to dropdown menu that I'm trying to access (form contains number of similar dropdowns)
    RSWApp.om.GetElementByPath "window(index=0).form(id=""aspnetForm"" | action=""advancedsearch.aspx"" | index=0).formelement[SELECT](name=""ctl00$MainContent$hardwareBrand"" | id=""ctl00_MainContent_hardwareBrand"" | index=16)", element
    Message was edited by: testtest

    The findElement method allows various attributes to be used to search. Take the following two examples for the element below:
    <Select Name=ProdType ID=testProd>
    </Select>
    I can find the element based on its name or any other attribute, I just need to specify what I am looking for. To find it by name I would do the following:
    Set x = RSWApp.om.FindElement("ProdType","SELECT","Name")
    If I want to search by id I could do the following:
    Set x = RSWApp.om.FindElement("testProd","SELECT","ID")
    Usually you will use whatever is available. Since the select element has no name or ID on the Empirix home page, I used the onChange attribute. You can use any attribute as long as you specify which one you are using (last argument in these examples)
    You can use the FindElement to grab links, text boxes, etc.
    The next example grabs from a link on a page
    Home
    Set x = RSWApp.om.FindElement("Home","A","innerText")
    I hope this helps clear it up.

  • How Can I get multi column values from dynamic search help?

    Hi Gurus;
    I'm using dynamic search help in my program.
    I want to get multi column values from search help. But I dont know solution for this issue.
    I'm using F4IF_INT_TABLE_VALUE_REQUEST FM.
    How Can I get multi column values from dynamic search help?
    Thanks.

    Believe it or not, the same FM worked for me in a dynpro. I will try to explain here how it works in custom screen and then you can do your work for other screens or program types. I am not going to write my actual work but will explain in general.
    I have 4 fields (FLD1, FLD2, FLD3, FLD4) and i made the search based on FLD2 and when user click on a line (could be any field), then this would bring the line on to the screens.
    There are like 3 steps.
    You have your value_tab for my fields FLD1, FLD2, FLD3 and FLD4. This is just the data that we pass into the FM. (data: IT_VALTAB type table of ZVAL_TABLE)
    Next map the screen fields into an internal table (data: It_dynpfld type table of dselc ). I also have other internal tables defined  (just to keep it straight, i will be putting here) data:  It_return type standard table of ddshretval.
    Next step is to call the function module. Make sure you have values in IT_VALTAB.
    call function 'F4IF_INT_TABLE_VALUE_REQUEST'
    exporting
            retfield        = 'FLD2'
            value_org       = 'S'
          tables
            value_tab       = It_VALTAB
            return_tab      = It_return
            dynpfld_mapping = It_dynpfld
          exceptions
            parameter_error = 1
            no_values_found = 2
            others          = 3.
        if sy-subrc <> 0.
          message id sy-msgid type sy-msgty number sy-msgno
          with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        else.
          perform get_selected_fields tables It_return.
        endif.
    The code within the perform GET_SELECTED_FIELDS  - We need to map the result fields after user selects it. The code goes like this. This is step is to update the dynpro fields.
    I need a internal table as well as a work area here. like,
    data: lt_fields type table of dynpread,
            la_fields type dynpread.
      field-symbols: <fs_return> type ddshretval.
    so fill out LT_FIELDS from the IT_RETURN table
    loop at lt_return assigning <fs_return>.
        la_fields-fieldname = <fs_return>-retfield.
        la_fields-fieldvalue = <fs_return>-fieldval.
        append la_fields to lt_fields.
        clear: la_fields.
      endloop.
    Call the FM to update the dynpro
    call function 'DYNP_VALUES_UPDATE'
        exporting
          dyname               = sy-repid
          dynumb               = '1002' "This is my screen number. You could use 1000 for selection screen (hope so)
        tables
          dynpfields           = lt_fields
        exceptions
          invalid_abapworkarea = 1
          invalid_dynprofield  = 2
          invalid_dynproname   = 3
          invalid_dynpronummer = 4
          invalid_request      = 5
          no_fielddescription  = 6
          undefind_error       = 7
          others               = 8.
      if sy-subrc <> 0.
        message id sy-msgid type sy-msgty number sy-msgno
                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      endif.
    good luck

  • Trying to get multiple cell values within a geometry

    I am provided with 3 tables:
    1 - The GeoRaster
    2 - The geoRasterData table
    3 - A VAT table who's PK is the cell value from the above tables
    Currently the user can select a point in our application and by using the getCellValue we get the cell value which is the PK on the 3rd table and this gives us the details to return to the user.
    We now want to give the worst scenario within a given geometry or distance. So if I get back all the cell values within a given geometry/distance I can then call my other functions against the 3rd table to get the worst scores.
    I had a conversation open for this before where JeffreyXie had some brilliant input, but it got archived while I was waiting on Oracle to resolve a bug (about 7 months)
    See:
    Trying to get multiple cell values within a geometry
    If I am looking to get a list of cell values that interact with my geometry/distance and then loop through them, is there a better way?
    BTW, if anybody wants to play with this functionality, it only seems to work in 11.2.0.4.
    Below is the code I was using last, I think it is trying to get the cell values but the numbers coming back are not correct, I think I am converting the binary to integer wrong.
    Any ideas?
    CREATE OR REPLACE FUNCTION GEOSUK.getCellValuesInGeom_FNC RETURN VARCHAR2 AS
    gr sdo_georaster;
    lb blob;
    win1 sdo_geometry;
    win2 sdo_number_array;
    status VARCHAR2(1000) := NULL;
    CDP varchar2(80);
    FLT number := 0;
    cdl number;
    vals varchar2(32000) := null;
    VAL number;
    amt0 integer;
    amt integer;
    off integer;
    len integer;
    buf raw(32767);
    MAXV number := null;
    r1 raw(1);
    r2 raw(2);
    r4 raw(200);
    r8 raw(8);
    MATCH varchar2(10) := '';
    ROW_COUNT integer := 0;
    COL_COUNT integer := 0;
    ROW_CUR integer := 0;
    COL_CUR integer := 0;
    CUR_XOFFSET integer := 0;
    CUR_YOFFSET integer := 0;
    ORIGINY integer := 0;
    ORIGINX integer := 0;
    XOFF number(38,0) := 0;
    YOFF number(38,0) := 0;
    BEGIN
    status := '1';
    SELECT a.georaster INTO gr FROM JBA_MEGARASTER_1012 a WHERE id=1;
    -- first figure out the celldepth from the metadata
    cdp := gr.metadata.extract('/georasterMetadata/rasterInfo/cellDepth/text()',
    'xmlns=http://xmlns.oracle.com/spatial/georaster').getStringVal();
    if cdp = '32BIT_REAL' then
    flt := 1;
    end if;
    cdl := sdo_geor.getCellDepth(gr);
    if cdl < 8 then
    -- if celldepth<8bit, get the cell values as 8bit integers
    cdl := 8;
    end if;
    dbms_lob.createTemporary(lb, TRUE);
    status := '2';
    -- querying/clipping polygon
    win1 := SDO_GEOM.SDO_BUFFER(SDO_GEOMETRY(2001,27700,MDSYS.SDO_POINT_TYPE(473517,173650.3, NULL),NULL,NULL), 10, .005);
    status := '1.2';
    sdo_geor.getRasterSubset(gr, 0, win1, '1',
    lb, win2, NULL, NULL, 'TRUE');
    -- Then work on the resulting subset stored in lb.
    status := '2.3';
    DBMS_OUTPUT.PUT_LINE ( 'cdl: '||cdl );
    len := dbms_lob.getlength(lb);
    cdl := cdl / 8;
    -- make sure to read all the bytes of a cell value at one run
    amt := floor(32767 / cdl) * cdl;
    amt0 := amt;
    status := '3';
    ROW_COUNT := (WIN2(3) - WIN2(1))+1;
    COL_COUNT := (WIN2(4) - WIN2(2))+1;
    --NEED TO FETCH FROM RASTER
    ORIGINY := 979405;
    ORIGINX := 91685;
    --CALCUALATE BLOB AREA
    YOFF := ORIGINY - (WIN2(1) * 5); --177005;
    XOFF := ORIGINX + (WIN2(2) * 5); --530505;
    status := '4';
    --LOOP CELLS
    off := 1;
    WHILE off <= LEN LOOP
    dbms_lob.read(lb, amt, off, buf);
    for I in 1..AMT/CDL LOOP
    if cdl = 1 then
    r1 := utl_raw.substr(buf, (i-1)*cdl+1, cdl);
    VAL := UTL_RAW.CAST_TO_BINARY_INTEGER(R1);
    elsif cdl = 2 then
    r2 := utl_raw.substr(buf, (i-1)*cdl+1, cdl);
    val := utl_raw.cast_to_binary_integer(r2);
    ELSIF CDL = 4 then
    IF (((i-1)*cdl+1) + cdl) > len THEN
    r4 := utl_raw.substr(buf, (i-1)*cdl+1, (len - ((i-1)*cdl+1)));
    ELSE
    r4 := utl_raw.substr(buf, (i-1)*cdl+1, cdl+1);
    END IF;
    if flt = 0 then
    val := utl_raw.cast_to_binary_integer(r4);
    else
    val := utl_raw.cast_to_binary_float(r4);
    end if;
    elsif cdl = 8 then
    r8 := utl_raw.substr(buf, (i-1)*cdl+1, cdl);
    val := utl_raw.cast_to_binary_double(r8);
    end if;
    if MAXV is null or MAXV < VAL then
    MAXV := VAL;
    end if;
    IF i = 1 THEN
    VALS := VALS || VAL;
    ELSE
    VALS := VALS ||'|'|| VAL;
    END IF;
    end loop;
    off := off+amt;
    amt := amt0;
    end loop;
    dbms_lob.freeTemporary(lb);
    status := '5';
    RETURN VALS;
    EXCEPTION
        WHEN OTHERS THEN
            RAISE_APPLICATION_ERROR(-20001, 'GENERAL ERROR IN MY PROC, Status: '||status||', SQL ERROR: '||SQLERRM);
    END;

    Hey guys,
    Zzhang,
    That's a good spot and as it happens I spotted that and that is why I am sure I am querying that lob wrong. I always get the a logic going past the total length of the lob.
    I think I am ok using 11.2.0.4, if I can get this working it is really important to us, so saying to roll up to 11.2.0.4 for this would be no problem.
    The error in 11.2.0.3 was an internal error: [kghstack_underflow_internal_3].
    Something that I think I need to find out more about, but am struggling to get more information on is, I am assuming that the lob that is returned is all cell values or at lest an array of 4 byte (32 bit) chunks, although, I don't know this.
    Is that a correct assumption or is there more to it?
    Have either of you seen any documentation on how to query this lob?
    Thanks

  • I have updated my mac from snow leopard to mountain lion 3 days back. I had some important data in my library folder and it got overwritten. Is there any way i can get the data back from my snow leopard library folder?

    I have updated my mac from snow leopard to mountain lion 3 days back. I had some important data in my library folder and it got overwritten. Is there any way i can get the data back from my snow leopard library folder?
    I tried mackeeper to recover files but it could not. Any other way any one has tried to recover a system library folder after OS upgrade?

    No, it doesn't store a clone. You would have needed to make one with either SuperDuper or CarbonCopy Cloner.
    If the files were in your ~/Library folder then they may still be there. As I said, you can access it by
    going to your Finder "Go" menu hold the option key to choose "Library". I wouldn't think an upgrade would overwrite anything in ~/Library.
    If you have a Time Machine backup you may also be able to use that to retrieve them.

  • How to change a date value from "java.util.Date" to "java.sql.Date"?

    Hi all,
    How to change a date value from "java.util.Date" to "java.sql.Date"?
    I m still confusing what's the difference between them.....
    thanks
    Regards,
    Kin

    Thanks
    but my sql statement can only accept the format (yyyy-MM-dd)
    such as "select * from xx where somedate = '2004-12-31'
    but when i show it to screen, i want to show it as dd-MM-yyyy
    I m using the following to change the jave.util.Date to str and vice versa. But it cannot shows the dd-MM-yyyy. I tried to change the format from yyyy-MM-dd to dd-MM-yyyy, it shows the wrong date in my application.
         public String date2str(java.util.Date thisdate)     {
              if (thisdate != null)     {
                   java.sql.Date thissDate = new java.sql.Date(thisdate.getTime());
                   return date2str(thissDate);
              }     else     {
                   return "";
         public String date2str(java.sql.Date thisdate)     {
              if (thisdate != null)     {
                   SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                   return sdf.format(thisdate);
              }     else     {
                   return "";
         public java.util.Date str2date(String thisdate)     {
              String dateFormat = "yyyy-MM-dd"; // = 1998-12-31
              java.util.Date returndate = null;
              if (thisdate != null)     {
                   SimpleDateFormat dateFormatter = new SimpleDateFormat(dateFormat);
                   try {
                        returndate = dateFormatter.parse(thisdate);
                   } catch (ParseException pe) {
                        System.out.println (pe.getMessage());
              return returndate;
         }

  • Trying to get old data off a g4 tower

    Hi- I am trying to get old data off a g4 tower using macbook and firewire but I am not succeeding. My old monitor doesn't seem to work. Any suggestions greatly appreciated. I also have a Gdrive if that might work.

    Here's another method.
    Buy one of these hard drive adapters.
    http://cgi.ebay.com/USB-2-0-SATA-PATA-3-5-2-5-Hard-Drive-Adapter-Cable-/14041077 1759?cmd=ViewItem&pt=LHDefaultDomain0&hash=item20b122592f
    Remove the hard drive from the G4. Using the above adapter, connect the drive to your MacBook. Copy the files you want.
     Cheers, Tom

  • Getting 2nd Least Value from Different Column

    Hi there All,
    I have one odd requirement.
    I hava table which has diffrent columns of numeric Datatype.
    The task is to get the least values from the table.
    I can take the least value by least(col1,col2,col3 ...) function.Until this stage it is fine.
    But also I have take 2nd least value and 3rd least value, which I am quite unsure how to get it.
    Looking forward for suggestions.
    Thanks in Advance.
    Regards,
    Ajeet

    The following is a generic solution that will allow you to select the nth least and allow you to pass as many column names as you like and will return null if the nth least requested exceeds the number of distinct values. The nleast function that I wrote uses the str2tbl function by Tom Kyte. I have included a demonstration of its usage below. The value returned for the 1st least is the same as that returned by the least function.
    This should have been posted on the SQL and PL/SQL discussion group of these forums, rather than the general database. I also posted the same response in the SQL discussion group of the Orafaq forums.
    scott@ORA92> -- test data:
    scott@ORA92> SELECT * FROM your_table
      2  /
          COL1       COL2       COL3
             1          2          3
             4          6          5
             8          7          9
            11         12         10
            15         13         14
            18         17         16
    6 rows selected.
    scott@ORA92> -- type and functions:
    scott@ORA92> create or replace type myTableType as table of number;
      2  /
    Type created.
    scott@ORA92> create or replace function str2tbl( p_str in varchar2 )
      2  return myTableType
      3  as
      4        l_str      long default p_str || ',';
      5        l_n         number;
      6        l_data    myTableType := myTabletype();
      7  begin
      8        loop
      9            l_n := instr( l_str, ',' );
    10            exit when (nvl(l_n,0) = 0);
    11            l_data.extend;
    12            l_data( l_data.count ) := ltrim(rtrim(substr(l_str,1,l_n-1)));
    13            l_str := substr( l_str, l_n+1 );
    14        end loop;
    15        return l_data;
    16  end;
    17  /
    Function created.
    scott@ORA92> CREATE OR REPLACE FUNCTION nleast
      2    (p_n        IN NUMBER,
      3       p_nums        IN VARCHAR2)
      4    RETURN           NUMBER
      5  AS
      6    v_nleast      NUMBER;
      7  BEGIN
      8    SELECT DISTINCT column_value
      9    INTO   v_nleast
    10    FROM   (SELECT column_value,
    11                  DENSE_RANK () OVER (ORDER BY column_value) AS num_rk
    12              FROM   (select *
    13                   from   table (CAST (str2tbl (p_nums) AS mytabletype)))
    14             WHERE   column_value IS NOT NULL)
    15    WHERE  num_rk = p_n;
    16    RETURN v_nleast;
    17  EXCEPTION
    18    WHEN OTHERS THEN RETURN NULL;
    19  END nleast;
    20  /
    Function created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> -- query:
    scott@ORA92> SELECT col1, col2, col3,
      2           LEAST (col1, col2, col3) AS the_least,
      3           nleast (1, col1 || ',' || col2 || ',' || col3) AS first_least,
      4           nleast (2, col1 || ',' || col2 || ',' || col3) AS second_least,
      5           nleast (3, col1 || ',' || col2 || ',' || col3) AS third_least,
      6           nleast (4, col1 || ',' || col2 || ',' || col3) AS fourth_least
      7  FROM   your_table
      8  /
          COL1       COL2       COL3  THE_LEAST FIRST_LEAST SECOND_LEAST THIRD_LEAST FOURTH_LEAST
             1          2          3          1           1            2           3
             4          6          5          4           4            5           6
             8          7          9          7           7            8           9
            11         12         10         10          10           11          12
            15         13         14         13          13           14          15
            18         17         16         16          16           17          18
    6 rows selected.

Maybe you are looking for

  • Terminal.app resize bug?

    I use the Terminal.app to log into a Linux machine. I usually open up multiple tabs per window, and I run emacs in some of the terminal window. The problem is that when I resize the windows, often the window can not remember what size it's supposed t

  • IPod Nano 2nd Gen. resets (Windows + Winamp)

    Hello, I have got a iPod Nano and I have the problem that it reboots when it tries to play certain files. I'm using Windows and Winamp. This has been annoying over a long time. Now I found out that the reboots happen if the file name ends with .MP3 (

  • Cases and Accessories for 5G iPods

    Ok, so ever since I purchased my Black 60GB iPod I started reading about how easily it scratched and realized I needed to get a case for it immediately. I was also surprised to discover that my old iTrip and other top docking accessories no longer wo

  • My adapter getting very hot

    hi everyone please help me...i have a one problem.During recharging my 60watt adapter is getting very hot. about 60celsuis.Is it normal? 

  • After updating to Yosemite, MacBook Pro freezes every 5 seconds and is unusable.

    Macbook pro was working perfectly fine for first day after update, but after a day it freezes and shows the rainbow wheel every 5 seconds so that I can't even use it. I've noticed when it logs in and I have two options of my accnt and guest, then whe