How Many Quotes To Use In Dynamic Query Using IN Clause With String

Nov 23, 2011

I have a dynamic query which has this clause in it: WHERE [COLUMN NAME] IN (' || theString || ')

My problem is that theString is being passed in through a C# call and the variable is a bunch of strings concatenated together and separated by a comma. Ex: theString = "'val1','val2'"

How many quotes are supposed to go around val1 and val2?

I've tried the following and none work:
'val1','val2'
''val1','val2''
''val1'',''val2''
'''val1'',''val2'''
''''val1'',''val2''''

When I run the procedure in Oracle it works with '''val1'',''val2'''

View 1 Replies


ADVERTISEMENT

SQL & PL/SQL :: Dynamic Sql Query String - Getting Error?

Aug 22, 2010

FUNCTION get_attributed_sedol( p_ref_number IN VARCHAR2,
p_field IN VARCHAR2 )
RETURN VARCHAR2
IS
l_query VARCHAR2(1000);

[code]...

It gives me an error on the line where the execute immediate statement is.
Quote:
ORA-00905
missing keyword

Cause: A required keyword is missing.

Action: Correct the syntax.

But when I check my stack trace table to see what the actual query string looks like, I see this

Quote:
SELECT sedol INTO l_attributed_sedol_code FROM integration.tmp_attributed_sedol WHERE CLIENT_LEDGER_REF='LEAE057090' AND ROWNUM=1

There's nothing wrong with that, is there? It executes fine if I try it manually.

View 3 Replies View Related

SQL & PL/SQL :: Using Apostrophe / Quotes In A String

Feb 9, 2011

Here is a sample function which takes in a string of CSV fields and prints the third field :

create or replace function restr(istr varchar2) return INTEGER
is
var_1 varchar2(30);
begin
dbms_output.put_line('input:'||istr);
select regexp_substr(',' || istr,1,3,null,1) into var_1 from dual;

[Code]..

When I pass an input string as :

JOHN,MARY,O'DONNEL,O'CONNELLY,MARK

with quotes/apostrophe in it to the function then it prints the input string in the first dbms_output but errors out at the select with ORA-01760.

how we can use the quote/apostrophe character here ?

View 6 Replies View Related

Server Utilities :: Loading String Has Double Quotes In It?

Aug 22, 2013

