Help needed using REPLACE function
Post Author: Domo
CA Forum: Formula
I need to swap out HTML special characters for their corresponding symbols.
The text field in question obviously contains many number codes, e.g. ' for an apostrophe (') and I would like to write a formula which replaces these for it's corresponding text character.
How would I go about this? I know how to use replace for single entries, e.g. Replace(, "'", "'"); but how do I apply this to multiple entries?
I have been using Crystal syntax for other formulas in the report (not sure if Basic and Crystal can be used?).
Post Author: Domo
CA Forum: Formula
Yeah it seems using a combination of Basic and Crystal syntax is possible in CR9.
I simply created the following formula in the end:
dim strInputstrInput = {TEXT.STRING}formula = replace(replace(replace(replace(replace(replace(replace(replace(replace(strinput, "<P>", "")," ", " "), "'", "'"), "</P>", ""), ":", ":"), "<BR>", CHR(13)), "<", "<"), ">", ">"), """, "''")
Looks a little messy but it works!
Similar Messages
-
Need help in using replace function with special characters
I have a column in a table where the data can contain ascii code for special characters such as an apostrophe.
The data looks like this:
CREEK'S LANE
ie for a street named CREEK'S LANE.
I want to replace the ascii representation with the apostrophe and have the returned data show up as: CREEK's LANE
When I try the query below I get prompted for substitution variable value.
I don't seem to be able to find the right syntax to make this query work.
SELECT REPLACE (street_name, ''', '''')
FROM
streets WHERE street_id = 1
Does anybody know how to do this?
Any help would be much appreciated.
Thanks.
Georgegeorge91 wrote:
I have a column in a table where the data can contain ascii code for special characters such as an apostrophe.
The data looks like this:
CREEK'S LANE
ie for a street named CREEK'S LANE.
I want to replace the ascii representation with the apostrophe and have the returned data show up as: CREEK's LANE
When I try the query below I get prompted for substitution variable value.
I don't seem to be able to find the right syntax to make this query work.
SELECT REPLACE (street_name, ''', '''')
FROM
streets WHERE street_id = 1
Does anybody know how to do this?
Any help would be much appreciated.
Thanks.
GeorgeHa! The codes you specified rendered in the HTML, but showed properly when I listed your original posting above. I didn't understand what you meant initially because the 5-character string represenation got rendered as the quote that you said you weren't able to get - a display problem.
You're getting prompted for the substituon variable because of the ampersand; you appear to be doing this in SQL*PLUS. The first thing I would try is to SET DEFINE OFF when using the ampersands to see if that works. If That doesn't work check the docs to delmit the ampersand (I think its a backslash before it but can't remember offhand). Another, harder option might be to use the TRANSLATE function replacing the literal character instead of using REPLACE (though replacing a quote will be a little tricky). If you're on 10g also consider using the advanced quoting
Good luck!
Edited by: riedelme on May 22, 2009 12:45 PM -
Help in using listagg function for more than 8000 char.
Hi Friends,
Need you urgent help in using listagg function for more than 8000 char.
I did the below sample SQL and in "e_orig" and "d_orig" for upto 4000 char it is working fine but I have to use it for more than 8000 char. and it is giving error,
I checked the listagg function is having limitation of 4000 char.
I tried but I am unable to achive this. Can someone provide me a sample example to achive this
select d.dname,d.loc,e.hiredate
,listagg(e.ename,',' ) within group (order by e.deptno) over (partition by e.deptno) as e_orig
,listagg(e.ename, ',') within group (order by e.sal) over (partition by e.deptno) as d_orig
from emp e, dept d
where e.deptno=d.deptno;[ This is my first post, I gone through the guideline for posting a post , and try to go according to that ( I have not pasted here create table and insert as I have used basic table emp, dept for example), please let me know if still I should give this, I will take care from my next post ]
Thanks in advanceInteresting, I didn't know you could do that, but...
BluShadow wrote:
You could write some PL/SQL code that does it all for you, but that would involve loops and would be slow.Well, objects are written in PL/SQL aren't they? And presumably there'll be implicit looping too? So it's not at all obvious that this method will be faster than doing the joining in PL/SQL in memory. The only way to find out is to benchmark them - so I have done that.
I noticed that OP's ref cursor actually only ever retrieves a single record for a bound department number, so I decided the best thing would be to test using a procedure that passes an output string back. I selected all (109) employees and put spaces in to ensure above 4000 characters. I also noticed that as he is using PL/SQL he probably can use a VARCHAR2 type, but just not ListAgg in the query, so I wrote short procedures as follows:
SimpleAggChr - bulk collect and array processing, VARCHAR2 output
ClobAggPrc - the custom aggregation method, CLOB output
SimpleAggClob - bulk collect and array processing, CLOB output
I then wrote a driving script that calls them in the order above and times each call (I like benchmarking so I have my own timing object to make it easy). I then print the lengths for checking, and my object writes the timings to my output table. Running a few times I got varying results, but generally it looks like there isn't a lot to choose between them for performance.
Here's the procedure code:
CREATE OR REPLACE TYPE char100_list_type AS TABLE OF VARCHAR2(100)
CREATE OR REPLACE PROCEDURE SimpleAggChr (x_out OUT VARCHAR2) IS
l_enames char100_list_type;
BEGIN
SELECT first_name || ' ' || last_name
BULK COLLECT INTO l_enames
FROM employees
ORDER BY salary;
FOR i IN 1..l_enames.COUNT LOOP
x_out := x_out || l_enames(i) || ',';
END LOOP;
END SimpleAggChr;
CREATE OR REPLACE PROCEDURE SimpleAggClob (x_out OUT CLOB) IS
l_enames char100_list_type;
BEGIN
SELECT first_name || ' ' || last_name
BULK COLLECT INTO l_enames
FROM employees
ORDER BY salary;
FOR i IN 1..l_enames.COUNT LOOP
x_out := x_out || l_enames(i) || ',';
END LOOP;
END SimpleAggClob;
SHO ERR
PROMPT ClobAggPrc
CREATE OR REPLACE PROCEDURE ClobAggPrc (x_out OUT CLOB) IS
BEGIN
SELECT clobagg(first_name || ' ' || last_name || ',')
INTO x_out
FROM employees
ORDER BY salary;
END ClobAggPrc;
SHO ERRand the driving script:
SET SERVEROUTPUT ON
SET TIMING ON
DECLARE
l_enames_c1 CLOB;
l_enames_c2 CLOB;
l_enames_v VARCHAR2(32767);
l_timer timer_set_type := timer_set_type ('Aggregation');
BEGIN
Utils.g_id := 'Aggregation';
SimpleAggChr (l_enames_v);
l_timer.Increment_Time ('SimpleAggChr');
ClobAggPrc (l_enames_c1);
l_timer.Increment_Time ('ClobAggPrc');
SimpleAggClob (l_enames_c2);
l_timer.Increment_Time ('SimpleAggClob');
DBMS_Output.Put_Line ('SimpleAggChr returned string of length ' || Length (l_enames_v));
DBMS_Output.Put_Line ('ClobAggPrc returned string of length ' || Length (l_enames_c1));
DBMS_Output.Put_Line ('SimpleAggClob returned string of length ' || Length (l_enames_c2));
l_timer.Write_Times;
END;
SET TIMING OFF
SET LINES 150
SET PAGES 1000
COLUMN id FORMAT A30
COLUMN line_text FORMAT A120
SELECT line_text
FROM output_log
WHERE id = 'Aggregation'
ORDER BY line_ind
/and the results:
SimpleAggChr returned string of length 5779
ClobAggPrc returned string of length 5779
SimpleAggClob returned string of length 5779
PL/SQL procedure successfully completed.
Elapsed: 00:00:27.05
LINE_TEXT
Timer Set: Aggregation, constructed at 03 Nov 2011 16:27:07, written at 16:27:35
================================================================================
[Timer timed: Elapsed (per call): 0.02 (0.000016), CPU (per call): 0.01 (0.000010), calls: 1000, '***' denotes corrected
line below]
Timer Elapsed CPU Calls Ela/Call CPU/Call
SimpleAggChr 9.84 0.36 1 9.84400 0.36000
ClobAggPrc 9.37 0.32 1 9.37400 0.32000
SimpleAggClob 8.25 0.22 1 8.25000 0.22000
(Other) 0.00 0.00 1 0.00000 0.00000
Total 27.47 0.90 4 6.86700 0.22500
13 rows selected. -
Bulk Replacements using Replace function in oracle 8i
Hi All,
Iam using oracle 8i version and i need to use Replace function for bulf replacements i mean i need to replace around 250 rows. So please anyone suggest me how to proceed
on this request as iam using oracle 8i version.
Thanks!
SriniWrite one update statement.
The where condition is the filter what rows need to be touched.
The SET condition will do the data change. For example it could use the REPLACE function if that is what it is needed.
One single update statement over 20 rows would mean the task is done in BULK. 20 single updates that each handle one row would mean it is row by row = slow by slow processing. -
Can I use Replace function in a decode??
Hello,
I am trying to use replace function inside a Decode Function,
Here is how I am doing it:
select
SUBSTR (
DECODE (
IH.DRVD_ALT_MAIL_ADDR_PRIM_FLAG,
'N',
REPLACE (
ih.subs_addr_1
|| ' '
|| ih.subs_addr_2
|| ' '
|| ih.subs_city
|| ','
|| ih.subs_state_code
|| ' '
|| ih.subs_zip_code,
'Y',
REPLACE (
IH.PRINT_ALT_MAIL_ADDR_LINE_1
|| ' '
|| IH.PRINT_ALT_MAIL_ADDR_LINE_2
|| ' '
|| IH.PRINT_ALT_MAIL_ADDR_LINE_3
|| ' '
|| IH.PRINT_ALT_MAIL_ADDR_LINE_4
|| ' '
|| IH.PRINT_ALT_MAIL_ADDR_LINE_5
|| ' '
|| IH.PRINT_ALT_MAIL_ADDR_LINE_6,
) 1,
50
address from x
Can anyone please tell me what am I doing wrong here, It always gives me an error about missing a right parenthesis.
Thanks in advance.Hi Jimmy,
Looks like you are missing the first comma in the SUBSTR function
SELECT SUBSTR (
DECODE (
ih.drvd_alt_mail_addr_prim_flag,
'N', REPLACE (
ih.subs_addr_1
|| ' '
|| ih.subs_addr_2
|| ' '
|| ih.subs_city
|| ','
|| ih.subs_state_code
|| ' '
|| ih.subs_zip_code,
'Y', REPLACE (
ih.print_alt_mail_addr_line_1
|| ' '
|| ih.print_alt_mail_addr_line_2
|| ' '
|| ih.print_alt_mail_addr_line_3
|| ' '
|| ih.print_alt_mail_addr_line_4
|| ' '
|| ih.print_alt_mail_addr_line_5
|| ' '
|| ih.print_alt_mail_addr_line_6,
), -- HERE
1,
50
address
FROM xRegards
Peter -
Help needed using adobe exportpdf
The first time I used adobe export pdf it worked well. However the next time and every other time I try to convert a pdf doc to word docx I get the error message at the end of the uploading session. "pdf doc failed to export to m,icrosoft word. There was an unexpected problem.
Anyone overcome this problem?Hi Stacy
Thanks for that info. I was aware of the 100MB limit but
your response made me think again and go back to the problem and this is
what I found. The first pdf document I uploaded into Adobe export pdf was 43
MB and it went through fine. when I looked at the conversion to Word docx I
found it had been transformed into 83MB.
So the conversion (which was a children's book with lots of images in it)
resulted in an increase of MBs by a factor of 1.7.
The second pdf document I uploaded was 64MB and this failed. If I apply the
1.7 factor then the Word docx I wanted was going to be 109MB and therefore
over the 100MB limit.
I didn't know that converting pdf to word would increase the MB like that.
Why, I don't know so thanks for your help I've learnt something new.
Cheers
Garth
In a message dated 07/10/2013 04:42:36 GMT Daylight Time,
[email protected] writes:
Re: Help needed using adobe exportpdf
created by StacySison (http://forums.adobe.com/people/StacySison) in
Adobe ExportPDF - View the full discussion
(http://forums.adobe.com/message/5740689#5740689) -
Help needed Converting MSSQL function to PL/SQL
Hello,
I have the following MSSQL code which I need to migrate to Oracle 10g. The problem I am having is the MSSQL code creates a temp table as the return type and I am unsure how to get the same functionality in PL/SQL.
MSSQL CODE_
CREATE FUNCTION [dbo].[QueryCurrentWhy]
@ColumnID INT,
@GroupID INT,
@Parents VARCHAR(8000)
RETURNS @R TABLE(ID1 int IDENTITY (1, 1) NOT NULL, ID2 int, ColID int, [Name] VARCHAR(255), Tlevel int, ParentID int, Processed BIT)
AS
BEGIN
RETURN
END
The code I have currently written in PL/SQL is below. I firstly create a global temp table and then a sequence and trigger for it. I then create the Function in the hope I can specify the temp table as the return type. Problem is I get the error "PLS-00201: identifier 'TEMPR' must be declared". Im guessing this is because the temp table is declared outside the function declaration?
ORACLE CODE_
CREATE GLOBAL TEMPORARY TABLE tempR
ID1 INT NOT NULL,
ID2 INT,
ColID INT,
Name VARCHAR2(255),
Tlevel INT,
ParentID INT,
Processed CHAR(1)
CREATE SEQUENCE gCounter
START WITH 1
INCREMENT BY 1
CREATE OR REPLACE TRIGGER gTrigger
BEFORE INSERT ON tempR
FOR EACH ROW
DECLARE TEMP_NO INT;
BEGIN
SELECT gCounter.NEXTVAL INTO TEMP_NO FROM DUAL;
:NEW.ID1 := TEMP_NO;
END;
CREATE OR REPLACE FUNCTION TSORADB.QueryCurrentWhy
aColumnID INT,
aGroupID INT,
aParents VARCHAR2(8000)
RETURN tempR
AS
BEGIN
RETURN;
EXCEPTION when NO_DATA_FOUND then null;
END;
Basically is it possible for me to declare the temp table in the return statement, if not then what is the best way to go about this?
Thanks in advance
Toby
Edited by: redeye on Jul 27, 2009 3:26 PMUnfortunately I didnt write the original function or stored procedure and the person who did is no longer with the company, so apologies for any confusion with what I am saying.
Maybe it'll be more helpful if i paste the contents of the function?
CREATE OR REPLACE FUNCTION TSORADB.QueryCurrentWhy
aColumnID INT,
aGroupID INT,
aParents VARCHAR2(8000)
RETURN tempR
AS
--BEGIN
aPKColTypeID INT;
aFKDColTypeID INT;
aFKDSColTypeID INT;
aFKIColTypeID INT;
aColType VARCHAR2(30);
aTableID INT;
aName VARCHAR2(255);
aNameWhyMost VARCHAR2(255);
aNameWhyMost2 VARCHAR2(255);
aLongNameStr VARCHAR2(1000);
aConnectStr VARCHAR2(1000);
aColID INT;
aColIDWhyMost INT;
aColIDWhyMost2 INT;
aColIDWhyMostLast INT;
aCount INT;
aID1 INT;
aID2 INT;
aPreID2 INT;
aMaxID2 INT;
aCurrentID2 INT;
aTLevel INT;
aTLevel2 INT;
aTlevelLast INT;
aNewLevel INT;
aMaxTLevel INT;
aMaxTLevel2 INT;
aParentID INT;
aParentID2 INT;
aNewParentID INT;
aProcessed number (1);
--aCurVar1 CURSOR;
aParent INT; aStrEntityIDSet varchar(2000); aStrPipeSepValsInput varchar(2000); aEndPointInput int; aSeperatorIndex int;
aNumTempDoc INTEGER := 0;
--aColumnID INT DEFAULT(0);
--aGroupID INT DEFAULT(0);
--aParents VARCHAR(8000) DEFAULT('');
BEGIN
SELECT ColumnTypeID INTO aPKColTypeID FROM TSORADB.HKColumnType WHERE ColumnTypeName = 'PK';
SELECT ColumnTypeID INTO aFKDColTypeID FROM TSORADB.HKColumnType WHERE ColumnTypeName = 'FKD';
SELECT ColumnTypeID INTO aFKDSColTypeID FROM TSORADB.HKColumnType WHERE ColumnTypeName = 'FKDS';
SELECT ColumnTypeID INTO aFKIColTypeID FROM TSORADB.HKColumnType WHERE ColumnTypeName = 'FKI';
IF (aGroupID is null)
THEN
aGroupID := -1;
END IF;
--Tokenize the parent array and get back a set of values.
IF(aParents is not null)
THEN
BEGIN
aStrEntityIDSet := aParents;
aStrPipeSepValsInput := '|' + ltrim(rtrim(aStrEntityIDSet)) + '|';
--print aStrPipeSepValsInput
aEndPointInput := INSTR(aStrPipeSepValsInput, '|');
aStrPipeSepValsInput := INSTR (aStrPipeSepValsInput, LENGTH (aStrPipeSepValsInput) - aEndPointInput); -- take out the '|' pattern
WHILE (LENGTH (aStrPipeSepValsInput) > 0)
LOOP
BEGIN
aEndPointInput := INSTR(aStrPipeSepValsInput, '|'); -- get the next '|' pattern
aParent := SUBSTR(aStrPipeSepValsInput, 1, aEndPointInput - 1);
--PRINT 'aParent is ' + CONVERT (NVARCHAR, aParent)
aStrPipeSepValsInput := INSTR (aStrPipeSepValsInput, LENGTH (aStrPipeSepValsInput) - aEndPointInput);
INSERT INTO TmpParent (ColID) VALUES (aParent);
END;
END LOOP;
END;
END IF;
SELECT hkc.TableID, hkc.Name, hkct.ColumnTypeName
INTO aTableID, aName, aColType
FROM TSORADB.HKColumns hkc
INNER JOIN TSORADB.HKColumnType hkct on hkc.ColTypeID = hkct.ColumnTypeID
WHERE hkc.ColumnID = aColumnID;
IF aColType in ('PK','PKD')
THEN
-- Generate Unique Path Table Start
SELECT
CASE WHEN FKIs3.Name is null
THEN PKs3.Name
ELSE FKIs3.Name
END Name
INTO aName
FROM TSORADB.HKColumns PKs3
INNER JOIN
SELECT hkc3.TableID FROM TSORADB.HKColumns hkc3
WHERE hkc3.ColumnID = aColumnID
) HKC3 ON PKs3.TableID = HKC3.TableID
LEFT OUTER JOIN
SELECT TableID, Name
FROM TSORADB.HKColumns
WHERE ColTypeID = aFKIColTypeID
) FKIs3 ON PKs3.TableID = FKIs3.TableID
WHERE PKs3.ColTypeID = aPKColTypeID AND ((aGroupID=-1 AND PKs3.GroupID IS NULL) OR PKs3.GroupID=aGroupID);
END IF;
-- Insert query column itself
aTlevel := 0;
aParentID := 0;
aID2 := 1;
IF (aColType = 'ATT')
THEN
BEGIN
INSERT INTO tempR(ID2, ColID, Name, Tlevel, ParentID, Processed)
SELECT distinct aID2, TopHKCs.ColumnID as ColID, aName as Name,aTlevel as Tlevel, aParentID as ParentID, 1 as Processed
FROM TSORADB.HKColumns TopHKCs
WHERE TopHKCs.ColumnID = aColumnID;
aID2 := aID2 + 1;
aTlevel := 1;
aParentID := aColumnID;
-- Get the non-compound name for the parent
SELECT
CASE WHEN FKIs3.Name is null
THEN PKs3.Name
ELSE FKIs3.Name
END Name
INTO aName
FROM TSORADB.HKColumns PKs3
INNER JOIN
SELECT hkc3.TableID FROM TSORADB.HKColumns hkc3
WHERE hkc3.ColumnID = (SELECT ColumnID FROM TSORADB.HKColumns WHERE TableID = aTableID AND ColTypeID = aPKColTypeID)
) HKC3 ON PKs3.TableID = HKC3.TableID
LEFT OUTER JOIN
SELECT TableID, Name
FROM TSORADB.HKColumns
WHERE ColTypeID = aFKIColTypeID
) FKIs3 ON PKs3.TableID = FKIs3.TableID
WHERE PKs3.ColTypeID = aPKColTypeID AND ((aGroupID=-1 AND PKs3.GroupID IS NULL) OR PKs3.GroupID=aGroupID);
INSERT INTO tempR(ID2, ColID, Name, Tlevel, ParentID, Processed)
SELECT aID2, ColumnID, aName, aTlevel, aParentID, 0
FROM TSORADB.HKColumns
WHERE TableID = aTableID
AND ColTypeID = aPKColTypeID;
aID2 := aID2 + 1;
END;
ELSE
BEGIN
INSERT INTO TmpR1(ColID, Name, Tlevel, ParentID, Processed)
SELECT nonCompoundHks.ColumnID as ColID, aName as Name,aTlevel as Tlevel, aParentID as ParentID, 0 as Processed
FROM TSORADB.HKColumns nonCompoundHks
WHERE nonCompoundHks.Name = aName --lower(nonCompoundHks.Name) = lower(aName)
AND ((aGroupID=-1 AND nonCompoundHks.GroupID IS NULL) OR nonCompoundHks.GroupID=aGroupID)
AND nonCompoundHks.ColTypeID = aPKColTypeID
AND EXISTS
select ColumnID
From TSORADB.HKColumns hkc4
WHERE hkc4.TableID = nonCompoundHks.TableID
AND (hkc4.ColTypeID = aFKDColTypeID OR hkc4.ColTypeID = aFKDSColTypeID)
AND NOT EXISTS
select ColumnID
From TSORADB.HKColumns hkc5
WHERE hkc5.TableID = nonCompoundHks.TableID
AND hkc5.ColTypeID = aFKIColTypeID
AND ((aGroupID=-1 AND hkc5.GroupID IS NULL) OR hkc5.GroupID=aGroupID)
INSERT INTO TmpR1(ColID, Name, Tlevel, ParentID, Processed)
SELECT compoundPk.ColumnID as ColID, aName as Name,aTlevel as Tlevel, aParentID as ParentID, 0 as Processed
FROM TSORADB.HKColumns compoundPk
INNER JOIN TSORADB.HKColumns compoundHkc on compoundHkc.TableID = compoundPk.TableID AND compoundHkc.ColTypeID = aFKIColTypeID
INNER JOIN (
SELECT hkc.ColumnID
FROM TSORADB.HKColumns hkc
WHERE hkc.ColTypeID = aPKColTypeID
AND hkc.Name = aName --lower(hkc.Name) = lower(aName)
AND ((aGroupID=-1 AND hkc.GroupID IS NULL) OR hkc.GroupID=aGroupID)
AND NOT EXISTS
select ColumnID
From TSORADB.HKColumns hkc2
WHERE hkc2.TableID = hkc.TableID
AND (hkc2.ColTypeID = aFKDColTypeID OR hkc2.ColTypeID = aFKDSColTypeID)
AND ((aGroupID=-1 AND hkc2.GroupID IS NULL) OR hkc2.GroupID=aGroupID)
) Indys ON Indys.ColumnID = compoundHkc.ForeignKey
WHERE compoundPk.ColTypeID = aPKColTypeID;
INSERT INTO tempR(ID2, ColID, Name, Tlevel, ParentID, Processed)
SELECT ID2, ColID, Name, Tlevel, ParentID, Processed FROM TmpR1;
FETCH FROM aCurVar1 INTO aColID, aName, aTlevel, aParentID, aProcessed
WHILE aafetch_status = 0
BEGIN
IF(aParents is null or EXISTS (SElECT ColID FROM aTmpParent WHERE ColID = aColID) )
BEGIN
INSERT INTO tempR(ID2, ColID, [Name], Tlevel, ParentID, Processed) VALUES(aID2, aColID, aName, aTlevel, aParentID, aProcessed)
SET aID2 = aID2 + 1
END
FETCH NEXT FROM aCurVar1 INTO aColID, aName, aTlevel, aParentID, aProcessed
END
CLOSE aCurVar1 */
END;
END IF;
begin
SELECT COUNT(*) INTO aNumTempDoc FROM tempR WHERE Processed = 0 and Tlevel < 1;
end;
WHILE aNumTempDoc > 0
LOOP
BEGIN
-- Get current row
SELECT ID1, ID2, ColID, Name, Tlevel, ParentID
INTO aID1, aID2, aColID, aName, aTlevel, aParentID
FROM tempR
WHERE Processed = 0 AND ROWNUM = 1
ORDER BY ID1;
UPDATE tempR SET processed = 1 WHERE ID1 = aID1;
aPreID2 := aID2;
-- Get why parents
declare CURSOR aCurVar1 IS --SELECT * FROM TSORADB.HKColumns;
SELECT distinct FKDPKs.ColumnID as ColID,
CASE WHEN FKDFKI.NAME is null
THEN FKDPKs.Name
ELSE FKDFKI.Name
END Name,
(aTlevel+1) as Tlevel,
PREHKCs.ColID AS ParentID,
0 as Processed
FROM TSORADB.HKColumns FKDPKs
INNER JOIN
TSORADB.HKColumns FKDFKs ON FKDPKs.ColumnID = FKDFKs.ForeignKey
INNER JOIN
TSORADB.HKColumns FKDFKs2 ON FKDFKs2.TableID = FKDFKs.TableID
INNER JOIN
tempR PREHKCs ON PREHKCs.ColID=aColID AND PREHKCs.ColID = FKDFKs2.ColumnID AND PREHKCs.Tlevel=aTlevel
LEFT OUTER JOIN
SELECT TableID, Name, GroupID
FROM TSORADB.HKColumns
WHERE ColTypeID = aFKIColTypeID
) FKDFKI ON FKDFKI.TableID = FKDPKs.TableID
INNER JOIN TSORADB.HKColumnType ON FKDPKs.ColTypeID=HKcolumnType.ColumnTypeID
WHERE FKDPKs.ColTypeID=aPKColTypeID AND FKDPKs.ColumnID <> aColumnID
AND FKDFKs.ColTypeID=aFKDColTypeID
AND ((aGroupID=-1 AND FKDPKs.GroupID IS NULL) OR FKDPKs.GroupID=aGroupID);
BEGIN
OPEN aCurVar1;
aCount := 1;
SELECT MAX(ID2) INTO aID2 FROM tempR;
LOOP
FETCH aCurVar1 INTO aColID, aName, aTlevel, aParentID, aProcessed;
Exit when aCurVar1%NOTFOUND; -- Exit the loop when no more rows are found.
--WHILE aafetch_status = 0
BEGIN
IF (aCount = 1) -- The first Why Parent
THEN
INSERT INTO tempR(ID2, ColID, Name, Tlevel, ParentID, Processed) VALUES(aPreID2, aColID, aName, aTlevel, aParentID, 0);
ELSE -- The multiple Why Parents
BEGIN
aID2 := aID2 + 1;
-- Copy the previous parent with increased ID2
INSERT INTO tempR(ID2, ColID, Name, Tlevel, ParentID, Processed) SELECT aID2 as ID2, ColID, Name, Tlevel, ParentID, 1 AS Processed FROM tempR WHERE ID1 <= aID1 AND ID2 = aPreID2;
-- Insert the new why parent
INSERT INTO tempR(ID2, ColID, Name, Tlevel, ParentID, Processed) VALUES(aID2, aColID, aName, aTlevel, aParentID, 0);
END;
END IF;
aCount := aCount + 1;
--FETCH NEXT FROM aCurVar1 INTO aColID, aName, aTlevel, aParentID, aProcessed;
END;
END LOOP;
CLOSE aCurVar1;
END;
SELECT COUNT(*) INTO aNumTempDoc FROM tempR WHERE Processed = 0 and Tlevel < 1;
END;
END LOOP;
-- Generate Unique Path Table End
RETURN;
EXCEPTION when NO_DATA_FOUND then null;
END;
The table which is returned to the SProc is used in the following way, (MSSQL code, as am yet to migrate). Basically using some of the returned column values along with DB values to populate a second temp table
INSERT INTO #TmpR1 SELECT * FROM QueryCurrentWhy(@ColumnID, @GroupID, @Parents)
SET @Tlevel = 1
INSERT INTO @R
SELECT HKColumns.Columnid as ColID, HKColumns.Tableid as TblID, R1.Name as [Name], HKColumns.NounID AS KeyCompA, R1.ParentID AS KeyCompB, HKColumns.ColTypeID as ColTypeID, ColumnTypeName as ColType, 0 as HasWhats,
CASE WHEN R2.ColID is null
THEN 0
ELSE 1
END HasWhyParent,
0 as IsSelected
FROM HKColumns
INNER JOIN #TmpR1 AS R1
ON HKColumns.ColumnID = R1.ColID AND R1.Tlevel=@Tlevel
INNER JOIN HKColumnType
ON HKColumns.ColTypeID=HKcolumnType.ColumnTypeID AND HKColumns.ColTypeID=@PKColTypeID
LEFT JOIN #TmpR1 AS R2
ON R2.ID2 = R1.ID2 AND R2.Tlevel=@Tlevel+1 AND R2.ParentID=R1.ColID -
Help needed with printf function!!!!
public class Try
{public static void main (String[] args)
{int a;
String b;
a = 000002;
b = "JSmith";
System.out.printf(b + "%d", a);
}}I need a help with the printf function.
The result of this small excercise that I just made is:
Jsmith2
How do I make it so that the zeros is also displayed? (using the printf)
I want it to look like this: Jsmith000002
Thank you in advanceTrySystem.out.printf(b + "%06d", a);(I don't have a compiler here so I haven't tested this).
The "6" is the width - the minimum number of characters that will be
printed and the "0" (it's a zero) is a flag indicating that the output should
be padded with zeros.
You should also note that the value of a is two. It doesn't matter whether
you say a=2; or a=0002; - a is still just plain two. -
Hi,
i have a function like below. basically what it does is, check whether first 2 places of a column_name is *'N_'*. if yes then i am replacing column_name which has *'N_' to ''*
CASE WHEN SUBSTR(column_name,1,2) = 'N_' THEN
*':NEW.'||REPLACE(column_name,'N_','')*
i designed this based on the requirement. now i am facing a small issue. i have a column name 'RGN_ID'. so the above function replaces the RGN_ID as RGID as N_ comes in the middle of the column_name the above function accidentally replaces this as well. wherein i need to replace the first 2 position of column_name which starts like 'N_'
can you please suggest any solution for this?
Edited by: user13178284 on Jun 29, 2010 6:11 AMThanks!. But i am afraid if this would help.
there may be many column names having 'N_' at whatever position. for eg., TRAN_ID. here N_ comes at 4th and 5th position.
i understand i need to place some kind of check above this function.so that if 'N_' comes anywhere in between the column_name i shouldnt replace it instead i should just replace column_name starting wtih 'N_'.
any idea about this? -
How to use replace function to replace word
I am trying to write a replace function in which I replace CA with California in an address string.
I am trying to avoid using regular expression and just use other functions like replace, instr, trim etc.
But what my main confusion is how do i take care of three cases in which.
CA can be present with spaces before and after it like.
- Redwood City, CA 96403
CA can be present with spaces only before it and after it the string ends.
- Redwood City, CA
and I do not want to replace any other CA in the string that is part of other word
- Blaca Street CA
( for example do not replace ca in Blaca)
or
- Cardinal Dr CA
ThanksHi,
user6287828 wrote:
... (only four of these abbreviations need to be replaced)In that case, nesting the functions one inside another won't be too bad. But watch out: this is exactly the kind of requirement that changes over time. You might only need 4 states now, nut next year they might expand the application so that you need all 50 states (plus Puerto Rico, and DC, and ....). In that case, something like MODEL, or a user-defined PL/SQL function, would be better.
As these are abbreviations these will always be stand alone words and never part of words. And these abbreviation can be at the beginning or end or in between the string.
And any abbreviation can be present in one column.
More than one abbreviation can be present in one column
None of the abbreviations can be present in this column.
For example
column
3251 BLACA ROAD CA 94305
74 CALDWIN STREET CA
67 DIGITAL DRIVE NM
NM UNIVERSITY AVENUE 890
7645 ROCHESTER NY PARK STREET
834 GRAND AVENUE ATLANTAPost CREATE TABLE and INSERT statements for the sample data.
Include all special cases, e.g. more that one abbreviation in the same column. -
Can we use replace function in bursting control file?
Hi All,
Greetings!!!!!!!!!!
Have a doubt can we use sql functions like replace,nvl,decode.. in xml bursting control file.
Please let me know if there is a option.
awaiting reply...
Thanks
RajeshIn Expression operator or in Filter, etc. you can type function name by hand.
Oleg -
Help needed in decode function
I am trying to use decode function shown below
select decode(deptid,(select deistinct dept_id from dept),'found') into id from student ;
it shows error ORA 01427:single-row subquery returns more than one row.
could you people help me resovle the issue.
Thanks.Funny thing how many mistakes can be in one little line. I try to list what is wrong here. maybe it helps you to understand what is going on.
select decode(deptid,(select deistinct dept_id from dept),'found') into id from student ;1) "deistinct" => wrong spelling "distinct"
2) Uniqueness => the typical DEPT table has DEPT_ID as a primary key. So DISTINCT would do nothing here. "select distinct dept_id from dept" is the same as "select dept_id from dept".
3) decode with a multi-row subquery => the decode function only accepts single values. e.g: ,"decode(deptid,(select max(dept_id) from dept),..." => THis is not really useful, just an example.
4) decode without handling other values => it is better to say what should happen, when the values does not match. decode(deptid,:x,'found','notfound')
5) select .. into ... from. => INTO is only used in a PL/SQL . So I assume this statement is part of a larger PL/SQL block. In that case "into id " is a problem. The select would return many values, but your ID variable could probably hold only one value.
6) Identification of values => For all students that could be returned, you only would know 'found'. At least select the ID for the student too, else you wouldn't know which student was found. select id, 'found' ... from student.
7) Don't select everthing and check for each row later. Select only relevent rows. That means do your checks in the WHERE clause of a select statement not in the SELECT clause. Example: "select id from student where dept_id in (select dept_id from dept);" Possible in this case is also a join "select student.id from student, dept where student.dept_id=dept.dept_id"
8) referential integrity. Why do have to do this check anyway? On table student there should be a FK constraint, so that only values can be inserted where the DEPT_ID is correct. Then you select would be "select id from student;". -
Help needed for Instr function
Hi,
I using instr function to find the delimiter '|' .the function does retrives value , if the character contains
special charcater. (i.e)INSTR('Carán|','|',1,6) returns
only zero as the value , which is not correct. kindly suggest me some solution for the above problem.
Thanks in advance.By INSTR('Carán|','|',1,6) , you are trying to find location of 6th occurance of special character '|' . Since there is no such occurence, it is returning 0.
sql> select instr('Caran|','|') from dual;
INSTR('CARAN|','|')
6
Thanks -
Help on Using Analytical Functions
I am hetting error when i use Analytical functions in Expressions
AVG( INGRP1.Test1 ) OVER (PARTITION BY INGRP1.Test2)
Error is as follows
Line 1, Col 28:
PLS-00103: Encountered the symbol "OVER" when expecting one of the following:
* & = - + ; < / > at in is mod remainder not rem
<an exponent (**)> <> or != or ~= >= <= <> and or like LIKE2_
LIKE4_ LIKEC_ between || multiset member SUBMULTISET_Hi,
the syntax of this part of the sql statement is okay. Please post the complete statement to identify the error.
Sometimes oracle identifies the wrong point for the error.
Regards,
Detlef -
Need help in using sleep function in pl/sql
Hi,
need help:
I have a condition where i want to validate total_pass=total_fail and
I want to use the sleep function in a pl/sql where i want to wait for 2 minutes ie.checking
whether total_pass=total_fail based upon class_id .
I have the data in the table as:
CLASS_ID TOT_PASS TOT_FAIL
1 10 10
2 5 4
3 6 6
4 7 5
Any help will be needful for meI'm not quite sure what you are lookg for here, but whatever it is, your code as posted won't do it. You will never break out of the WHILE r_Class.Tot_Pass = r_Class.Tot_Fail loop, since these values will never change because you never get the next record form the cursor.
From your original data, it looks like your cursor will return multiple rows which implies to me that you want to fetch the first row from the cursor, check if tot_pass = tot_fail, if they are equal, sleep for two minutes then get the next row. This does not make sense to me. Once the select in the cursor is executed, the data it returns will not change due to Oracle's read consistency model, so there seems to me no point in the sleep.
The other alternative I can see is that you want to check all the returned rows, and if tot_pass = tot_fail for one of the rows (or possibly for all of the rows), then you want to sleep and try again.
If you can explain in words what it is you are trying to accomplish, someone will be able to point you to a solution.
John
Maybe you are looking for
-
ITunes PLAY/PAUSE Will Not Work After 10.5.4 Install
I have just installed Leopard 10.5.4 on my iMac G5 and iTunes player will not work. When I select a song, it will show in the player window, but, PLAY/PAUSE button will not function. I have checked iTunes Prefs and see nothing there that is not corre
-
Recording Flash with iShowU and importing into FCP?
I need to create some motion graphics for a video, though I am not good enough yet with Motion and would like to use Flash. I am wondering if there are any issues with creating my project in Flash, playing it back and recording it with iShowU and jus
-
What is the status of my order from CDW?
I ordered premiere pro cs6 from CDW and I have an email from their sales department that shows, under 'tracking details', tracking number: n/a and shipping method: drop ship. Drop shipping by definition means CDW has passed the shipping responsibili
-
Dear, I have installed Java Studio Creator Update 2 on my PC and I have prepared a prototype. now I have noticed that there are some components "xmlns:ui = " http://www.sun.com/web/ui ". My question is: Can these components be used to Run Time to cos
-
Attach ethernet port to SSH tunnel
Anyone know if I can setup one ethernet port on a Mac Pro to provide DHCP/NAT and direct all traffic on that port to an SSH tunnel? What I want to be able to do is create an SSH tunnel to a proxy server and then have any device I plug into one of my