Generating alphanumeric string
Hi,
I'm new to java programming and
I was wondering if anyone could help.
I need to generate an alphanumeric string
consisting of one uppercase letter and 4 digits.
Ant help gratefully received
import java.util.Random;
public class Test {
private static final char[] uppercaseLetters = { 'A', 'B', 'C', 'D', 'E', 'F',
'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'R', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
public Test() {
final StringBuffer sb = new StringBuffer();
sb.append(uppercaseLetters[(int)(Math.random() * uppercaseLetters.length)]);
for (int i = 0; i < 4; i++) sb.append((int)(Math.random() * 10));
System.out.println(sb);
public static void main(String[] args) {
new Test();
}
Similar Messages
-
Generate random alphanumeric string as pk
Hallo,
I want to generate a random and unique alphanumeric string (4-digit).
Uniqueness is very important, because it will be used as primary key.
Is this supported by oracle 10?You can try the sys_guid function:
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for Linux IA64: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
SQL> select sys_guid() from dual;
SYS_GUID()
439F46B40AAAFB59E04014ACAE650DC1
SQL> create table guid_tbl(str varchar2(300), constraint guid_tbl_pk primary key
(str));
Table created.
SQL> begin
2 for i in 1..1000 loop
3 insert into guid_tbl(str) values(sys_guid());
4 end loop;
5 end;
6 /
PL/SQL procedure successfully completed.
SQL> select count(*) from guid_tbl;
COUNT(*)
1000
SQL>Amiel -
Hi,
I need one function which generates a Random alphanumeric string which I want to use as a primary key value. So it must be unique too.
Something similar to sys_guid in oracle, However I need length of the string fixed to be 6. sys_guid is not helpful as it generates 32 characters long string.
Can somebody help please?
Thanks in advance!
RKYou can find many examples by doing a search on this forum:
Alphanumeric sequence number generator -
Finding the smallest letter in a single alphanumeric string
How do I find the smallest letter in a single alphanumeric input?
I already wrote and successfully tested the code that takes an alphanumeric string as input, separates the number from the alphabet, and creates a new alphabetic string. However, I'm unsuccesful in writting the code to find the smallest letter within the alphabetic string. I am almost certain that the easy answer is Arrays.sort, but I unsuccesfully tried writing the code to place the alphabetic string into an array. I researched compareTo, but I do not have another object to compare?! Any suggetsions?Ahh flaimbait - I'm sure I'll get criticized for this... but - while we are talking about time-to-market, etc...:
The most important issue in development is to make sure that you understand the project requirements. The requirements in this situation were:
Find the smallest character in a string.
Given that, then any developer that goes through the trouble of looking up the sort APIs, etc... is not helping themselves - all they really needed to do was to write one line of code (as xxxx graciously posted):
for (int x=0; x<foo.length(); x++) if (foo.charAt(i)<low) low=foo.charAt(x);I absolutely guarantee that any Java programmer could write the above faster than they could figure out how to split a string appart by characters, look up the arraysort API, etc...
The arraysort functions are EXTREMELY efficient, and I would never suggest that someone re-implement them. The point here is that just because you've got a wrecking ball available, you can still use a hammer to drive a nail. -
Generate alphanumeric sequence using oracle sequence
Hi,
Can we generate alphanumeric sequence from Oracle sequence.
Sequence would be something like this. Please advice
TEMP-0001
TEMP-0002
TEMP-0010
Thanks,
Lakhi,
You can try below procedure...
SQL> create sequence sec
2 minvalue 0
3 start with 001
4 increment by 1
5 nocache;
Sequence created.
SQL> select 'temp-'||to_char(sec.nextval) from dual;
'TEMP-'||TO_CHAR(SEC.NEXTVAL)
temp-1 -
SAP Soamanager WSDL generates n0:string instead of xsd:string in 7.3
I´m using the Soamanager to create a Service for a Enterprise Service
Provider. The web service is generated based on a custom function
module. My intention is to consume a soap webservice via .net
application. Actually this works fine with the legacy BW 7.0 system.
But after we migrate the web service to the new BW 7.3 system, the web service interface is changed.
I have taken a look at the generated WSDL-file from Soamanager, the soamanager
generates the different type for string parameters. The
Import/Export parameter should be of type xsd:string, but it is
actually n0:string. but i need xsd:string for soap.
I´ve tried several datatypes in function module, e.g string,
char,....but always the same...n0:string instead of xsd:string.
Can you help on how to change the sting type in wsdl?
Thanks,How about a slight change to the xsd? Try with the following, it seems to work fine:
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Orders" type="Orders"/>
<xsd:complexType name="Orders">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="ligne">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Field1" type="xsd:string" />
<xsd:element name="Field2" type="xsd:string" />
<xsd:element name="Field3" type="xsd:string" />
<xsd:element name="Field4" type="xsd:string" />
<xsd:element name="Qte" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:schema>
You might also find this tool useful for testing such scenarios:
http://xsdvalidation.utilities-online.info/
By the way - how did you get the xsd that you are currently using? -
Does anyone have sample code to generate a random string of 12 characters?
Urgently needed.
Thanks very much for any replies.You could generate a random number between 1 and 999999999999 (see RUTRANDU program). Then you could convert each position in the number to a corresponding character. 0 = A, 1 = B, etc.
Hope it helps
Regards -
User Exit for generating alphanumeric serial number when P.O created
Hi All,
i am a na ABAPer.The PP guy in my module has asked me to look for an user exit which generates an alphanumeric Serial Number
when a purchase order is generated.
Any help as i have no clue about this.
Thanks in Advance,
Saket.Hi,
Try the following exits by putting break point in the include.
IQSM0001 Automatic Serial Number Assignment
PPCO0018 Check for changes to production order header
PPCO0019 Checks for changes to order operations
PPCO0021 Release Control for Automatic Batch Determination
Regards
Kiran Sure -
Importing SAP BAPI as Generated Item - String Object
Am new to BizTalk, working on BT 2013 using Visual Studio 2012. Am adding a "generated item" for Z_BAPI_SALESORDER_CHANGE (using the "Consume Adapter Service" dialog) and am receiving the message below. Our ABAP programmer tells me it's
type STRING which is causing the issue, but STRING is supposed to be an acceptable type (here: http://msdn.microsoft.com/en-us/library/dd787893%28v=bts.80%29.aspx). What am I missing?
Appreciate the help!
Microsoft.ServiceModel.Channels.Common.MetadataException: Retrieval of Type Metadata has failed while building WSDL at 'SAPTABLE/ZSSM_SO_HEADER_IN_CHANGE'
---> Microsoft.ServiceModel.Channels.Common.MetadataException: The SAP system returned error: Details: ErrorCode=RFC_EXCEPTION. ErrorGroup=RFC_ERROR_APPLICATION_EXCEPTION. SapErrorMessage=UNSUPPORTED_TYPE. AdapterErrorMessage=The RfcGetStructureInfoAsTable
API returned the error code 2 when obtaining metadata for the type ZSSM_SO_HEADER_IN_CHANGE. Check the RFC SDK trace files for details.. when trying to retrieve metadata for table: ZSSM_SO_HEADER_IN_CHANGE.Is it possible that your table is an ITAB II type table?
Because that is not supported by the SAP Adapter in BizTalk, see the limitations list
http://msdn.microsoft.com/library/dd787849(BTS.10).aspx
Glenn Colpaert - MCTS BizTalk Server - Blog : http://blog.codit.eu -
Regular Expression Pattern maching class to Validate Alphanumeric String
Hi
MY DB version is Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
I wanted to use the pattern maching classes given by oracle to check whether a given input string is alphanumeric or not.
Oracle 10g documentation says about the classes like [:digit:], [:alnum:] and many others.
http://www.dba-oracle.com/t_regular_expressions.htm
However these classes seems not to be working with my DB version.
Can someone tell me the DB version in which these classes works ?
Below is the code I am using to validate a input string.
SQL> CREATE OR REPLACE FUNCTION fn_is_alphanumeric
2 (
3 pi_value IN VARCHAR2
4 )
5 RETURN VARCHAR2
6 IS
7 lv_length NUMBER;
8 BEGIN
9 lv_length := length(pi_value);
10 IF ( REGEXP_LIKE(pi_value,'[:alnum:]{'||lv_length||'}')) THEN
11 RETURN 'TRUE';
12 ELSE
13 RETURN 'FALSE';
14 END IF;
15 END fn_is_alphanumeric;
16 /
Function created.
SQL>
SQL>
SQL> SELECT fn_is_alphanumeric('abc123') alpha FROM DUAL;
ALPHA
FALSE
SQL>
SQL>
SQL> CREATE OR REPLACE FUNCTION fn_is_alphanumeric
2 (
3 pi_value IN VARCHAR2
4 )
5 RETURN VARCHAR2
6 IS
7 lv_length NUMBER;
8 BEGIN
9 lv_length := length(pi_value);
10 IF ( REGEXP_LIKE(pi_value,'[A-z0-9]{'||lv_length||'}')) THEN
11 RETURN 'TRUE';
12 ELSE
13 RETURN 'FALSE';
14 END IF;
15 END fn_is_alphanumeric;
16 /
Function created.
SQL> SELECT fn_is_alphanumeric('abc123') alpha FROM DUAL;
ALPHA
TRUECharacter classes are working fine with regexp engine in your database version - simply change your function definition to:
CREATE OR REPLACE FUNCTION fn_is_alphanumeric
pi_value IN VARCHAR2
RETURN VARCHAR2
IS
lv_length NUMBER;
BEGIN
lv_length := length(pi_value);
IF ( REGEXP_LIKE(pi_value,'[[:alnum:]]{'||lv_length||'}')) THEN
RETURN 'TRUE';
ELSE
RETURN 'FALSE';
END IF;
END fn_is_alphanumeric;
/(brackets should be doubled as compared with your original version).
You can use both , range-based and class-based expressions, but you have to keep in mind, that range-based are nls dependant as opposite to class-based.
SQL> alter session set nls_sort=binary;
Session altered.
SQL> with t as (
2 select 'üäö123' s from dual
3 )
4 select
5 case
6 when regexp_like(s,'^[a-zA-Z0-9]+$') then 'Alphanumeric'
7 else 'Not Alphanumeric'
8 end range,
9 case
10 when regexp_like(s,'^[[:alnum:]]+$') then 'Alphanumeric'
11 else 'Not Alphanumeric'
12 end class
13 from t
14 /
RANGE CLASS
Not Alphanumeric Alphanumeric
SQL>
SQL> alter session set nls_sort='GERMAN';
Session altered.
SQL> with t as (
2 select 'üäö123' s from dual
3 )
4 select
5 case
6 when regexp_like(s,'^[a-zA-Z0-9]+$') then 'Alphanumeric'
7 else 'Not Alphanumeric'
8 end range,
9 case
10 when regexp_like(s,'^[[:alnum:]]+$') then 'Alphanumeric'
11 else 'Not Alphanumeric'
12 end class
13 from t
14 /
RANGE CLASS
Alphanumeric AlphanumericBest regards
Maxim -
Hi My randomString() method is generating junk character, I know this is due to some character set problem .I have not handeled properly the generation of randomCharacter.Please help.
package javaProg.completeReferance;
import java.util.*;
import javaProg.completeReferance.*;
public class TestMap
public static void main(String [] args)
Map m= new HashMap();
System.out.println("The Size of the Map is "+m.size());
fillMap(m,12);
System.out.println("The Size of the Map after fillMap Method is "+m.size());
ArrayList1.space("");
Collection c = m.entrySet();
Iterator i=c.iterator();
displayMap(i);
public static void fillMap(Map map,int number)
for(int i=1;i<=number;i++)
map.put(nextString(5),((int)(Math.random()*500)));
public static void displayMap(Iterator i)
while (i.hasNext())
Map.Entry m= ((Map.Entry) i.next());
System.out.print(m.getKey()+" "+m.getValue());
System.out.println();
public static String nextString(int length)
int randomInt=0;
char randomChar=' ';
StringBuffer randomString = new StringBuffer("");
for(int i=1;i<=length;i++)
randomInt = ((int)(5+Math.random()*500));
randomChar = (char) randomInt;
randomString.append(randomChar);
return (randomString.toString()).trim();
}Hi It still shows juck character, below is the sample output.
We are using
t?O%q 298
?W?8! 424
pR*fz 12
]5dA? 310
Ek?7? 466
/@JYL 313
UNY 262
(⌂%3? 25
?z,?? 98
????q 414
V?0s? 370
?_?oo 91 -
I may have missed something obvious but the SAX & DOM bits of
the XML Parser don't seem to supply any way of getting from a
set of parsed (or created) Document Java objects to a marked up
XML string. Is this something we have to do ourselves by
navigating through the node tree and adding the necessary
markup? It seems generic enough to be provided by one of your
APIs (such as the XSL bits?).
Thanks,
Dave
nullThanks,
I found the print method on the XMLDocument class which
generates an encoded string from that XMLDocument. This is fine
but what I had was a DocumentFragment reference returned from
the XSLProcessor.
I assume you have to get an XMLDocument from this
DocumentFragment (since XMLDocument doesnt implement that
interface) by creating an empty XMLDocument and then appending
the DocumentFragment as a child element. You can then use the
print method to get the XML string containing the styled XML.
This seems to work ok. Is this the right way to go about it?
Cheers,
Dave
Oracle XML Team wrote:
: In oracle.xml.parser.NodeFactory you will find a
createDocument
: method which will create the document node to get your XML
: document starter. This method was omitted in the DOM Level 1
: Req but has been added for Level 2. We have implemented it in
: both our v1 and v2 parsers.
: Oracle XML Team
: http://technet.oracle.com
: Oracle Technology Network
: Dave Barton (guest) wrote:
: : I may have missed something obvious but the SAX & DOM bits
of
: : the XML Parser don't seem to supply any way of getting from
a
: : set of parsed (or created) Document Java objects to a marked
: up
: : XML string. Is this something we have to do ourselves by
: : navigating through the node tree and adding the necessary
: : markup? It seems generic enough to be provided by one of
your
: : APIs (such as the XSL bits?).
: : Thanks,
: : Dave
null -
How to generate random strings
Gday all,
So I have to create a simple guessing game where the user guesses a 3 letter string that is randomly generated:
"For each new game your program will generate three unique random numbers between 0 and 9
inclusive, and convert them into a String of three characters in the range A to J. This String will be an
input to a game, where the user tries to guess the correct letters in the correct order. Examples of valid
input Strings would be, �JAD�, �ABC�, �IBE� and �EFG�. Examples of some invalid input Strings could be
�abc�, �AAA�, �123�, �AdE� or �NME�."
Just wondering how to create this random string? I know how to generate a random 3 char number (num = (int) (Math.random() * 1000)) but I dont know how to convert this into a corresponding string, as the instructions say.
I know this is very basic, but any tips?I know how to generate a random 3 char number (num = (int) (Math.random() * 1000)) but I dont know how to convert this into a corresponding stringUse string concatenation (+ with one or two String operands).
int i = 42;
char ch1 = '*';
char ch2 = '!';
String str = "foo";
// the System.out.println() is not important
// in each case a string is being created and printed
System.out.println("" + i);
System.out.println("2 times i = " + (2 * i));
System.out.println(i + "*2=" + (2 * i));
System.out.println("" + ch1 + ch2); // hint, hint
System.out.println(1 + 2 + "???");
System.out.println("???" + 1 + 2); -
Generating random string not like - example
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
Hi,
I want to generate a random one char string of which is not like a char.
select str from (select DBMS_RANDOM.STRING('U',1) str from dual) where str!='A';
some times i am getting NULL. How can i get some char all the time? i want to create a function using this logic. can some one help me to achieve this?
Thanks,
sgOne more way to do this... (Without function)
WITH t AS (SELECT 'X' charac FROM DUAL) --- 'X' is the input
SELECT COLUMN_VALUE letter
FROM ( SELECT *
FROM t a,
TABLE (sys.odcivarchar2list ('A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z')) b
WHERE COLUMN_VALUE <> a.charac
ORDER BY DBMS_RANDOM.VALUE ())
WHERE ROWNUM = 1;
Cheers,
Manik. -
To generate sql string of desired row using function.
Hi l,
I return the below query to get sum of vehicles which falls between the specific weight ranges.
It returns 20 rows( As I selected 4 classification vehicles).I was expect only 4 rows .One row for each classification of vehicles.
Is there a way if do some loop or decode in my function logic?
will tht work?
"(This is only smple. In my real appilication, if I use 15 classification vehicles it returns 320 rows. But i expect only 16 rows - 0 to 15 one row for each classification .Duirng runtime I'm getting an error as buffer string too small)"
How could I solve this?
I use this query inside a function and I call that function in a dynamic sql.
SELECT 'SUM('
|| 'CASE '
|| 'WHEN weight_report_data.weight >= '|| repo_range_param.min_value ||'
AND weight_report_data.weight < repo_range_param.max_value
THEN weight_report_data.weight_count '
|| 'ELSE 0 '
|| 'END '
|| ') "Class ' || repo_param.r_value || '" '
FROM repo_param
JOIN repo_range_param
ON repo_param.r_id = repo_range_param.r_id
WHERE repo_param.r_id = 1
AND repo_param.r_group = 'class'
AND repo_param.r_name = 'class'
AND repo_range_param.r_group = 'gvw'
AND repo_range_param.r_name = 'gvw'
ORDER BY CAST(repo_param.r_value AS NUMBER) ASC;
"sample sql string output when I run the above query "
SUM(CASE WHEN weight_report_data.weight >=10
AND weight_report_data.weight <15
THEN weight_report_data.weight_count ELSE 0 END ) "Class 0"
SUM(CASE WHEN weight_report_data.weight >=15
AND weight_report_data.weight <20
THEN weight_report_data.weight_count ELSE 0 END ) "Class 1"
SUM(CASE WHEN weight_report_data.weight >=5
AND weight_report_data.weight <10
THEN weight_report_data.weight_count ELSE 0 END ) "Class 2"
SUM(CASE WHEN weight_report_data.weight >=20
AND weight_report_data.weight <25
THEN weight_report_data.weight_count ELSE 0 END ) "Class 3"
"sample data for the tables involved"
CREATE TABLE weight_report_data
start_date_time TIMESTAMP NOT NULL,
end_date_time TIMESTAMP NOT NULL,
weight NUMBER(12,0) NOT NULL,
weight_count NUMBER(12,0) NOT NULL
INSERT INTO weight_report_data(start_date_time, end_date_time, weight, weight_count)
VALUES('01-JUL-08 12:00:00','03-JUL-08 12:00:00',4,5);
INSERT INTO weight_report_data(start_date_time, end_date_time, weight, weight_count)
VALUES('01-JUL-08 12:00:00','03-JUL-08 12:00:00',3,1);
INSERT INTO weight_report_data(start_date_time, end_date_time, weight, weight_count)
VALUES('01-JUL-08 12:00:00','03-JUL-08 12:00:00',8,6);
INSERT INTO weight_report_data(start_date_time, end_date_time, weight, weight_count)
VALUES('01-JUL-08 12:00:00','03-JUL-08 12:00:00',25,9);
CREATE TABLE repo_param
R_ID NUMBER(12,0),
R_GROUP VARCHAR2(10),
R_NAME VARCHAR2(10),
R_VALUE VARCHAR2(10)
INSERT INTO repo_param(r_id, r_group, r_name, r_value)
VALUES(1,'class','class',0);
INSERT INTO repo_param(r_id, r_group, r_name, r_value)
VALUES(1,'class','class',1);
INSERT INTO repo_param(r_id, r_group, r_name, r_value)
VALUES(1,'class','class',2);
INSERT INTO repo_param(r_id, r_group, r_name, r_value)
VALUES(1,'class','class',3);
CREATE TABLE repo_range_param
R_ID NUMBER(12,0),
R_GROUP VARCHAR2(10),
R_NAME VARCHAR2(10),
MIN_VALUE NUMBER(3,0),
MAX_VALUE NUMBER(3,0)
INSERT INTO repo_range_param(r_id, r_group, r_name, min_value, max_value)
VALUES(1,'gvw','gvw',0,5);
INSERT INTO repo_range_param(r_id, r_group, r_name, min_value, max_value)
VALUES(1,'gvw','gvw',5,10);
INSERT INTO repo_range_param(r_id, r_group, r_name, min_value, max_value)
VALUES(1,'gvw','gvw',10,15);
INSERT INTO repo_range_param(r_id, r_group, r_name, min_value, max_value)
VALUES(1,'gvw','gvw',15,20);
INSERT INTO repo_range_param(r_id, r_group, r_name, min_value, max_value)
VALUES(1,'gvw','gvw',20,25);
Thanks in advance
Edited by: user10641405 on Jun 18, 2009 4:10 PM
Edited by: user10641405 on Jun 18, 2009 4:15 PM
Edited by: user10641405 on Jun 18, 2009 4:15 PM
Edited by: user10641405 on Jun 18, 2009 4:16 PM
Edited by: user10641405 on Jun 18, 2009 4:17 PM
Edited by: user10641405 on Jun 18, 2009 7:47 PM
Edited by: user10641405 on Jun 19, 2009 4:15 PMSay you have a 3 tables
Table name Description rowcount()
============================================================================
weight_report_data report table having weights and counts 4
repo_param having id column gives different classes 4
repo_range_param is detail table of repo_param with id 4
as foreign key and defines weight
min max ranges.
Now you need to report
per class how many weights weights are there ?
--not understood report id clearly in relation to weight_report_data
step1:
need to map each row of weight_report_data againist its class.
select wrd.weight,wrd.weight_count,(select rp.class||rp.value
from repo_range_param rrp,
repo_param rp
where rrp.id= rp.id
and rp.id=1 -- add your other join condition
and wrd.weight between rrp.min and rrp.max ) class_nm
from weight_report_data wrd ;
This will give 4 rows , i.e for each row in wrd it tells which class it falls.
now you want to group by class_nm to get sum or count of weights.
step2:
select class_nm,sum(weight), count(weight), sum(weight_count)
from (
select wrd.weight,wrd.weight_count,(select rp.class||rp.value
from repo_range_param rrp,
repo_param rp
where rrp.id= rp.id
and rp.id=1 -- add your other join condition
and wrd.weight between rrp.min and rrp.max ) class_nm
from weight_report_data wrd ) wrd_classnm
group by class_nm;
I hope this helps .
suggestion: first analyse and breakdown into stpes how you r going to do if you do by hand and then translate into sql and then optimise
Maybe you are looking for
-
How to transport Parameter changes in a crystal report
Hi All, Very Good morning!!! I have designed a crystal report with static parameters. Earlier i used to have a dropdown kind of input selection for my parameters. Now i got a new requirement for a direct input in the field....tht means no dropdown ..
-
Using two editor instances within JTable
Hello, I'm struggling around using component editors within JTable. E.g. selectAll text on entering a JTextField cell or immediately raising the popup while entering a JComboBox cell. In my analysis most of these problems arises due the re-use of the
-
Problems with enveloping in Flash
I'm trying to create a shape tween, in which I use the envelop transform. Somehow, when I change the position of the points on the left side of the object, the object rotates during the shape tween; if I change the position of the points on the left
-
OIM 11g - ldap sync - Post Process event handler 'CREATE' faillling
Hi Gurus, We have ldap sync set up between OIM 11.1.1.5 and ODSEE 11g, Post process event handler on user creation with is setting a attribute with random 16 digit character, This event handler is getting triggered and setting the attribute in OIM bu
-
Loyalty points are stored in which entity?
Hi, I need to integrate Siebel's loyalty management with ATG and for That I need to know What is the data that flows from Siebel to ATG for loyalty functionality. So I need to know below things- In which entity loyalty/reward points are stored in Sie