Sql function for fetching only initail char of string

Hi All,
I would like to know is there any sql builtin function which returns initial char(abbrevation) of any string pass to it
for eg. DEPARTMENT SUB GROUP should return DSG..
Pls do share with me if any 1 is aware of this or who has already self defined any function for this purpose.
Thanks in Advance

And if you have 10g available, here's the regex version:
with t as (select 'DEPARTMENT SUB GROUP' col1
             from dual)
select t.col1, regexp_replace(t.col1, '(\w)\w*\s*', '\1')
  from t;Small correction, just in case we only have 1 letter words.
C.

Similar Messages

  • Help in using listagg function for more than 8000 char.

    Hi Friends,
    Need you urgent help in using listagg function for more than 8000 char.
    I did the below sample SQL and in "e_orig" and "d_orig" for upto 4000 char it is working fine but I have to use it for more than 8000 char. and it is giving error,
    I checked the listagg function is having limitation of 4000 char.
    I tried but I am unable to achive this. Can someone provide me a sample example to achive this
    select d.dname,d.loc,e.hiredate
    ,listagg(e.ename,',' ) within group (order by e.deptno) over (partition by e.deptno) as e_orig
    ,listagg(e.ename, ',') within group (order by e.sal) over (partition by e.deptno) as d_orig
    from emp e, dept d
    where e.deptno=d.deptno;[ This is my first post, I gone through the guideline for posting a post , and try to go according to that ( I have not pasted here create table and insert as I have used basic table emp, dept for example), please let me know if still I should give this, I will take care from my next post ]
    Thanks in advance

    Interesting, I didn't know you could do that, but...
    BluShadow wrote:
    You could write some PL/SQL code that does it all for you, but that would involve loops and would be slow.Well, objects are written in PL/SQL aren't they? And presumably there'll be implicit looping too? So it's not at all obvious that this method will be faster than doing the joining in PL/SQL in memory. The only way to find out is to benchmark them - so I have done that.
    I noticed that OP's ref cursor actually only ever retrieves a single record for a bound department number, so I decided the best thing would be to test using a procedure that passes an output string back. I selected all (109) employees and put spaces in to ensure above 4000 characters. I also noticed that as he is using PL/SQL he probably can use a VARCHAR2 type, but just not ListAgg in the query, so I wrote short procedures as follows:
    SimpleAggChr     - bulk collect and array processing, VARCHAR2 output
    ClobAggPrc     - the custom aggregation method, CLOB output
    SimpleAggClob     - bulk collect and array processing, CLOB output
    I then wrote a driving script that calls them in the order above and times each call (I like benchmarking so I have my own timing object to make it easy). I then print the lengths for checking, and my object writes the timings to my output table. Running a few times I got varying results, but generally it looks like there isn't a lot to choose between them for performance.
    Here's the procedure code:
    CREATE OR REPLACE TYPE char100_list_type AS TABLE OF VARCHAR2(100)
    CREATE OR REPLACE PROCEDURE SimpleAggChr (x_out OUT VARCHAR2) IS
      l_enames     char100_list_type;
    BEGIN
      SELECT first_name || '                                        ' || last_name
        BULK COLLECT INTO l_enames
        FROM employees
       ORDER BY salary;
      FOR i IN 1..l_enames.COUNT LOOP
        x_out := x_out || l_enames(i) || ',';
      END LOOP;
    END SimpleAggChr;
    CREATE OR REPLACE PROCEDURE SimpleAggClob (x_out OUT CLOB) IS
      l_enames     char100_list_type;
    BEGIN
      SELECT first_name || '                                        ' || last_name
        BULK COLLECT INTO l_enames
        FROM employees
       ORDER BY salary;
      FOR i IN 1..l_enames.COUNT LOOP
        x_out := x_out || l_enames(i) || ',';
      END LOOP;
    END SimpleAggClob;
    SHO ERR
    PROMPT ClobAggPrc
    CREATE OR REPLACE PROCEDURE ClobAggPrc (x_out OUT CLOB) IS
    BEGIN
      SELECT clobagg(first_name || '                                        ' || last_name || ',')
        INTO x_out
        FROM employees
       ORDER BY salary;
    END ClobAggPrc;
    SHO ERRand the driving script:
    SET SERVEROUTPUT ON
    SET TIMING ON
    DECLARE
      l_enames_c1     CLOB;
      l_enames_c2     CLOB;
      l_enames_v     VARCHAR2(32767);
      l_timer     timer_set_type := timer_set_type ('Aggregation');
    BEGIN
      Utils.g_id := 'Aggregation';
      SimpleAggChr (l_enames_v);
      l_timer.Increment_Time ('SimpleAggChr');
      ClobAggPrc (l_enames_c1);
      l_timer.Increment_Time ('ClobAggPrc');
      SimpleAggClob (l_enames_c2);
      l_timer.Increment_Time ('SimpleAggClob');
      DBMS_Output.Put_Line ('SimpleAggChr returned string of length ' || Length (l_enames_v));
      DBMS_Output.Put_Line ('ClobAggPrc returned string of length ' || Length (l_enames_c1));
      DBMS_Output.Put_Line ('SimpleAggClob returned string of length ' || Length (l_enames_c2));
      l_timer.Write_Times;
    END;
    SET TIMING OFF
    SET LINES 150
    SET PAGES 1000
    COLUMN id FORMAT A30
    COLUMN line_text FORMAT A120
    SELECT line_text
      FROM output_log
    WHERE id = 'Aggregation'
    ORDER BY line_ind
    /and the results:
    SimpleAggChr returned string of length 5779
    ClobAggPrc returned string of length 5779
    SimpleAggClob returned string of length 5779
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:27.05
    LINE_TEXT
    Timer Set: Aggregation, constructed at 03 Nov 2011 16:27:07, written at 16:27:35
    ================================================================================
    [Timer timed: Elapsed (per call): 0.02 (0.000016), CPU (per call): 0.01 (0.000010), calls: 1000, '***' denotes corrected
    line below]
    Timer              Elapsed          CPU          Calls        Ela/Call        CPU/Call
    SimpleAggChr          9.84         0.36              1         9.84400         0.36000
    ClobAggPrc            9.37         0.32              1         9.37400         0.32000
    SimpleAggClob         8.25         0.22              1         8.25000         0.22000
    (Other)               0.00         0.00              1         0.00000         0.00000
    Total                27.47         0.90              4         6.86700         0.22500
    13 rows selected.

  • Built in SQL Function for Sum of Geometric Progression

    Hi all,
    Please let me know if there is any availble built in SQL function for
    SUm of Geometric Progression.
    Thanks in Advance,
    Kaushik B.

    and also relatively simple to write:
    s = a*(1-power(r,n+1))/(1-r)
    assuming you have a row with values of a,r and n (and that's the sum you need)
    Jon

  • Displaying diff dates using PL/SQL expression for 'display only' item ?

    Hi ,
    I am having a display only item -- :P2_FROM_Date . If its Thu,Fri,Sat or Sun I want to set the date as the last Monday's date . If its Mon,Tue or Wed then it should be the present Monday's date .
    E.g: Today is Friday and the last Monday was on 18th .
    So for yesterday , today,tomorrow and Sunday , the date should be displayed as 18-JUN-2012.
    From the coming Monday to Wednesday , the date should of be the coming Monday i.e , 24-JUN-2012
    I tried it doing under 'Source ' of item using PL/SQL expression and PL/SQL function body. Not working
    Can someone help ?
    Thanks & Regards
    Umer

    Nice1 wrote:
    declare
    lv_date number;
    begin
    select to_char(sysdate,'D') into lv_date from dual;
    if lv_date=2 then
    :P2_FROM_DATE := to_char(sysdate-1);
    end if;
    end;I tried this under " PL/SQL function body " in "Source " tab of the item P2_FROM_DATE
    When I run this , nothing is displayed corresponding to the item P2_FROM_DATEExactly as expected. This code will only set a value for <tt>P2_FROM_DATE</tt> when run on Mondays in territories where the first day of the week is Sunday, and when run on Tuesdays where Monday is the first day of of the week:
    SQL> var P2_FROM_DATE varchar2(30)
    SQL> alter session set nls_date_format='Dy DD-MON-YYYY';
    Session altered.
    SQL> select sysdate from dual
    SYSDATE
    Mon 25-JUN-2012
    SQL> alter session set nls_territory='AMERICA';
    Session altered.
    SQL> declare
      2  lv_date number;
      3  begin
      4  select to_char(sysdate,'D') into lv_date from dual;
      5  if lv_date=2 then
      6  :P2_FROM_DATE := to_char(sysdate-1);
      7  end if;
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    SQL> print p2_from_date
    P2_FROM_DATE
    Sun 24-JUN-2012
    SQL> alter session set nls_territory='UNITED KINGDOM';
    Session altered.
    SQL> exec :p2_from_date := null
    SQL> declare
      2  lv_date number;
      3  begin
      4  select to_char(sysdate,'D') into lv_date from dual;
      5  if lv_date=2 then
      6  :P2_FROM_DATE := to_char(sysdate-1);
      7  end if;
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    SQL> print p2_from_date
    P2_FROM_DATE
    SQL>Hence the questions about language above.
    >
    I am having a display only item -- :P2_FROM_Date . If its Thu,Fri,Sat or Sun I want to set the date as the last Monday's date . If its Mon,Tue or Wed then it should be the present Monday's date .
    E.g: Today is Friday and the last Monday was on 18th .
    So for yesterday , today,tomorrow and Sunday , the date should be displayed as 18-JUN-2012.
    From the coming Monday to Wednesday , the date should of be the coming Monday i.e , 24-JUN-2012
    >
    The coming Monday is 25-JUN-2012.
    Aren't these rules equivalent to "Monday this week, where Monday is the first day of the week"? In which case the PL/SQL Expression you require is:
    trunc(sysdate, 'iw')For example:
    SQL> with t as (
      2    select date '2012-06-21' + level d from dual connect by level <= 17)
      3  select
      4            d
      5          , trunc(d, 'iw')  monday
      6  from
      7            t;
    D               MONDAY
    Fri 22-JUN-2012 Mon 18-JUN-2012
    Sat 23-JUN-2012 Mon 18-JUN-2012
    Sun 24-JUN-2012 Mon 18-JUN-2012
    Mon 25-JUN-2012 Mon 25-JUN-2012
    Tue 26-JUN-2012 Mon 25-JUN-2012
    Wed 27-JUN-2012 Mon 25-JUN-2012
    Thu 28-JUN-2012 Mon 25-JUN-2012
    Fri 29-JUN-2012 Mon 25-JUN-2012
    Sat 30-JUN-2012 Mon 25-JUN-2012
    Sun 01-JUL-2012 Mon 25-JUN-2012
    Mon 02-JUL-2012 Mon 02-JUL-2012
    Tue 03-JUL-2012 Mon 02-JUL-2012
    Wed 04-JUL-2012 Mon 02-JUL-2012
    Thu 05-JUL-2012 Mon 02-JUL-2012
    Fri 06-JUL-2012 Mon 02-JUL-2012
    Sat 07-JUL-2012 Mon 02-JUL-2012
    Sun 08-JUL-2012 Mon 02-JUL-2012
    17 rows selected.
    SQL> alter session set nls_territory='AMERICA';
    Session altered.
    SQL> alter session set nls_date_format='Dy DD-MON-YYYY';
    Session altered.
    SQL> with t as (
      2    select date '2012-06-21' + level d from dual connect by level &lt;= 17)
      3  select
      4            d
      5          , trunc(d, 'iw')  monday
      6  from
      7            t;
    D               MONDAY
    Fri 22-JUN-2012 Mon 18-JUN-2012
    Sat 23-JUN-2012 Mon 18-JUN-2012
    Sun 24-JUN-2012 Mon 18-JUN-2012
    Mon 25-JUN-2012 Mon 25-JUN-2012
    Tue 26-JUN-2012 Mon 25-JUN-2012
    Wed 27-JUN-2012 Mon 25-JUN-2012
    Thu 28-JUN-2012 Mon 25-JUN-2012
    Fri 29-JUN-2012 Mon 25-JUN-2012
    Sat 30-JUN-2012 Mon 25-JUN-2012
    Sun 01-JUL-2012 Mon 25-JUN-2012
    Mon 02-JUL-2012 Mon 02-JUL-2012
    Tue 03-JUL-2012 Mon 02-JUL-2012
    Wed 04-JUL-2012 Mon 02-JUL-2012
    Thu 05-JUL-2012 Mon 02-JUL-2012
    Fri 06-JUL-2012 Mon 02-JUL-2012
    Sat 07-JUL-2012 Mon 02-JUL-2012
    Sun 08-JUL-2012 Mon 02-JUL-2012
    17 rows selected.Also note that using the item source properties will only set the <tt>P2_FROM_DATE</tt> in the rendered page, not in session state.

  • XMLType schema detail lost in pl/sql function for a jdeveloper webservice

    If I write a very simple pl/sql procedure to wrap as a web service to return the XML from an XMLtype table column, the jdeveloper (11.1.1.3) web service generation process seems to ignore the detail
    of the registered XMLTypes' schema, and converts the 'output' to an xsd:string in the generated WSDL file, which has knock on effect that generated data controls are 'dumb' in only seeing output as a string, and providing no real data functionality at XML schema level. Since I know web service data controls work fine when provided with the correct level of detail in the WSDL, what am I missing in terms of pursuading jdeveloper to generate wsdl's with full xsd schema info for the return XMLType?
    This is my table:
    ID NOT NULL NUMBER(12)
    SPEC SYS.XMLTYPE(XMLSchema "http:
    //localhost:8080/public/demo
    /xsd/sample2.xsd" Element "b
    ooks") STORAGE BINARY
    PRD_ID NOT NULL NUMBER(10)
    ISSUE NOT NULL NUMBER(6)
    EDIT_NO NOT NULL NUMBER(6)
    PUBLISHED_BY_PEO_ID NUMBER(10)
    PUBLISHED_ON_DT DATE
    EFFECTIVE_FROM_DT NOT NULL DATE
    EFFECTIVE_TO_DT DATE
    =======================================================
    This is the XML Schema:
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="urn:books"
    xmlns:bks="urn:books">
    <xsd:element name="books" type="bks:BooksForm"/>
    <xsd:complexType name="BooksForm">
    <xsd:sequence>
    <xsd:element name="book"
    type="bks:BookForm"
    minOccurs="0"
    maxOccurs="unbounded"/>
    </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="BookForm">
    <xsd:sequence>
    <xsd:element name="author" type="xsd:string"/>
    <xsd:element name="title" type="xsd:string"/>
    <xsd:element name="genre" type="xsd:string"/>
    <xsd:element name="price" type="xsd:float" />
    <xsd:element name="pub_date" type="xsd:date" />
    <xsd:element name="review" type="xsd:string"/>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:string"/>
    </xsd:complexType>
    </xsd:schema>
    =================================================
    This is the pl/sql:
    function GetSpecificationById (p_spec_id in NUMBER) return XMLType
    IS
    l_specification sys.XMLType;
    BEGIN
    select specification
    into l_specification
    from specifications
    where id = p_spec_id;
    return l_specification;
    EXCEPTION
    WHEN OTHERS THEN -- handles all other errors
    ROLLBACK;
    END GetSpecificationById;
    ==============================================
    And this is the generated WSDL:
    <?xml version="1.0" encoding="UTF-8" ?>
    <wsdl:definitions
    name="MyWebService1"
    targetNamespace="http://devsafetrytrailcom/MyWebService1.wsdl"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:tns="http://devsafetrytrailcom/MyWebService1.wsdl"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
    >
    <wsdl:types>
    </wsdl:types>
    <wsdl:message name="MyWebService1_getspecificationbyid">
    <wsdl:part name="pSpecId" type="xsd:decimal"/>
    </wsdl:message>
    <wsdl:message name="MyWebService1_getspecificationbyidResponse">
    *<wsdl:part name="result" type="xsd:string"/>*
    </wsdl:message>
    <wsdl:portType name="MyWebService1">
    <wsdl:operation name="getspecificationbyid" parameterOrder="pSpecId">
    <wsdl:input message="tns:MyWebService1_getspecificationbyid"/>
    <wsdl:output message="tns:MyWebService1_getspecificationbyidResponse"/>
    </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="MyWebService1" type="tns:MyWebService1">
    <soap:binding style="rpc"
    transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="getspecificationbyid">
    <soap:operation soapAction="http://devsafetrytrailcom/MyWebService1.wsdl/getspecificationbyid"/>
    <wsdl:input>
    <soap:body use="literal"
    namespace="http://devsafetrytrailcom/MyWebService1.wsdl"
    parts="pSpecId"/>
    </wsdl:input>
    <wsdl:output>
    <soap:body use="literal"
    namespace="http://devsafetrytrailcom/MyWebService1.wsdl"
    parts="result"/>
    </wsdl:output>
    </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="MyWebService1">
    <wsdl:port name="MyWebService1Port" binding="tns:MyWebService1">
    <soap:address location="http://localhost:7101/SafetyTrail-Model-context-root/MyWebService1Port"/>
    </wsdl:port>
    </wsdl:service>
    </wsdl:definitions>
    Edited by: user592403 on Jul 26, 2010 9:57 AM

    Anyone seen this problem before??

  • How can i make a pl/sql function for BLOB datatype

    hi..anyone here who is very familiar about BLOB datatype. i have a COLUMN_ID, COLUMN_A in a certain TABLE_1. COLUMN_A is blob datatype that contains almost 250,000rows
    SQL>select column_A from table_1 where column_id=1234567
    column_A
    00000001000000010000000606D4E833074B69EC06D4E91F074CO18406D50C58074C031E
    how can i make a user-defined function to compute and convert this blob datatype into decimal length value. this hex value are points in the map.. the function must contain
    1.get the length of a blob then
    2.convert blob to variable hexadecimal characters by parsing it into 8
    3.to_number function or other function used to convert haxadecimal characters to decimal numbers
    4.phythagorean formula to compute length between two points. this is the formula i think LENGTH =
    SQRT(power((coordinate_x-prev_coordinate_x),2)+power((coordinate_y-prev_y),2));
    after this when i type this
    SQL>select user_function(column_A) from table_1 where column_id=1234567
    user_functions(column_A)
    --output length will be in decimal value already
    the function will goes like this
    step1 is to get the blob length
    00000001000000010000000606D4E833074B69EC06D4E91F074CO18406D50C58074C031E
    step2 is parsing of data by eights
    00000001 =>1
    00000001 =>1
    00000006 =>6 (number of coordinates)
    06D4E833 => X1
    074B69EC => Y1
    06D4E91F => X2
    074CO184 => Y2
    06D50C58 => X3
    074C031E => Y3
    step3 to_number function used to convert hex char to decimal
    step4 compute by phytagorean (NOTE ! when computing length the third parsed eight will tell how many coordinates are there..the number of coordinates is ranging from 2 up to E..above example shows 6 coordinates so it means
    LENGTH1 =
    SQRT(power((X2-X1),2)+power((Y2-Y1),2));
    LENGTH2=
    SQRT(power((X3-X2),2)+power((Y3-Y2),2));
    TOTAL LENGTH=LENGTH1 + LENGTH2
    thanks

    its my first time to use that.There's got to be a first tiem for anything. Be brave.
    btw if theres more easy suggestion pls feel free..Well of course the easiest solution would be if the calling program passed in the parameters as separate arguments instead of glomming them together in a string that has to be parsed. This sort of kluj really ought not to have survived into C21.
    Cheers, APC

  • Using pl/sql functions for transformation

    How can I use pl/sql functions in the transformation mapping field for my interface?
    I have a name field where firstname and lastname are concatenated via a space-character and I would like to extract this 'name' field to 2 separate database attributes.
    This means that I need to use a function that uses SUBSTRING and INSTR to be able to get the firstname and lastname separatly out of the name-field.
    The INSTR-function isn't known inside the expression editor in ODI so I'm wondering how I can use my own function?

    Hi Romanna,
    Are you sure? Where did you do your transformation?
    -Source, Staging area or Target
    I try this on Oracle target...
    FIRST_NAME = substr(MYTABLE.FIRST_LASTNAME, 1, instr(MYTABLE.FIRST_LASTNAME, ' ')-1)
    LAST_NAME = substr(MYTABLE.FIRST_LASTNAME,instr(MYTABLE.FIRST_LASTNAME, ' ')+1)

  • PL/SQL-Function for validation

    I wrote a PL/SQL function in order to validate that the SUM of input-values doesn't exceed 100.
    I used validation rule from APEX for PL/SQL-expression (same like SQL-expression):
    f_page_16_validation(:P16_PSP_PSP)<=100 (Condition: CREATE, SAVE)
    source code for function:
    CREATE OR REPLACE FUNCTION f_page_16_validation
    (pi_p16_psp_psp VARCHAR2)
    RETURN NUMBER
    IS
    vl_sum NUMBER(5) := 0;
    BEGIN
    SELECT NVL(SUM(psp_anteil_projekt),0) INTO vl_sum
    FROM st_psp_projekt_psp
    WHERE UPPER(psp_psp) = pi_p16_psp_psp;
    RETURN vl_sum;
    END f_page_16_validation;
    When I check in SQL*Plus against database: SELECT f_page_16_validation('A_TEST_UHL_PSP%') FROM dual;
    I get the correct value. When I input into APEX-Application the validation rule doesn't fire (CREATE). If my SUM is over 100 and try to change
    one value (in order to come under 100) (SAVE) - the validation rule fires but quite independent of the SUM - it accepts NO VALUE!!
    Apex-Version: 3.1.1.00.09
    Can somebody tell me what's wrong? Is there any other way - SQL,PL/SQL-expression, PL/SQL-function body (bool, error text) didn't work.

    1. If your PL/SQL expression is written as you stated:
    f_page_16_validation(:P16_PSP_PSP)<=100then you will receive an error message if the total is <= 100 and not if it exceeds 100.
    2. Where in your code do you consider the input values? I see that you are selecting from a table, where your already inserted values are but I see no input values. Are you using a form or a tabular form? If I look at the names of your buttons then I wouls say you are using a form.
    3. You are talking about condition. What type of condition you use? I would use a PL/SQL Expression like this:
    :REQUEST IN ('CREATE', 'SAVE')4. I would suggest to use a validation of type PL/SQL Function Returning Error Text since you can put all the code in one.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • SQL Function for calculating IP Address

    Hi Experts ,
    I have an IP Range i need to find out the First Host detail for the IP using a SQL scalar function .
    Example : 11.30.10.40
    Subnet Mask is 26
    Output required
    First host: 11.30.10.1
    am confused how i can derive the first host  values from a sql function kindly help .
    Thanks
    Priya

    DECLARE @Mask TINYINT = 26;
    DECLARE @AddressIP VARCHAR(15)= '11.30.10.40';
    DECLARE @AddressValue BIGINT = PARSENAME(@AddressIP,4)*CAST(256*256*256 AS BIGINT)+PARSENAME(@AddressIP,3)*256*256+PARSENAME(@AddressIP,2)*256+PARSENAME(@AddressIP,1);
    WITH
    n0(n) AS (SELECT 0 UNION ALL SELECT 0)
    ,n1(n) AS (SELECT 0 FROM n0 a CROSS JOIN n0)
    ,n2(n) AS (SELECT 0 FROM n1 a CROSS JOIN n1)
    ,n3(n) AS (SELECT 0 FROM n2 a UNION ALL SELECT 0 g FROM n2)
    ,t (n) AS (SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) FROM n3)
    ,bits(b,v) AS (SELECT n,POWER(CAST(2 AS BIGINT),32-n) FROM t)
    SELECT @AddressIP [Address]
    ,CAST((SUM(v) / 256 / 256 / 256) % 256 AS VARCHAR(3)) + '.' + CAST((SUM(v) / 256 / 256) % 256 AS VARCHAR(3)) + '.' + CAST((SUM(v) / 256) % 256 AS VARCHAR(3)) + '.' + CAST(SUM(v) % 256 AS VARCHAR(3)) [Netmask]
    ,CAST(((SUM(v) ^ 0xFFFFFFFF) / 256 / 256 / 256) % 256 AS VARCHAR(3)) + '.' + CAST(((SUM(v) ^ 0xFFFFFFFF) / 256 / 256) % 256 AS VARCHAR(3)) + '.' + CAST(((SUM(v) ^ 0xFFFFFFFF) / 256) % 256 AS VARCHAR(3)) + '.' + CAST(((SUM(v) ^ 0xFFFFFFFF)) % 256 AS VARCHAR(3)) [Wildcard]
    ,CAST(((@AddressValue & SUM(v)) / 256 / 256 / 256) % 256 AS VARCHAR(3)) + '.' + CAST(((@AddressValue & SUM(v)) / 256 / 256) % 256 AS VARCHAR(3)) + '.' + CAST(((@AddressValue & SUM(v)) / 256) % 256 AS VARCHAR(3)) + '.' + CAST(((@AddressValue & SUM(v))) % 256 AS VARCHAR(3)) + '/' + CAST(MAX(b) AS VARCHAR(2)) [NetworkAddress]
    ,CAST(((((SUM(v) ^ 0xFFFFFFFF)) | @AddressValue) / 256 / 256 / 256) % 256 AS VARCHAR(3)) + '.' + CAST(((((SUM(v) ^ 0xFFFFFFFF)) | @AddressValue) / 256 / 256) % 256 AS VARCHAR(3)) + '.' + CAST(((((SUM(v) ^ 0xFFFFFFFF)) | @AddressValue) / 256) % 256 AS VARCHAR(3)) + '.' + CAST(((((SUM(v) ^ 0xFFFFFFFF)) | @AddressValue)) % 256 AS VARCHAR(3)) [BroadcastAddress]
    ,CAST(((@AddressValue & SUM(v)) / 256 / 256 / 256) % 256 AS VARCHAR(3)) + '.' + CAST(((@AddressValue & SUM(v)) / 256 / 256) % 256 AS VARCHAR(3)) + '.' + CAST(((@AddressValue & SUM(v)) / 256) % 256 AS VARCHAR(3)) + '.' + CAST(((@AddressValue & SUM(v))) % 256 + 1 AS VARCHAR(3)) [FirstHost]
    ,CAST(((((SUM(v) ^ 0xFFFFFFFF)) | @AddressValue) / 256 / 256 / 256) % 256 AS VARCHAR(3)) + '.' + CAST(((((SUM(v) ^ 0xFFFFFFFF)) | @AddressValue) / 256 / 256) % 256 AS VARCHAR(3)) + '.' + CAST(((((SUM(v) ^ 0xFFFFFFFF)) | @AddressValue) / 256) % 256 AS VARCHAR(3)) + '.' + CAST(((((SUM(v) ^ 0xFFFFFFFF)) | @AddressValue)) % 256 - 1 AS VARCHAR(3)) [LastHost]
    ,(((SUM(v) ^ 0xFFFFFFFF)) | @AddressValue) - (@AddressValue & SUM(v)) - 1 [TotalHostCount]
    FROM bits WHERE @Mask BETWEEN 1 AND 32 AND b <= @Mask
    Jon

  • Equivalent Sql function for Forms NAME_IN() built in

    Please let me know, is there any equivalent Sql function equivalent to Forms Name_in() built in. Thanks.

    What would such a function do in pure SQL? Or are you asking if you can refer to Forms variables in SQL that you issue from Forms?
    The answer to the first question I will delay until you define what it is that you want to do. The answer to the second question is that there is no way to do that. The database has no way of knowing how to resolve references to variables defined in client side PLSQL.

  • SQL function for PKIDs in 6.1.1

    Hi,
    I would like to ask if there is a new SQL function to generate the shorter PKIDs in 6.1.1?
    Thanks in advance.

    We do not yet have database functions to generate the new shortened PKIDs. If you want this, you can log an Enhancement Request with support..
    Thanks,
    Ron

  • Using pl/sql function for each day between two dates.

    Hi,
    create TABLE EMP(
    ID_EMP NUMBER,
    DT_FROM DATE,
    DT_TO DATE,
    CREATE_DATE DATE);
    into EMP(ID_EMP, DT_FROM, DT_TO, CREATE_DATE)
    Values(100, TO_DATE('07/01/2008 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('04/30/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),TO_DATE('05/08/2009 14:11:21', 'MM/DD/YYYY HH24:MI:SS'));
    I have a function called  elig_pay_dates(date p_date), which returns the code for  person payment eligibility for a particular date. For paid dates it's 'P' and for unpaid dates it's 'N'.
    How can I check this function between two dates for each day. Example : 07/01/2008 to 04/30/2010.
    By using this function with select I needs to display the dates when there is a change in status.
    I am expecting data in following manner from above logic(this is example):
    07/01/2008 --- 07/01/2009 ---'P'
    07/02/2009 -- 07/25/2009 ----'N'
    07/26/2009 -- 01/01/2010 ---'P'
    01/02/2010 -- 01/13/2010 --'N'
    01/14/2010 -- 01/18/2010 --'P'
    01/19/2010 -- 04/30/2010 -- 'N'
    I thought of looping for each day date but that seems to be expensive for online application. Is there any way that I can achieve this requirement with sql query ?
    Thanks for your help,

    Certainly not the best way to code the requirement, but it does achieve the result you are looking for in a fairly quick time
    create or replace
    function test_ret_paid_unpaid (p_date in date)
    return varchar2
    is
      v_ret     varchar2(1);
    begin
      if ( (p_date between to_date('07/02/2009', 'MM/DD/YYYY') and to_date('07/25/2009', 'MM/DD/YYYY') ) or
           (p_date between to_date('01/02/2010', 'MM/DD/YYYY') and to_date('01/13/2010', 'MM/DD/YYYY') ) or
           (p_date between to_date('01/19/2010', 'MM/DD/YYYY') and to_date('04/30/2010', 'MM/DD/YYYY') )
        then v_ret := 'N';
      else
        v_ret := 'Y';
      end if;
      return v_ret;
    end;
    Wrote file afiedt.buf
      1  with get_paid_unpaid as
      2  (
      3    select dt_from start_date, dt_to end_date, dt_from + level - 1 curr_date, test_ret_paid_unpaid(dt_from + level - 1) paid_unpaid,
      4           row_number() over (order by dt_from + level - 1) rn_start,
      5           row_number() over (order by dt_from + level - 1 desc) rn_end
      6      from test_emp
      7    connect by level <= dt_to - dt_from + 1
      8  ),
      9  get_stop_date as
    10  (
    11  select start_date init_date, end_date, curr_date, paid_unpaid,
    12         case when paid_unpaid != lag(paid_unpaid) over (order by curr_date) or rn_start = 1 or rn_end = 1
    13          then curr_date
    14          else null
    15         end start_date,
    16         case when paid_unpaid != lead(paid_unpaid) over (order by curr_date) or rn_start = 1 or rn_end = 1
    17          then curr_date
    18          else null
    19         end stop_date
    20    from get_paid_unpaid
    21  )
    22  select period, paid_unpaid
    23    from (
    24  select init_date, curr_date, start_date, end_date, stop_date,
    25         case when paid_unpaid = lead(paid_unpaid) over (order by curr_date)
    26                then nvl(start_date, init_date) || ' - ' || lead(stop_date, 1, end_date) over (order by curr_date)
    27              else null
    28         end period,
    29         paid_unpaid
    30    from get_stop_date
    31   where stop_date is not null or start_date is not null
    32         )
    33*  where period is not null
    12:06:10 SQL> /
    PERIOD                                             PAID_UNPAID
    01-JUL-08 - 01-JUL-09                              Y
    02-JUL-09 - 25-JUL-09                              N
    26-JUL-09 - 01-JAN-10                              Y
    02-JAN-10 - 13-JAN-10                              N
    14-JAN-10 - 18-JAN-10                              Y
    19-JAN-10 - 30-APR-10                              N
    6 rows selected.
    Elapsed: 00:00:00.35

  • Sql function for trimming from center

    Hi Experts;
    Is there any function which can remove/trim from center like i have a number
    01-1552963-01 and i want to remove - from it.
    01155296301
    note that i dont want to use substr and concat ||
    regards,

    RB wrote:
    AND With REGEXP_REPLACE
    SQL>  SELECT REGEXP_REPLACE('01-1552963-01','-','')  Sample from dual;
    SAMPLE
    01155296301
    An empty string is considered null in Oracle so that's the same as:
    SQL>  SELECT REGEXP_REPLACE('01-1552963-01','-')  Sample from dual;
    SAMPLE
    01155296301which, let's face it is pretty pointless when a regular REPLACE function will do the same.
    You should only really use the regular expression versions when you have a pattern that needs matching, not just a fixed set of characters.

  • Function for fetching date

    Hi all,
    Can anyone help me to find a date say Friday was 10-Oct-2005 then the before year same day was 01-Oct-2004 which is also a friday... SO can v have a sql code which when todays day is given last year same day is given by calculation...
    Thanks in advance....

    Hi,
    Check if this helps:
    select :p_sysdate , to_char(to_date(:p_sysdate),'Day') P_SYSDATE_DAY,
           next_day( to_date('01-'||to_char(add_months(to_date(:p_sysdate), -12), 'MON-YYYY'), 'DD-MON-YYYY') - 1, to_char(to_date(:p_sysdate),'Day')) LAST_YRS_DATE,
           TO_CHAR(next_day( to_date('01-'||to_char(add_months(to_date(:p_sysdate), -12), 'MON-YYYY'), 'DD-MON-YYYY') - 1, to_char(to_date(:p_sysdate),'Day')), 'Day') LAST_YRS_DATES_DAY
    from dual;
    SQL output:
    SQL> select &p_sysdate , to_char(to_date(&p_sysdate),'Day') P_SYSDATE_DAY,
           next_day( to_date('01-'||to_char(add_months(to_date(&p_sysdate), -12), 'MON-YYYY'), 'DD-MON-YYYY') - 1, to_char(to_date(&p_sysdate),'Day')) LAST_YRS_DATE,
           TO_CHAR(next_day( to_date('01-'||to_char(add_months(to_date(&p_sysdate), -12), 'MON-YYYY'), 'DD-MON-YYYY') - 1, to_char(to_date(&p_sysdate),'Day')), 'Day') LAST_YRS_DATES_DAY
    from dual
    SQL>/
    Enter value for p_sysdate: '07-OCT-2005'
    Enter value for p_sysdate: '07-OCT-2005'
    old   1: select &p_sysdate , to_char(to_date(&p_sysdate),'Day') P_SYSDATE_DAY,
    new   1: select '07-OCT-2005' , to_char(to_date('07-OCT-2005'),'Day') P_SYSDATE_DAY,
    Enter value for p_sysdate: '07-OCT-2005'
    Enter value for p_sysdate: '07-OCT-2005'
    old   2:        next_day( to_date('01-'||to_char(add_months(to_date(&p_sysdate), -12), 'MON-YYYY'), 'DD-MON-YYYY') - 1, to_char(to_date(&p_sysdate),'Day')) LAST_YRS_DATE,
    new   2:        next_day( to_date('01-'||to_char(add_months(to_date('07-OCT-2005'), -12), 'MON-YYYY'), 'DD-MON-YYYY') - 1, to_char(to_date('07-OCT-2005'),'Day')) LAST_YRS_DATE,
    Enter value for p_sysdate: '07-OCT-2005'
    Enter value for p_sysdate: '07-OCT-2005'
    old   3:        TO_CHAR(next_day( to_date('01-'||to_char(add_months(to_date(&p_sysdate), -12), 'MON-YYYY'), 'DD-MON-YYYY') - 1, to_char(to_date(&p_sysdate),'Day')), 'Day') LAST_YRS_DATES_DAY
    new   3:        TO_CHAR(next_day( to_date('01-'||to_char(add_months(to_date('07-OCT-2005'), -12), 'MON-YYYY'), 'DD-MON-YYYY') - 1, to_char(to_date('07-OCT-2005'),'Day')), 'Day') LAST_YRS_DATES_DAY
    '07-OCT-200 P_SYSDATE LAST_YRS_ LAST_YRS_                                                          
    07-OCT-2005 Friday    01-OCT-04 Friday    Regards
    Imran
    Edited by: Imran Soudagar on May 11, 2010 2:32 PM

  • SQL function for adding street, city and postal code.

    I would like to know how to add to my code to display the addresses.
    Any ideas?
    SELECT departments.department_name "Department Name", locations.state_province "Mailing Address"
    FROM departments, locations
    WHERE departments.location_id=locations.location_id
    AND locations.country_id='US'
    ORDER BY department_name;
    OUTPUT SO FAR:
    Department Name Mailing Address
    Accounting Washington
    Administration Washington
    Contracting Washington
    Executive Washington
    IT Texas
    Shipping California

    Hi,
    Do you want the four database columns to appear as one output column, perhaps with a space between the columns?
    If so, concatenate the strings into one big string using ||
    SELECT departments.department_name "Department Name"
    , street_address
    || ' ' || city
    || ' ' || locations.state_province
    || ' ' || postal_code AS "Mailing Address"
    FROM departments, locations
    WHERE departments.location_id=locations.location_id
    AND locations.country_id='US'
    ORDER BY department_name;
    Message was edited by:
            Frank Kulash                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for