Make a large string using sql
Ok all I want to do is generate a string of length X.
so to generate a 1000 character string of 'X's I'm doing the following:
select replace ('X','Y',1000) from dualThis is Just giving me X.
What am I doing wrong.
Use LPAD/RPAD:
select lpad('X', 1000, 'Y')
, length(lpad('X', 1000, 'Y'))
from dual;http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions082.htm#SQLRF00663
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions140.htm#SQLRF06103
Similar Messages
-
How do count how many 'A' s in this string using sql stmt?
hi all,
i have a string like 'AAAAARAMAAAAKRISHNAAAA'.
in this ,i want to find out how many 'A's .
how do find out this using select stmt.(length(s) - nvl(length(replace(s, 'A')), 0)) / length('A')but consider (by modifying the question slightly to "how do count how many 'AA' s in this string using sql stmt? ")
SQL> select (length('AAAAARAMAAAAKRISHNAAAA') - nvl(length(replace('AAAAARAMAAAAKRISHNAAAA', 'AA')), 0)) / length('AA') x from dual
X
6
1 row selected.couldn't I argue that the result should be 10 as e.g. in
SQL> select * from xmltable('let $str := "AAAAARAMAAAAKRISHNAAAA"
let $search := "AA"
for $i in 1 to string-length($str)
where substring($str, $i, string-length($search)) = $search
return substring($str, $i, string-length($search))' columns x varchar2(10) path '.')
X
AA
AA
AA
AA
AA
AA
AA
AA
AA
AA
10 rows selected.Matter of definition I suppose .... ;)
btw. regexp_count also yields 6:
SQL> select regexp_count('AAAAARAMAAAAKRISHNAAAA', 'AA') x from dual
X
6
1 row selected. -
Need Help in Splitting a String Using SQL QUERY
Hi,
I need help in splitting a string using a SQL Query:
String IS:
AFTER PAINT.ACOUSTICAL.1..9'' MEMBRAIN'I would like to seperate this string into multiple lines using the delimeter .(dot)
Sample Output should look like:
SNO STRING
1 AFTER PAINT
2 ACOUSTICAL
3 1
4
5 9" MEMBRAIN
{code}
FYI i am using Oracle 9.2There's this as well:
with x as ( --generating sample data:
select 'AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN' str from dual union all
select 'BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN' str from dual)
select str,
row_number() over (partition by str order by rownum) s_no,
cast(dbms_xmlgen.convert(t.column_value.extract('//text()').getstringval(),1) as varchar2(100)) res
from x,
table(xmlsequence(xmltype('<x><x>' || replace(str,'.','</x><x>') || '</x></x>').extract('//x/*'))) t;
STR S_NO RES
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 1 AFTER PAINT
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 2 ACOUSTICAL
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 3 1
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 4
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 5 9" MEMBRAIN
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 1 BEFORE PAINT
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 2 ELECTRIC
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 3 2
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 4
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 5 45 caliber MEMBRAIN
{code} -
Hi, EveryOne,
I tried to insert(update) a string data type using Fixed SQL Query as, for a example:
insert into Masters(MasterName) values([Param.1])
In html form I enter a value in field and press button to call the function. But if enter in the field a String value - nothing inserted in table but if I enter Number - everything works fine. I tried to use commas but the effect is the same.
Thnks,
SerjHello Sergey,
Ryan's sql statement is right. The ' sign is used to mark the [Param.1] as a string.
The sql statement (connection) is language independent, but you have to make sure that you mark up strings and timestamps in the correct way.
In your first statement
Masters(MasterName) values([Param.1])
xMII will replace [Param.1] with the value you type in("yourvalue"). For strings("yourvalue") it will look like this
Masters(MasterName) values(yourvalue)
this should bring back a sql error. You can try it in another sql client.
Hope this help as an explanation.
Regards,
Martin -
Trying to compare 2 strings using sql...should be an easy one
I have a String variable named 'code' that = "xyz". I have "xyz" in my DB under the userCodes column. And I have the following in my Java code:
String query = "SELECT userCodes FROM accounts";
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
thisCode = rs.getString("userCodes");
if (thisCode == code) { System.out.println("ITS THE SAME CODE"); }The problem is that Java is not recognizing thisCode as being equal to code, when they clearly are equal. Could someone please tell me why the two strings are not equal?
Thanks.Since strings are objects you have to use equals metho to test the equality of the strings.
Or in sql you can do this by adding a where clause
PreparedStatement ps = connection.prepareStatement("SELECT userCode FROM accounts WHERE userCode=?");
ps.setString(1,code);
ResultSet rs = ps.executeQuery();
... -
How to make comparison between strings using Labview
helo, i want to know, how to make comparison between array of string.?
the transmitter have send the assign text such as
A hello Bhye CbyeHi Syanitaa,
You actually only need to post the question once.
Multiple duplication. Please refer to this thread. -
Compare Encrypted String Using SQL
I have some data encrypted in SQL.
I want to use the LIKE command in SQL to compare a submitted form value to an encrypted value in the table.
How can I do this?
<cfquery>
SELECT *
FROM table
WHERE decrypt(name,key) = '#form.name#'
</cfquery>
Of course the decrpyt does not work in the example above as it gives an error. But how can I achieve the results without error?
Thanks.
ChuckMaking some headway here.
Here is what I have so far.
<cfquery name="cust" datasource="#DSN#" username="#USER#" password="#PASS#">
SELECT *
FROM customer
</cfquery>
<CFLOOP query="cust">
<CFSET temp = QuerySetCell(cust,"decust_co","#Decrypt(cust.cust_co,variable.ekey)#",#cust.currentrow#)>
<CFSET temp = QuerySetCell(cust,"decust_last","#Decrypt(cust.cust_last,variable.ekey)#",#cust.currentro w#)>
<CFSET temp = QuerySetCell(cust,"decust_first","#Decrypt(cust.cust_first,variable.ekey)#",#cust.current row#)>
</CFLOOP>
[Didn't think you would have to loop the QuerySetCell's, but you do
<cfquery dbtype="query" name="decust">
SELECT *
FROM cust
WHERE custid > 0
AND (decust_co LIKE '%#search#%'
OR decust_last LIKE '%#search#%'
OR decust_first LIKE '%#search#%'
OR acct_no LIKE '%#search#%')
ORDER BY decust_co
</cfquery>
OK...the part that is not working is my wildcard seach values. When I send a search variable of a single letter - C, M, H, etc...it will bring back results. If I send a NULL search variable - it will bring back all results...when I send a search variable with more than two characters - zero results. I am using two characters like "Ch" and one of the values is "Chuck". It should bring back a result. This query worked fine, prior to encrypting this data. I have verified the data in the QuerySetCell variables above are populating and decrypting correctly when I dumped the query.
Any idea? -
How to split a string using sql
Hi All,
I've to write a query where I need to split a string, how this can be done? So let's say a column has value as 1,2,3,4,5 and I want to split this string and output it as:
1
2
3
4
5
Please advise.Lots of articles:
Snap this user defined function too:
CREATE FUNCTION [dbo].[ufn_SplitString_Separator](@InputStr VARCHAR(MAX), @Separator VARCHAR(1))
RETURNS @tmpTable TABLE (OutputStr VARCHAR(MAX))
AS BEGIN
DECLARE @TmpPOS integer
SET @TmpPOS = CHARINDEX(@Separator,@InputStr)
WHILE @TmpPos > 0 BEGIN
IF @TmpPos > 0 BEGIN
INSERT INTO @tmpTable VALUES (LTRIM(RTRIM(SUBSTRING(@InputStr,1,@TmpPos-1))))
SET @InputStr = SUBSTRING(@InputStr, @TmpPOS + 1, LEN(@InputStr) - @TmpPos)
SET @TmpPOS = CHARINDEX(@Separator,@InputStr)
END ELSE BEGIN
INSERT INTO @tmpTable VALUES (LTRIM(RTRIM(@InputStr)))
SET @TmpPos = 0
END
END
IF LEN(@InputStr) > 0 BEGIN
INSERT INTO @tmpTable VALUES (LTRIM(RTRIM(@InputStr)))
END
RETURN
END
GO
And you can use like this:
SELECT * FROM DBO.[ufn_SplitString_Separator]('1,2,3,4,5',',')
"If there's nothing wrong with me, maybe there's something wrong with the universe!" -
Spliting a large string using regular expression which contain special char
I have huge sting(xml) containing normal character a-z,A-Z and 0-9 as well as special char( <,>,?,&,',",;,/ etc.)
I need to split this sting where it ends with </document>
for e.g.
Original String:
<document>
<item>sdf</item>
<item><text>sd</text</item>
</document>
<document>hi</document>
The above sting has to be splited in to two parts since it is having two document tag.
Can any body help me to resolve this issue. I can use StringTokenizer,String split method or Regular expression api too.manas589 wrote:
I used DOM and sax parser and got few exception. Again i don't have right to change xml. so i thought to go with RegularExpression or some other way where i can do my job.If the file actually comes in lines like what you posted, you should just be able to compare the contents of each line to see if it contains "</document>" or whatever you're looking for. I wouldn't use regex unless I needed another problem.
I got excpetion like: Caused by: org.xml.sax.SAXParseException: The entity "nbsp" was referenced, but not declared.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)So then it isn't even XML.
Edit: sorry, I just realized why you're considering all of these heavy-duty ideas. It's just that you don't know how to break the string into lines. You do it like this:
BufferedReader br = new BufferedReader(new StringReader(theNotXMLString)); -
To make one larger array using other two arrays
Hi,
I have two one dimensional arrays, using these two arrays as index need to create another larger one dimensional array.
like : if two one dimensional arrays namely X and Y, then X and Y should go as index for the final array.
Please help.
Thank youkathyayini wrote:
I have two one dimensional arrays, using these two arrays as index need to create another larger one dimensional array.
like : if two one dimensional arrays namely X and Y, then X and Y should go as index for the final array.
Please help.I second jverd, but you might want to look at Arrays.copy() and System.arrayCopy().
Winston -
Hi all,
I have a column(address) which I have to split into 4 parts. This may contain 1 or more lines(separated by new line). How to split this.
create table t(address varchar2(50));
insert into t values('first'||chr(10)||chr(13)||'second');
Antony Paul.Hi,
My first guess would be a simple substr with an instr.
Find the position of the chr(10) chr(13) combination and do a substring. It will not be very fast, but it will work.
An alternitive is using a function to return the values you need.
Jeroen -
Count the number of times a character is in a string using pl/sql
I need to count the number of times ":" appers in the string ":XXX:CCC:BBB:".
I have sound some solution using SQL but I do not want the context switch.
Also I am on 10g so I can not use REGEXP_COUNT.
Any help would be great.Hi,
length(REGEXP_REPLACE(':XXX:CCC:BBB:','[[:alnum:]]'))counts all kinds of punctuation, spaces, etc., not just colons. Change any (or all) of the colons to periods and it will still return 4. Use '[^:]' instead of '[[:alnum:]]' if you really want to count just colons.
Also, "SELECT ... FROM dual" is usually needed only in SQL*Plus or similar front end tools. In PL/SQL, you can call functions without a query, like this:
x := NVL (LENGTH (REGEXP_REPLACE (txt, '[^:]')), 0); -
How to make a photo DVD (using very large format photos)
I am attempting to make a photo DVD using iDVD. The program seems to lockup when exporting a slide show from iPhoto.
I am using a 21 mega pixial camera, so the file size is about 15-18 mb, per photo, 266 photo.
8
I
Have had to force a close of the pogram, several times.You're image are much to large. This Apple docukment deescribes how to prepare photos for slideshows: iDVD 7.0 Help (iLife '08): Preparing images for iDVD slideshows.
OT -
How do I make a connection to SQL Server Express using SQL Developer 1.5.3?
How do I make a connection to SQL Server Express using SQL Developer 1.5.3, if it's possible at all?
Also, I received a SQL Server dump file of some sort. Is there any way to read this file in SQL Developer and migrate the db to Oracle? Unfortunately I don't have raw DDL and DML for this database--just some sort of a binary dump file from SQL Server.
Thanks.
DanaAre you using SQL Developer 1.5.3 or 1.5.4?
If using an older version (i.e. 1.5.3), then you'll have to add a DLL to your environment. This is [ntlauth.dll].
If you don't find this DLL in your SQL Developer directory, then obtain the JDBC SQL SERVER Pluggin (jtds-1.2.2-dist.zip) from:
http://sourceforge.net/project/showfiles.php?group_id=33291&package_id=25350
Copy the ntlmauth.dll in the ...\\...\ide\lib directory (no need to register it).
Note: this approach should work if using DQL Developer 1.5.3 and SQL Server Express 2008
Regards,
M. R. -
Installed Azure VM From gallary with Sql Server 2012, even after allowing 1433 port through firewall, still cant get access to Sql Server from outside vm, So please provide steps for getting exact ServerName for connecting Sql Server on VM for connecting
from Visual Studio Application.
Thanks.Hi,
You can check the DNS name of the VM in the VM instance page of the Azure management portal.
In addition, you can also refer to the third-party article below:
http://thomaslarock.com/2014/02/connect-to-a-windows-azure-vm-using-sql-server-management-studio/
( Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please
make sure that you completely understand the risk before retrieving any suggestions from the above link.)
Best regards,
Susie
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected]
Maybe you are looking for
-
Can't update because it wants a wrong id
All my ILife apps won't update because when I set up my mac book it want an account and I used my google email address which was fine when I set it up but now the apps want to update using my apple id which is a tottally different email address. What
-
dear all, when i am booking in MIRO- subsequent debit, i do it with reference to purchase orders. when i click on "More allocation criteria" (because sometimes i have a lot of PO, not just one) it pop up a window called "reference to purchase orders"
-
elements 12 with windows 7 cannot be reloaded without going to the task manager and manually deleting the process lines for elements 12. How can this glitch be eliminated?
-
Print Screen not working for user but working for Administrator
Satellite A100 Laptop Print Screen Not working for USER but is working for Administrator[ New ] 09-14-2009 11:25 AM Hi I am new to this forum and am asking for your help. We are sharing a computer, the PrtSc key is working for the Administrator but
-
Profit center config for new Division
Hi SAP Experts, I need guidance for new Division implementation for our client. my client started a new branch its like a existing company but not separate a legal entity,requirement is they need every thing P and L ,Balance sheet for new branch. how