How to use a single quote string in where condition
Hi,
I have one problem in building a query.
SELECT agx_drug_indication.record_id, agx_drug_indication.fk_ad_rec_id,
agx_drug_indication.drugindicationmeddraver, agx_drug.record_id,
agx_drug.fk_apat_rec_id,
REPLACE (agx_drug.medicinalproduct, '''', '''') AS "MEDICINALPRODUCT",
pack_imp_objects.fn_get_arisg_code
(147,
agx_drug_indication.drugindicationmeddraver
) AS "DRUGINDICATIONMEDDRAVER",
agx_drug.drugindication,
NVL (agx_drug.drugcharacterization, 1) AS "DRUGCHARACTERIZATION",
agx_safety_report.record_id, agx_safety_report.case_identifier_no,
agx_safety_report.fk_apat_rec_id,
pack_imp_objects.fn_meddra_llt_matching
(agx_drug_indication.drugindication,
agx_drug_indication.drugindication,
agx_drug_indication.drugindicationmeddraver,
1
) AS "LLT_CODE",
pack_imp_objects.fn_meddra_soccode_matching
(agx_drug_indication.drugindication,
agx_drug_indication.drugindicationmeddraver
) AS "PRIMARY_SOC_CODE",
pack_imp_objects.fn_meddra_soccode_matching
(agx_drug_indication.drugindication,
agx_drug_indication.drugindicationmeddraver
) AS "CASE_SOC_CODE",
pack_imp_objects.fn_meddra_pt_matching
(agx_drug_indication.drugindication,
agx_drug_indication.drugindication,
agx_drug_indication.drugindicationmeddraver
) AS "PT_CODE",
pack_imp_objects.fn_get_aer_id (11) AS "AER_ID"
FROM agx_drug_indication,
agx_drug,
agx_safety_report
WHERE agx_drug_indication.fk_ad_rec_id = agx_drug.record_id
AND agx_drug.fk_apat_rec_id = agx_safety_report.fk_apat_rec_id
AND agx_safety_report.case_identifier_no IS NOT NULL
AND agx_drug_indication.drugindication IS NOT NULL
AND agx_drug.medicinalproduct =
REPLACE ('*-qVAGX_DRUG.MEDICINALPRODUCT*', '''', '''')
In the above query last line '-qVAGX_DRUG.MEDICINALPRODUCT' is a dynamic variable which may or may not contain the single quotes.
Ex: ABC's or just ABC.
The query has to support both single quote and without quote in it.
I wanted everything to be done in the sinlq query on not a PL/SQL Block.
Please help me ASAP
kumar0828 wrote:
<font color="#FF0000"> ... </font>
REPLACE (agx_drug.medicinalproduct, '''', '''') AS "MEDICINALPRODUCT",
<font color="#FF0000"> ... </font> <pre>
REPLACE (agx_drug.medicinalproduct, '<font style="background-color: #E7FA6B">''</font>', '<font style="background-color: #E7FA6B">''</font>')
</pre>
With the above statement you are replacing single quote with another single quote
(which is nonsense).
<font color="#FF0000"> ... </font>
AND agx_drug.medicinalproduct = REPLACE ('*-qVAGX_DRUG.MEDICINALPRODUCT*', '''', '''')
In the above query last line '-qVAGX_DRUG.MEDICINALPRODUCT' is a dynamic variable which may or may not contain the single quotes.This is not a dynamic variable but a string value:
<pre>
AND agx_drug.medicinalproduct =
REPLACE (<font style="background-color: #FF3D55">'*</font>-qVAGX_DRUG.MEDICINALPRODUCT<font style="background-color: #FF3D55">*'</font>, '<font style="background-color: #E7FA6B">''</font>', '<font style="background-color: #E7FA6B">''</font>')
</pre>
*-qVAGX_DRUG.MEDICINALPRODUCT* <pre>
AND agx_drug.medicinalproduct =
REPLACE (<font style="background-color: #FF3D55">q'*</font>-qVAGX_DRUG.MEDICINALPRODUCT<font style="background-color: #FF3D55">*'</font>, '<font style="background-color: #E7FA6B">''</font>', '<font style="background-color: #E7FA6B">''</font>')
</pre>
-qVAGX_DRUG.MEDICINALPRODUCT q'[a]' => a
q'[a']' => a'
q'[a'']' => a''
q'*a*' => a
q'*a'*' => a'
q'*a''*' => a''
A variable also cannot contain a dot (.):
<pre>VAGX_DRUG<font style="background-color: #FF3D55">.</font>MEDICINALPRODUCT</pre>
Ex: ABC's or just ABC.
The query has to support both single quote and without quote in it.
I wanted everything to be done in the sinlq query on not a PL/SQL Block.
Please help me ASAPTry this:
<pre>
AND agx_drug.medicinalproduct = MY_VARIABLE
</pre>
Similar Messages
-
Single quote in dynamic where condition
BAPI_STUDENT_IDENTIFIC_ADD has a field called IDENTIFICATIONNUMBER. This field is later used in a dynamic where condition and causes a short dump when it contains a single quote. I will change the program that calls the BAPI to check for single quotes, but is there anything else I need to check for to ensure a correct where condition?
Thanks,
DanHi Dan,
The best way to ensure correctness of syntax of a dynamic where condition is:
Run the program in debugging mode, Get the Query that is generated dynamically and write it to some other ABAP program and perform syntax check.
This will help you to remove all the syntax errors.
Regards,
Darshil -
How to pass a single quote in a URL using Javascript
Can someone tell me how to pass a single quote in a URL using Javascript. I have created a Javascript funciton in which I pass several column values from an APEX report.
The URL for the report link I am using is "JAVASCRIPT:passBack('#EMP_ID#','#Name#','#e-mail#')"
The problem occurs with the Name and e-mail columns contain a single quote (i.e. James O'Brien)Thank you Saad, that worked.
Since I built the report using type 'SQL Query (PL/SQL function fody returning SQL query)' I had to add some additional quotes to get it to work.
i.e.
replace(EMP_EMAIL_NAME,'''''''',''\'''''')
or
replace(EMP_EMAIL_NAME,chr(39),''\'''''')
Thanks for the help,
Jason -
How to escape a single quotes from a string of dynamic sql clause?
if a single quotes exist in a dynamic sql clause for a string,
like
v_string :='select tname from tab where tabtype='table'',
there tabtype='table' will conflict with the single quote ahead.
could somebody tell me how to escape this single quotes?
thanks for your tips,
frederickfredrick,
To represent one single quotation mark within a literal, enter two single quotation marks. For example :
v_string :='select tname from tab where tabtype=''table'''
Regards,
Srinivas -
How to Delimit the Single quotes ( ' )
Hi friends.
how to delimite the single quotes ( ' ) or
how to move the single quotes in fields.
any body pls reply
thanks
pauldharmaHi,
Use for single quotes and that will result in a single quote.
i.e.
lv_quote = ''''.
Darren -
How to use type cast change string to number(dbl)?can it work?
how to use type cast change string to number(dbl)?can it work?
Do you want to Type Cast (function in the Advanced >> Data Manipulation palette) or Convert (functions in the String >> String/Number Conversion palette)?
2 simple examples:
"1" cast as I8 = 49 or 31 hex.
"1" converted to decimal = 1.
"20" cast as I16 = 12848 or 3230 hex.
"20" converted to decimal = 20.
Note that type casting a string to an integer results in a byte by byte conversion to the ASCII values.
32 hex is an ASCII "2" and 30 hex is an ASCII "0" so "20" cast as I16 becomes 3230 hex.
When type casting a string to a double, the string must conform the the IEEE 32 bit floating point representation, which is typically not easy to enter from the keyboard.
See tha attached LabView 6.1 example.
Attachments:
TypeCastAndConvert.vi 34 KB -
How to select data from a table using a date field in the where condition?
How to select data from a table using a date field in the where condition?
For eg:
data itab like equk occurs 0 with header line.
select * from equk into table itab where werks = 'C001'
and bdatu = '31129999'.
thanks.Hi Ramesh,
Specify the date format as YYYYMMDD in where condition.
Dates are internally stored in SAP as YYYYMMDD only.
Change your date format in WHERE condition as follows.
data itab like equk occurs 0 with header line.
select * from equk into table itab where werks = 'C001'
and bdatu = <b>'99991231'.</b>
I doubt check your data base table EQUK on this date for the existince of data.
Otherwise, just change the conidition on BDATU like below to see all entries prior to this date.
data itab like equk occurs 0 with header line.
select * from equk into table itab where werks = 'C001'
and <b> bdatu <= '99991231'.</b>
Thanks,
Vinay
Thanks,
Vinay -
(JDBC)how to diffrenciate a single quote in string ? eg : 'Micheal's Store'
Hi all,
I wanted to difrrenciate a single quote in string. Is there any way to do so ?
I'm using Java.
ThanksIf you're using Java, I assume you're using straight JDBC rather than one of the many APIs layered on top of JDBC.
You should be using PreparedStatement objects with bind variables and you should be passing in string values by making appropriate setString() calls. When you're using bind variables, rather than building up SQL strings in your app, you won't have any issues with escaping quotes. You also won't have to worry about defending against SQL injection attacks and your application will perform much better since you won't be re-parsing the same statement over and over and won't be flooding your library cache with thousands of mostly identical statements.
Justin
I intended to say that you won't be flooding your shared pool with thousands of mostly identical statements, not the library cache.
Message was edited by:
Justin Cave -
How do I pass single quotes into a string variable?
Thanks for any help?
Example
Select xdat, yday
from foo
where
xdat = to_char(sysdate, 'mm/dd/yyyy')
How do I pass the single quoted stuff above into a string variable?Thank you but that is not the same thing. I am building a dynamic sql statement and need to pass the quoted material into a statement that is quoted Is that not what my example above shows?
My example above has a quoted string inside a string. I think this is exactly what you were asking for. -
SSRS Report Returning Double Quote string from a Single Quote String
Hi, I'm getting weird thing in resultset from SSRS report when executed. When I pass parameter to a report, which passes String that has single quote value to a split function , it returns rows with double quote.
For example following string:
'N gage, Wash 'n Curl,Murray's, Don't-B-Bald
Returns:
''N gage, Wash ''n Curl,Murray''s, Don''t-B-Bald
through SSRS report.
Here is the split function Im using in a report.
CREATE Function [dbo].[fnSplit] (
@List varchar(8000),
@Delimiter char(1)
Returns @Temp1 Table (
ItemId int Identity(1, 1) NOT NULL PRIMARY KEY ,
Item varchar(8000) NULL
As
Begin
Declare @item varchar(4000),
@iPos int
Set @Delimiter = ISNULL(@Delimiter, ';' )
Set @List = RTrim(LTrim(@List))
-- check for final delimiter
If Right( @List, 1 ) <> @Delimiter -- append final delimiter
Select @List = @List + @Delimiter -- get position of first element
Select @iPos = Charindex( @Delimiter, @List, 1 )
While @iPos > 0
Begin
-- get item
Select @item = LTrim( RTrim( Substring( @List, 1, @iPos -1 ) ) )
If @@ERROR <> 0 Break -- remove item form list
Select @List = Substring( @List, @iPos + 1, Len(@List) - @iPos + 1 )
If @@ERROR <> 0 Break -- insert item
Insert @Temp1 Values( @item ) If @@ERROR <> 0 Break
-- get position pf next item
Select @iPos = Charindex( @Delimiter, @List, 1 )
If @@ERROR <> 0 Break
End
Return
End
FYI: I'm getting @List value from a table and passing it as a string to split function.
Any help would be appreciated!
ZKAnother user from TSQL forum posted this code which is returning the same resultset but when I execute both codes in SQL server it works and return single quote as expected.
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/8d5c96f5-c498-4f43-b2fb-284b0e83b205/passing-string-which-has-single-quote-rowvalue-to-a-function-returns-double-quoate?forum=transactsql
CREATE FUNCTION dbo.splitter(@string VARCHAR(MAX), @delim CHAR(1))
RETURNS @result TABLE (id INT IDENTITY, value VARCHAR(MAX))
AS
BEGIN
WHILE CHARINDEX(@delim,@string) > 0
BEGIN
INSERT INTO @result (value) VALUES (LEFT(@string,CHARINDEX(@delim,@string)-1))
SET @string = RIGHT(@string,LEN(@string)-CHARINDEX(@delim,@string))
END
INSERT INTO @result (value) VALUES (@string)
RETURN
END
GO
ZK -
How to escape a single quote in a find mode view
Hello,
I'm working with JDeveloper 10g.
I've defined a view that is used in "find mode" in a JSP.
When a value with a single quote is inserted in a field of the search form, an exception is thrown:
JBO-27122: SQL error during statement preparation.
ORA-00907: missing right parenthesis.
The problem is that the "single quote" is not being escaped:
WHERE STREET LIKE 'ABAT ESCARRE, DE L'A'
How could I force the view to escape the "single quote"?
ThanksArrest the single quote by calling a javascript method.
This might help you
Re: af:clientListener javascript function call question
http://download.oracle.com/docs/cd/E12839_01/apirefs.1111/e12419/tagdoc/af_clientListener.html
Edited by: Srinidhi on Mar 23, 2011 3:46 PM -
How to deal with single quote (') in a field value?
I can successfully insert value with single quoet using
Prepared statement with placeholder(?) construct .
I can also successfuly use value with single quote(') in
WHERE clause.
My question is, is there a way to use string with single
quote if a Statement like:
String slqString ="INSERT INTO customers (name, address) VALUES ( 'O'Reilly Bob', 'St Mary's Street') ";
Statement sqlStmt = con.createStatement();
sqlStmt.executeUpdate(sqlString);
The last statement will thow an SQLException because due to single quotes
Any ideas?I think the question was regarding the ' in O'Reily. Use ' twice when using the Statement interface, i.e.
("O''Reilly Bob", "St Mary''s Street")
So that's two single quotes, not a double quote, to successfully insert a single quote, if you know what I mean....
But like you said PreparedStatement does things like this for you. -
How can i concatenate single quote to a field symbol
hi
i have a senario where i have to concatenate a single quote (') to the field symbol. it is simple but i' m not able to do that.
concatenate ''' <f> ''' into lv_f.
CONCATENATE lv_condition_temp lv_f INTO
lv_condition_temp
SEPARATED BY space.
this is the code which i used. could someone help me in solving this...
thanks & regards,
subha....hi
i tried using the following code
data : lv_text(10) type c.
concatenate ''' <f> ''' into lv_text.
it is giving me a spelling or incorrect comma error.
thanks & regards,
subhashini. -
How to escape the single quote from email value?
Hi,
Is there any way to escape the special character single quote from the email value.
String ownerQry = "Select Id, email from User where email in('0000'";
for(int i=0; i<accountData.length; i++)
ownerQry += ",'" + accountData.TEAM_EMAIL+"'";
ownerQry += ")";
QueryResult qrTeam = sfdcCtrl.query(ownerQry);
When i tried to set the email value on a custom object, its throwing the error as below and failed to update. <xml-fragment xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:fault.enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><faultcode>sf:MALFORMED_QUERY</faultcode><faultstring>MALFORMED_QUERY:
'[email protected]','brenden.o'[email protected]','[email protected]'
^ ERROR at Row:1:Column:963 expecting a right parentheses, found 'connor'</faultstring><detail><sf:fault xsi:type="sf:MalformedQueryFault" xmlns:sf="urn:fault.enterprise.soap.sforce.com"><sf:exceptionCode xmlns:sf="urn:fault.enterprise.soap.sforce.com">MALFORMED_QUERY</sf:exceptionCode><sf:exceptionMessage xmlns:sf="urn:fault.enterprise.soap.sforce.com">
'[email protected]','brenden.o'[email protected]','[email protected]'
^ ERROR at Row:1:Column:963 expecting a right parentheses, found 'connor'</sf:exceptionMessage><sf:row xmlns:sf="urn:fault.enterprise.soap.sforce.com">1</sf:row><sf:column xmlns:sf="urn:fault.enterprise.soap.sforce.com">963</sf:column></sf:fault></detail></xml-fragment>Thanks Dr.Clap.
I think its very tricky to implement this.
Here is the SOQL query. i am passing all the email values.
Select Id, email from User where email in('0000','o\'[email protected]','[email protected]')
These values are coming from oracle DB table in the form of array accountData[].TEAM_EMAIL
String ownerQry = "Select Id, email from User where email in('0000'";
for(int i=0; i<accountData.length; i++)
ownerQry += ",'" + accountData.TEAM_EMAIL+"'";
ownerQry += ")";the array value may contain the email with single quote before @gmail.com which i need to ignore. :-( i think this is very tricky. who knows the solution for this? -
How to insert a single quote ........
hi,
How do i insert a sngle quote in a table from sql prompt
suppose if i want to insert Luna's car.
how i do it...
i get error...on sql promptdear satyaki ,
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
SQL> desc tst
Name Null? Type
X VARCHAR2(50)
SQL> insert into tst
2 values (q'!luna's car!');
ERROR:
ORA-01756: quoted string not properly terminated
i still get this message
Maybe you are looking for
-
Deploying an app from export script stored in the database.
I am in the situation where I want to deploy a copy of an application programatically into the current workspace, but each against a separate schema. The end game would be to have many copies of the same App in the same workspace (obviously with diff
-
Skipping request for user policy assignments due to agent configuration for authority
Hello all, Symptoms: The Configuration Manager only shows the following actions: Application Deployment Evaluation Cycle Machine Policy Retrieval & Evaluation Cycle Software Updates Deployment Evaluation Cycle User Policy Retrieval & Evaluation Cycle
-
When I use the window.print() Java script or browser's Print button, it prints the whole page that is viewed on the browser. I want to send only some specific data to be printed that is the result set from the database t
-
NaN when running, but not when debugging
Hello out there, I am creating a JSP application with JDeveloper, and when I run the application the first time, it works without problems... but when I submit the values again to recalculate, the results of some operations that I'm doing are display
-
Is Subinventory Transfer Possible after Picking?
We're currently preparing a Conference Room Pilot (CRP) 2 for an important client, a big Fast Moving Consumer Goods company. The client wants to use its Shipping Trucks as Subinventories under WMS-enabled Warehouses/Inventory Organisations. Goods are