I am loading .csv file into Oracle using sql loader file has strings, and numberics, Strings are surrounded by double quotes(") and field terminated by comma(,)

load data
BADFILE '/var/opt/app/bad/filename'
DISCARDFILE '/var/opt/app/discard/filename'
append into table source_file
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS

Some time String fields may have double quotes in it, at that time it is rejecting the records. how to handle those records to load into table.

View 3 Replies View Related

SQL & PL/SQL :: Remove Spaces By Excluding Double Quotes From A String

Oct 29, 2012

I want to remove more than one space from a string by excluding double quotes.

For example:

I/P: Item .getChildByType(" Agreement").getParent( ) .hasChildByType("Agreement ")

O/P : Item.getChildByType(" Agreement").getParent().hasChildByType("Agreement ")

View 17 Replies View Related

SQL & PL/SQL :: Dynamic WHERE Clause - Too Big

Aug 18, 2011

I have to create a WHERE clause like :

SELECT * FROM wc_claims WHERE part_nbr in l_part_nbr ;

I have three tables:
table A has - user_id, supplier
table B has - supplier, part_nbr
table C , wc_claims, has part_nbr and 78 other columns.

what i need to do is when user logs in with his user_id, he should see only that info from table C, corresponding to his supplier, and the part_nbr.

SELECT supplier from table_A WHERE user_id = 'abc' ;
supp_abc
SELECT distinct part_nbr from table_B WHERE supplier = 'supp_abc' ;
partA, partB, partC,........partZZ

SELECT * FROM wc_claims WHERE part_nbr in (partA, partB, partC,........partZZ );

I have created a function :

create or replace Function wcl_partnbr ( p_supp IN varchar2 )
RETURN CLOB
IS

[Code].....

so that I can use that in the WHERE clause, because one supplier can have thousands of parts...so it works fine, if there are 200 part numbers for one supplier, but above that.. it doesnt.

View 15 Replies View Related

SQL & PL/SQL :: Dynamic Where Clause

Jul 9, 2010

I having below table :

EXAM2@orcl> desc search_table;
Name Null? Type
----------------------------------------- -------- ----------------------------
ROL NOT NULL VARCHAR2(7)
CNM NOT NULL VARCHAR2(30)
FNM NOT NULL VARCHAR2(30)
MNM NOT NULL VARCHAR2(30)
DOB NOT NULL DATE
YEAR NOT NULL NUMBER(4)
EXAM NOT NULL VARCHAR2(1)
MAIN_SUPP NOT NULL VARCHAR2(1)

In a dotnet application user is going to input/select all/any of the above column in where clause.If user has given value for rol column then ref cursor should be :

select * from search_table where rol like <given value>
endif
and/or

If user has given value for cnm column then ref cursor should be :

select * from search_table where rol like <given value> and/or cnm like <given value>
endif

I mean whatever value is being given; it should be part of where clause.For it i am going to :

EXAM2@orcl> CREATE OR REPLACE PACKAGE rollsearch AS
2 TYPE t_cursor IS REF CURSOR;
3 Procedure rol_cursor(c_rol in varchar2,c_cnm in varchar2,c_fnm in varchar2,
4 c_mnm in varchar2,d_dob in date,n_year in number,c_exam in varchar2,c_main_supp in varchar2,
5 io_cursor IN OUT t_cursor);
6 END rollsearch;
7 /

EXAM2@orcl> CREATE OR REPLACE PACKAGE BODY rollsearch AS
2 Procedure rol_cursor(c_rol in varchar2,c_cnm in varchar2,c_fnm in varchar2,
3 c_mnm in varchar2,d_dob in date,n_year in number,c_exam in varchar2,c_main_supp in varchar2,
4 io_cursor IN OUT t_cursor)
5 IS
6 v_cursor t_cursor;
7 sql varchar2(1000);
8 BEGIN
9

What should i write further; so that i may get ref cursor as whereed clause for given value. So that i may populate my datagrid view for that web form.

View 14 Replies View Related

PL/SQL :: Dynamic WHERE Clause With Multiple ORs?

Jul 1, 2013

I need to build a SQL statement dynamically such that the WHERE clause looks/works as follows: WHERE x LIKE '%1%' OR x LIKE '%2%' OR x LIKE '%3%' .

View 2 Replies View Related

PL/SQL :: Dynamic Where Clause Change

Mar 1, 2013

I have code as below

Scenario1
FOR i in (Select .................... from table1 Where id in(select id from Sample_table where status='Submit'))
Loop
.
.
.
End loop;

Scenario2
FOR i in (Select .................... from table1 Where id in(select id from Sample_table where status='Saved'))

Loop
.
.
.

End loop;

Scenario3
FOR i in (Select .................... from table1 Where id in(select id from Sample_table where status='Inprogress'))
Loop
.
.
.
End loop;Query is same here but only chage is where clause

Total length of this query is exceeding varchar2 length. so i cant use variable to hold this query and append where clause dynamically.

Do we have any other method to change where clause dynamically?

View 6 Replies View Related

SQL & PL/SQL :: Dynamic SQL Returning Clause Into Collection

Nov 8, 2010

I have been testing some functionalist, I have been trying to get the updated dept no values into an array and then print the count. But i am getting the following error.

I have implemented, the whole example is to know about 'dynamic sql returning clause into collection'

s@ORCL> select * from t_dept;

DEPTNO DNAME LOC
---------- -------------- -------------
10 comp NEW YORK
20 Compt DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
60 Comp Ahaaa
80 data ab
80 data ab
80 data ab
80 data ab

9 rows selected.

s@ORCL> ed
Wrote file afiedt.buf

1 declare
2 type tp_dept is table of number;
3 arr_dept tp_dept;
4 begin
5 execute immediate q'['update t_dept set dname = 'Pointers' where deptno = 80 returning deptno into :out]'
6 returning into arr_dept;
7 dbms_output.put_line('The count is '||arr_dept.count);
8* end;
s@ORCL> /
returning into arr_dept;
*
ERROR at line 6:
ORA-06550: line 6, column 19:
PLS-00597: expression 'ARR_DEPT' in the INTO list is of wrong type
ORA-06550: line 5, column 4:
PL/SQL: Statement ignored

