Equivalent of JavaScript escape function in PLSQL
Hi,
Is there any equivalent of JavaScript's "escape()" function in PlSql for web development? cos I found that whenever I have links generated in stored procedure with text that has space, single quote and so on will become invalid url syntax when user clicks on the hyperlink.
So I hope to convert the text to valid syntax while generating the link.
Please advise.
Thank you so much.
Hi,
CREATE OR REPLACE FUNCTION UNESCAPE_F
(P_TEXT IN VARCHAR2 := null) RETURN VARCHAR2 IS
V_HEX2 VARCHAR2(1);
V_CHAR VARCHAR2(1);
V_TEXT VARCHAR2(4000);
V_RETURN VARCHAR2(4000) := NULL;
V_HEX1 VARCHAR2(1);
BEGIN
IF p_text IS NULL THEN
v_return := NULL;
ELSE
v_text := p_text;
WHILE INSTR(v_text, '%') > 0 LOOP
v_return := v_return | | SUBSTR(v_text, 1, INSTR(v_text, '%') - 1);
v_text := SUBSTR(v_text, INSTR(v_text, '%') + 1);
v_hex1 := SUBSTR(v_text, 1, 1);
v_hex2 := SUBSTR(v_text, 2, 1);
v_text := SUBSTR(v_text, 3);
SELECT
CHR(
(DECODE(v_hex1,'0',0,'1',1,'2',2,'3',3,'4',4,'5',5,'6',6,'7',7,'8',8,'9',9,'A',10,'B',11,'C',12,'D',13,'E',14,'F',15,0) * 16) +
DECODE(v_hex2,'0',0,'1',1,'2',2,'3',3,'4',4,'5',5,'6',6,'7',7,'8',8,'9',9,'A',10,'B',11,'C',12,'D',13,'E',14,'F',15,0) )
INTO v_char
FROM dual;
v_return := v_return | | v_char;
END LOOP;
v_return := v_return | | v_text;
END IF;
RETURN(v_return);
END UNESCAPE_F;
Regards Michael
Similar Messages
-
How can I decode Japanese character using java from JavaScript escape() function
Hi:
I have an application which supports Japanese character. I am using JavaScript escape() function to encode the text field before I posted it through web server and then I will just convert it into hex number to decode it through an Integer. It works fine for the character between ascii 1-255. However, it faild on all the double bytes character. All the unicode has the format of "%uXXXX" after it is escaped from JavaScript. How can I resolve the decoding problem?
Thank,
DavidPlease use 'encodeURI()', though it is supported only IE after 5.5.
I'm not sure Netscape.
Thanks,
Katsumi
dwang <[email protected]> wrote:
Hi:
I have an application which supports Japanese character. I am using JavaScript
escape() function to encode the text field before I posted it through
web server and then I will just convert it into hex number to decode
it through an Integer. It works fine for the character between ascii
1-255. However, it faild on all the double bytes character. All the
unicode has the format of "%uXXXX" after it is escaped from JavaScript.
How can I resolve the decoding problem?
Thank,
David -
Javascript escape() function
Hello everyone,
I have a select input in a form, some of the options have strings in which there is
a space. like "San Francisco", "Los Angelos". I know javascript escape function can transform
those strings to URL string like, "San%20Francisco". But i tried several times with no luck:
Here is my code:<select name="city">
<option value=escape('<%= cityName%>') selected> <%= cityName%>
</select> The value it submitted to server is not what I expected, it submit the whole thing:
escape("San Francisco").
Does anyone know what is the right way to invoke escape function in this circumstance?
Thank you in advance !
RachelHmm.. it should be the same for GET or POST. The javascript encode function doesn't work the way you were using it. It would work if you did something like this:
<script>document.write('<option value="<%=city%>"><%=city%></option>');</script>
But the problem with this is you need to make the user aware that they need to have JavaScript enabled. So better to encode in Java before writing with URLEncoder, like you said.
But I'm pretty sure GET or POST shouldn't be different for that type of thing. Browser bug, maybe? -
Is there any Java API equivalent to Javascript eval() method?
Is there any Java API equivalent to Javascript eval() method?
Regards
RakeshNo there isn't however you can use Jython (or another scripting language of your choice) to reproduce this functionality.
-
JavaScript Alert functionality in PL/SQL
I'm in need of implementing the JavaScript "Alert" functionality (display message and wait for user to acknowledge) in the "before displaying the page" PL/SQL block of portal reports and forms. While I'm at it - How about the JavaScript "history.back" function as well?
Is this possible? Can you point me in the right direction.Hi,
Where Portal says "before displaying the page" what it means is that it will run this code before it starts to htp.p() out the HTML of the page.
In WebDB this was actually what happened, in Portal there are some elements of HTML output BEFORE this block of code is run.
Anyway I don't think that you can have an alert that displays before the page is loaded. The page will still show behind the alert.
To get around this you would need a blank page to show your alert that forwards you on to the required page.
The history function can be called by the onclick event of a button or you can access Javascript through an anchor tag:-
link text
Regards Michael -
Javascript sort() function not working correctly
I have an image gallery that automatically loads via a PHP readdir function which populates an array, and then I have a Javascript sort() function which sorts the images in order numerically. In Chrome and Safari, the images display as numbered in the directory. However, in Firefox and Internet Explorer, they display out of order (firefox) and not at all (ie). Here is the code for the php file: <?
Header("content-type: application/x-javascript");
function returnimages($dirname=".") {
$pattern="(\.jpg$)|(\.png$)|(\.jpeg$)|(\.gif$)";
$files = array();
$curimage=0;
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
$file = basename($file,".jpg");
echo 'myImg['.$curimage.']="'.$file .'";';
$curimage++;
closedir($handle);
return($files);
echo 'var myImg=new Array();';
returnimages()
?>
and here is the code for the javascript sort:
function sortNumber(a,b)
return a - b;
myImg.sort(sortNumber);
// Tell browser the type of file
myImgEnd = ".jpg";
var i = 0;
// Create function to load image
function loadImg(){
document.imgSrc.src = myImg[i] + myImgEnd;
Any ideas as to why Firefox is behaving this way?After you check the box to sort on the column, are you making sure to select a sort order for the same column?
Earl -
Can I use Count, Max function in PLSQL BLOCK.
Can U help me to use count, max function in PLSQL BLOCK.
Because it is giving me error "It is a SQL function"SELECT COUNT(*)
INTO l_variable
FROM dual;
Will work inside PL/SQL -
Equivalent to calling a function in labview
Hi,
I don't use Labview regularly and would appreciate some advice for what is probably a straightforward problem! If I have one process started and running in a while loop, how can I start and run a second process in another while loop while simultaneously stopping the first while loop? For example, I have a button which when pressed turns on an indicator. When a second button is pressed the first indicator goes off and the second goes on simultaneously.
Thanks for your help.Nested Loops?
Edit to add: This is not the equivalent to calling a function like in C. The equavilant to calling a function in LV is to make a sub-vi. The sub-vi would be the same as a function. Place the sub-VI on another (higher level) block diagram and wire to it is like calling that function. -
Can record comparisons be done without functions or PLSQL
I am used to writing Oracle functions to do record comparisons, however on this particular project the managers do not want to use functions or PLSQL
Is there a way to do the following with a SQL statement rather than writing a function - see data set below? Oracle 9i.
I have the following data set used to track packages that are moved from warehouse to warehouse on trucks
I only want to retrieve a record if the starting location is Dallas Ft Worth and the end location is another city.
I do not want to retrieve a record if the package moves between other cities (say Boston and New York)
For this data set package 1324 was added and removed to the warehouses at Dallas 4 times via truck 735 before it was finally moved to a warehouse in Boston by the same truck
I want the query to return the following record
105273 345 1324 725 11/3/2010 14:32 11/3/2010 15:46 Dallas Ft Worth WH4
Showing the last location in Dallas before it was moved to Boston
I do not want to return any of the Boston or NY records or any of the previous Dallas Ft Worth Records.
The way the system updates the records is as follows:
If a package is added to a warehouse the record gets an added date.
When it is removed the system updates the removed date of that same record
Once it is added to a new warehouse there is a new record with an added date and null date for the removed date unless it leaves that location
In the record set if the removed date is null then that is the current location of the package
CREATE TABLE package_location
( track_id NUMBER(10)
, sender_id NUMBER(10)
, package_id NUMBER(10)
, truck_id NUMBER(10)
, package_add_date DATE,
, package_remove_date DATE,
, city VARCHAR2 (50)
, Warehouse VARCHAR2(50)
INSERT ALL
INTO package_location(track_id, sender_id, package_id, truck_id, package_add_date, package_remove_date, city, warehouse) VALUES (100012
, 345, 1324, 725, 8/4/2010 2:39:48 PM, 8/4/2010 2:53:07 PM, 'Dallas Ft Worth', 'WH1')
INTO package_location(track_id, sender_id, package_id, truck_id, package_add_date, package_remove_date, city, warehouse) VALUES (100016
, 345, 1324, 725, 8/4/2010 2:53:07 PM, 9/30/2010 10:41:01 AM, 'Dallas Ft Worth', 'WH2')
INTO package_location(track_id, sender_id, package_id, truck_id, package_add_date, package_remove_date, city, warehouse) VALUES (103055
, 345, 1324, 725, 9/30/2010 10:41:01 AM, 11/3/2010 2:32:14 PM, 'Dallas Ft Worth', 'WH3')
INTO package_location(track_id, sender_id, package_id, truck_id, package_add_date, package_remove_date, city, warehouse) VALUES (105273
, 345, 1324, 725, 11/3/2010 2:32:14 PM, 11/3/2010 3:46:22 PM, 'Dallas Ft Worth', 'WH4')
INTO package_location(track_id, sender_id, package_id, truck_id, package_add_date, package_remove_date, city, warehouse) VALUES (105284
, 345, 1324, 725, 11/3/2010 3:46:22 PM, 11/22/2010 11:55:18 AM, 'Boston', 'WH34')
INTO package_location(track_id, sender_id, package_id, truck_id, package_add_date, package_remove_date, city, warehouse) VALUES (106674
, 345, 1324, 725, 11/22/2010 11:55:18 AM, NULL, 'New York', 'WH56')
I tried to do a query with a subquery... the main query was getting all the records with Dallas Ft Worth and then the subquery was to check if the location was not Dallas Ft Worth, but so far I haven't quite been able to get the correct dataset.
Any help is greatly appreciated. I don't know if there is a way to do this with just a sql query, if not other suggestions are welcomed!
Thanks in advanceI added a couple of rows to your table, shipping the package back from New York to Dallas on a different truck, then back out from Dallas to New York just to make sure I understand the requirements.
SQL> SELECT * FROM package_location;
TRACK_ID SENDER_ID PACKAGE_ID TRUCK_ID PACKAGE_ADD_DATE PACKAGE_REMOVE_DATE CITY WAREH
100012 345 1324 725 04-aug-2010 14:39:48 04-aug-2010 14:53:07 Dallas Ft Worth WH1
100016 345 1324 725 04-aug-2010 14:53:07 30-sep-2010 10:41:01 Dallas Ft Worth WH2
103055 345 1324 725 30-sep-2010 10:41:01 03-nov-2010 14:32:14 Dallas Ft Worth WH3
105273 345 1324 725 03-nov-2010 14:32:14 03-nov-2010 15:46:22 Dallas Ft Worth WH4
105284 345 1324 725 03-nov-2010 15:46:22 22-nov-2010 11:55:18 Boston WH34
106674 345 1324 725 22-nov-2010 11:55:18 New York WH56
106675 345 1324 804 25-nov-2010 09:55:18 30-nov-2010 15:46:22 Dallas Ft Worth WH4
106676 345 1324 804 25-nov-2010 09:55:18 01-dec-2010 15:46:22 New York WH42Given this data, you would want to get back track_id 105273 and 106675 correct?
If so, then something like:
SQL> SELECT track_id, sender_id, package_id, truck_id, package_add_date,
2 package_remove_date, city, warehouse
3 FROM (SELECT track_id, sender_id, package_id, truck_id, package_add_date,
4 package_remove_date, city, warehouse,
5 LEAD (city) OVER(PARTITION BY package_id
6 ORDER BY package_remove_date) next_city
7 FROM package_location)
8 WHERE city = 'Dallas Ft Worth' and
9 next_city != city;
TRACK_ID SENDER_ID PACKAGE_ID TRUCK_ID PACKAGE_ADD_DATE PACKAGE_REMOVE_DATE CITY WAREH
105273 345 1324 725 03-nov-2010 14:32:14 03-nov-2010 15:46:22 Dallas Ft Worth WH4
106675 345 1324 804 25-nov-2010 09:55:18 30-nov-2010 15:46:22 Dallas Ft Worth WH4John
Edited by: John Spencer on Aug 14, 2011 2:22 PM
Fixed non-displaying operator -
Is it possible to call a java function from plsql?
I have a plsql script which loads data in to a table. One of the fields is a notes field. I would like to use advance offerings of java to manipulate the data before inserting. Is there away I can pass the data to a java function and have it return the manipulated data?
Thanks
AaronYou can use java stored procedure to call java function from plsql.
1. Create a java class with a static function(which will be called from plsql).
2. Compile and load the class into database using LOADJAVA command.
3. Create a wrapper stored procedure or function in plsql which calls the above java function.
4. Access this plsql procedure like normal database procedure. This will invoke underlying java function in which you can do all the processing and return result.
Refer this url for help on implementing above steps :
http://otn.oracle.com/tech/java/jsp/pdf/developing_o8i_apps_with_plsql_and_java_twp.pdf
Samples on java stored procedure :
http://otn.oracle.com/sample_code/tech/java/jsp/oracle9ijsp.html
Chandar -
Invoke Javascript alert withing a PLSQL Function Block
Hello,
I am having trouble trying to achieve the following functionality. I have a page with an update button. On submit of this update button I have created a PL/SQL Function Body which returns TRUE for CASE 1, and FALSE for CASE 2. If CASE1 is achived then the process will update the data in the underlying table and will do nothing for CASE2. What I simply want to do is for CASE2, I also want to throw up an Alert informing the user that he is in CASE2. My existing PL/SQL function looks something like:
BEGIN
IF CASE 1 THEN
RETURN TRUE;
ELSE
RETURN FALSE;
END;
I want something like:
IF CASE 1 THEN
RETURN TRUE;
ELSE
RETURN FALSE;
javascript:alert('Update did not work!');
END;
Can anybody help me?
Thanks
MiteshIf you have submitted the page it is too late for javascript to run, javascript runs in the client, and the pl/sql runs on the server. If you want that to popup at that point you will need to have it popup on onLoad of the resulting page. Or do all of the validation in javascript then have javascript submit the page.
-
I think i have an escaping problem, could someone please help me out:
<script>
function deleteConfirm(ID, thema){
var theText = "" + thema;
if( confirm("Weet u zeker dat u " + theText + " wilt verwijderen?")) {
document.location='lib/event_frm_process.jsp?action=delete&ID='+ ID;
</script>
Link using this function:
<a href="\"javascript:deleteConfirm('<%=resultset.getString("ID")%">','<%=resultset.getString("thema")%>');"\><img src="images/verwijderen_hog_icon.gif" width="20" height="19" border="0" align="absmiddle"></a>
Thank you in advance .......</a>Try:
<a href="javascript:deleteConfirm('<%=resultset.getString("ID")%>','<%=resultset.getString("thema")%>');"\>The quotes inside the <%= %> do not conflict with the HTML quotes since they are handled server side and the HTML/javascript is handled client side.
If that doesn't work, you will have to look at the HTML generated and see what the text coming out of the result set it (if it contains quotes or apostrophes itself). It the string coming from the result set is problematic you will have to re-arrange your quotes or process it some more before it is inserted... -
How can I use JavaScript extention functions with Xalan for transforming XML with XSL
While transforming standart XML and XSL files to HTML with this servlet:
package mypackage1;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.net.URL;
import javax.xml.transform.*;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import org.mozilla.javascript;
public class Servlet2 extends HttpServlet
private static final String CONTENT_TYPE = "text/html; charset=windows-1252";
public void init(ServletConfig config) throws ServletException
super.init(config);
public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
try
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
TransformerFactory tFactory = TransformerFactory.newInstance();
Source xmlSource = new StreamSource(new FileReader("c:/aaa.xml"));
Source xslSource = new StreamSource(new FileReader("c:/bbb.xsl"));
Transformer transformer = tFactory.newTransformer(xslSource);
transformer.transform (xmlSource, new StreamResult(out));
catch (Exception e)
e.printStackTrace();
everything is going ok,
but when try to use javascript function in XSL file, for example like in this:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:lxslt="http://xml.apache.org/xslt" xmlns:my-ext="ext1"
extension-element-prefixes="my-ext">
<lxslt:component prefix="my-ext"
functions="getdate">
<lxslt:script lang="javascript">
function getdate() {
var d = new Date();
return d.toUTCString();
</lxslt:script>
</lxslt:component>
<xsl:template match="/">
<p><xsl:copy-of select="my-ext:getdate()"/></p>
</xsl:template>
</xsl:stylesheet>
recieve error-message:
XSL-1000: (Fatal Error) Error while parsing XSL file (Extension function namespace should start with 'http://www.oracle.com/XSL/Transform/java/'.).
What kind of namespace I should specify?Hello, Paul.
I'm sure you may not use JavaScript as a language for creating XSLT extention functions with Oracle XDK Parser. This is since parser might have JavaScript interpreter to work with JavaScript, but it has not.
If you need to build any XSLT extention functions you must build them as Java class' static methods.
After that, you define the usage of the class by mean of namespace declaration as:
xmlns:your-ns="http://www.oracle.com/XSL/Transform/java/yourpackage.Yourclass"
(Prefix "http://www.oracle.com/XSL/Transform/java/" may differs if you use non-Oracle XML parser)
and use class' static method in XSLT:
<xsl:value-of select="your-ns.staticMethodName(paramsIfAny)"/>
In your case you may wish to use standard Date class:
xmlns:date="http://www.oracle.com/XSL/Transform/java/java.util.Date"
<xsl:value-of select="date:toString(date:new)"/> -
How to write decode function in plsql
hi
guys
can u plz help me in this topic
.........Hi ,
You could use the decode function in an SQL statement as follows:
SELECT supplier_name,
decode(supplier_id, 10000, 'IBM',
10001, 'Microsoft',
10002, 'Hewlett Packard',
'Gateway') result
FROM suppliers;
The above decode statement is equivalent to the following IF-THEN-ELSE statement:
IF supplier_id = 10000 THEN
result := 'IBM';
ELSIF supplier_id = 10001 THEN
result := 'Microsoft';
ELSIF supplier_id = 10002 THEN
result := 'Hewlett Packard';
ELSE
result := 'Gateway';
END IF;
The decode function will compare each supplier_id value, one by one.
Regards,
xaheer -
Trouble with using javascript $s function to populate a page item
Hello Oracle APEX Community,
I'm working on a drilldown dashboard page and have been encountering a problem when i try to populate a Text Page Item (hidden or not) using the javascript built in $s function.
The function works great when the data is a number such as dept_id (even if the field type is varchar). However, trying to pass anything which is a text the process fails, except when a value is hard-coded as a parameter for the function. So for example, I have a chart with counts of constituents by state. I would like to populate (filter) a table based on when you click on a bar for a state without having to submit the page. I'm using dynamic actions and a built in javascript function in the SQL for the chart to accomplish this; but again, it works great when I use a varchar field like the FIPS code (i.e. the FIPS for Texas is '48'), but when I try to populate the page item using the state abbreviation 'TX' (again varchar) it fails.
Here's an example of code that works:
SELECT 'javascript:$s("P1_DEPTNO",'||d.deptno||')' LINK,
d.dname LABEL,
sum(e.SAL) sal
FROM emp e, dept d
where e.deptno = d.deptno
group by 'javascript:$s("P1_DEPTNO",'||d.deptno||')', d.dname And here's an example of code that does not work:
SELECT 'javascript:$s("P1_DEPTNO",'||d.loc||')' LINK,
d.dname LABEL,
sum(e.SAL) sal
FROM emp e, dept d
where e.deptno = d.deptno
group by 'javascript:$s("P1_DEPTNO",'||d.loc||')', d.dname However, when I hard code a text value the script works:
SELECT 'javascript:$s("P1_DEPTNO","BOSTON")' LINK,
d.dname LABEL,
sum(e.SAL) sal
FROM emp e, dept d
where e.deptno = d.deptno
group by 'javascript:$s("P1_DEPTNO","BOSTON")', d.dname
ORDER BY d.dname I'm encountering this problem on several versions of APEX: (4.0.2.00.07-local installation) and (4.1.0.00.28-apex.oracle.com)
Does anybody know of this problem and how to solve it? I've looked for settings on the page item itself, and can't figure it out.
I've re-written my sql to utilize the value fields of my tables instead but I have some objects on the page which are really going to depend on the character based data instead.
Thanks,
WayneIn your javascript you are generating, surround your value with double-quotes and it'll should then always work with both numbers and strings (your strings are probably being interpreted as variable names and they don't exist at runtime, hence erroring out).
Example:
SELECT 'javascript:$s("P1_DEPTNO","'||d.loc||'")' LINK,Edited by: gti_matt on Aug 16, 2011 9:50 AM
Maybe you are looking for
-
How can I custom my date in OBIEE.
How can I custom my date in OBIEE.I want to see date in my user friendly format for Date Format MM/DD/YYYY to filter with leading zero(number) eg (01.21.2008) and not M/D/YYYY (1.21.2008) that i am seeing.I would appreciate it if you could give me a
-
Why don't my contacts sort the same way they are sorted in Outlook? We are a business, we need to sort by a company name not by contact name. Please help.
-
Same songs synching each time despite no changes?
Each time I sync my iPhone I see between 11 to 15 songs being synched. However, my songs/playlists haven't changed. To reproduce the bug I do the following: 1. Dock the iPhone, synch it. 2. Select "eject". 3. Repeat step 1. Has anyone else noticed th
-
I am trying to setup a webserver for a PeopleSoft install on HP-UX. I have run into a number of errors and had a case with PeopleSoft. After several days I was basically told that I have to use the same ID to install OAS_Home as I do to setup the web
-
is there anyone to disable itunes so it doesn't open when i plug my iphone in?