Align the text of the varchar2 column data

Hello

It is in reference below thread:
Re: Align the text of varchar2

I think I should post my question in this forum, rather than General database,

I created a table and inserted the same that in the thread that above, and when I said:
Select ID, FILLED_TEXT(DESCRIPTION,30) FROM T;

It does not show the data in the column as aligned in 30 word boundaries. I thought, that I would be able to resolve the issue with the help of the http://soft.buaa.edu.cn/oracle/bookshelf/Oreilly/prog2/ch11_02.htm link, but failed.

Kindly help me more.

Kind regards.

Okay, so you're saying there is already a tags in the code to indicate where the line breaks are necessary, so a small adjustment of the data to include these tags and also the code...

DROP TABLE test_data
/
CREATE TABLE test_data as
select 1 as id, q'[For several days after leaving Nantucket, nothing above hatches was seen of Captain Ahab. The mates regularly relieved each other at the watches, and for aught that could be seen to the contrary, they seemed to be the only commanders of the ship; only they sometimes issued from the cabin with orders so sudden and peremptory, that after all it was plain they but commanded vicariously.<>Yes, their supreme lord and dictator was there, though hitherto unseen by any eyes not permitted to penetrate into the now sacred retreat of the cabin.]' as txt from dual union all
select 2, q'[Every time I ascended to the deck from my watches below, I instantly gazed aft to mark if any strange face were visible; for my first vague disquietude touching the unknown captain, now in the seclusion of the sea, became almost a perturbation. This was strangely heightened at times by the ragged Elijah's diabolical incoherences uninvitedly recurring to me, with a subtle energy I could not have before conceived of. But poorly could I withstand them, much as in other moods I was almost ready to smile at the solemn whimsicalities of that outlandish prophet of the wharves.<> But whatever it was of apprehensiveness or uneasiness - to call it so - which I felt, yet whenever I came to look about me in the ship, it seemed against all warrantry to cherish such emotions. For though the harpooneers, with the great body of the crew, were a far more barbaric, heathenish, and motley set than any of the tame merchant-ship companies which my previous experiences had made me acquainted with, still I ascribed this - and rightly ascribed it - to the fierce uniqueness of the very nature of that wild Scandinavian vocation in which I had so abandonedly embarked. But it was especially the aspect of the three chief officers of the ship, the mates, which was most forcibly calculated to allay these colorless misgivings, and induce confidence and cheerfulness in every presentment of the voyage. Three better, more likely sea-officers and men, each in his own different way, could not readily be found, and they were every one of them Americans; a Nantucketer, a Vineyarder, a Cape man. Now, it being Christmas when the ship shot from out her harbor, for a space we had biting Polar weather, though all the time running away from it to the southward; and by every degree and minute of latitude which we sailed, gradually leaving that merciless winter, and all its intolerable weather behind us. It was one of those less lowering, but still grey and gloomy enough mornings of the transition, when with a fair wind the ship was rushing through the water with a vindictive sort of leaping and melancholy rapidity, that as I mounted to the deck at the call of the forenoon watch, so soon as I levelled my glance towards the taffrail, foreboding shivers ran over me. Reality outran apprehension; Captain Ahab stood upon his quarter-deck. End]' from dual
/

CREATE OR REPLACE FUNCTION wordwrap (p_txt IN VARCHAR2, p_linesize IN NUMBER) RETURN t_wordwrap_txt PIPELINED IS
  cursor cur_wordwrap(p_txt in varchar2) is
    select rn, txt
    from (
          select rownum as rn
                ,trim(regexp_substr(p_txt,'.{1,'||p_linesize||'}( |$)',1,rownum)) as txt
          from dual
          connect by rownum <= ceil(length(p_txt)/p_linesize)+10
         )
    where txt is not null
    order by rn;
  v_txt varchar2(4000);
  v_length number := 0;
  v_paratxt varchar2(4000) := p_txt;
  v_paratxt_part varchar2(4000);
  v_pos number;
  v_srch varchar2(100) := '<>';