View 4 Replies View Related

SQL & PL/SQL :: Where Clause - Literal Does Not Match Format String

Feb 28, 2011

In query I have WHERE clause like this:

WHERE TO_DATE(TO_CHAR(RR.PEROFOPFROM,'DD-MON-YYYY')||RR.AIRCRAFTSTD,'DD-MON-YYYY:HH24MI') >
TO_DATE(TO_CHAR(RR.PEROFOPFROM,'DD-MON-YYYY')||RR.AIRCRAFTSTA,'DD-MON-YYYY:HH24MI')

I have data like this:

PEROFOPFROMAIRCRAFTSTD

29/03/20102150
NULL NULL
NULL NULL
30/03/20102150

When I execute the query it always gives me the error "literal does not match format string".

View 7 Replies View Related

SQL & PL/SQL :: Execute Immediate Doesn't Like Dynamic String

Feb 29, 2012

why is this procedure with EXECUTE IMMEDIATE not working for me, when I pass a dynamic string to it.

this is the proc:

CREATE OR REPLACE FUNCTION MIGRATION.execute_sql (pSQL varchar2) RETURN varchar2 IS
vResult Varchar(200);
BEGIN
vResult := null;
[code]......

and when I invoke it like this it's fine:

select execute_sql ('select sysdate from dual') test from dual. However, when I try something like this, it won't work:

select execute_sql ('select max(al_code) from alert_log where al_user= '||user) test_sql from dual

the error message I get is:

ORA-00904: "MIGRATION": invalid identifier
ORA-06512: at "MIGRATION.EXECUTE_SQL", line 26

View 11 Replies View Related

Reports & Discoverer :: Between Clause To Compare Two String Values

Jun 15, 2013

I have a problem with Between clause used in where statement to compare two string variable.

Query is like this,

select item_code, item_deacrption
from itm_master, invoce_det
where im_code = item_code
AND invd_item_number BETWEEN (:startNum) AND (:endNum)

Here invd_item_number is a DB field and is of type varchar2(41), and (:startNum),(:endNum) are of same type.

now invd_item_number has one value '001003002001'
if we give :startNum = '001003001002' and :endNum = '001003004006'

:startNum and :endNum is composed of separate field values (ie, 1st 3 character shows color code, next 3 for catagory, next 3 for size etc). These codes are entered separately and are combined at run time.

it is still fetching the invd_item_number with value '001003002001'. (the last set of character(type code) in the :startNum is greater than invd_item_number's type code value. But it is smaller than the previous code (size code), that's why it is fetching).

But how can i get around this as i don't need that value to be fetched.

View 7 Replies View Related

PL/SQL :: Passing String Values To Partition Clause In A Merge Statement?

May 24, 2013

I am using the below code to update specific sub-partition data using oracle merge statements.

I am getting the sub-partition name and passing this as a string to the sub-partition clause.

The Merge statement is failing stating that the specified sub-partition does not exist. But the sub-partition do exists for the table.

We are using Oracle 11gr2 database.

Below is the code which I am using to populate the data.

declare
ln_min_batchkey PLS_INTEGER;
ln_max_batchkey PLS_INTEGER;
lv_partition_name VARCHAR2 (32767);
lv_subpartition_name VARCHAR2 (32767);
begin

[code]....

View 2 Replies View Related

SQL & PL/SQL :: Create View From Dynamic Query (or Function Returning Query)

Dec 5, 2012

I have a dynamic query stored in a function that returns a customized SQL statement depending on the environment it is running in. I would like to create a Materialized View that uses this dynamic query.

