Problem with single quote around ANYINTERACT
CREATE TABLE JUNK
as SELECT s.survey_id,s.shape,s.original_depth
FROM bathyuser.sounding s,m_covr r
WHERE SDO_GEOM.RELATE (s.shape, 'ANYINTERACT', R.geom, 0.5) = 'TRUE'
AND R.DSNM=CNT.DSNM
and
s.SURVEY_ID in
(SELECT unique s.survey_id FROM header s, m_covr r
WHERE SDO_GEOM.RELATE (s.shape, 'ANYINTERACT', r.geom, 0.5) = 'TRUE'
AND DSNM=CNT.DSNM)';
This above SQL works fine in SQL prompt. But when I put it together in PL/SQL it gives me this error :
WHERE SDO_GEOM.RELATE (s.shape, 'ANYINTERACT', R.geom, 0.5) = 'TRUE'
ERROR at line 17:
ORA-06550: line 17, column 39:
PLS-00103: Encountered the symbol "ANYINTERACT" 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_
Could someone help me fix this error. I know I have to try it with "EXECUTE IMMEDIATE" command, but I'm having problem with "||" (concatinate).
Thanks so much
Cuong
This is how you go about debugging execute immediate statements. I am assuming that you fixed the first problem as marias suggested and cam up with something like this. Note, I changed the table in your surso to dual since I do not have your tables, but the effect is the same. I changed the EXECUTE IMMEDIATE to DBMS_OUTPUT.Put_Line so you can actually see what you are trying to execute. I also added some carriage returns to make the formatting a littel easier to see. This is what I got:
SQL> DECLARE
2 statement varchar2(1000);
3 CURSOR C_DSNM5 IS
4 SELECT dummy dsnm FROM dual;
5 BEGIN
6 FOR CNT IN C_DSNM5 LOOP
7 STATEMENT := 'CREATE TABLE JUNK'||
8 ' AS SELECT s.survey_id,s.shape,s.original_depth'||CHR(10)||
9 ' FROM bathyuser.sounding s,m_covr r '||CHR(10)||
10 'WHERE SDO_GEOM.RELATE (s.shape, '||
11 '''ANYINTERACT'''||
12 ', R.geom, 0.5) = '||'''TRUE'''||CHR(10)||
13 ' AND R.DSNM = CNT.DSNM '||CHR(10)||
14 ' AND s.SURVEY_ID IN '||
15 ' (SELECT UNIQUE s.survey_id FROM HEADER s, m_covr r'||CHR(10)||
16 ' WHERE SDO_GEOM.RELATE (s.shape, '||
17 '''ANYINTERACT'''||
18 ', r.geom, 0.5) = '||
19 '''TRUE'''||CHR(10)||
20 ' AND R.DSNM = '||CNT.DSNM||' )';
21 DBMS_OUTPUT.Put_Line (statement);
22 END LOOP;
23 END;
24 /
CREATE TABLE JUNK AS SELECT s.survey_id,s.shape,s.original_depth
FROM bathyuser.sounding s,m_covr r
WHERE SDO_GEOM.RELATE (s.shape, 'ANYINTERACT', R.geom, 0.5) = 'TRUE'
AND R.DSNM = CNT.DSNM
AND s.SURVEY_ID IN (SELECT UNIQUE s.survey_id FROM HEADER s, m_covr r
WHERE SDO_GEOM.RELATE (s.shape, 'ANYINTERACT', r.geom, 0.5) = 'TRUE'
AND R.DSNM = X )
PL/SQL procedure successfully completed.You have at least two issues with this CREATE TABLE statement. The last line needs to have the X (which came from dual) quoted since it is a string. You also still have a reference to CNT.DSNM, unless you fixed both occurences.
Another major problem is that if your cursor will return more than one row, and by the structure of this I assume that it might, the on the second record you are going to get:
ORA-00955: name is already used by an existing object.
Although I see no reason why you need dynamic sql here, you really need to use bind variables whereever possible (everywhere you use a variable except ofr names of database objects. So, your procedure should look more like:
DECLARE
statement varchar2(1000);
CURSOR C_DSNM5 IS
SELECT distinct DSNM from M_COVR where dsnm like 'US5%';
BEGIN
FOR CNT IN C_DSNM5 LOOP
STATEMENT := 'CREATE TABLE JUNK'||
' AS SELECT s.survey_id,s.shape,s.original_depth'||
' FROM bathyuser.sounding s,m_covr r '||
'WHERE SDO_GEOM.RELATE (s.shape, '||
'''ANYINTERACT'''||
', R.geom, 0.5) = '||'''TRUE'''||
' AND R.DSNM = :b1 '||
' AND s.SURVEY_ID IN '||
' (SELECT UNIQUE s.survey_id FROM HEADER s, m_covr r'||
' WHERE SDO_GEOM.RELATE (s.shape, '||
'''ANYINTERACT'''||
', r.geom, 0.5) = '||
'''TRUE'''||
' AND R.DSNM = :b2 )';
EXECUTE IMMEDIATE statement USING cnt.dsnm, cnt.dsnm
END LOOP;
END;But it is still very wrong.
Perhaps if you can explain in words what you are trying to accomplish someone can provide a much better response.
John
Similar Messages
-
Importing excel files - problem with single quote
When importing excel files using 1.5, I can't get data with single quotes (') imported.
When I run the insert statement given in SQLPlus I get "ORA-01756: quoted string not properly terminated", which is different than the error that SQL Developer gives me (see below).
Also, I have a numeric value shown without a thousands comma-separator in the XLS file that I'm trying to load into a varchar2 field. But, the insert statements have added a thousands comma-separator which I don't want.
REM Error starting at line 1 in command:
REM INSERT INTO table (ID, NAME, CODE)
REM VALUES (2427407, 'Ed-u-care Children's Center', '73,000');
REM Error at Command Line:2 Column:37
REM Error report:
REM SQL Error: ORA-00917: missing comma
REM 00917. 00000 - "missing comma"
REM *Cause:
REM *Action:
One last thing, TOAD gives a way to automap columns chosen from XLS to the columns in the database. It sure would be nice to have this functionality in SQL Developer.
Thanks,
SteveDid you consider both to be bugs (i.e., single quote issue and thousands comma separator issue)?
Thanks -
Problem with single quote when exporting insert statement
Hi
I'm using Oracle SQL Developer 2.1.1.64 on Ubuntu 10.04. I got some records which has single quote in it.
For example,
Let says Table '*TABLE_A*' has varchar2 column called '*COL_A*'.
And there is only one record in the table and the value is:
his friend's dog name is dog.
When I export that table data to insert statement, i got this:
Insert into TABLE_A (COL_A) VALUES ('his friend's dog name is dog.');
As you can see friend's is wrong, it should be friend''s instead. (note the double single quotes).
Anyone knows how to fix this please?Yes - that's a bug. But probably not what you're expecting.
Mind you really can't use "normal" SQL on LOBs, because they're just too big to fit in the statements.
You should export and import them through e.g. the DBMS_LOB package.
I do remember some request on the SQL Developer Exchange to automate this, so go vote there to add weight for future implementation.
So the bug is that the column's fields should all yield NULL inside the INSERTs.
Regards,
K. -
Single quotes around a variable
Hi,
I have values that are being passed into a variable with single quotes around.
for eg: 'test'. So the value in variable v_empname will hold the value 'test'
But then below sql statement returns null:
select empid
into v_empid
from emp where empname = v_empname
When I checked the value of the variable it's 'test' and compared as '''test'''.
How can I get around this?
Thanks for the help.
SK.Doh!
SQL> create or replace procedure get_empno (i_name in varchar2)
2 as
3 v_empno number;
4 begin
5 select empno into v_empno
6 from emp
7 where ename = i_name;
8 dbms_output.put_line('empno is '||v_empno);
9 exception
10 when no_data_found then
11 dbms_output.put_line('No such person, or did you mean '||upper(i_name)||'?');
12 end;
13 /
Procedure created.
SQL>
SQL> set serveroutput on
SQL> exec get_empno('king');
No such person, or did you mean KING?
PL/SQL procedure successfully completed.
SQL> exec get_empno('KING');
empno is 7839
PL/SQL procedure successfully completed. -
How to put single quotes around selected data
Is there a way to return selected column value with single quotes around it?
Example I have a table:
select name from test_table;
returns: George Clooney
I want it to return 'George Clooney'
I tried: select '''||name||''' from test_table;
returns: '||name||'...or
SCOTT@demo102> select chr(39)||ename||chr(39) from emp;
CHR(39)||ENA
'SMITH'
'ALLEN'
'WARD'
'JONES'
'MARTIN'
'BLAKE'
'CLARK'
'SCOTT'
'KING'
'TURNER'
'ADAMS'Nicolas. -
Dynamic SQL and Data with Single Quotes in it.
Hi There,
I have a problem in that I am using dynamic SQL and it happens that one of the columns does contain single quotes (') in it as part of the data. This causes the resultant dynamic SQL to get confused as the single quote that is part of the data is taken to mean end of sting, when in fact its part of the data. This leaves out a dangling single quote that was meant to enclose the string. Here is my dynamic SQL and the result of the parsed SQL that I have captured:
****Dynamic SQL*****
l_sql:='select NOTE_TEMPLATE_ID '||
'FROM TMP_NOTE_TEMPLATE_VALUES '||
'where TRIM(LEGACY_NOTE_CODE)='''||trim(fp_note_code)||''' '||
'and TRIM(DISPLAY_VALUE)='''||trim(fp_note_text)||''' ';
execute immediate l_sql INTO l_note_template_id;
Because the column DISPLAY_VALUE contains data with single quotes, the resultant SQL is:
******PARSED SQL************
select NOTE_TEMPLATE_ID
FROM TMP_NOTE_TEMPLATE_VALUES
where TRIM(LEGACY_NOTE_CODE)='INQ' and TRIM(DISPLAY_VALUE)='Cont'd'
And the problem lies with the single quote between teh characters t and d in the data field for DISPLAY_ITEM. How can I handle this?
Many thanks,I have been reliably informed that if one doesn't enclose char/varchar2 data items in quotes, the right indices may not be usedI am into oracle for past 4 years and for the first time i am hearing this.
Your reliable source is just wrong. Bind variables are variables that store your value and which are used in SQL. They are the proper way to use values in your SQL. By default all variables in PL/SQL is bind variable.
When you can do some thing in just straight SQL just do it. Dynamic SQL does not make any sense to me here.
Thanks,
Karthick. -
IN operator with single quotes
Hi All,
I am having problem dealing with Single Quotes with IN operator. Below procedure will explain my problem:
create or replace procedure sp_countemp
p_empnames in varchar2
is
v_cnt integer:=0;
BEGIN
select count(*) into v_cnt from emp where ename in (p_empnames);
DBMS_OUTPUT.PUT_LINE(v_cnt);
END;I will be getting p_empnames as 'ALLEN','SMITH'
But I am not getting any records here.
Thanks,
DanishHope this helps..
DECLARE
TYPE strarray IS TABLE OF VARCHAR2(100);
p_empnames STRARRAY;
v_tot INTEGER :=0;
v_cnt INTEGER := 0;
BEGIN
p_empnames := strarray('Allen','Smith');
FOR i IN p_empnames.FIRST .. p_empnames.LAST LOOP
SELECT COUNT(*) INTO v_tot FROM emp WHERE ename = p_empnames(i);
v_cnt := v_cnt + v_tot;
END LOOP;
DBMS_OUTPUT.PUT_LINE('Count '||v_cnt);
END;
Count 2 -
SQL: Need help putting single quote around string
I want to put single quotes around string in my output.
I am running the following command as a test:
select ' ' hello ' ' from dual;
My expectation is to get 'hello' (Single quote around hello)
However I am getting the following error:
ERROR at line 1:
ORA-00923: FROM keyword not found where expected
When I do SHOW ALL at my SQL command prompt, the escape is set as follows:
escape "\" (hex 5c)
I even tried: select '\'hello\'' from dual;
I get back: select ''hello'' from dual
ERROR at line 1:
ORA-00923: FROM keyword not found where expectedHi,
user521525 wrote:
I want to put single quotes around string in my output.
I am running the following command as a test:
select ' ' hello ' ' from dual;
My expectation is to get 'hello' (Single quote around hello)You probably read that you can get a single-quote within a string literal by using two of them in a row.
That's true, but they really have to be in a row (no spaces in between), and you still need the single-quotes at the beiginning and end of the literal.
So what you want is
SELECT '''hello'''
FROM dual;Starting in Oracle 10, you can also use Q-notation, For example:
SELECT Q'['hello']'
FROM dual; -
Place single quote around string
Hi,
I am wondering how I can Place single quote around string in the following. I have tried double and triple quote but it doesn't take variable name from rec.tablename.
any idea
rec.table_name ==> 'rec.table_name'
rec.column_name ==> 'rec.column_name'
v_sql:= 'DELETE USER_SDO_GEOM_METADATA WHERE TABLE_NAME= ' || rec.table_name ;
execute immediate v_sql;
-- Insert Table Record in Sdo_User_Geom_Metadata
v_sql:= 'INSERT INTO USER_SDO_GEOM_METADATA(TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) ' ||
'VALUES (' || rec.table_name || ',' || rec.column_name || ', MDSYS.SDO_DIM_ARRAY( ' ||
'MDSYS.SDO_DIM_ELEMENT(''X'',-2147483648, 2147483647, .000005), ' ||
'MDSYS.SDO_DIM_ELEMENT(''Y'',-2147483648, 2147483647, .000005)), 2958)' ;
execute immediate v_sql;
NancyI have 2 suggestions, 2nd one being the better choice.
SQL> set serveroutput on
SQL>
SQL> declare
2 v_sql varchar2(4000);
3 table_name varchar2(4000);
4 begin
5 table_name := 'MY_TABLE';
6 v_sql:= 'DELETE USER_SDO_GEOM_METADATA WHERE TABLE_NAME= ''' || table_name || '''';
7 dbms_output.put_line(v_sql);
8 end;
9 /
DELETE USER_SDO_GEOM_METADATA WHERE TABLE_NAME= 'MY_TABLE'
PL/SQL procedure successfully completed
SQL> or using DBMS_ASSERT for a more elegant solution against SQL injection:
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.4.0
Connected as fsitja
SQL> set serveroutput on
SQL>
SQL> declare
2 v_sql varchar2(4000);
3 table_name varchar2(4000);
4 begin
5 table_name := dbms_assert.QUALIFIED_SQL_NAME('ALL_TABLES');
6 v_sql:= 'DELETE USER_SDO_GEOM_METADATA WHERE TABLE_NAME= ' || dbms_assert.ENQUOTE_NAME(table_name);
7 dbms_output.put_line(v_sql);
8 end;
9 /
DELETE USER_SDO_GEOM_METADATA WHERE TABLE_NAME= "ALL_TABLES"
PL/SQL procedure successfully completed
SQL> [Docs referencing validation checks against SQL injection|http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/dynamic.htm#LNPLS648]
Regards,
Francisco -
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 to concatenate a string with single quotes
Hi all,
how to concatenate a string with single quotes to a variable.
SathyaHi sathyabama,
1. simple
2. use TILDE character <b>(`)</b>
(just left to the '1' key)
<b> `'mystring'`</b>
3. just copy paste
report abc.
data : m(100) type c.
concatenate `'amit mittal'` 'hello' into m separated by space.
write m.
regards,
amit m. -
Firefox is replacing double quotes with single quotes.
In WordPress and at other sites where I input and save text, Firefox is replacing double quotes with single quotes when I save. It's also showing double quotes as single quotes on websites. I tried uninstalling and reinstalling, and it's still happening.
Do you have the needed font installed?
*http://en.wikipedia.org/wiki/Punctuation -
Changing of the standard port 1521 and afterward problems with Single Sign
System / Host Environment
Operating System: HP-UX 11i, Existing Oracle RDBMS Vers. 9.2 x, Listener on standard port 1521
9iAS System Architecture: 9iAS Infrastructure and Middle tier (AS Instance) on the same machine
Problem Environment:
-Before and during the installation of 9iAS infrastructure the Listener of the existing Oracle RDBMS was stopped
-The installation of 9iAS Infrastructure (db: IASDB) Version 9.0.2.0 works well
-Afterwards the port 1521 of IASDB changed to 1525. For a detail description of IASB port changing please refer to Doc. ID: 211 929.1 AFTER CHANGE 'IASDB' LISTENER PORT
-The installation of Patch Set 2 (Common Patch 2703110) follows (9iAS is now up to Release 9.0.2.2).
-The Installation of 9iAS Middle tier (AS Instance) Version 9.0.3 follows
Problem description:
-During the installation of 9iAS Middle tier problems with Single Sign On occurs.
The reason of this problems seems a communication problem between the Single Sign On login sequence and the IASDB. After a reset of the port changing (back to the standard port 1521) the installation of 9iAS Middle tier works well.
Through this incorrect and problematic behaviour we have some notes and questions:
-Well at first the description of the port changing in Doc. ID: 211 929.1 seems us incomplete. Some configuration still carry on the standard port 1521 and not the knew value of the port 1525.
-So we want to know all configuration files and parts where we have to change the port value manually ?
-What will happened to the Single Sign On function with this manually port changing. Does Single Sign On works later on correct or have we to change much more ?Currently, changing the listener port is not supported. It must stay on 1521. I believe this is to be fixed in a latter release (perhaps 9.0.4)
-
Replacing " (double quote) with ' (single quote)
Hi there,
I have the following method to manipulate user input. All I want to do is, to replace the double quote with a single quote. The implementation I tried was,
this.replace(desc, "\"", "'");
This does not work for me. It jsut removes the double quote and does not introduces the single quote. Could any one please advise?
Thanks,
Des
public static String replace(String line, String oldString, String newString) {
if(line != null && oldString != null && newString != null) {
int index = 0;
while ((index = line.indexOf(oldString, index)) >= 0) {
line = line.substring(0, index) +
newString +
line.substring(index + oldString.length());
index += newString.length();
return line;
}Bad luck.. I am unable to get it still.
This is the code I am using (implemetation is in a JSP. I am using this code to test it).
public class Test{
public static void main(String args[]){
String s = args[0];
Test t = new Test();
String doubleQuote = "\"";
System.out.println(" output :"+ t.replace(s,doubleQuote,"'"));
//System.out.println(" output :"+ t.replace(s,"\"","'"));
//System.out.println(" output :"+ t.replace('"', '\''));
public static String replace(String line, String oldString, String newString) {
if(line != null && oldString != null && newString != null) {
int index = 0;
while ((index = line.indexOf(oldString, index)) >= 0) {
System.out.println(" line count :");
line = line.substring(0, index) +
newString +
line.substring(index + oldString.length());
index += newString.length();
return line;
}mshn02
The main problem is I am stuck with the server's version of Java (which I have no control on it). I could not use 1.4.2 -
Passing value in procedure with single quotes intact
HI,
I have the following procedure.
create or replace procedure p1( a varchar2) is
begin
execute immediate ' update emp set sal = 20*Sal + sal
where ename like ' || a;
end;
when I try to run this and pass a value to a. the single quotes
r removed and the entire string becomes.
'update emp set sal = 20*sal + sal where ename like scott'
hence the error.
now my problem is how can i make sure the scott goes like 'scott'
i.e the single quotes are intact. or otherwise 'scott%'
thanx in advance
Sreekant VadlamaniYou can also use triple quotes to do this. the effects of
multiple quotes can be seen below. The same stuff works in
procedures
Connected to:
Oracle8i Enterprise Edition Release 8.1.5.0.0 - Production
With the Partitioning and Java options
PL/SQL Release 8.1.5.0.0 - Production
SQL> select 'hello' from dual;
'HELL
hello
SQL> select ''hello'' from dual;
select ''hello'' from dual
ERROR at line 1:
ORA-00923: FROM keyword not found where expected
SQL> select '''hello''' from dual;
'''HELL
'hello'
SQL> select ''''hello'''' from dual;
select ''''hello'''' from dual
ERROR at line 1:
ORA-00923: FROM keyword not found where expected
SQL> select '''''hello''''' from dual;
'''''HELL
''hello''
SQL>
Maybe you are looking for
-
OS 10.6.8 printing problem (HP 882C)
People, I have an iMac Intel Core 2 Duo. My printer is an HP Deskjet 882C. I have been running Leopard OS 10.5.8. I needed to upgrade to Snow Leopard so I could run TurboTax. I saved my data and erased the partition on my hard drive that contained th
-
I remove my hard drive from time machine,now it won't recognize hard drive
i got a delayed error on my time machine backup saying Time Machine couldn't complete the backup to my back up hardrive, so what i did i removed my hard drive in time machine "select disk" , thinking if ill plug it back it'll recognize but it didn't.
-
Ora-31655 using dbms_datapump
i am using dbms_datapump to make a logical backup. it works fine, when i use just to schema mode. when i try to execute using table mode, it raised a error 31655 "no data or metadata objetcs selected for job". in both cases, i am connected by SYS. it
-
Finding Shapes in image Hi, I have to determine the location and size of a black rectangle (stroke 1-2 millimeter, black) in a tiff-image. My current approach is: 1) Start detection in defined loacation (to limit detect-area) 2) Start detection in sa
-
Reports with Designer E/R Diagrams
Hi gurus: IHAC who want to insert an E/R Diagram from Designer in a report built with Reports Builder, print it, wiew in a browser,... Can I do it? How? Thanks in advance. Luz FV