Sorting the numbers in a Varchar2 Column
I've a column in a table which contains two type of values, either 0-30 or A-Z. Can I sort the values of this column firstly on numbers and then on Characters like this:
1
2
3
4
10
A
B
with t as (
select 'A' str from dual union all
select 'B' str from dual union all
select to_char(level) str from dual connect by level <= 10
select str
from t
order by case
when translate(str,'A0123456789','A') is null then to_number(str)
end nulls last,
str
STR
1
2
3
4
5
6
7
8
9
10
A
STR
B
12 rows selected.
SQL> SY.
Similar Messages
-
What is the eye symbol and what do the numbers mean in its column on "Sent Files" page?
What does the eye symbol mean on the "Sent Files" page?
Hi Chrislegal,
That column indicates how many times the file has been viewed. You can click the number in that column to see who's viewed the file, and how many times.
Please let us know if you have additional questions.
Best,
Sara -
Copy array and sort the numbers in the new array
Hi!
I have an array containing some digits where some of the digits are zeros. I want to copy the digits to another array but the zeros (well, I actually want to copy the zeros as well but I want to have them in the end of the new array).
I suppose I need an if-statement that checks if the old array contains any zeros and in that if-statement copy the content to the new array and put the zeros in the end.
This is my code so far and I don�t know how to go on from here:
int[] new_array = new int[array.length];
for (int i = 0; i < array.length; i++)
if (array[i] > 0)
new_array[i] = array;
new_array = array;
System.out.print(new_array[i] + " ");Roxxor wrote:
I think I know how to do it but only if I can catch the digits bigger than zero.
My code below just checks if there are positive digits and if there are, the whole old array is copied to the new one.Yes. Don't do that, you can see it's wrong.
So my problem is that I don�t know how to catch the digits bigger than zero and copy them. Is there any built in java keyword that catches signs, number etc?
if (array>=0)
new_array[i] = array[i];
new_array = array;
Yes, there is such a keyword. And you are already using it correctly in your code. You are already testing if the array entry is bigger than zero. Your only problem is, you don't know what to do when it is. But now you've been given two hints about what to do. -
How do I sort the data in the spreadsheet?
This is a fairly basic question and something I do all the time. I need to sort the data on a particular column or set of columns and am frustrated that it is this difficult to find. In trying to figure this out I know also have a chart on my spreadsheet that I can't seem to delete.
If you don't see a gray bar above the table, then tap a cell to show the gray bar.
Select a column by tapping the gray bar directly above the column. After the column is selected, tap the exact same spot again to show a menu.
In the menu, tap on Sort... etc...
Sort will sort the selected column, but will also update the entire table accordingly. If you don't want the rest of the table to update, then you have to copy that column (with the columns that you do want to update) and paste them onto the canvas so they appear in their own table. Sort the column then and paste it back into the original table.
Delete the chart from a menu that appears similarly as Sort. Tap on the chart one time to select it. Tap it again to show the menu with Delete. If you are doing this and choosing Delete, but the chart is not disappearing, then there might be a problem with the file. -
Oracle Best practices for changing Byte to Char on Varchar2 columns
Dear Team,
Application Team wanted to change Byte to Char on Varchar2 columns to accommodate Multi byte character on couple of production tables.
Wanted to know is it safe to have mixture of BYTE and CHAR semantics in the same table i have read on the couple of documents that It's good practice to avoid using a mixture of BYTE and CHAR semantics columns in the same table.
What happens if we have mixture of BYTE and CHAR semantics columns in the same table?
Do we need to gather stats & rebuild indexes on the table after these column changes .
Thanks in Advance !!!
SKApplication Team wanted to change Byte to Char on Varchar2 columns to accommodate Multi byte character on couple of production tables.
Wanted to know is it safe to have mixture of BYTE and CHAR semantics in the same table i have read on the couple of documents that It's good practice to avoid using a mixture of BYTE and CHAR semantics columns in the same table.
No change is needed to 'accommodate Multibyte characters'. That support has NOTHING to do with whether a column is specified using BYTE or CHAR.
In 11g the limit for a VARCHAR2 column is 4000 bytes, period. If you specify CHAR and try to insert 1001 characters that each take 4 bytes you will get an exception since that would require 4004 bytes and the limit is 4000 bytes.
In practice the use of CHAR is mostly a convenience to the developer when defining columns for multibyte characters. For example for a NAME column you might want to make sure Oracle will allocate room for 50 characters REGARDLESS of the actual length in bytes.
If you provide a name of 50 one byte characters then only 50 bytes will be used. Provide a name of 50 four byte characters and 200 bytes will be used.
So if that NAME column was defined using BYTE how would you know what length to use for the column? Fifty BYTES will seldom be long enough and 200 bytes SEEMS large since the business user wants a limit of FIFTY characters.
That is why such columns would typically use CHAR; so that the length (fifty) defined for the column matches the logical length of the number of characters.
What happens if we have mixture of BYTE and CHAR semantics columns in the same table?
Nothing happens - Oracle could care less.
Do we need to gather stats & rebuild indexes on the table after these column changes .
No - not if you by 'need' you mean simply because you made ONLY that change.
But that begs the question: if the table already exists, has data and has been in use without their being any problems then why bother changing things now?
In other words: if it ain't broke why try to fix it?
So back to your question of 'best practices'
Best practices is to set the length semantics at the database level when the database is first created and to then use that same setting (BYTE or CHAR) when you create new objects or make DDL changes.
Best practices is also to not fix things that aren't broken.
See the 'Length Semantics' section of the globalization support guide for more best practices
http://docs.oracle.com/cd/E11882_01/server.112/e10729/ch2charset.htm#i1006683 -
I have downloaded and installed the latest version of numbers on my mac. Everytime I save and then try to reopen that document, I receive a message telling me that I need a new version of numbers. Also, when I try to sort the date column, it sorts out of order. The last version sorted fine.
Welcome to Apple Support Communities
When you install the new iWork version, the old iWork version is kept, so it looks like you are opening your old version.
To fix this, open a Finder window, choose Applications in the sidebar and drag the new Numbers version to the Dock, so you can access to it quickly. Open all documents from this version. I don't recommend you to delete the old Numbers version in case you need it.
Respecting to the second question, you will get better answers in the Numbers for OS X forum -
Interactive Report - sort strings/numbers in the same column
Hi all,
I have an interactive report and have a column value.
It has type varchar2 in Database.
Problem: There are existing numbers and chars in this column.
Now I want to sort as numbers as chars.
Now it's like this:
10
2
23
3
no
yes
I want like this:
2
3
10
23
no
yes
How can I receive this???
All suggestions are welcome.without regexp option:
select vc
, case when instr('#1#2#3#4#5#6#7#8#9#0#',substr(vc,1,1)) = 0 then 1 else 0 end sort_column
from
select '10' vc from dual union all
select '2' from dual union all
select '23' from dual union all
select '3' from dual union all
select 'no' from dual union all
select 'yes' from dual union all
select 'yas' from dual
order by 2,lpad(vc,'9',0) --First sort on numbers, then on characters -
Sort Order for a VARCHAR2 Column
Hello Everyone,
This is probably quite simple, however I cannot see it. I am trying to sort on a varchar2 column that has numbers, text, dashes, tildes, carets and underscores which are mixed to compose a wire number. I have come up with an order by that changes the sort order from alpha to numeric satisfying one portion of the requirement.
select wirenbr,fromitem "from",frompin,diagnbr,sht,toitem,topin,effect
from acft_wires
order by decode(to_char(nvl(length(translate(wirenbr,'A1234567890','A')),0)),'0',lpad(wirenbr,18),wirenbr);
The select returns:
1
2
3
20
21
200
201
1000
A
ADT1
AEN1
AE1
AE9
AFA
B
1A
2U7230A-ZZ
2000A
213-22
22X100A20
220-11
The customer preferred sort looks like:
1
2
3
10
10A
11
200
201
201-01
202
1000
1000A
1001
I will build a shrine in my hall of honor to this forum if someone can point me in the right direction on how to solve this problem.
Thanks everyone for your help.ok, start with this
order by
translate(substr(wirenbr,1,1),'1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ-','0000000000ZZZZZZZZZZZZZZZZZZZZZZZZZZZ')
, nvl(length(substr(wirenbr,1,instr(translate(wirenbr,'1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ-','1234567890XXXXXXXXXXXXXXXXXXXXXXXXXXX'),'X')-1)),length(wirenbr))
, to_number(translate(wirenbr,'1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ-','123456789000000000000000000000000000'))
First, all that start with number go to the beginning and all that start with a letter go to the end.
Next, sort by the length of the first numerical part, as per Al's first solution.
Next, sort by the numerical part.
I started getting what I think is the right sort by that point. However, I think that you'll also have to add
stuff to sort by the alpha part, mine was
, NVL(RTRIM(LTRIM(wirenbr,'0123456789'),'0123456789'),0)
The biggest problem I see is all of the different number-letter-number
number-letter-number-letter formats. How many levels of recursion you'll have to go through to get it perfectly sorted, could you have ZZ999ZZ99Z9Z9Z9Z99?
Any ideas for breaking this value up? -
How do you sort the entire table in numbers with OSX Maverick?
Before the upgrade of Numbers 3.0 & Maverick, you use to sort the enire table by (1) Highlighting the entire table, (2) using the drop down arrow in the columns, (3) select the option to set your sort requirements.
Now, I am not able to find a way to do this.
Please help!Frederick -
Thanks for the idea, however, I'm trying to Reoganize my entire table. I'm afraid it is a very convient function that has been removed.
Sad to think that the ones designing these programs, don't actually use them.
~K~ -
TO_NUMBER function on varchar2 column with numbers and strings
I need to create a column in a view that converts a varchar2 column data to number. The problem is that some
of the data have strings and some numbers. I get "ORA-01722: invalid number" error when Oracle tries to covert
strings (e.g. 'ABCD') to number. What I need is to get a NULL value if the data is an invalid number.
How can I rewrite the following to get NULL value is a string is invalid number?
select to_number('abcd') numberColumn
from dual
thanx
AlfredSQL> select * from test_char_num;
ALPHA_NUM
ABC
DEF
123
234
A12
SQL> select decode(NVL(length(trim(translate(alpha_num, '1234567890', ' '))), 0),
2 0, alpha_num, 'NULL') new_alpha_num
3 from test_char_num;
NEW_ALPHA_
NULL
NULL
123
234
NULLP.S I am printing 'NULL' just to show the result, Please replace the 'NULL string with NULL value in SQL.
Thx,
Sri -
Sorting the report by clicking the column header
Hello,
Currently working on a requirement where i need to sort the report by clicking the column header. Can anyone please help me on this.
Suppose i have 3 colums deptno,dname,sal fields in my report. if i click deptno column header, report has to sort by deptno.Like that i need for other columns also.
Any help is really appreciated
Thanks
RamHello,
You can sort the fields using method suggested by Cauvery. However if you would like to have Ascending/ Descending sort order control at column header, then would require to implement few additional steps.
First do the sorting of field using the way suggested by Cauvery. Once sorting is done, right click on the column name and select the option ' Bind Sort Control'. You will see the sorted field in the window. select the field and click ok.
Now you would get 2 arrows on column. If you click upper arrow, fields would be sorted in Ascending Order and if you click on down arrow, it would be in Descending order.
Regards,
Chinmay Athavale -
have an Adobe PRO 11 user converting a word Document to PDF using PDFMAKER and all of the numbering is disappearing from left column,. Has anyone had this happen and if so what is the fix?
Is it possible to post a sample page some place for us to try out (dropbox or acrobat.com)? Is your Acrobat updated? What version of WORD are you using?
-
When I import a text file(comma separated) into a numbers spreadsheet all the data goes into one column instead of individual columns based on the comma separators. Excel allows you to do this during the import.. Is there a way to accomplish this in numbers without opening it in Excel and the importing into Numbers.
Your user info says iPad. This is the OS X Numbers forum. Assuming you are using OS X… Be sure the file is named with a .csv suffix.
(I don't have an iPad, so I don't know the iOS answer.) -
How do I get numbers to automatically add the next date down a column in numbers?
How do I get numbers to automatically add the next date down a column in numbers?
Hi Dd,
If you want the next date automaitcally filled in when you add a row to the bottom of the table, you can use a formula.
Here's an example, done in Numbers 2.3 (Numbers '09). The method is basically the same in Numbers 3.
Formulas in row 3:
B3: =B2+1
C3: =C2+7
D3: =D2+14
These have been filled down to the last row of the table.
The same table is shown below after three rows have been added by dragging the Row control handle (below the tab for row 7) down. No changes other than adding thse three rows were made by the user.
Note that rows 1 and 2 are header rows, and that row 2 contains the starting date for the seraies of date in each column. In the formula, the number at the end tells Numbers how many days to add to the previous date to get the next date.
Autofill of the formula requires that every non-header cell located above the cell into which the formula is to be filled contains the same formula.
Regards,
Barry -
Sorting the values in a column in a Web Template Report
Hi All,
I have a report build on WAD in which a table is displayed with certain rows and columns and have certain text values in one column and few numeral values in the other few columns. When i right click on the 1st column(having text values) and click on Sort Ascending by Name, the values are sorted in groups.There are other 3 columns next to that column which have text values as well but when i right click on them and try to sort it in some order(ascending by name/descending by name), there are no reorganization of the values in the column. Again, once i go to the other remaining columns having numeral values in it, the values get sorted in ascending/descending order as per the sort selection. Please advise on how i can make the sort possible in the columns in which the rearrangement is not happening. Do i need to change the Query to some settings? Please advise.
Thanks!
Subhra Ghosh.Subhra,
In BW reports, the sorting of characteristic values always happens left-to-right. When you choose to sort by columns 2 - 4, you are actually just specifying whether to sort ascending|descending and/or by key or text. This sort happens for each value of the first column, however. Therefore, the sort in column 2 is only noticeable when you have more than one row with the same value in column 1, etc.
This sorting behavior is different than the Excel type of sorting, which may be your confusion here.
If you want to sort first by a column other than column 1, you must swap the columns so that the desired characteristic is in column 1.
Hope this helps...
Bob
Maybe you are looking for
-
Connection Timed Out and Airport Admin Utility Issues
Our lab has and Airport Extreme (802.11g). Intermittently (once a week to a couple of times a day) our airport extreme will stop allowing new connections. Here's what appears to happen. The airport still appears in the the list of networks in the air
-
Download Link as a Column of Report
Hi All, I really tried from my side to somehow implement this requirement but couldn't find a way. Requirement: A report with two main columns - One has unique value and the other has a download link. This download link need to be used to fetch a set
-
Can't get my ejbs work in orion...
Hi everybody, I'm a newbie in EJBs, so I was trying to deploy some basic ejbs in orion, but all I get when I try to invoke a method is Servlet error: Unable to get home interface: javax.naming.NameNotFoundException: ejb/UserHome not found in myApp It
-
Freight costing calculation steps & T - codes
Hi experts, Can any one please help me with the steps involved in freight costing, the scenario is that I am ok with SPRO settings(shipment, shipment cost docs, item cate etc ) but not able to run the entire cycle is easy access ? regards, Vineet
-
I'm trying to download a paid membership of CC photoshop onto a second computer. No matter what I do, the site sends me to a blank page instead of downloading. How can I get out of this endless flight pattern?