Covert number to comma separated number

I have to covert number to comma separated number
Please let me know how to do this.
Example :
Input: 10000 Output: 100,00
Input: 1000 Output: 10,00
Input: 1000044 Output: 100,00,44

Like this
with t as
( select 1234 a from dual union all
  select 1234456 from dual union all
  select 123 from dual union all
  select 12 from dual union all   
  select 124579652 from dual union all
  select 12235 from dual
select to_char(a,'999,99,99,99,99,99') formatted
  from t Regards
Arun

Similar Messages

  • Unable to load comma separated number using sqlldr

    Hi
    See the example below.
    I have problem in loading “bonus” into my emp table.
    Appreciate your help.
    Here I have appended the following.
    -     demo04.ctl – controfile
    -     demo04.dat – datafile
    -     demo04.log - logfile
    Error :
    ===============================
    Record 1: Rejected - Error on table EMP, column BONUS.
    ORA-01722: invalid number
    sqlldr userid=scott/tiger@orcl , control=demo04.ctl , log=demo04.log
    Create table emp
    Empno      number,
    Ename     varchar2(80),
    Sal     number(15,2),
    bonus      number
    cat demo04.ctl
    ==========================
    LOAD DATA
    INFILE 'demo04.dat'
    INTO TABLE emp
    FIELDS TERMINATED BY ','
    OPTIONALLY ENCLOSED BY '"'
    Empno INTEGER EXTERNAL,
    Ename ,
    Sal DECIMAL EXTERNAL,
    bonus DECIMAL EXTERNAL ????
    cat demo04.dat
    ==============================================
    "1000", "*XXX,XXXX", "9820.760000","3,395"
    "1001", "*XXX,XXXX", "9821.760000","88,883,395"
    cat demo04.log
    ============================
    SQL*Loader: Release 8.1.7.4.0 - Production on Fri Oct 13 17:58:31 2006
    (c) Copyright 2000 Oracle Corporation. All rights reserved.
    Control File: demo04.ctl
    Data File: demo04.dat
    Bad File: demo04.bad
    Discard File: none specified
    (Allow all discards)
    Number to load: ALL
    Number to skip: 0
    Errors allowed: 50
    Bind array: 64 rows, maximum of 65536 bytes
    Continuation: none specified
    Path used: Conventional
    Table EMP, loaded from every logical record.
    Insert option in effect for this table: INSERT
    Column Name Position Len Term Encl Datatype
    EMPNO FIRST * , O(") CHARACTER
    ENAME NEXT * , O(") CHARACTER
    SAL NEXT * , O(") CHARACTER
    BONUS NEXT * , O(") CHARACTER
    Record 1: Rejected - Error on table EMP, column BONUS.
    ORA-01722: invalid number
    Record 2: Rejected - Error on table EMP, column BONUS.
    ORA-01722: invalid number
    Table EMP:
    0 Rows successfully loaded.
    2 Rows not loaded due to data errors.
    0 Rows not loaded because all WHEN clauses were failed.
    0 Rows not loaded because all fields were null.
    Space allocated for bind array: 65016 bytes(63 rows)
    Space allocated for memory besides bind array: 0 bytes
    Total logical records skipped: 0
    Total logical records read: 2
    Total logical records rejected: 2
    Total logical records discarded: 0
    Run began on Fri Oct 13 17:58:31 2006
    Run ended on Fri Oct 13 17:58:32 2006
    Elapsed time was: 00:00:01.14
    CPU time was: 00:00:00.05

    Try
    bonus CHAR "to_number(:bonus, '999G999G999')"

  • Output number with comma separator

    I have the value 1250 as an amount in a smartform.  And I want to output this as 1,250.  How do I do this?

    Hi...
    Use this function module.....
    it will satify your requirements...
    pass that changing parameter to the smartform..
    DATA: v_cur like TCURX-CURRKEY,
            c_cur(10) type c VALUE '1250'..
      CALL FUNCTION 'SD_CONVERT_CURRENCY_FORMAT'
        EXPORTING
          i_currency                  = v_cur
    *   IMPORTING
    *     E_CURRENCY_INT_FORMAT       =
        changing
          c_currency_ext_format       = c_cur
       EXCEPTIONS
         WRONG_FORMAT                = 1
         OTHERS                      = 2
      IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      WRITE: C_CUR.
    I believe this will greatly help you.
    Thanks and regards
    Bhuvana

  • Separating number in inputext with comma

    hi all
    I need to separate numbers with comma without using Enter .
    I have an input text and used an clientListner on it : code is bellow
      <f:view>
        <af:document id="d1">  
         <af:resource type="javascript" source="/js/accounting.js"/>
         <af:resource type="javascript" source="/js/functions.js"/>
         <!--<af:resource type="javascript" source="/js/accounting.min.js"/>-->
          <af:form id="f1">
    <af:panelGroupLayout id="pgl1">
    <af:inputText label="Label 1" id="it1">
    <af:clientListener method="formatNum" type="keyUp"/>
    </af:inputText>
            </af:panelGroupLayout>
          </af:form>
        </af:document>
      </f:view>
    I run this JavaScript on HTML page that is OK and my input text show separated number during entering ,
    but I run my above jspx page ,it does not show until press the Enter key ...
    please guide me .... I have an emergency condition please answer me soon
    and then use this function for handling...
    function.js :
    function formatNum(evt) {
        var inputfield = evt.getSource();
        var num = accounting.unformat(inputfield.getValue());
        var formatNum = accounting.formatNumber(num);
        inputfield.setValue(formatNum);
        return true;
    accounting.js
    * accounting.js v0.3.2
    * Copyright 2011, Joss Crowcroft
    * Freely distributable under the MIT license.
    * Portions of accounting.js are inspired or borrowed from underscore.js
    * Full details and documentation:
    * http://josscrowcroft.github.com/accounting.js/
    (function(root, undefined) {
    /* --- Setup --- */
    // Create the local library object, to be exported or referenced globally later
    var lib = {};
    // Current version
    lib.version = '0.3.2';
    /* --- Exposed settings --- */
    // The library's settings configuration object. Contains default parameters for
    // currency and number formatting
    lib.settings = {
    currency: {
    symbol : "$", // default currency symbol is '$'
    format : "%s%v", // controls output: %s = symbol, %v = value (can be object, see docs)
    decimal : ".", // decimal point separator
    thousand : ",", // thousands separator
    precision : 2, // decimal places
    grouping : 3 // digit grouping (not implemented yet)
    number: {
    precision : 0, // default precision on numbers is 0
    grouping : 3, // digit grouping (not implemented yet)
    thousand : ",",
    decimal : "."
    /* --- Internal Helper Methods --- */
    // Store reference to possibly-available ECMAScript 5 methods for later
    var nativeMap = Array.prototype.map,
    nativeIsArray = Array.isArray,
    toString = Object.prototype.toString;
    * Tests whether supplied parameter is a string
    * from underscore.js
    function isString(obj) {
    return !!(obj === '' || (obj && obj.charCodeAt && obj.substr));
    * Tests whether supplied parameter is a string
    * from underscore.js, delegates to ECMA5's native Array.isArray
    function isArray(obj) {
    return nativeIsArray ? nativeIsArray(obj) : toString.call(obj) === '[object Array]';
    * Tests whether supplied parameter is a true object
    function isObject(obj) {
    return obj && toString.call(obj) === '[object Object]';
    * Extends an object with a defaults object, similar to underscore's _.defaults
    * Used for abstracting parameter handling from API methods
    function defaults(object, defs) {
    var key;
    object = object || {};
    defs = defs || {};
    // Iterate over object non-prototype properties:
    for (key in defs) {
    if (defs.hasOwnProperty(key)) {
    // Replace values with defaults only if undefined (allow empty/zero values):
    if (object[key] == null) object[key] = defs[key];
    return object;
    * Implementation of `Array.map()` for iteration loops
    * Returns a new Array as a result of calling `iterator` on each array value.
    * Defers to native Array.map if available
    function map(obj, iterator, context) {
    var results = [], i, j;
    if (!obj) return results;
    // Use native .map method if it exists:
    if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
    // Fallback for native .map:
    for (i = 0, j = obj.length; i < j; i++ ) {
    results[i] = iterator.call(context, obj[i], i, obj);
    return results;
    * Check and normalise the value of precision (must be positive integer)
    function checkPrecision(val, base) {
    val = Math.round(Math.abs(val));
    return isNaN(val)? base : val;
    * Parses a format string or object and returns format obj for use in rendering
    * `format` is either a string with the default (positive) format, or object
    * containing `pos` (required), `neg` and `zero` values (or a function returning
    * either a string or object)
    * Either string or format.pos must contain "%v" (value) to be valid
    function checkCurrencyFormat(format) {
    var defaults = lib.settings.currency.format;
    // Allow function as format parameter (should return string or object):
    if ( typeof format === "function" ) format = format();
    // Format can be a string, in which case `value` ("%v") must be present:
    if ( isString( format ) && format.match("%v") ) {
    // Create and return positive, negative and zero formats:
    return {
    pos : format,
    neg : format.replace("-", "").replace("%v", "-%v"),
    zero : format
    // If no format, or object is missing valid positive value, use defaults:
    } else if ( !format || !format.pos || !format.pos.match("%v") ) {
    // If defaults is a string, casts it to an object for faster checking next time:
    return ( !isString( defaults ) ) ? defaults : lib.settings.currency.format = {
    pos : defaults,
    neg : defaults.replace("%v", "-%v"),
    zero : defaults
    // Otherwise, assume format was fine:
    return format;
    /* --- API Methods --- */
    * Takes a string/array of strings, removes all formatting/cruft and returns the raw float value
    * alias: accounting.`parse(string)`
    * Decimal must be included in the regular expression to match floats (defaults to
    * accounting.settings.number.decimal), so if the number uses a non-standard decimal
    * separator, provide it as the second argument.
    * Also matches bracketed negatives (eg. "$ (1.99)" => -1.99)
    * Doesn't throw any errors (`NaN`s become 0) but this may change in future
    var unformat = lib.unformat = lib.parse = function(value, decimal) {
    // Recursively unformat arrays:
    if (isArray(value)) {
    return map(value, function(val) {
    return unformat(val, decimal);
    // Fails silently (need decent errors):
    value = value || 0;
    // Return the value as-is if it's already a number:
    if (typeof value === "number") return value;
    // Default decimal point comes from settings, but could be set to eg. "," in opts:
    decimal = decimal || lib.settings.number.decimal;
    // Build regex to strip out everything except digits, decimal point and minus sign:
    var regex = new RegExp("[^0-9-" + decimal + "]", ["g"]),
    unformatted = parseFloat(
    ("" + value)
    .replace(/\((.*)\)/, "-$1") // replace bracketed values with negatives
    .replace(regex, '')         // strip out any cruft
    .replace(decimal, '.')      // make sure decimal point is standard
    // This will fail silently which may cause trouble, let's wait and see:
    return !isNaN(unformatted) ? unformatted : 0;
    * Implementation of toFixed() that treats floats more like decimals
    * Fixes binary rounding issues (eg. (0.615).toFixed(2) === "0.61") that present
    * problems for accounting- and finance-related software.
    var toFixed = lib.toFixed = function(value, precision) {
    precision = checkPrecision(precision, lib.settings.number.precision);
    var power = Math.pow(10, precision);
    // Multiply up by precision, round accurately, then divide and use native toFixed():
    return (Math.round(lib.unformat(value) * power) / power).toFixed(precision);
    * Format a number, with comma-separated thousands and custom precision/decimal places
    * Localise by overriding the precision and thousand / decimal separators
    * 2nd parameter `precision` can be an object matching `settings.number`
    var formatNumber = lib.formatNumber = function(number, precision, thousand, decimal) {
      // Resursively format arrays:
    if (isArray(number)) {
    return map(number, function(val) {
    return formatNumber(val, precision, thousand, decimal);
    // Clean up number:
    number = unformat(number);
    // Build options object from second param (if object) or all params, extending defaults:
    var opts = defaults(
    (isObject(precision) ? precision : {
    precision : precision,
    thousand : thousand,
    decimal : decimal
    lib.settings.number
    // Clean up precision
    usePrecision = checkPrecision(opts.precision),
    // Do some calc:
    negative = number < 0 ? "-" : "",
    base = parseInt(toFixed(Math.abs(number || 0), usePrecision), 10) + "",
    mod = base.length > 3 ? base.length % 3 : 0;
    // Format the number:
    return negative + (mod ? base.substr(0, mod) + opts.thousand : "") + base.substr(mod).replace(/(\d{3})(?=\d)/g, "$1" + opts.thousand) + (usePrecision ? opts.decimal + toFixed(Math.abs(number), usePrecision).split('.')[1] : "");
    * Format a number into currency
    * Usage: accounting.formatMoney(number, symbol, precision, thousandsSep, decimalSep, format)
    * defaults: (0, "$", 2, ",", ".", "%s%v")
    * Localise by overriding the symbol, precision, thousand / decimal separators and format
    * Second param can be an object matching `settings.currency` which is the easiest way.
    * To do: tidy up the parameters
    var formatMoney = lib.formatMoney = function(number, symbol, precision, thousand, decimal, format) {
    // Resursively format arrays:
    if (isArray(number)) {
    return map(number, function(val){
    return formatMoney(val, symbol, precision, thousand, decimal, format);
    // Clean up number:
    number = unformat(number);
    // Build options object from second param (if object) or all params, extending defaults:
    var opts = defaults(
    (isObject(symbol) ? symbol : {
    symbol : symbol,
    precision : precision,
    thousand : thousand,
    decimal : decimal,
    format : format
    lib.settings.currency
    // Check format (returns object with pos, neg and zero):
    formats = checkCurrencyFormat(opts.format),
    // Choose which format to use for this value:
    useFormat = number > 0 ? formats.pos : number < 0 ? formats.neg : formats.zero;
    // Return with currency symbol added:
    return useFormat.replace('%s', opts.symbol).replace('%v', formatNumber(Math.abs(number), checkPrecision(opts.precision), opts.thousand, opts.decimal));
    * Format a list of numbers into an accounting column, padding with whitespace
    * to line up currency symbols, thousand separators and decimals places
    * List should be an array of numbers
    * Second parameter can be an object containing keys that match the params
    * Returns array of accouting-formatted number strings of same length
    * NB: `white-space:pre` CSS rule is required on the list container to prevent
    * browsers from collapsing the whitespace in the output strings.
    lib.formatColumn = function(list, symbol, precision, thousand, decimal, format) {
    if (!list) return [];
    // Build options object from second param (if object) or all params, extending defaults:
    var opts = defaults(
    (isObject(symbol) ? symbol : {
    symbol : symbol,
    precision : precision,
    thousand : thousand,
    decimal : decimal,
    format : format
    lib.settings.currency
    // Check format (returns object with pos, neg and zero), only need pos for now:
    formats = checkCurrencyFormat(opts.format),
    // Whether to pad at start of string or after currency symbol:
    padAfterSymbol = formats.pos.indexOf("%s") < formats.pos.indexOf("%v") ? true : false,
    // Store value for the length of the longest string in the column:
    maxLength = 0,
    // Format the list according to options, store the length of the longest string:
    formatted = map(list, function(val, i) {
    if (isArray(val)) {
    // Recursively format columns if list is a multi-dimensional array:
    return lib.formatColumn(val, opts);
    } else {
    // Clean up the value
    val = unformat(val);
    // Choose which format to use for this value (pos, neg or zero):
    var useFormat = val > 0 ? formats.pos : val < 0 ? formats.neg : formats.zero,
    // Format this value, push into formatted list and save the length:
    fVal = useFormat.replace('%s', opts.symbol).replace('%v', formatNumber(Math.abs(val), checkPrecision(opts.precision), opts.thousand, opts.decimal));
    if (fVal.length > maxLength) maxLength = fVal.length;
    return fVal;
    // Pad each number in the list and send back the column of numbers:
    return map(formatted, function(val, i) {
    // Only if this is a string (not a nested array, which would have already been padded):
    if (isString(val) && val.length < maxLength) {
    // Depending on symbol position, pad after symbol or at index 0:
    return padAfterSymbol ? val.replace(opts.symbol, opts.symbol+(new Array(maxLength - val.length + 1).join(" "))) : (new Array(maxLength - val.length + 1).join(" ")) + val;
    return val;
    /* --- Module Definition --- */
    // Export accounting for CommonJS. If being loaded as an AMD module, define it as such.
    // Otherwise, just add `accounting` to the global object
    if (typeof exports !== 'undefined') {
    if (typeof module !== 'undefined' && module.exports) {
    exports = module.exports = lib;
    exports.accounting = lib;
    } else if (typeof define === 'function' && define.amd) {
    // Return the library as an AMD module:
    define([], function() {
    return lib;
    } else {
    // Use accounting.noConflict to restore `accounting` back to its original value.
    // Returns a reference to the library's `accounting` object;
    // e.g. `var numbers = accounting.noConflict();`
    lib.noConflict = (function(oldAccounting) {
    return function() {
    // Reset the value of the root's `accounting` variable:
    root.accounting = oldAccounting;
    // Delete the noConflict method:
    lib.noConflict = undefined;
    // Return reference to the library to re-assign it:
    return lib;
    })(root.accounting);
    // Declare `fx` on the root (global/window) object:
    root['accounting'] = lib;
    // Root will be `window` in browser or `global` on the server:
    }(this));

    hi all
    I have an input text that I want to separate it's value with comma
    this is my input text :
    <af:inputText value="#{bindings.LacreditAmt.inputValue}"
    label="#{bindings.LacreditAmt.hints.label}"
    required="#{bindings.LacreditAmt.hints.mandatory}"
    columns="#{bindings.LacreditAmt.hints.displayWidth}"
    shortDesc="#{bindings.LacreditAmt.hints.tooltip}"
    id="it8"
    maximumLength="#{bindings.LacreditAmt.hints.precision}"
    converter="converter.BIGDECIMALMONEYCONVERTER"
    clientComponent="true">
    <f:validator binding="#{bindings.LacreditAmt.validator}"/>
    <!--<af:convertNumber groupingUsed="false"
    pattern="#{bindings.LacreditAmt.format}"/>-->
    <af:clientListener method="handleNumberFormatConversion" type="keyUp"/>
    </af:inputText>
    and use this  java Script for comma separated value :
    problem is : when I used firebug for testing this java Script ,everything is OK and 'result' variable shown
    the correct value (comma separated value) but in fact the correct value did not show
    in input text  !!!!!
    please guide me soon.
    I appreciated in advance
    function handleNumberFormatConversion(evt){
            var inputField = evt.getCurrentTarget();
            var keyPressed = evt.getKeyCode();
            var oldValue = inputField.getSubmittedValue();
            var validKeys = new Array(48,49,50,51,52,53,54,55, 56,57,96,97,98,99,100, 101,102,103,104,105,AdfKeyStroke.ARROWRIGHT_KEY, AdfKeyStroke.ARROWLEFT_KEY, AdfKeyStroke.BACKSPACE_KEY, AdfKeyStroke.DELETE_KEY, AdfKeyStroke.END_KEY, AdfKeyStroke.ESC_KEY, AdfKeyStroke.TAB_KEY);
            var numberKeys = new Array(48,49,50,51,52,53,54,55, 56,57,96,97,98,99,100, 101,102,103,104,105, AdfKeyStroke.BACKSPACE_KEY, AdfKeyStroke.DELETE_KEY);
            var isValidKey = false;
            for (var i=0; i < validKeys.length; ++i){
                if (validKeys[i] == keyPressed) {
                    isValidKey = true;
                    break;
            if(isValidKey){
                    var isNumberKey = false;
                for (var n=0; n < numberKeys.length; ++n){
                    if(numberKeys[n] == keyPressed){
                        isNumberKey = true;
                        break;
                if(isNumberKey){
                    var formatLength = 25;
                    if(formatLength == oldValue.length){
                        inputField.setValue(oldValue);
                        evt.cancel();
                    else {
                        var firstNeg = false;
                        var lastNeg = false;
                        if (oldValue.charAt(0) == '(')
                            firstNeg = true;
                        if(oldValue.contains(')')){
                          lastNeg = true;                              
                        oldValue = oldValue.replace('(', "");
                        oldValue = oldValue.replace(')', "");
                        var result = "";
                        while (oldValue.contains(",")) {
                            oldValue = oldValue.replace(",", "");
                        for (i = oldValue.length - 3;i > 0;i -= 3) {
                            result = ",".concat(oldValue.substring(i, i + 3), result);
                        result = oldValue.substring(0, (oldValue.length % 3 == 0) ? 3 : oldValue.length % 3).concat(result);
                        if (firstNeg)
                            result = '(' + result;
                        if (lastNeg) {
                            result = result + ')';
                        inputField.setValue(result);
                        evt.cancel();
                        return true;                   
            else {
                inputField.setValue(oldValue);
                evt.cancel();

  • Displaying a number with commas in gid

    Hi EveryOne,
                       This is Ram Prasad.I want to display a number with commas in the grid (eg:1,000).In the grid it is shown as 1000.I wan to add commas for this number to be shown in the grid display template.Can any one help on this.

    That's an odd format, so I assume you mean 1 million to be displayed as:  1,000,000 ?
    http://help.sap.com/saphelp_xmii115/helpdata/en/Applet_Reference_Details/ParameterReference.htm#Number Formatting
    #,##0 should provide you with a comma as the thousands separator for all numbers in this column of your iGrid.

  • Commas in Number Values

    Hi,
    We have a requirement to show all the number fields (messagestyledtext/messagetextInput with Type-Number) in a comma separated format i.e. comma after every three digits (for currency values). what are the ways to achieve it ?
    Thanks for your help.
    Amit

    Hello,
    Please refer the below link
    Formatting Currency Value
    Thanks & Regards,
    Raj Papdeja

  • The datediff function resulted in an overflow. The number of dateparts separating two date/time instances is too large. Try to use datediff with a less precise datepart.

    The below function is giving me the hours difference what I wanted, but today it is giving us the below error: 
    Msg 535, Level 16, State 0, Line 1
    The datediff function resulted in an overflow. The number of dateparts separating two date/time instances is too large. Try to use datediff with a less precise datepart.
    Please Help..
    ALTER FUNCTION [dbo].[GetHoursExcludingWeekdays](@StartDate datetime2,@EndDate datetime2)
    returns decimal(12,3)
    as
    begin
        if datepart(weekday,@StartDate) = 1
            set @StartDate = dateadd(day,datediff(day,0,@StartDate),1)
        if datepart(weekday,@StartDate) = 7
            set @StartDate = dateadd(day,datediff(day,0,@StartDate),2)
        -- if @EndDate happens on the weekend, set to previous Saturday 12AM
        -- to count all of Friday's hours
        if datepart(weekday,@EndDate) = 1
            set @EndDate = dateadd(day,datediff(day,0,@EndDate),-2)
        if datepart(weekday,@EndDate) = 7
            set @EndDate = dateadd(day,datediff(day,0,@EndDate),-1)
        declare @return decimal(12,3)
        set @return = ((datediff(second,@StartDate,@EndDate)/60.0/60.0) - (datediff(week,@StartDate,@EndDate)*48))
        return @return
    end
    ReportingServices

    You'll get this error if the difference between the start and end date is greater that about 68 years due to the "second" DATEDIFF specification.  Perhaps the dates are greater than the expected range due to a data quality issue. 
    Taking the advice from the error message, you could use minutes instead of seconds like the example below the version below.  This could still result in the error of the difference is greater than a couple of hundred years, though.  You might consider
    validating the dates and returning NULL if outside expected limits.
    ALTER FUNCTION [dbo].[GetHoursExcludingWeekdays](@StartDate datetime2,@EndDate datetime2)
    returns decimal(12,3)
    as
    begin
    if datepart(weekday,@StartDate) = 1
    set @StartDate = dateadd(day,datediff(day,0,@StartDate),1)
    if datepart(weekday,@StartDate) = 7
    set @StartDate = dateadd(day,datediff(day,0,@StartDate),2)
    -- if @EndDate happens on the weekend, set to previous Saturday 12AM
    -- to count all of Friday's hours
    if datepart(weekday,@EndDate) = 1
    set @EndDate = dateadd(day,datediff(day,0,@EndDate),-2)
    if datepart(weekday,@EndDate) = 7
    set @EndDate = dateadd(day,datediff(day,0,@EndDate),-1)
    declare @return decimal(12,3)
    set @return = ((datediff(minute,@StartDate,@EndDate)/60.0) - (datediff(week,@StartDate,@EndDate)*48))
    return @return
    end
    GO
    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

  • Display a number with commas

    Here's a way to display a number with commas. See attached
    code.
    I had searched here for help on how to do it, and couldn't
    find anything. So, then I wrote this. I'm a hack, self-taught
    coder, so there may be a more eloquent way, but this does
    work.

    Nice, I'm always happy to be humbled.
    One more point. If you're going ot use a return statement I
    like to keep it
    at the very end of the function. So, in a conditional
    statement, setting a
    local variable to the value to be returned allows you to
    return that local
    variable and always keep the return statement as the last
    line. It just
    saves a little searching around for returns in longer
    functions. Just a
    style choice not necessarily better.
    Craig Wollman
    Word of Mouth Productions
    phone 212 928 9581
    fax 212 928 9582
    159-00 Riverside Drive West #5H-70
    NY, NY 10032
    www.wordofmouthpros.com
    "duckets" <[email protected]> wrote in
    message
    news:[email protected]...
    >
    quote:
    Originally posted by:
    FasterPastor
    > I had searched here for help on how to do it, and
    couldn't find
    > anything.
    >
    > You should have asked! here's one I have had sitting
    around for a while.
    > (code
    > attached below). It handles lots of cases which the
    other handlers posted
    > so
    > far do not. Specifically:
    >
    > Negative numbers - input: -123456
    > - craig's: -,123,456
    > - dougs's: -,123,456
    > - mikes's: -,123,456
    > - duck's: -123,456
    >
    > Floating point numbers - input: pi
    > - craig's: 3
    > - dougs's: 3
    > - mikes's: 3.1,416
    > - duck's: 3.1416
    >
    > Numbers larger than the maxinteger - input: 149668992000
    > - craig's: -,654,863,360
    > - dougs's: -,654,863,360
    > - mikes's: 14,966,899,200,0.0,000
    > - duck's: 149,668,992,000
    >
    > Negative floats - input: -123456.7890
    > - craig's: -,123,457
    > - dougs's: -,123,457
    > - mikes's: -12,345,6.7,890
    > - duck's: -123,456.789
    >
    > Floats larger than the maxinteger - input:
    2233445566.7788
    > - craig's: -2,061,521,729
    > - dougs's: -2,061,521,729
    > - mikes's: 223,344,556,6.7,788
    > - duck's: 2,233,445,566.7788
    >
    > Yes.. the code is longer, but if you want to print
    something like the
    > distance
    > in meters to the sun, you need to handle floats
    properly!
    >
    > enjoy ;-)
    >
    > - Ben
    >
    >
    >
    > on stringNumber n
    >
    > outputString = ""
    > inputString = string(n)
    >
    > if inputString.char[1] = "-" then
    > negative = true
    > delete inputString.char[1]
    > else
    > negative = false
    > end if
    >
    > fraction = ""
    >
    > if inputString contains "e" then
    >
    > mantissa = inputString.char[1..(offset("e",
    inputString)-1)]
    > exponent = value(inputString.char[(offset("e",
    > inputString)+1)..inputString.length])
    >
    > decimalChar = mantissa.char[2]
    > mantissa = mantissa.char[1] &
    mantissa.char[3..mantissa.length]
    >
    > if mantissa.length < exponent+1 then
    > plainNumber = mantissa
    > repeat while plainNumber.length < exponent+1
    > put "0" after plainNumber
    > end repeat
    > else
    > plainNumber = mantissa.char[1..(exponent+1)]
    > fraction = mantissa.char[(exponent+2)..mantissa.length]
    > end if
    >
    > else
    >
    > if offset(".", inputString)>0 then
    > decimalChar = "."
    > end if
    > if offset(",", inputString)>0 then
    > decimalChar = ","
    > end if
    >
    > if offset(decimalChar, inputString)>0 then
    > plainNumber = inputString.char[1..(offset(decimalChar,
    > inputString)-1)]
    > fraction = inputString.char[(offset(decimalChar,
    > inputString)+1)..inputString.length]
    > else
    > plainNumber = inputString
    > fraction = ""
    > decimalChar = string(1.2).char[2]
    > end if
    >
    > end if
    >
    > if decimalChar = "." then
    > separatorChar = ","
    > else
    > separatorChar = "."
    > end if
    >
    >
    > repeat while plainNumber.char[1] = "0"
    > delete plainNumber.char[1]
    > end repeat
    >
    >
    > repeat while plainNumber.length > 0
    > if plainNumber.length > 3 then
    > nextDigits =
    >
    separatorChar&plainNumber.char[plainNumber.length-2..plainNumber.length]
    > delete
    plainNumber.char[plainNumber.length-2..plainNumber.length]
    > else
    > nextDigits = plainNumber
    > plainNumber = ""
    > end if
    > put nextDigits before outputString
    > end repeat
    >
    > repeat while fraction.char[fraction.length] = "0"
    > delete fraction.char[fraction.length]
    > end repeat
    >
    > if fraction.length > 0 then
    > put decimalChar&fraction after outputString
    > end if
    >
    >
    > if negative then
    > put "-" before outputString
    > end if
    >
    > return outputString
    >
    > end
    >

  • How can i get all these values in single row with comma separated?

    I have a table "abxx" with column "absg" Number(3)
    which is having following rows
    absg
    1
    3
    56
    232
    43
    436
    23
    677
    545
    367
    xxxxxx No of rows
    How can i get all these values in single row with comma separated?
    Like
    output_absg
    1,3,56,232,43,436,23,677,545,367,..,..,...............
    Can you send the query Plz!

    These all will do the same
    create or replace type string_agg_type as object
    2 (
    3 total varchar2(4000),
    4
    5 static function
    6 ODCIAggregateInitialize(sctx IN OUT string_agg_type )
    7 return number,
    8
    9 member function
    10 ODCIAggregateIterate(self IN OUT string_agg_type ,
    11 value IN varchar2 )
    12 return number,
    13
    14 member function
    15 ODCIAggregateTerminate(self IN string_agg_type,
    16 returnValue OUT varchar2,
    17 flags IN number)
    18 return number,
    19
    20 member function
    21 ODCIAggregateMerge(self IN OUT string_agg_type,
    22 ctx2 IN string_agg_type)
    23 return number
    24 );
    25 /
    create or replace type body string_agg_type
    2 is
    3
    4 static function ODCIAggregateInitialize(sctx IN OUT string_agg_type)
    5 return number
    6 is
    7 begin
    8 sctx := string_agg_type( null );
    9 return ODCIConst.Success;
    10 end;
    11
    12 member function ODCIAggregateIterate(self IN OUT string_agg_type,
    13 value IN varchar2 )
    14 return number
    15 is
    16 begin
    17 self.total := self.total || ',' || value;
    18 return ODCIConst.Success;
    19 end;
    20
    21 member function ODCIAggregateTerminate(self IN string_agg_type,
    22 returnValue OUT varchar2,
    23 flags IN number)
    24 return number
    25 is
    26 begin
    27 returnValue := ltrim(self.total,',');
    28 return ODCIConst.Success;
    29 end;
    30
    31 member function ODCIAggregateMerge(self IN OUT string_agg_type,
    32 ctx2 IN string_agg_type)
    33 return number
    34 is
    35 begin
    36 self.total := self.total || ctx2.total;
    37 return ODCIConst.Success;
    38 end;
    39
    40
    41 end;
    42 /
    Type body created.
    [email protected]>
    [email protected]> CREATE or replace
    2 FUNCTION stragg(input varchar2 )
    3 RETURN varchar2
    4 PARALLEL_ENABLE AGGREGATE USING string_agg_type;
    5 /
    CREATE OR REPLACE FUNCTION get_employees (p_deptno in emp.deptno%TYPE)
    RETURN VARCHAR2
    IS
    l_text VARCHAR2(32767) := NULL;
    BEGIN
    FOR cur_rec IN (SELECT ename FROM emp WHERE deptno = p_deptno) LOOP
    l_text := l_text || ',' || cur_rec.ename;
    END LOOP;
    RETURN LTRIM(l_text, ',');
    END;
    SHOW ERRORS
    The function can then be incorporated into a query as follows.
    COLUMN employees FORMAT A50
    SELECT deptno,
    get_employees(deptno) AS employees
    FROM emp
    GROUP by deptno;
    ###########################################3
    SELECT SUBSTR(STR,2) FROM
    (SELECT SYS_CONNECT_BY_PATH(n,',')
    STR ,LENGTH(SYS_CONNECT_BY_PATH(n,',')) LN
    FROM
    SELECT N,rownum rn from t )
    CONNECT BY rn = PRIOR RN+1
    ORDER BY LN desc )
    WHERE ROWNUM=1
    declare
    str varchar2(32767);
    begin
    for i in (select sal from emp) loop
    str:= str || i.sal ||',' ;
    end loop;
    dbms_output.put_line(str);
    end;
    COLUMN employees FORMAT A50
    SELECT e.deptno,
    get_employees(e.deptno) AS employees
    FROM (SELECT DISTINCT deptno
    FROM emp) e;
    DEPTNO EMPLOYEES
    10 CLARK,KING,MILLER
    20 SMITH,JONES,SCOTT,ADAMS,FORD
    30 ALLEN,WARD,MARTIN,BLAKE,TURNER,JAMES
    CREATE OR REPLACE FUNCTION concatenate_list (p_cursor IN SYS_REFCURSOR)
    RETURN VARCHAR2
    IS
    l_return VARCHAR2(32767);
    l_temp VARCHAR2(32767);
    BEGIN
    LOOP
    FETCH p_cursor
    INTO l_temp;
    EXIT WHEN p_cursor%NOTFOUND;
    l_return := l_return || ',' || l_temp;
    END LOOP;
    RETURN LTRIM(l_return, ',');
    END;
    COLUMN employees FORMAT A50
    SELECT e1.deptno,
    concatenate_list(CURSOR(SELECT e2.ename FROM emp e2 WHERE e2.deptno = e1.deptno)) employees
    FROM emp e1
    GROUP BY e1.deptno;
    DEPTNO EMPLOYEES
    10 CLARK,KING,MILLER
    20 SMITH,JONES,SCOTT,ADAMS,FORD
    30 ALLEN,WARD,MARTIN,BLAKE,TURNER,JAMES
    CREATE OR REPLACE TYPE t_string_agg AS OBJECT
    g_string VARCHAR2(32767),
    STATIC FUNCTION ODCIAggregateInitialize(sctx IN OUT t_string_agg)
    RETURN NUMBER,
    MEMBER FUNCTION ODCIAggregateIterate(self IN OUT t_string_agg,
    value IN VARCHAR2 )
    RETURN NUMBER,
    MEMBER FUNCTION ODCIAggregateTerminate(self IN t_string_agg,
    returnValue OUT VARCHAR2,
    flags IN NUMBER)
    RETURN NUMBER,
    MEMBER FUNCTION ODCIAggregateMerge(self IN OUT t_string_agg,
    ctx2 IN t_string_agg)
    RETURN NUMBER
    SHOW ERRORS
    CREATE OR REPLACE TYPE BODY t_string_agg IS
    STATIC FUNCTION ODCIAggregateInitialize(sctx IN OUT t_string_agg)
    RETURN NUMBER IS
    BEGIN
    sctx := t_string_agg(NULL);
    RETURN ODCIConst.Success;
    END;
    MEMBER FUNCTION ODCIAggregateIterate(self IN OUT t_string_agg,
    value IN VARCHAR2 )
    RETURN NUMBER IS
    BEGIN
    SELF.g_string := self.g_string || ',' || value;
    RETURN ODCIConst.Success;
    END;
    MEMBER FUNCTION ODCIAggregateTerminate(self IN t_string_agg,
    returnValue OUT VARCHAR2,
    flags IN NUMBER)
    RETURN NUMBER IS
    BEGIN
    returnValue := RTRIM(LTRIM(SELF.g_string, ','), ',');
    RETURN ODCIConst.Success;
    END;
    MEMBER FUNCTION ODCIAggregateMerge(self IN OUT t_string_agg,
    ctx2 IN t_string_agg)
    RETURN NUMBER IS
    BEGIN
    SELF.g_string := SELF.g_string || ',' || ctx2.g_string;
    RETURN ODCIConst.Success;
    END;
    END;
    SHOW ERRORS
    CREATE OR REPLACE FUNCTION string_agg (p_input VARCHAR2)
    RETURN VARCHAR2
    PARALLEL_ENABLE AGGREGATE USING t_string_agg;
    /

  • How to get the values entered in parameter as comma separated

    Hi friends,
    I need to capture the values entered in the parameter which is entered as comma separated in the srs window o
    for ex in the parameter : 1234,4586,356,.....
    now i need to capture all the values to select in my list of
    employee numbers as
    employee number in(1234,4586,356...)
    how to do this
    pls help

    Please refer to SQL and PL/SQL FAQ
    Sybrand Bakker
    Senior Oracle DBA

  • Query on column with comma separated values

    I have a proposed table with unnormalized data like the following:
    ID COLA COLB REFLIST
    21 xxx  zzz  24,25,78,412
    22 xxx  xxx  21
    24 yyy  xxx  912,22
    25 zzz  fff  433,555,22
    .. ...  ...  ...There are 200 million rows. There is maximum of about 10 IDs in the REFLIST, though typically two or three. How could I efficiently query this data on the REFLIST column? e.g. something like:
    SELECT id FROM mytable WHERE :myval in reflistLogically there is a many to many relationship between rows in this table. The REFLIST column contains pointers to ID values elsewhere in the table. The data could be normalized so that the relationship keys are in a separate table (in fact this is the current solution that we want to change).
    ID  REF
    21  24
    21  25
    21  78
    21  412
    22  21
    24  912
    ... ...The comma separated list seems instinctively like a bad idea, however there are various reasons for proposing it. The main reason is because the source for this data has it structured like the REFLIST example. It is an OLTP-like system rather than a data warehouse. The source code (and edit performance) would benefit greatly from not having to maintain the relationship table as the data changes.
    Going back to querying the REFLIST column, the problem seems to be building an approriate index for the data. The ideas proposed so far are:
    <li>Make a materialized view that presents the relationships as normalized (e.g. as in the example with ID, REF columns above), then index the plain column - the various methods of writing the view SQL have been widely posted.
    <li>Use a Oracle Text Index (not something I have ever had call to use before).
    Any other ideas? Its Oracle 10.2, though 11g could be possible.
    Thanks
    Jim

    Something like this ?
    This is test demo on my 11.2.0.1 Windows XP
    SQL> create table test (id number,reflist varchar2(30));
    Table created.
    SQL> insert into test values (21,'24,25,78,412');
    1 row created.
    SQL> insert into test values (22,'21');
    1 row created.
    SQL> insert into test values (24,'912,22');
    1 row created.
    SQL> insert into test values (25,'433,555,22');
    1 row created.
    SQL> select * from test
      2  where
      3  ',' || reflist || ',' like '%,22,%';
            ID REFLIST
            24 912,22
            25 433,555,22
    SQL>Source:http://stackoverflow.com/questions/7212282/is-it-possible-to-query-a-comma-separated-column-for-a-specific-value
    Regards
    Girish Sharma
    Edited by: Girish Sharma on Jul 12, 2012 2:31 PM

  • Comma separated values for input and return multiple values

    Hello everyone,
    I have this simple package. Can someone suggest a way to accept multiple empno as input (comma separated) and to return set of salary values for the set of employee numbers (compatible to work with lower Oracle versions). Thanks much!
    CREATE OR REPLACE PACKAGE test_multi IS
    FUNCTION GET_sal(P_empno IN emp.empno%TYPE) RETURN NUMBER;
    END test_multi;
    CREATE OR REPLACE PACKAGE BODY test_multi IS
    FUNCTION GET_sal(P_empno IN emp.empno%TYPE) RETURN NUMBER IS
    V_sal NUMBER(10,2);
    MSG VARCHAR2(200);
    BEGIN
    SELECT sal
    INTO V_sal
    FROM emp
    WHERE empno = p_empno;
    RETURN V_sal;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    DBMS_OUTPUT.PUT_LINE('No data found.');
    IF (V_sal IS NULL OR V_sal = 0) THEN
    V_sal := 0;
    END IF;
    RETURN V_sal;
    WHEN OTHERS THEN
    MSG := SUBSTR(SQLERRM, 1, 70);
    DBMS_OUTPUT.PUT_LINE(MSG);
    END GET_sal;
    END test_multi; -- End package

    A way to do this in 10g or above...
    SQL> ed
    Wrote file afiedt.buf
      1  with e as (select '7499,7698,7654,7902' as enos from dual)
      2  --
      3  select empno, sal
      4  from emp
      5  where empno in (select regexp_substr(enos,'[^,]+',1,rownum)
      6                  from   e
      7*                 connect by rownum <= length(regexp_replace(enos,'[^,]'))+1)
    SQL> /
         EMPNO        SAL
          7902       3000
          7698       2850
          7654       1250
          7499       1600
    SQL>As for Oracle 8, .... well.... like Oracle, I no longer use unsupported versions, so I'd recommend you upgrade to something that is supported.

  • Comma Separated File

    Hello Experts,
    I am working on Interface, where i have the data in Internal Table. Now I am required to transfer the internal table data into Comma separated file with extension  '.csv' .
    I used the FM 'SAP_CONVERT_TO_CSV_FORMAT' and provided the de-limiter as ',' . When i downloaded the file in '.xls' format , all fields in row appeared in single cell of excel sheet.
    example : in 1 cell A1 the data was : abc,123,thr,456
    But the needed thing is 'abc' should appear in A1 cell , '123' should appear in B1 column etc...
    Please help me to attain the solution.
    Thanks in advance.
    Regards.

    You can concatenate all your field into a string, separated by ',' and then save the file.
    otherwise, you can save file into a csv where field are separated by tabulator, using the following:
    call function 'GUI_DOWNLOAD'
        exporting
          filename                = i_filename
          filetype                = 'ASC'
          write_field_separator   = 'X'
          dat_mode                = 'X'
        tables
          data_tab                = i_data
          fieldnames              = i_header
        exceptions
          file_write_error        = 1
          no_batch                = 2
          gui_refuse_filetransfer = 3
          invalid_type            = 4
          no_authority            = 5
          unknown_error           = 6
          header_not_allowed      = 7
          separator_not_allowed   = 8
          filesize_not_allowed    = 9
          header_too_long         = 10
          dp_error_create         = 11
          dp_error_send           = 12
          dp_error_write          = 13
          unknown_dp_error        = 14
          access_denied           = 15
          dp_out_of_memory        = 16
          disk_full               = 17
          dp_timeout              = 18
          file_not_found          = 19
          dataprovider_exception  = 20
          control_flush_error     = 21
          others                  = 22.
      if sy-subrc <> 0.
        message id sy-msgid type sy-msgty number sy-msgno
                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      endif.
    Regards
    Andrea

  • Need to have comma separated format

    Hi all
    I have developed a code in which is a file is stored in application server.  The text in the file is continous without any space.  I need to have text in comma separated format.
    Plz help. Its urgent.
    Regrds
    Mona

    Hi,
    Following report tis the sample report for your requirement.
    *Reading and Writing a text file from and to the application server*
    * sy-subrc = 0              Record read from file
    * sy-subrc = 4              End of file reached
    data:  w_dataset1(27) value '/var/textfile.txt',
              w_dataset2(27)  value '/var/outfile.txt'.
    data:begin of itab1 occurs 0,         "Text file format
               matnr(18),      "MATERIAL NUMBER
               bwkrs(4),       "PLANT
           end of itab1.
    *Uploading of text file from Application server.
    open dataset w_dataset1 for input in text mode.
           do.
                  if sy-subrc <> 0.
                      exit.
                  endif.
                  read dataset w_dataset1 into itab1.
                 append itab1.
                 clear itab1.
            enddo.
    close dataset w_dataset1.
    *Downloading of text file to Application server.
    open dataset w_dataset2 for output in text mode.
    loop at itable.
        transfer itable to w_dataset2.
    endloop.
    close dataset w_dataset2.
    Thanks,
    Sankar M

  • Using comma separator in numeric variables

    Hi Everyone,
    In my movie i have a shopping cart which adds up a total of all items. When the total reaches more the 1000.00 i need to add in a comma separator as in 1,000.00 if i do this manually flash no longer see's the variable as a number, how do i get around this one?
    Many Thanks
    Matt

    Hi Ned,
    Ok that sounds like a good idea but what coding would i need to accomplish this?
    Many Thanks
    Matt

Maybe you are looking for

  • After ipod 4g went dead it will no longer turn on

    after my ipod went dead i left in sitting for about a week and i tried charging after that and it wont even turn on. tried eveything. the comp wont even recognize it.

  • My mail app on my Macbook Pro is not working.

    Starting last month (october) my Mail App on my Macbook Pro has not been working properly. It does not automatically update itself and then it just stoped recieving emails all together. The Mail App does not close properly and I can not even force cl

  • I have an 1st Generation Ipod Touch stuck in recovery mode.

    I have an 1st Generation Ipod Touch stuck in recovery mode. Error message shows "The Ipod "Ipod" could not be restored.  An unknown error occurred (1).  No back up.

  • Saving search criteria in table

    Hi All, How to save search criteria in the table instead of saving in the weblogic domain? Many thanks in advance. Regards Kaushik Gopalakrishnan

  • Problem in Forms11g

    Hi all, Iam migrating the forms6i to forms11g , i have a control block in header with one field, and detail block having fields . Once the Form opens cursor will be in control block field and if user simply pressed the tab data will display in detail