begin
  loop
    exit when v_paratxt is null;
    v_pos := instr(v_paratxt,v_srch);
    v_paratxt_part := case when v_pos = 0 then v_paratxt else substr(v_paratxt,1,v_pos-1) end;
    v_paratxt := case when v_pos = 0 then null else trim(substr(v_paratxt,v_pos+length(v_srch))) end;
    for w in cur_wordwrap(v_paratxt_part)
    loop
      v_txt := w.txt;
      loop
        exit when length(v_txt) = p_linesize or instr(v_txt,' ') = 0;
        for i in 1..p_linesize-length(v_txt)
        loop
          v_txt := regexp_replace(v_txt,'([^ ]) ','\1  ',1,i);
        end loop;
      end loop;
      v_length := v_length + length(v_txt);
      if length(v_txt) > 0 then
        pipe row(v_txt);
      end if;
    end loop;
    if v_paratxt is not null then
      pipe row(''); -- new line before next part
    end if;
  end loop;
  return;
end;
/

results...

SQL> select test_data.id, x.column_value
  2  from test_data, table(wordwrap(test_data.txt,50)) x
  3  /

        ID COLUMN_VALUE
---------- ---------------------------------------------------
         1 For  several days after leaving Nantucket, nothing
         1 above  hatches was seen of Captain Ahab. The mates
         1 regularly  relieved each other at the watches, and
         1 for aught that could be seen to the contrary, they
         1 seemed to be the only commanders of the ship; only
         1 they  sometimes  issued from the cabin with orders
         1 so  sudden  and  peremptory, that after all it was
         1 plain     they    but    commanded    vicariously.
         1
         1 Yes,  their  supreme  lord and dictator was there,
         1 though  hitherto  unseen by any eyes not permitted
         1 to  penetrate  into  the now sacred retreat of the
         1 cabin.
         2 Every  time I ascended to the deck from my watches
         2 below,  I  instantly  gazed  aft  to  mark  if any
         2 strange  face  were  visible;  for  my first vague
         2 disquietude  touching  the unknown captain, now in
         2 the   seclusion   of  the  sea,  became  almost  a
         2 perturbation.  This  was  strangely  heightened at
         2 times    by   the   ragged   Elijah's   diabolical
         2 incoherences  uninvitedly  recurring to me, with a
         2 subtle  energy  I  could not have before conceived
         2 of.  But poorly could I withstand them, much as in
         2 other  moods  I  was  almost ready to smile at the
         2 solemn  whimsicalities  of that outlandish prophet
         2 of                   the                  wharves.
         2
         2 But   whatever   it  was  of  apprehensiveness  or
         2 uneasiness  -  to  call  it so - which I felt, yet
         2 whenever  I  came to look about me in the ship, it
         2 seemed  against  all  warrantry  to  cherish  such
         2 emotions.  For  though  the  harpooneers, with the
         2 great  body of the crew, were a far more barbaric,
         2 heathenish,  and  motley  set than any of the tame
         2 merchant-ship    companies   which   my   previous
         2 experiences  had  made me acquainted with, still I
         2 ascribed  this  - and rightly ascribed it - to the
         2 fierce  uniqueness of the very nature of that wild
         2 Scandinavian   vocation   in   which   I   had  so
         2 abandonedly  embarked.  But  it was especially the
         2 aspect  of  the  three chief officers of the ship,
         2 the  mates,  which was most forcibly calculated to
         2 allay   these  colorless  misgivings,  and  induce
         2 confidence  and  cheerfulness in every presentment
         2 of   the   voyage.   Three   better,  more  likely
         2 sea-officers  and  men,  each in his own different
         2 way,  could  not  readily  be found, and they were
         2 every  one  of  them  Americans;  a Nantucketer, a
         2 Vineyarder,  a  Cape  man. Now, it being Christmas
         2 when  the  ship  shot  from  out her harbor, for a
         2 space  we had biting Polar weather, though all the
         2 time running away from it to the southward; and by
         2 every  degree  and  minute  of  latitude  which we
         2 sailed,  gradually  leaving that merciless winter,
         2 and  all its intolerable weather behind us. It was
         2 one  of  those  less  lowering, but still grey and
         2 gloomy  enough  mornings  of  the transition, when
         2 with  a fair wind the ship was rushing through the
         2 water  with  a  vindictive  sort  of  leaping  and
         2 melancholy rapidity, that as I mounted to the deck
         2 at  the  call  of the forenoon watch, so soon as I
         2 levelled   my   glance   towards   the   taffrail,
         2 foreboding  shivers  ran  over  me. Reality outran
         2 apprehension;   Captain   Ahab   stood   upon  his
         2 quarter-deck.                                  End

