How format column value

Hi,
I've this table TAB_COD:
COD_ID
00-300001-P01
01-1-P01
00-34-P01
00-200001-P01
00-1671-P01
00-300001-P01
00-100001-P01
00-200001-T01
00-400001-C01
00-900001-R01
PNRST01-P01
C0RTN-P01
ABCFRT01-P01
00-12-P01
Id like to get new cod_id with this conditions:
- eliminate "-" in the Third position
- add zero on the left (from Fourth position) until 6 Characters Leaving unchanged last 4 Characters (-P01, -R01,....)
- Leaving unchanged cod_id Alphanumeric without last 4 Characters (-P01, -R01,....)
In my case I'd like to have this output:
COD_ID
00300001-P01 --eliminate "-" in the Third position and add zero on the left (from Fourth position)
01000001-P01
00000034-P01
00200001-P01
00001671-P01
00300001-P01
00100001-P01
00200001-T01
00400001-C01
00900001-R01
PNRST01-P01 -- Leaving unchanged cod_id Alphanumeric
C0RTN-P01
ABCFRT01-P01
00000012-P01
I tried this query:
select SUBSTR(COD_ID,1,2)||LPAD(SUBSTR(COD_ID,4),6,'0')||'-'||SUBSTR(COD_ID,-3)
from TAB_COD;
But semms not correct
How can I write this query to get my output?
Thanks in advance!

You could try something like this:
test@ORA10G>
test@ORA10G> with tab_cod as (
  2    select '00-300001-P01' as cod_id from dual union all
  3    select '01-1-P01' from dual union all
  4    select '00-34-P01' from dual union all
  5    select '00-200001-P01' from dual union all
  6    select '00-1671-P01' from dual union all
  7    select '00-300001-P01' from dual union all
  8    select '00-100001-P01' from dual union all
  9    select '00-200001-T01' from dual union all
10    select '00-400001-C01' from dual union all
11    select '00-900001-R01' from dual union all
12    select 'PNRST01-P01' from dual union all
13    select 'C0RTN-P01' from dual union all
14    select 'ABCFRT01-P01' from dual union all
15    select '00-12-P01' from dual)
16  --
17  select
18    cod_id,
19    case instr(cod_id,'-',1,1)
20      when 3 then
21        substr(cod_id,1,2)||lpad(substr(cod_id,4,instr(cod_id,'-',1,2)-4),6,'0')||substr(cod_id,instr(cod_id,'-',1,2))
22      else cod_id
23    end as mod_cod_id
24  from tab_cod;
COD_ID        MOD_COD_ID
00-300001-P01 00300001-P01
01-1-P01      01000001-P01
00-34-P01     00000034-P01
00-200001-P01 00200001-P01
00-1671-P01   00001671-P01
00-300001-P01 00300001-P01
00-100001-P01 00100001-P01
00-200001-T01 00200001-T01
00-400001-C01 00400001-C01
00-900001-R01 00900001-R01
PNRST01-P01   PNRST01-P01
C0RTN-P01     C0RTN-P01
ABCFRT01-P01  ABCFRT01-P01
00-12-P01     00000012-P01
14 rows selected.
test@ORA10G>
test@ORA10G>pratz

