SQL & PL/SQL :: Sorting VARCHAR2 Field
Mar 23, 2010sort data set A,B,1,2,A1,A2,B1,B2,2B,1000 as A,B,1,2,1000,A1,A2,B1,B2,2B.
I tried with LPAD and EXPREG_REPLACE funtion. But it did not work.
sort data set A,B,1,2,A1,A2,B1,B2,2B,1000 as A,B,1,2,1000,A1,A2,B1,B2,2B.
I tried with LPAD and EXPREG_REPLACE funtion. But it did not work.
I need to partition a existing table based on varchar2 field (which is actaully date value but storing as character in the table). Using below statement for creating table, but getting error.
create table TST_CUST_ARC
(
interact_id NUMBER(10),
extrn_id VARCHAR2(38),
src_cd VARCHAR2(25),
full_nm VARCHAR2(45),
run_control_date VARCHAR2(13)
[code]....
Getting error : ORA-00907: missing right parenthesis
we have 2 databases with AR8MSWIN1256 characterset (arabic). our client machine has English windows installed. our .NET application, which runs on the client machine, using ODAC and it reads and writes from one db to another db. We have no problems with nvarchar fields containing arabic, but with varchar fields it seems that it reads the data just fine - we can see it in GUI.but when it writes the data to the second db, arabic becomes question marks. We tried to set client NLS_LANG in registry to AR8MSWIN1256 and to WE8MSWIN1252. It doesnt work.
View 4 Replies View RelatedI have been used to the consciousness that we should use the minimum length for varchar2 field that can store the data we need manipulate. But recently I was told that it has little impact on performance if we assign a much longer size.
View 13 Replies View RelatedIs there some functions to convert the long type field data to varchar2 type?
View 2 Replies View Relatedi am fairly new in the oracle arena, but what would cause a statement such as
ALTER TABLE TEST_TABLE MODIFY text_field1 varchar2(100) DEFAULT 'testval' NULL
to change a column's type from VARCHAR2(100) to VARCHAR2(100 byte)? i found a few mentions of the 100 byte concept online but nothing that jumped out at me.
I have the following query
SQL>
SQL> SELECT DECODE(act.statement_flag, NULL, 'Total',act.statement_flag) "Monthly Statement?",
2 COUNT(account_id) "Count",
3 ROUND(((COUNT(account_id)/
(SELECT COUNT(account_id) FROM accounts
WHERE account_status_id = consts$.acct_sts_active))* 100),2) || '%' "Percent of Active Accounts"
4 FROM accounts act
5 WHERE act.account_status_id = consts$.ACCT_STS_active
6 GROUP BY ROLLUP(act.statement_flag)
SQL> /
Monthly Statement? Count Percent of Active Accounts
------------------ ---------- -----------------------------------------
N 1892 98.08%
Y 37 1.92%
Total 1929 100%
I want the output to be in the following fashion:
Monthly Statement? Count Percent of Active Accounts
------------------ ---------- -----------------------------------------
Y 37 1.92%
N 1892 98.08%
Total 1929
And I would also like to know is there another way to find the Percent of Active accounts in the query.
I got the following data for which I will like to sort in ascending order.
B51-01-008/04022013/CRE1005/1
B51-01-008/04022013/CRE1005/2
B51-01-008/15-1-13/SSA6280/1
B51-01-008/31012013/CRE1005/1
B51-01-008/31012013/CRE1005/10
B51-01-008/31012013/CRE1005/2
and expected result will be
B51-01-008/15-1-13/SSA6280/1
B51-01-008/31012013/CRE1005/1
B51-01-008/31012013/CRE1005/2
B51-01-008/31012013/CRE1005/10
B51-01-008/04022013/CRE1005/1
B51-01-008/04022013/CRE1005/2
I will like to sort it based on the order on second segment for which is date, the earlier appear first then only the rest.
The db field is a string-type field that hold strings such as:
'1234'
'753'
'textstring'
'345'
Obviously, if you sort it, it'll be stored as a string such as:
'1234'
'345'
'753'
'textstring'
My client wants it so the numbers sort as integers, followed by string-like strings (sorted alphabetically), so it's like.
'345'
'753'
'1234'
'textstring'
Is there a quick and dirty SQL-only way to doing this in Oracle?
Is it possible to sort records based on hierarchy in such a way that records sorts in sequence and records of same level comes in the last (in sorting order)
Eg: Default hierarchy level order: 0,1,2,2,3,3,3,4,5
Above given is the default sorting order of an query for an parent 'NODE_A1' having multiple same level i.e 2 and 3
Expected Hierarchy level order: 0,1,2,3,4,5,2,3,3
Please check attached file for an example.
I am trying to sort columns base on cluster and alpha numeric field.
Column1 Columns2 column3
1 2-CA6R-234 9
1 2-CA6R-231 8
1 ARCT-0037000000ewegZ 10
2 2-QIZFF7 1
3 2-PIZFF6 6
3 ARCT-0037000000ewipk 9
3 2-QIZTF7 1
Wanted to sort in a way that column1 will be same order and the second column will order first with ARCT-XXXXX and then reset of the column2. It should look like this
Column1 Columns2 column3
1 ARCT-0037000000ewegZ 10
1 2-CA6R-231 8
1 2-CA6R-234 9
2 2-QIZFF7 1
3 ARCT-0037000000ewipk 9
3 2-PIZFF6 6
3 2-QIZTF7 1
I'm trying to sort a collection in a nested table in PL/SQL so these value can be used later for a display and for export to Excel. The sort is failing.
-- PLS-00642: local collection not allowed in SQL statements
-- PL/SQl: ORA-00902: invalid datatype
The error message are also noted below in the code on the line that fails.
A quick overview of this code- Using a nested table MyNestedTable the values from several select queries are combined into MyRecordsetZero using CURSOR, and MULTISET UNION. I'm trying to either sort MyRecordsetZero or populate MyRecordsetSorted with the sorted values for futher use.
IMPORTANT: The code is running in an enviroment that does not have permission to create.
Versions:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Developer: 8.0.0.1480
DECLARE
-- Declare the variable MyTID to be used by select statements and
-- set its data type and max character count
MyTID varchar2(10);
[code]....
In test.pks file I declared the following type
TYPE tab_tests is table of NUMBER(15);
In test.pkb, I have the following procedure
PROCEDURE report (
i_cid IN NUMBER
)
IS
test1 tab_tests := tab_tests();
test2 tab_tests;
BEGIN
-- I populate test1 with the data and it works fine. But when I tried to make a sorted nested table with the following command.
I got this error 'ORA-00902: invalid datatype',
a nested table than the following, like a built in Oracle collection method?
execute immediate 'select cast( multiset (select * from table(test1) order by 1) as tab_tests) INTO test2 FROM dual';
END;
I have report where there are multiple columns and requirement is user may choose his own sorting order from form, any sample .rdf.
CREATE TABLE EMP (EMP_CODE VARCHAR2(12),EMP_NAME VARCHAR2(20),SAL NUMBER);
INSERT INTO EMP VALUES ('1','A',10);
INSERT INTO EMP VALUES ('2','C',3);
INSERT INTO EMP VALUES ('3','B',20);
[Code]..
--note order by is changing, how its doable in report 6i.
1) eno list values ASC , DESC
priority Column : 2
2) DNO List Values ASC , DESC
priority column : 1
3) DTNO List Values ASC , DESC
priority column : 3
So i need the sorting order output like this
LIST VALUES ASC (OR) DESC USER SELECT AT RUN TIME ANY VALUE.
ORDER BY DNO DESC , ENO ASC , DTNO ASC
* The Priority is user will enter at run time based on the number the column should be sorting.
I have three SQLS which I am running using "Union"
e.g
select col1,count(*) from table where type ='parts'
group by col1
union
select col1,count(*) from table where type ='consumables'
group by col1
union
select 'Total',count(*) from table
group by 'Total'
I want to force the total column to be the last row of the select and the parts column to be the first row always. I did try something like prefixing the col1 with an alphabet. But that shows up in the output also. Was looking for a better way!
I have two list items and from left list item values are populated to right list item through Add and Remove buttons and vice versa.My requirement is
1.) I need to sort the values of list item whenever a new element is added to the list item.
I have a Group report based on one group.For eg..there is machine (Group) and it has detail records .The problem is there are certain specific machine on which i want sorting to be done the rest will be not sorted.
machine WX
Details not be sorted
machine sh4
Details to be sorted
machine sh5
Details to be sorted
machine AN1
Details not to be sorted
Jow can i sort field data getting from formula column. The filed that i want to sort have source of that formula column. When i use order by clause with :abc ---(formula column) then it doesn't not work.
View 3 Replies View RelatedI have a table in which I extract the year and the month and both in combination (from a date type). This is needed to summarize for example the year in a chart.
I need the combination of month and year because people could do a query which switches through years. For expample: From 02.2012 to 03.2013.My problem is I dont know how to tell anychart to sort the dates. I have already tried:
to_number(to_char(testdate,'YYYY')) as Year,
to_number(to_char(testdate,'YYYY'))||to_number(to_char(testdate,'MM')) as MonthyearApex now sorts:
20121,201212,20122
I would like that apex realizes to order:
1.2012,2.2012,3.2012 .........01.2013,02.2013.03.2013
The report itself has now four date relating collums:
1) Date (Type Date)
2) Year (Type Number)
3) Month (Type Number)
4) Monthyear (Type varchar)
Is there a way to short a Matrix report? The query shorts correctly in PLSQL but not in the generated report file.
There are columns like Date,Device,Operator Id etc and the report should be able to short depending on the requirement. For example,
it should be able to short by device, or by Date or both. I tried sorting in the 'Break order' but doesn't come out as required.
Even though i am using COL1 CHAR(500) NULLIF COL1=BLANKS, then also i am getting same error for those columns.
View 13 Replies View RelatedI have a table where i need to update one field values based on another field of the same table , simply as it is.I have done this using one select all check box , on clicking that all check boxes of item_trans table will get selected , then i will un select some of check box and then using one button, i will update the value of the fields which are checked only.
I have put the sample code but when i am updating its taking long time and hanging.I am also attaching the form based on the test case provided.
--tables with insert statement
create table item_trans (trans_item varchar2(12),trans_qty number,trans_act_qty number)
insert into item_trans(TRANS_ITEM,TRANS_QTY,TRANS_ACT_QTY) VALUES ('TREE1',40,NULL);
insert into item_trans(TRANS_ITEM,TRANS_QTY,TRANS_ACT_QTY) VALUES ('TREE2',20,NULL);
insert into item_trans(TRANS_ITEM,TRANS_QTY,TRANS_ACT_QTY) VALUES ('TREE3',20,NULL);
--i want to set the value of trans_Act_qty as trans_qty
--i create one dummy or test block to keep the select all check box. for that table test script is
CREATE TABLE TEST
(
C VARCHAR2(2000 BYTE),
B NUMBER,
A NUMBER
);
insert into test (C,B,A) values ('A',1,1);
--code written in select all check box which is created on test.block.
BEGIN
GO_BLOCK('item_trans');
FIRST_RECORD;
LOOP
:M_END_YN := :M_END_ALL;
[code].......
--code written in M_END_YN ( actual check boxes where i will uncheck).
IF :M_END_YN = 'N' THEN
:M_END_ALL := 'N';
END IF;
--code written on button to update those values which are checked.
BEGIN
GO_BLOCK('item_trans');
FIRST_RECORD;
LOOP
IF :M_END_YN = 'Y' THEN
[code]......
I am New to Apex. Im using Apex Version 4.2.
I have a tab named APPROPRIATIONS it has 10 fields. Among which is PROJECT NUMBER, AUTHORIZAION DATE (CALENDER TYPE POPUP), And FUNDS CHECK FLAG.
The Scenario is depending upon PROJECT NUMBER the Fields are Populated including FUNDS CHECK FLAG .
But the AUTHORIZAION DATE is a MANDATORY field has to be filled by User
The Requirement is to make AUTHORIZAION DATE as MANDATORY only when the FUNDS CHECK FLAG is *"BLANK "* or *āYā*
If the FUNDS CHECK FLAG is *āNā* then the AUTHORIZAION DATE to be made OPTIONAL.
I need to update a field with the 1st 9 characters of another field in the same record.
View 1 Replies View RelatedI have a table called Customer_Type with following fields
Customer_type ,Active_date, Inactive_date
regular,11/01/2011
daily,11/04/2011
monthly,11/05/2011/11/11/2011
Tbale 2:Customer
Customer_name,Customer_type,Customer_Inactive_date
John,regular,
James,monthly,
Jake,daily,
Jill,monthly
What i wnat is to update the Customer_inactive_date with the Incative_date field from Customer_type based on their Customer_type... So james and Jill would have their rows updated in this scneario ..How can i achive this in pl/Sql
I have teh code using merge function..I want something in traditional old fashion..
The sql statements are below
CREATE TABLE CUSTOMER_TYPE
(
type_code VARCHAR2(10),
[Code]....
I have a column named "col1" with datatype "varchar2(10)" and row wise entries like "1,1A, 2,3...,10,2A,..." like. I want to order it like "1, 1A ,2,2A, 2B,3... 10...".I tried it with to_number() but it gives me
1,10,11,2,....like that.
What is the best alternative to using VARCHAR2 if the output gets truncated after 4000 bytes in a PL/SQL function?
View 10 Replies View Relatedin our application we are using clob column instead of varchar2 because varchar2 does not allow more that 4000 chars, so Using clob allows to put data of any length, will it cause performance issues ? we have this column in almost in all tables .
View 2 Replies View Relatedcreate table members(
memberID varchar2(7),
locationID number(5),
roomID varchar2(5)
)
/
[Code]....
MEMBERI LOCATIONID ROOMI
------- ---------- -----
2007209 1 1
2006253 1 1-A
2006253 1 1-A
2006265 1 1-B
2006240 1 1-C
2005064 1 1-D
2007836 1 100
2007211 1 101
2007075 1 102
2007110 1 105
[Code]...
Function created.
SQL> select * from members
2 order by safe_to_number(roomID);
MEMBERI LOCATIONID ROOMI
------- ---------- -----
2007209 1 1
2007185 1 2
2007089 1 3
2007023 1 4
[Code]....
How can I sort the output to get the result like below
2007209 1 1
2006253 1 1-A
2006253 1 1-A
[Code]...
and so on...