65 rows selected.

SQL>

Tags: Database

Similar Questions

  • The analysis of the VARCHAR2 column data to extract information

    Hi guys,.

    Let me give the information of DB first:

    SQL > select * from v version $;

    BANNER

    --------------------------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE 10.2.0.4.0 Production
    AMT for Solaris: release 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production

    My problem is: the interface of the application sends a large chain in VARCHAR2 (4000 BYTES) field. The string it sends is a bit like this-


    <strong>Crit:</strong> Some text. <br><strong>Distinguished</strong> (points 3):Some comment text1. <blockquote> </blockquote><strong>Crit:</strong> Some other text.<br><strong>Distinguished</strong> (points 3):Some comment text2. <blockquote> </blockquote><strong>Crit:</strong> Some more text. <br><strong>Distinguished</strong> (points 3):Some comment text3. <blockquote> </blockquote><strong>Overall comments:</strong><br> Final text!!
    I want to analyze the text and put in separate columns. Number of writes: maybe more than 3; its 3 up there. But the basic structure is the same. What is the best way to analyze this in PL/SQL code? I want something like

    Table 1
    Crit                       Points           Comment
    Some text                3        Some comment text1.
    Some other text        3        Some comment text2.
    Some more text        3        Some comment text3.
    Table 2
    Overall comments
    Final text!!
    Let me know if you need more information.


    Thank you.

    It could be a few slightly neater ways to do it with the REGULAR expression functions, but this will do what ypu want to:

    TABLE 1:

    WITH t AS
    (SELECT 'Crit: Some text. 
    Distinguished (points 3):Some comment text1.
    Crit: Some other text.
    Distinguished (points 3):Some comment text2.
    Crit: Some more text.
    Distinguished (points 3):Some comment text3.
    Overall comments:
    Final text!!' string FROM dual) SELECT SUBSTR(REGEXP_SUBSTR(string,'Crit:[^<]+', 1, level), 15) "Crit", SUBSTR(REGEXP_SUBSTR(string,'points [^\)]+', 1, level), 8) "Points", SUBSTR(REGEXP_SUBSTR(string,'\):[^<]+', 1, level), 3) "Comments" FROM t CONNECT BY LEVEL <= (LENGTH(string) - LENGTH(REPLACE(string, 'Crit:')))/5

    TABLE2:

    WITH t AS
    (SELECT 'Crit: Some text. 
    Distinguished (points 3):Some comment text1.
    Crit: Some other text.
    Distinguished (points 3):Some comment text2.
    Crit: Some more text.
    Distinguished (points 3):Some comment text3.
    Overall comments:
    Final text!!' string FROM dual) SELECT SUBSTR(string, INSTR(string, '', -1) + 8, INSTR(string, '', -1) - INSTR(string, '', -1) - 8) "Overall", SUBSTR(string, INSTR(string, '
    ', -1) + 4) "Final" FROM t
  • Need to convert the Varchar2 column number for the extraction of data based on the range of values.

    Hello

    I have a ZIP column which is the Varchar2 data type, it has values such as 2345, 09485, 10900, 07110, 06534.

    I have to go look up records from the range of values for the ZIP column as between 00000 and 07500.

    Could you give a logic.

    Thank you.

    Hello

    I think you can use the following code:

    SELECT T.*

    OF t

    WHERE the to_number (ZIP) between TO_NUMBER('0000') and TO_NUMBER('07500')

    ;

    CGomes

  • Get only the Varchar2 column channels

    Hello
    How can I extract only strings form varchar2 column type?
    I have data like below.

    25 - Abc xy
    233 - xyz jj
    x23A
    9 - dd
    5 - AAA (pp)

    I need the outputs (-also be deleted)

    ABC xy
    XYZ jj
    xA
    DD
    AAA (pp)


    Thank you
    Sujnan

    Maybe...

    API> WITH t AS (SELECT '25-Abc xy' AS col FROM DUAL
      2          UNION
      3          SELECT '233-xyz jj' FROM DUAL
      4          UNION
      5          SELECT 'x23A'  FROM DUAL
      6          UNION
      7          SELECT '9-dd'  FROM DUAL
      8          UNION
      9          SELECT '5-aaa(pp)'  FROM DUAL)
     10    SELECT TRANSLATE(col, '1234567890-', ' ') AS RES
     11    FROM t;
    
    RES
    ----------
    xyz jj
    Abc xy
    aaa(pp)
    dd
    xA
    
    Transcurrido: 00:00:00.93
    
  • Add the new column data IF

    Hi, can someone help with this...



    Select entered_on_date as START_DATE
    due_by
    id
    Object
    status
    resolution_date
    closed_date
    of XT_PORTAL
    where entered_on_date > = ' 01-SEPT.-10'
    entered_on_date ASC order

    which works very well.
    you want to put the new column entitled late...
    If closed_date is > resolution date fill in the column 'late' with 'Y '.
    If closed_date < resulution date fill in the 'overdue' column with "n".

    Published by: user11299998 on 10 Sep, 2010 08:02

    You can add additional code to deal with closed_date = resolution_date and if are NULL, but it's a start:

    CASE
    WHEN closed_date > resolution_date THEN 'Y'
    WHEN closed_date < resolution_date THEN 'N'
    END overdue
    
  • Resize the VARCHAR2 column on a large table

    Hello

    I need to resize a column VARCHAR2 with a large table (several hundred million lines).
    The column will be reduced from VARCHAR2 (40) to VARCHAR2 (50).
    Please check if someone has idea, will be this column resizing take a lot of time or a lot of resources that the table is highly accessible.
    Thank you.

    Kind regards
    Tarman.

    This should be an update of the dictionary: so it should very quickly because the existing data will not be changed.

    See http://asktom.oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:1542606219593 #1956714100346356542.

  • What is the difference between the "Received" column &amp; "Date"?

    The entries in the columns of "Receipt" and "Date" of the re CT should be the same; When they differ, it is no more than a few minutes. I wonder, that these columns show exactly? Why do these two categories? It obviously has something to do with the header lines, but I could not find it.

    one is the date of the sending of the message, the other the arrival time. Usually it is only a minute or two different these days, hours were not uncommon in the past and even now, Google, will try and deliver a week. If your server down lovers and it takes 5 days to fix or the submarine cable is blown, you will get the google mail which takes days in the date but also fresh column like today in the received.

    I have only the date. By clicking on the right-hand column headings allow you to customize the columns are displayed

  • ODI 12 - problem with missing data in the store column data types

    Hello world

    We have recently installed Studio 12 on Oracle RDBMS ODI. We have created some topologies, contexts and the logical architecture. We have created the necessary templates and made reverse engineering. The strange thing is when a model data store opening, we have noticed, the data types of its attributes are not displayed and cannot be selected in the drop-down list because they do not exist yet. You can see the image below.

    Untitled1.jpg

    So the mappings are not correctly executed because on the stage of the creation of work tables CREATE script was not generated correctly. (It's something like "CREATE TABLE < name > ()")

    Anyone can give an idea what could be the reason for this and how might be solved?

    Any ideas would be appreciated.

    Thank you in advance.

    Hello

    Please see the links below this should help you.

    http://gerardnico.com/doc/ODI/Webhelp/en/refmanual/topology/snpdt.htm

    http://gerardnico.com/doc/ODI/Webhelp/en/UserManual/topology/topology/topo_reverse_datatypes.htm

    http://odiexperts.com/data-types-creating-what-is-missing-for-any-technology/

  • Add the 2 columns to date

    Hi all

    I have a requirement where I have a column date and number in the other column. Its similar is Hire_date column that has a value of date (2009-01-17) and the other column is the Service over the years which is like a number (5).

    Now, I have to add one more column who should add the two columns (date of hire + Service over the years) and give the voltage output (17/01/2014).

    Can someone help me please how can I do this in OBIEE report.

    Thanks in advance!

    Any help would be very crowded.


    correct your expression;

    TIMESTAMPADD (SQL_TSI_MONTH, (TIMESTAMPDIFF (SQL_TSI_MONTH, 'Employee'. "" Date of hire ".

    VALUEOF (CURRENT_DT))), "employee." ("" Date of hire ")

    what you are aiming for using above? Why you should add and subtract?

    Made with this

  • Problem with the type of data in a view

    Hi all

    I have modified a view. For this reason my view passed to varchar2 column data type number automatically. But it should be only a number.

    Updated the view that changes the data type of column varchar2

    VIEW to CREATE or REPLACE v1
    AS
    SELECT Decode (Sign (mta.base_transaction_value), 0, Decode (Sign (mta.transaction_value), Decode (Sign (mta.primary_quantity),-1, NULL, 0))
    MTA.base_transaction_value),
    -1, NULL,
    Decode (Sign (mta.primary_quantity),-1, NULL, NULL
    MTA.base_transaction_value),
    (0)
    1, MTA.base_transaction_value,
    Col1 is NULL)
    Mtl_transaction_accounts MTA

    Old view that keeps this column under the number:

    VIEW to CREATE or REPLACE v1
    AS
    SELECT Decode (Decode (Sign (mta.base_transaction_value), 0, Decode (Sign (mta.transaction_value), 0, Decode (Sign (mta.primary_quantity), 1,0,))))
    0,0,
    (NULL),
    1.0,
    (NULL),
    1, MTA.base_transaction_value,
    Col1 NULL))
    Mtl_transaction_accounts MTA

    -> Create a note that the type of data of base_transaction_value, transaction_value, primary_quantity columns is number

    No help for making the data type of column 'col1' number using my first query?

    Thank you
    Srini

    The data type of an expression of DECODE() is determined by that of his first return value. Oracle has decided that a NULL value is a VARCHAR2 data type (because there must be something ).

    The changes to your code are extremely intertwined and twisted out and frankly too hard to work through. However, I think at some point the changes that you have implemented it had that effect.

    SQL> create or replace view v1
      2  as
      3  select decode(to_number(to_char(sysdate, 'dd')), 1, 0, 99) as col1
      4  from dual
      5  /
    
    View created.
    
    SQL> desc v1
     Name                                                  Null?    Type
     ----------------------------------------------------- -------- ----------------
     COL1                                                           NUMBER
    
    SQL> create or replace view v1
      2  as
      3  select decode(to_number(to_char(sysdate, 'dd')), 1, null, 99) as col1
      4  from dual
      5  /
    
    View created.
    
    SQL> desc v1
     Name                                                  Null?    Type
     ----------------------------------------------------- -------- ----------------
     COL1                                                           VARCHAR2(2)
    
    SQL>
    

    Cheers, APC

    blog: http://radiofreetooting.blogspot.com

  • Need for clarification to varchar2 column

    I get xml that will be inserted in the local table messages
    It is, I don't really know the size of the incoming xml message data.
    Design of the structure of the table is now difficult.
    If I design the column in the table for column varchar2 with VARCHAR2 (4000) and if the message contains the value
    as 'SAM', 'GEORGE' (no more than 10 characters) then it does not seem good for the VARCHAR2 COLUMN (4000)
    Oracle does not create the table with VARCHAR2 (without specifying the size)

    Any suggestions?

    S

    There's no real difference if you use varchar2 (4000) or varchar2 (100). Apart from the obvious that you can store up to 4000 bytes, against only 100/characters multibyte.

    However, there are a few minor side effects. Few of them and a comparison of the performance is described here: http://arjudba.blogspot.de/2009/08/does-oversize-of-datatype-varchar2.html

    (1) the varchar2 column indexing 4000 could be a problem (the ora-01450 exceeded max key length).

    (2) the size of the table could be actually smaller for tables with many sparesly populated varchar2 4000 columns. I can't find the source for that at the moment, but it had to do with the way oracle reserves future space required for the column.

    (3) migration of rank is more likely to happen if the great texts are added (= update) later.

    (4) If you define a variable with % rowtype in the table, it will use more expensive space PGA

    (5) some tools like TOAD could get questions or need of more resources to operate on 4 k columns.

  • How to view the data in the text file to the format column

    Hello

    I am acquiring data from an oscilloscope.

    Wen I save the data in a text file to aid wite spreadsheet string, all the displayed voltage values r first, then values of time... in addition to its delimited by tabs

    How can I view it like the r of time values in a single column and the voltyage of the r-values in the other column

    thanx

    Hello

    I don't know what is exactly the format that you found. I think you should try to use the function Array transpose (from the palette of function table) before you pass the array to write to string of spread sheet function or directly loyal to Terminal son transposes on writing worksheet function and see if you get the desired results.

    PS. : Share your code would be appreciated.

    Kind regards

    Amine31

    (Kudos are always welcome, mark it as a solution if it is the only)

  • align the text in multicolumn listbox to Center

    Hello world... How can align symbols text and multi-column list box point toward the Center? I attach a small picture of my multicolumn list box... Thank you

    Programaticaly using the Node property

  • Text flow auto adjustable upward so that the right column is filled first then the left column, I have 44 000 membership numbered cards to be 10up on A4 (4 400 pages)

    Auto flow text can be set up so that the right column is filled first and then the left column

    I have 44 000 membership numbered cards to be 10up on A4 (4 400 pages)

    Try to manually create blocks of text on the master page, and then screw them in the order you want the text to flow.

    But it's more like a data merge project, that does not use your guides or frames. Why must fill in that order? I guess it will be eventually cut apart.

  • XMLTable: definition of the columns data type of table

    Hello world

    I am using ORACLE 11 g and you want to shred XML into a table called test used. I was hoping I'd be able to get the types of data to the employees table existing instead of specify them in the clause of columns. Is this possible?

    Here is an example of what I'm trying to do. But I get an error: PL/SQL: ORA-00907: lack the right parenthesis on the line starting with columns.
        insert into EMPLOYEES
         select *
           from xmltable(
           '/employees/employee'
            passing EMP_XML
    
            columns FIRST_NAME EMPLOYEES.FIRST_NAME%TYPE path 'first_name',
                    LAST_NAME  EMPLOYEES.LAST_NAME%TYPE  path 'last_name',
                    GENDER     EMPLOYEES.GENDER%TYPE     path 'gender',
                    AGE        EMPLOYEES.AGE%TYPE        path 'age'
            );
    Error details
            columns FIRST_NAME EMPLOYEES.FIRST_NAME%TYPE path 'first_name',
                                *          
    
    ERROR at line 16:
    ORA-06550: line 16, column 42:
    PL/SQL: ORA-00907: missing right parenthesis
    ORA-06550: line 11, column 5:
    PL/SQL: SQL Statement ignored
    Thank you.

    Specification of column names is required, but you can omit the declaration of data types.

    See: the function XMLTABLE SQL/XML in Oracle XML DB

    XMLTable is used with storage XML based on a schema of XMLType data type is optional. If absent, the data type is inferred from the XML schema. If Oracle > XML DB is unable to determine the right type of a node, a default type VARCHAR2 (4000) is used.

    It is an Oracle extension; in the SQL/XML standard, the data type is always required.

    Note:
    The alleged data type might change as a result of the application of a patch or upgrade of Oracle XML DB. In particular, a new set of release or patch might be able to > determine the data type when the previous version was unable to do so (and therefore not reimbursed to VARCHAR2 (4000)). To protect against such an eventuality, specify an explicit data type with the data type.

Maybe you are looking for