Similar Messages

  • How: making column value as column of select statement

    Hi
    Quickly I have searched in this forum for following solution but not able to find it.
    I need to make a query in such a way that the value of one column in one table should act as a column-name of another table
    Eg:-
    tab1
    col1,col2,*col3*,col4
    tab2
    col11 col22 col33 col44
    row1 a b col3 d
    row2 aa bb cc dd
    So the query should be something like --- in row2 if the value is col3 then from tab1 I should pick the col3 in select statement (basically there will be some join in tab1 and tab2 )
    Hope I am able to make u all understand my query.
    regards

    Hi all,
    Sorry for late response.Just now I checked all the replies.
    Actually I tried in this way.
    CREATE OR REPLACE function Proc_caption (in_tan varchar2, in_order in number)
    return varchar2
    is
    d varchar2(100) ;
    begin
    SELECT col1 into d
    from tab1
    Where
    col2 = in_tanid
    AND col3 = 'Y'
    AND col4 = in_order ;
    return d ;
    Exception
    WHen No_DATA_FOund then
    return 'N' ;
    end ;
    create or replace procedure proc_generate_view(in_tan varchar2, in_soc varchar2)
    is
    x varchar2(2000);
    v4 varchar2(50) ;
    v5 varchar2(50) ;
    cnt number ;
    begin
    v4:= PROC_Caption (in_tan,4) ;
    v5:= PROC_Caption (in_tan,5) ;
    x := ' Create view v_generate as '
    || ' SELECT a , b, c, d ' ;
    if v4 <> 'N' THEN
    x := x || ' , ' || PROC_Caption (in_tan,4) || ' as Caption4 ' ;
    end if;
    if v5 <> 'N' THEN
    x := x || ' , ' || PROC_Caption (in_tan,5) || ' as Caption5 ' ;
    end if;
    x := x || ' FROM tab2 WHERE col1 = ''' || in_socid || ''''
    || ' AND col2 = ''' || in_tan || '''' ;
    select count(1) into cnt from USER_OBJECTS where OBJECT_NAME = 'V_GENERATE'
    and OBJECT_TYPE = 'VIEW' ;
    if cnt > 0 then
    EXECUTE IMMEDIATE ' DROP view V_GENERATE' ;
    END IF ;
    execute immediate x ;
    end ;
    NOTE:- I have just renamed the table name and column names in order to make it non confedential...
    I have created this successfully with actual table name and column names and able to get the result as per my requirement.
    regards

  • Mysterious formatting columns table

    Hi all,
    i don't post a problem, but a curiosity. I'm managing a Oracle BI environment developed by others, so many aspects are unknown for me. I've observed that if i make an Answers request dragging and dropping any columns from my subject area, any of them are still formatted. In detail, if i drag and drop a column that contains double values it is formatted, otherwise if (from same table) i drag and drop a column that contains integer values it isn't formatted. All columns have same class "TableHdg".
    I ask me, where is specified this behaviour? In css style? But how a css style can distinguish between a double and integer values to decide how formatting columns?
    Thanks
    Giancarlo
    Edited by: 832596 on 15-apr-2011 3.47

    Hi,
    thanks for your reply. I've formatted hundreds of tables but i've never noted these options. Incredible!!!!!!!!!. Can you tell me, when i click on "Save as the system-wide for this data type" (for example), where Oracle BI saves formatting options? In a css file? What?
    Thanks
    Giancarlo

  • How to format table column values to currency?

    All,
    I have bound a context attribute (type - string)  to a table column (TextView) which is used to display currency.
    It displays the value as 123456789.00
    How do I format the value as 123,456,789.00?
    Is there any FM available to format?
    I don't want to change the above context attribute type to CURR.
    Thanks
    Thruna

    >I don't want to change the above context attribute type to CURR.
    Why not?  That is the correct thing to do. That way you get formatting, sorting, even the correct decimal position and notation for different currencies and user settings.
    If you must go with string for the context attribute then I still assume your source data is type CURR.  When you 'move' this content into the string of the context attribute use the WRITE statement.  This will format the currency variable for output.

  • How to get column values on item added event receiver

    Hi,
    I have two columns in a document library and one is people or group column and the other one is choice column with check boxes.
    I want to know how to read column values on Item Added event receiver, so that I can create if statements based on those values.
    Thank you,
    AA.

    Hi AOK2013, 
    Have you had a look at this Microsoft tutorial: http://msdn.microsoft.com/en-us/library/office/gg981880(v=office.14).aspx
    Essentially, you want to use the AfterProperties property to access the changed field value. 
    E.g. 
    var personvalue = properties.AfterProperties["YourPersonFieldName"]
    Regards, Matthew
    MCPD | MCITP
    My Blog
    View
    Matthew Yarlett's profile
    See my webpart on the TechNet Gallery that allows administrative users to upload, crop and format user profile photos. Check it out here:
    Upload and Crop User Profile Photos

  • How to populate values dynamically & allows user to edit some other columns

    Hi..I am new to Apex..please help me to sove it out...
    I have a scenario like editing the some of the Customer details where as one field is dynamically populating from a different table.
    Columns like Include, Frequency, Communication, Address and Exclude has to be displayed in tabular format and data should be stored in a table called "om_customer_catalog ".
    In this "Communication " column value is dynamically populating from a table called "om_customer_settings" and the no. of records in the om_customer_settings table may vary time to time as per the settins in the Admin module.
    I want the user to edit all details except Communication column for all the rows which is displayed and the no. of rows should be displayed dynamically as per the settings.
    how can i achieve this?...which way i need to proceed like whether report kind of thing..or someother way..
    hope some reply....
    More Column details:
    Include - a Check box with editable(values Y or N)
    Communication - text field with display only(values like Promotional Email, All Email etc.)
    Frequecny - Drop downbox with editable(values Annually/Monthly/Weekly etc)
    Address - Drop down with editable(static values like Me, Father, Mother,Brother etc)
    Exclude Reason - text field with editable(any text value)
    Apply - a button for saving the changes
    thanks in advace...
    renjish

    Hello Renjish,
    Solution is quite tricky, You have to make a procedure which select each row of your tabular form and executes the update statement (customized).
    e.g
    to select each row of table use
    begin
    FOR I in 1..APEX_APPLICATION.G_F01.COUNT
    LOOP
    insert into table_name values(APEX_APPLICATION.G_F01(i),'PENDING',sysdate,'RESOURCE','','','','');
    end loop;
    end;
    here APEX_APPLICATION.G_F01(i) will return the value of the first column of selected row. Pick the values and make a cutomized update command.
    Regards,
    bhanwar

  • How to format the value in narrative ?

    Hi Experts,
    In BIEE 11,
    How to format the value in narrative , such as separator.
    In table or pivot property, I have set the separator for measure , but in narrative, the format will be disappeared. So how to implement this requirment?

    I had this problem with 11.1.1.6.0
    If you want this format as the default display format for this column everywhere, then you can save that format as default display format for the column or data type (Lower right corner of data format tab: "Save as Default" button, "Save as the system-wide default for "Table"."Column"). When I had the problem the narratives did use the default display format.
    Another workaround could be a direct database call to convert the data to a string. For example, in Oracle
    EVALUATE('TO_CHAR(%1,%2)' AS CHAR(30), “Table".“Column" ,'$9,999.00')
    but you may need to set EVALUATE_SUPPORT_LEVEL in your nqsconfig.ini, and this ties you to the database technology.

  • How can I replace column value with a particular value in SQL

    Hi All,
    Can anyone please tell me how can I format my output with replacing a column value with a specific value which actually depends on the present value of the column
    I am executing the following SQL statement
    select state,count(id) from <table_name> where composite_dn= <composite_dn_name> group by state;
    My Present output is:
    State No.Of Instance
    1 3
    3 28
    I want to replace the value in the column state as follows
    State No.OfInstances
    Completed 3
    Faulted 28
    I want "1" to be reppaced by "Completed" and "3" to be replaced by "Faulted"
    Is is possible with SQL or PL/SQL , if it is then how can I achieve this required result. Please help!!
    Thanks in Advance!!
    Edited by: Roshni Shankar on Oct 27, 2012 12:38 AM

    Hi Roshni,
    I guess this CASE clause can be simulated by a DECODE and also it is very easy to use.
    Refer -- http://www.techonthenet.com/oracle/functions/decode.php
    select decode(t1.state,t2.state_id,t2.state_name), t1.count_id
    from <table_2> t2, (select state,count(id) count_id
    from <table_name>
    where composite_dn= <composite_dn_name>
    group by state) t1
    where t1.state = t2.state_id;HTH
    Ranit B.
    Edited by: ranit B on Oct 27, 2012 2:02 PM
    -- link added
    Edited by: ranit B on Oct 27, 2012 2:19 PM
    -- sample code added

  • HTML code for Column value formating.

    Hi All,
    We have a requirement that, in a report we have some column values. For one of the column value we need to show that in bold with boarder like
    Column1| Column2| Column3.....
    Val1 | Val2 | Val3
    Val4   | Val5       | Val6_
    we want to show val4 column as bold and with boarder, because of some other constraints we have to use pivot table view. How can we achieve that
    Thanks in advance.

    Criteria tab->Column Properties->Style
    For Border you can use Style->Border
    You wold have mention entire row instead of vlo4!!
    If you have any condition to identify the row then go with conditional format
    Edited by: Veeravalli on Nov 26, 2012 7:01 AM
    Edited by: Veeravalli on Nov 26, 2012 7:03 AM

  • How to add spaces to the column value to make it up specifi length string please

    Hello There,
    Could you please guide me here to solve this issue,
    in my column (named as State) contains values as below
    California
    Washington
    Utah
    Connecticut
    Massachusets
    in the output how can i add a spaces to make up every column values as 15 length (for ex, Utah is 4 length then need to add 11 spaces, California is 10 would like to add 5 spaces)
    i tried below but no use in Sql 2008 R2
    SELECT  distinct state
       state
    +SPACE(35-len(state)),
    len(state+SPACE(35-len(state)))
    FROM dbo.ordersInfo
    Thank you in advance
    Milan

    Fixed length CHAR(n) data in SQL is automatically padded with spaces. Either change the column's data type or cast to it. Also, the ISO-11179 rules are that the column should be "state_name" and not just the root attribute "state" -- state_code, state_population,
    etc are a few of the confusions you created. 
    Another rule of RDBMS is that we do not do display formatting in the data. That is what presentation layers do. Why are you trying to fake COBOL in SQL? 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Formating the Row Based on one column value

    Hi Friends
    I am trying to format the Entire row based on the value of the first column in my Answers.
    Example if first column value in 'F' now i want the Entire row to be colored
    I can do conditional formating on one column but i want to do it on the entire row
    F     8.1 %     12.0 %
    E     5.2 %     3.5 %
    M     2.3 %     3.3 %
    If any one has done this or any suggestions please respond
    Thanks
    Sang

    Its a Pivot View
    F 8.1 % 12.0 %
    E 5.2 % 3.5 %
    M 2.3 % 3.3 %
    the column 1 --> F,E,M are the Product
    the column 2 --> 8.1% , 5.2% , 2.3% are the sales in year 2008
    the column 3 --> 12.0 % , 3.5 %, 3.3 % are the sales in year 2009
    So will i be able to apply the formating in pivot view based on one column to other column If yes please let me know how or
    suggest if this can be done using the BI Office , or BI publisher
    sing the BI Office i can do the formating in Excel but once i refresh the data all the formating is gone ... :(
    I am donno BI Publisher if we have to use BIP please suggest any solution its very very very urgent and important report formating they need here ....
    Thanks in advance David
    sango

  • How To Concatenate Column Values from Multiple Rows into a Single Column?

    How do I create a SQL query that will concatenate column values from multiple rows into a single column?
    Last First Code
    Lesand Danny 1
    Lesand Danny 2
    Lesand Danny 3
    Benedi Eric 7
    Benedi Eric 14
    Result should look like:
    Last First Codes
    Lesand Danny 1,2,3
    Benedi Eric 7,14
    Thanks,
    David Johnson

    Starting with Oracle 9i
    select last, first, substr(max(sys_connect_by_path(code,',')),2) codes
    from
    (select last, first, code, row_number() over(partition by last, first order by code) rn
    from a)
    connect by last = prior last and first = prior first and prior rn = rn -1
    start with rn = 1
    group by last, first
    LAST       FIRST      CODES                                                                                                                                                                                                  
    Lesand         Danny          1,2,3
    Benedi         Eric           7,14Regards
    Dmytro

  • How to insert column values into database as rows

    Hi,
    I have 8 columns and some not null columns. Based on not null columns I want to insert into table as rows. The 8 columns may contain values or no value. If the first column contains data, then I have to insert into one row. if the second column contains data I have to insert a row and in second column. respectively...So How can I insert column values into rows. Can I write 8 insert statements. (OR) is it possible to insert data from columns using where clause.
    Please help me out....
    Thanks in Advance

    Lines Table:
    line_id, orcl_bank_account_num, product_type, service_type, lease_type,
    funding_type, cpi, billing_frequency_unit_cd , annual_due_date ,
    pricing_start_date, pricing_end_date, install_date, contract_end_date ,
    prdct_replacement_cost_amt, cradle_replacement_amt, supranet_contract,
    issuance_fee, board_inactive_date, header_id, creation_date, last_modified_date,
    created_by_nam, modified_by_nam, activeinactive_flg, prdct_bill_amt_yr1,
    prdct_bill_amt_yr2, prdct_bill_amt_yr3, prdct_bill_amt_yr4, prdct_bill_amt_yr5,
    prdct_bill_amt_yr6, prdct_bill_amt_yr7, prdct_bill_amt_yr8, activation_fee_yr1,
    activation_fee_yr2, activation_fee_yr3, activation_fee_yr4, activation_fee_yr5,
    activation_fee_yr6, activation_fee_yr7, activation_fee_yr8,
    In this table the columns structure is :
    -- PRDCT_BILL_AMT_YR (1 to 8) NUMBER(14,4)
    -- ACTIVATION_FEE_YR (1 to 8) NUMBER(8,2)
    I have one more table:
    PRDCT_INS_AMT               NUMBER(14,4)
    ACTIVATION_FEE_AMT          NUMBER(14,4)
    I want to insert prdct_bill_amt_yr (1 to 8) columns data into PRDCT_INS_AMT column. similarly activation_fee (1 to 8) columns data.
    But the data should be inserted based product_type, service_type, lease_type columns values. (These 3 columns may contain upto 45 combinations).

  • Custom row-fetch and how to get column values from specific row of report

    Hi -- I have a case where a table's primary key has more than 3 columns. My report on the
    table has links that send the user to a single-row DML form, but of course the automatic
    fetch won't work because 1) I can't set more than 3 item values in the link and 2) the
    auto fetch only handles 2 PK columns.
    1)
    I have written a custom fetch (not sure it's the most elegant, see second question) that is working
    for 3 or few PK columns (it references the 1-3 item values set in the link), but when there are
    more than 3, I don't know how to get the remaining PK column values for the specific row that was
    selected in the report. How can I access that row's report column values? I'll be doing it from the
    form page, not the report page. (I think... unless you have another suggestion.)
    2)
    My custom fetch... I just worked something out on my own, having no idea how this is typically
    done. For each dependent item (database column) in the form, I have a source of PL/SQL
    function that queries the table for the column in question, using the primary key values. It works
    beautifully, though is just a touch slow on my prototype table, which has 21 columns. Is there
    a way to manually construct the fetch statement once for the whole form, and have APEX be smart
    about what items get what
    return values, so that I don't have to write PL/SQL for every item? Because my query data sources
    are sometimes in remote databases, I have to write manual fetch and dml anyway. Just would like
    to streamline the process.
    Thanks,
    Carol

    HI Andy -- Well, I'd love it if this worked, but I'm unsure how to implement it.
    It seems I can't put this process in the results page (the page w/ the link, that has multiple report rows), because the link for the row will completely bypass any after-submit processes, won't it? I've tried this in other conditions; I thought the link went directly to the linked-to page.
    And, from the test of your suggestion that I've tried, it's not working in the form that allows a single row edit. I tried putting this manually-created fetch into a before header process, and it seems to do nothing (even with a hard-coded PK value, just to test it out). In addition, I'm not sure how, from this page, the process could identify the correct PK values from the report page, unless it can know something about the row that was selected by clicking on the link. It could work if all the PK columns in my edit form could be set by the report link, but sometimes I have up to 5 pk columns.
    Maybe part of the problem is something to do with the source type I have for each of the form items. With my first manual fetch process, they were all pl/sql functions. Not sure what would be appropriate if I can somehow do this with a single (page level?) process.
    Maybe I'm making this too hard?
    Thanks,
    Carol

  • How to get the column values from a BC4J View Table in UIXML?

    I am using a default UiXML Application for Order Entry system with Orders & Order Lines & Customers. I have a uix file OrdersView1_View.uix which displays (no updateable columns) all the Orders. How do I get the column value of a selected row in a BC4J Table (example:OrdersId) when a Submit button is pressed using UIXML or Java Classes?
    I appreciate any help on this.

    Hi,
    You need to use keyStamp, an example:
    <bc4j table name="orders">
    <bc4j:keyStamp>
    <bc4j:rowKey name="key" />
    </bc4j:keyStamp>
    Furthermore, you can automatically send the selected row key using the go event handler, so in the handlers section you could send the key to an orderInfo page:
    <event name="show">
    <!-- forward to the update page, passing
    the selected key as a page property -->
    <ctrl:go name="orderInfo" redirect="true">
    <ctrl:property name="key">
    <ctrl:selection name="orders" key="key" />
    </ctrl:property>
    </ctrl:go>
    </event>

Maybe you are looking for