View 1 Replies View Related

How To Use String Buffer Instead Of String Query

May 9, 2008

show an ex to use string buffer for select statemnt

View 1 Replies View Related

SQL & PL/SQL :: Query With CASE Where Clause?

May 14, 2012

The query has a case statement in the where clause so that results can be filtered. If I pass "ut" for sso_id then the query returns 21 rows. If I remove the case statement and hard code "a.sso_id like lower('ut'||'%')" then the query returns 41 rows. The query should be returning 41 rows all the time.

Problem:

When passing "ut" as an SSOID parameter to the Procedure the query returns 21 rows.Taking the query and hard coding "a.sso_id like lower('ut'||'%')" the query returns 41 rows.

Result:
query should be returning 41 rows when "ut" is passed an an SSOID parameter.

Returns 21 rows

procedure SSO (SSOID in varchar2 default null,
Name in varchar2 default null,
Campus in varchar2 default null,
Department in varchar2 default null,

[code]...

Returns 41 rows

open Results for
select a.sso_id,
(a.name_last||', '||a.name_first) as name,
b.site,

[code]...

Test Data
CREATE TABLE ID
(
SSO_ID VARCHAR2(60 BYTE),
NAME_FIRST VARCHAR2(100 BYTE),
NAME_LAST VARCHAR2(100 BYTE),

[code]...

Test Data
CREATE TABLE NT
(
LOWER_NT_ID VARCHAR2(60 BYTE),
DEPARTMENT VARCHAR2(100 BYTE),

[code]....

View 3 Replies View Related

PL/SQL :: Sub-query Inside IN Clause?

Jul 25, 2013

Below is the block which i am trying to test in scott schema. I dont want to substute IN clause values directly. So i have written cursor and have added in separate variable separeated by comma.But its not working.  

declares varchar2(1000);s1 varchar2(1000);v number := 0;v1 varchar2(2000) := 'SCOTT';j number := 0;cursor hhis select ename from emp;beginselect count(*) into v from emp;  for i in hh loops := s||''''||i.ename||''''; j := j+1;if j <> vthen s := s||',';end if;s1 := s1||s;s := null; end loop;dbms_output.put_line(S1); case when v1 in (s1) then dbms_output.put_line('Y');  else dbms_output.put_line('N'); end case;end;  

View 3 Replies View Related

PL/SQL :: Query Execution On Where Clause

Oct 22, 2013

I have the where cluase as below , I would like to know how does oracle decides which one to execute first,  

WHERE S.PERSPECTIVE='S'and s.shipment_gid=sb.shipment_gid AND SB.BILL_GID=CBIL.INVOICE_GIDand inv.invoice_gid=cbil.invoice_gid AND S.SOURCE_LOCATION_GID=LC.LOCATION_GID and l.location_gid=lc.location_gid AND TRUNC(cbil.insert_date)=TRUNC(tc.tesco_cal_date)AND(lc.location_gid='N' OR lc.corporation_gid='TESCO.10719')AND s.source_location_gid=lc.location_gid AND tc.tesco_year='2013' AND tc.tesco_period=6AND tc.tesco_week_number=23     

View 9 Replies View Related

SQL & PL/SQL :: Dynamic Column Value Query?

Nov 3, 2010

I have a Strange requirement from client data is loaded from excel to Oracle Table- TST_TBL (with Header in Excel)

CREATE TABLE TST_TBL
(
JOB_DETAIL_ID NUMBER,
SHEET_NAME VARCHAR2(100 BYTE),
COL1 VARCHAR2(400 BYTE),
COL2 VARCHAR2(400 BYTE),
COL3 VARCHAR2(400 BYTE),
COL4 VARCHAR2(400 BYTE),

[Code]...

After the Data is loaded, we see data look like the above.

(1) Always COL3 column name have data value as 'Gen1' which is the indication for us from where data starts. But Gen1, Gen2, Gen3 etc... is dynamic. ie. This month we get gen1 and gen2 columns followed by null value in a column. Next month we get gen1,2,3,4 followed by null column.
(2) Null Column indicate us that there is a break in the column.
(3) Then next we need to look for next group of data (Monthly) and then insert into the same table again with different sheet_name column.
(4) Next for Quater and then YTD. None of the column Values are fixed and its all dynamic.

If you load the below data, you will come to know what i am looking for. I tried using UNPIVOT. But couldnt able to achieve it. Is there an option to do it in sigle query? or Do I need to go for Stored Procedure?

Insert into TST_TBL
(JOB_DETAIL_ID, SHEET_NAME, COL1, COL2, COL3,
COL4)
Values
(100, 'Wire_1', 'Gen1',
'Gen2', 'Gen3', 'Gen4');
Insert into TST_TBL

[Code]....

View 1 Replies View Related

Use Of Query Clause For Nested Tables During Export

Aug 30, 2010

I have a query regarding nested tables while exporting. Are we not allowed to use Query clause during the export of nested table?

I am getting the error:
"EXP-00053: unable to execute QUERY on table NT_LP_COREBAL_MAINT because the table has inner nested tables
Export terminated successfully with warnings."

The exp command we are using is:
exp XXXX/XXXX@XXXX file=test1.dmp log=test1.log tables=nt_lp_corebal_maint query='where domain_id=10110307'.

View 1 Replies View Related

Using Array Values In IN Clause Of Select Query?

Sep 9, 2008

I have some issues in passing array values to IN clause.

I am passing a String Array from Java to PL\SQL and want to use the Array values in the IN CLAUSE of Select Query

cust_array is the Array
search_id VARCHAR2(1000);
search_id := '';
FOR j IN 1 .. cust_array.count
LOOP
IF (j != 1) THEN
search_id := search_id || ''',''' || cust_array(j) || ''';
ELSE
search_id := search_id || '''' || cust_array(j) || '''';
END IF;
END LOOP;

trying to form a string of below form: search_id '3211335201','3211335209','3211335279','3211335509'

and use the string search_id in the IN clause of the search Query select * from DPP_EMP where empl in (search_id)

but the query does not returns any result

When I try to hardcode the values in the query as below, its returing 4 rows

select * from DPP_EMP where empl in ('3211335201','3211335209','3211335279','3211335509')

How to achieve this (String to the IN clause) or is there a better way of passing the Array values to the IN clause

View 13 Replies View Related

SQL & PL/SQL :: How To Use (select Statement) Rather Than (in Clause) In Pivot Query

May 27, 2011

I'm using pivot query feature of oracle 11g and came across a strange situation where i need to pass a "select statement" in a "in clause" of pivot query.

SQL> CREATE TABLE TEST1
2 (
3 UIN NUMBER(8) NOT NULL,
4 TESTING_ID NUMBER(4),
5 PFA_RESULT VARCHAR2(30 BYTE)
6 );

[code]....

I have tried with pivot xml but it not giving desired output in sql*plus session.It is giving unreadable output.

select * from
(select uin,testing_id,pfa_result from test1)
pivot xml (max(pfa_result) as result
for (testing_id) in (select distinct testing_id from test1));

[code]....

Here actually i want to use "select distinct id from test1" instead of "in (11,12,13,14,15)". Because i don't know how many id's will be there and of which values. e.g. 11 or 21 or 25.

View 3 Replies View Related

SQL & PL/SQL :: Query Gets Slower By Adding Order By Clause

Apr 14, 2010

I have a query, running the query with order by and without orderby clasue casues big performance difference.

here without order by it takes 5 sec
.
SELECT
audit_number,
formatted_audit_number,
ag.sys_audit_id,
audit_begin_date,
audit_end_date,

[Code]....

here with order by it takes 2 min

SELECT
audit_number,
formatted_audit_number,
ag.sys_audit_id,
audit_begin_date,
audit_end_date,
auditee_name,
ein,

[Code]....

I have like 10,000 records.

View 16 Replies View Related

SQL & PL/SQL :: Define A Cursor Using Dynamic Query?

Aug 29, 2010

Is it possible to define a cursor using dynamic sql. Reason being is, I want to fetch data from 4 diffrent tables but dont want 4 diffrent cursors for this purpose.

I have a procedure that takes an in parameter . Cursor is declared in this procedure. Again is there a way to use dynamic sql so that this cursor declared in procedure uses all 4 table one at a time i.e cursor c1 is select * from table_name(I want this table name to be updated every time with new table name).

View 5 Replies View Related

SQL & PL/SQL :: Using Escape Character In Dynamic Query?

Aug 28, 2012

I'm trying to replace the variable value v_tblname in dynamic SQL. But not able to escape the single quotes character.

DECLARE
v_sqlcols VARCHAR2(2000);
v_sqlcols1 VARCHAR2(2000);
v_tblname VARCHAR2(50) := 'DEPT';
BEGIN
v_sqlcols := q'[SELECT LISTAGG(COL,',' ||CHR(10)) WITHIN GROUP (ORDER BY COL)
FROM (

[code]....

View 5 Replies View Related

SQL & PL/SQL :: How To Get Count On Executing Dynamic Query

Sep 16, 2010

l_query := 'SELECT sedol ' ||
'FROM integration.tmp_attributed_sedol ' ||
'WHERE ' || p_field || '=''' || p_ref_number || ''' ';

by using the execute immediate or any other command, how can i check whether the query returned any rows or not?

View 2 Replies View Related

SQL & PL/SQL :: Dynamic Query For Swapping Names

Mar 25, 2011

writing dynamic sql query for swapping names:

the output shuld be like that

input output

a a
a b b a
a b c c b a
a b c d d c b a

i have writen it in static form by using instr,substr.But i m having difficulty in making it dynamic by using select statement.I have to make it for retrieving data from database.

View 13 Replies View Related

SQL & PL/SQL :: Using NULL And DECODE In Dynamic Query

Sep 2, 2011

small piece of PL SQL code. how to make this query.Requirement is that a concurrent program is run with parameters and one of them i_num_org_id is non mandatory so it can come as NULL...Now in an existing code which i have to change, it uses a query as

SELECT xyz
FROM abc_table
WHERE <various conditions>
AND DECODE(i_num_org_id,NULL,1,table.organization_id) = NVL(i_num_org_id,1);

Now with the above way, if the program is run with some value for i_num_org_id or run as normal query (with NULL as the value) inside a PLSQL procedure/package then it runs fine.This query if you run in Toad etc then too it will work fine but if it is made a dynamic SQL and then used as either EXECUTE IMMEDIATE or opened as a cursor then we get a "Missing expression". I created this small anonymous block to test this and this will go into missing expression error

declare
l_num_org_id NUMBER := NULL;
l_temp VARCHAR2(100);
l_sql varchar2(1000);
begin
l_sql := 'SELECT '||''''||'abcd'||''''||'
[code].....

how i can reformat this query so that even if NULL value comes for i_num_org_id then it is handled.I am aware about CASE but that cannot be used in WHERE clause i guess.

View 10 Replies View Related

PL/SQL :: Pipelined Function With Dynamic Query?

Nov 12, 2013

 Orcl Ver: 11g R2. I am leveraging the Oracle's pipelined table function.It's working fine for static SQL.  

create or replace package test13_pkg as type r_disc_req is record(disc_line_id number,              

req_id number);    type t_disc_req is table of r_disc_req;    function F_GetDiscReq return t_disc_req pipelined;     procedure P_ProcessDiscReq;end;  CREATE OR REPLACE PACKAGE BODY test13_pkgAS   FUNCTION F_GetDiscReq      RETURN t_disc_req      PIPELINED   IS      lo_disc_req   r_disc_req;   BEGIN      FOR r_row IN (SELECT disc_line_id, req_id                      FROM edms_disc_lines_stg                     WHERE ROWNUM < 10)      LOOP         lo_disc_req.disc_line_id := r_row.disc_line_id;         lo_disc_req.req_id := r_row.req_id;         PIPE ROW (lo_disc_req);  
   
[code]...

View 11 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved