Passing SQL in a variable
In a nutshell, user selects a bunch of radio buttons to
search. On the next page, I try to put that information into
queryable form:
<cfif frm_int_interest_ind neq "">
<cfset search_frm_int_interest_ind = "(">
<cfloop index="el" list="#frm_int_interest_ind#">
<cfset search_frm_int_interest_ind =
"#search_frm_int_interest_ind#'#el#',">
</cfloop>
<cfset len_search_frm_int_interest_ind =
"#len(search_frm_int_interest_ind)#">
<cfset search_frm_int_interest_ind =
"#Left(search_frm_int_interest_ind,
evaluate(len_search_frm_int_interest_ind - 1))#">
<cfset search_frm_int_interest_ind =
"#search_frm_int_interest_ind#)">
<!--- Now that the list is properly formatted, set up the
query string --->
<cfset queryvariables = "AE_int.int_interest_ind
in#search_frm_int_interest_ind#">
</cfif>
<cfquery name="Entrepreneur_Int_search"
datasource="#AlumDS#">
SELECT *
FROM Alumni A JOIN Alumni_Entrepreneur_Int AE_int
On A.User_Login = AE_int.User_Login
Where
#queryvariables#
</cfquery>
The error that gets returned is: Diagnostics: ODBC Error Code
= 37000 (Syntax error or access violation)
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 6:
Incorrect syntax near '1'.
The cfdump (and cfoutput) of #queryvariables# is:
AE_int.int_interest_ind
in('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19', '20','21','22','23','24','25')
which I can cut and copy into the cfquery tag and execute
just fine.
I assume something is wrong with the #queryvariables# format,
but trying evaluate or de has not worked.
Also, if there is a more elegant way to handle building the
sql, I'd appreciate the suggestion(s).
Thanks,
Chris
The PreserveSingleQuotes function will probably work.
Similar Messages
-
Script fails when passing values from pl/sql to unix variable
Script fails when passing values from pl/sql to unix variable
Dear All,
I am Automating STATSPACK reporting by modifying the sprepins.sql script.
Using DBMS_JOB I take the snap of the database and at the end of the day the cron job creates the statspack report and emails it to me.
I am storing the snapshot ids in the database and when running the report picking up the recent ids(begin snap and end snap).
From the sprepins.sql script
variable bid number;
variable eid number;
begin
select begin_snap into :bid from db_snap;
select end_snap into :eid from db_snap;
end;
This fails with the following error:
DB Name DB Id Instance Inst Num Release Cluster Host
RDMDEVL 3576140228 RDMDEVL 1 9.2.0.4.0 NO ibm-rdm
:ela := ;
ERROR at line 4:
ORA-06550: line 4, column 17:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
( - + case mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current exists max min prior sql stddev sum variance
execute forall merge time timestamp interval date
<a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
The symbol "null" was substituted for ";" to continue.
ORA-06550: line 6, column 16:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
( - + case mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current exists max min prior sql stddev su
But when I change the select statements below the report runs successfully.
variable bid number;
variable eid number;
begin
select '46' into :bid from db_snap;
select '47' into :eid from db_snap;
end;
Even changing the select statements to:
select TO_CHAR(begin_snap) into :bid from db_snap;
select TO_CHAR(end_snap) into :eid from db_snap;
Does not help.
Please Help.
TIA,
NischalHi,
could it be the begin_ and end_ Colums of your query?
Seems SQL*PLUS hs parsing problems?
try to fetch another column from that table
and see if the error raises again.
Karl -
Issue with passing schema name as variable to sql file
Hi,
I have a scenario wherein from SYS a Java process (Process_1) is invoking SQL files and executing the same in SQLPLUS mode.
DB: Oracle 11.2.3.0
Platform: Oracle Linux 5 (64-bit)
Call_1.sql is being invoked by Java which contains the below content:-
ALTER SESSION SET CURRENT_SCHEMA=&&1;
UPDATE <table1> SET <Column1> = &&1;
COMMIT;
@Filename_1.sql
Another process (Process_2) again from SYS user is also accessing Filename_1.sql.
The content of Filename_1.sql is:-
DECLARE
cnt NUMBER := 0;
BEGIN
SELECT COUNT(1) INTO cnt FROM all_tables WHERE table_name = 'TEST' AND owner = '&Schema_name';
IF cnt = 1 THEN
BEGIN
EXECUTE IMMEDIATE 'DROP TABLE TEST';
dbms_output.put_line('Table dropped with success');
END;
END IF;
SELECT COUNT(1) INTO cnt FROM all_tables WHERE table_name = 'TEST' AND owner = '&Schema_name';
IF cnt = 0 THEN
BEGIN
EXECUTE IMMEDIATE 'CREATE TABLE TEST (name VARCHAR2(100) , ID NUMBER)';
dbms_output.put_line('Table created with success');
END;
END IF;
End;
Process_2 uses "&Schema_Name" identifier to populate the owner name in Filename_1.sql. But Process_1 needs to use "&&1" to populate the owner name. This is where I am looking a way to modify Call_1.sql file so that it can accommodate both "&&1" to populate owner name values in Filename_1.sql (with avoiding making any changes to Filename_1.sql).
Any help would be appreciated.
Thanks.Bad day for good code. Have yet to spot any posted today... Sadly, yours is just another ugly hack.
The appropriate method for using SQL*Plus substitution variables (in an automated fashion), is as command line parameters. Not as static/global variables defined by some other script ran prior.
So if a script is, for example, to create a schema, it should look something as follows:
-- usage: create-schema.sql <schema_name>
set verify off
set define on
create user &1 identified by .. default tablespace .. quota ... ;
grant ... to &1;
--eof
If script 1 wants to call it direct then:
-- script 1
@create-schema SCOTT
If script 2 want to call it using an existing variable:
-- script 2
@create-schema &SCHEMA
Please - when hacking in this fashion, make an attempt to understand why the hack is needed and how it works. (and yes, the majority of SQL*Plus scripts fall into the CLI hack category). There's nothing simple, beautiful, or elegant about SQL*Plus scripts and their mainframe roots. -
SQL Task Expression: SQL Command using variable tables
Hello,
I've got a question I hope someone could help me out with. I'm working on a SSIS project that basically synchronises logins of a Source and Destination server that are part of an AlwaysOn Cluster.
The idea is as followed: On the source server there are variable tables created named Logins_<SourceServerName>_To_<DestinationServerName> for example. This one is filled with all the login information from that server, then on the Destination
server the same table is created and the data is transfered. The Source and Destination server names are project variables.
Once all data is copied I use a set of code from the dba_CopyLogins script I got from SQLSoldier (http://www.sqlsoldier.com/wp/sqlserver/transferring-logins-to-a-database-mirror) to create the missing logins on the Destination server.
What I've found is that I can't use expressions to handle the code, at least I haven't found a way yet, expression evaluation will give an error on (for example) the following code:
Begin
Set @SQL = 'Create Login ' + quotename(@LoginName)
If @Type In ('U', 'G')
Begin
Set @SQL = @SQL + ' From Windows;'
End
Else
Begin
Set @PasswordHashString = '0x' +
Cast('' As XML).value('xs:hexBinary(sql:variable("@PasswordHash"))', 'nvarchar(300)');
Set @SQL = @SQL + ' With Password = ' + @PasswordHashString + ' HASHED, ';
Set @SIDString = '0x' +
Cast('' As XML).value('xs:hexBinary(sql:variable("@SID"))', 'nvarchar(100)');
Set @SQL = @SQL + 'SID = ' + @SIDString + ';';
End
I've tried various things to get this to work as an expression, however I seem to continue to get the error:
The expression might contain an invalid token, an incomplete token, or an invalid element. It might not be well-formed, or might be missing part of a required element such as a parenthesis.
So the next thing I tried was just using the script as Direct input with Parameter Mapping on the tables but I've got the error:
Must declare the table variable "@P1".
All the way up to @P12. Since we're talking about 12 variables that are in the script in total. But they are table variables and apparently Parameter mapping is not possible on table variables or am I wrong here? Pieces of code for example are:
Set @MaxID = (Select Max(LoginID) From ?)
Set @CurrID = (Select Min(LoginID) From ?)
I hope there's someone who could help me out or at least can give me a direction to look into.
Yes we could use the script provided, but we don't want to work with LinkedServers, besides I'd have to make local jobs on the servers instead of controlling it all from 1 centralised server.
Thank for looking at the topic and I hope you have a clue about what to do...
Regards,
DannyThe code you posted is a t-sql code. If you want to store it inside ssis variable syntax is different. As per what you say what might be best would be to warp above code inside a procedure and then call it from SSIS execute sql task after passing values
through SSIS variable
also for
Set @MaxID = (Select Max(LoginID) From ?)
etc
create variable in SSIS, set EvaluateAsExpression true and set expression as
"Select Max(LoginID) AS MaxID From " + @[User::TableName]
Where TableName is SSIS variable through which you pass the table name. Then use above statement inside execute sql task and set resultset option as single row and map resultset to SSIS variable (say @[User::MaxID]) to get return value
similarly for other statements
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
Passing values to global variables while running job via management console
Hi All,
I have a requirement, where I have to use HANA view with input parameters as source. I am doing the same by placing the HANA query for view with input parameters, in SQL transform and assigning values to placeholders using global variables. This is working fine at the designer level.
But where I am stuck is, it possible to pass values to global variables while running job in Management console or in a third party scheduler. Should I do any changes in the batch job to achieve the same ?
Please help me with the same and also let me know whether my approach of using Global variables to assign values to input parameter of HANA view is right?
Thanks,
DeepaSelect Batch > Batch Job Configuration > Add Schedule and Expand the Global Variables section in the Schedule Batch Job tab. You can then specify a value for all your global variables.
Alternatively, work with control tables and assign values to the global variables in an initialisation script. -
Is it possible to pass a subquery with variable value ?
Hi
Is it possible to pass a subquery with variable as date ....which inturn is used to retrieve the value from the main query .
For ex, this query is used to obtain the forecast details based on month and i need to obatain the month value from the sub query where the user need to select the forecast date as one of the parameter
select OFCT.Name,Fct1.ItemCode,sum(fct1.Quantity) as S_Qty,month(Fct1.date)as For_Month
from Fct1,OFct
where Fct1.absid = ofct.absid
and fct1.ItemCode = '26259939'
and month(fct1.date) in (select month(fct1.date)from fct1 where fct1.date =<b> '[1%]'</b>)
Hope somebody will respond
Regards
MiniHi Owen,
I have tried this query in Query Generator after trying it SQL Query Analyzer for syntax error as you had mentioned ,
The query i have tried and is working with Analyser is :
select OFCT.Name,Fct1.ItemCode,sum(fct1.Quantity) as S_Qty,month(Fct1.date)as For_Month
from Fct1,OFct
where Fct1.absid = ofct.absid
and FCT1.ItemCode = '4/4650017/2'
and month(fct1.date) = '11'
group by FCT1.itemcode,OFCT.NAme,FCT1.date
In Query Generator when i try the same query,the Itemcode and Month need to be entered as variable, Iam able to take the item.Even the variable window shows me the Forecast date but the query throws an error 8180.
Any help will be appreciated.
Thank you
Mini -
Passing value to bind variable of another table from one table
hi,
I have a multi select table. When one row is selected from this table (no button is clicked, only selection is done), an attribute from that selected row (say userid) should be passed to the bind variable of another table and the corresponding details of that particular userid should be displayed in the other table. When more than one row is selected, the other table should display no rows.
My main problem is what code has to be written to pass value to bind variable and where it should be written.
Please give me a detailed explaination as soon as possible.
Thank you.Sorry, didnot add this. The table is multi select table.
-
Pass a Value to Variable from the unix environment in ODI (ELT)
Hi
i am very new to ODI environment.
i want know how to pass a value to variables in oracle data integrator from unix environment.
Example:
Variable name : Sales
for variable name sales i want to pass the value from unix environment.
Regards,
Raj
Edited by: user11137587 on Aug 19, 2009 6:26 AMWork Around !
You can execute OS commands using Jython script. Probably you need to flush your enviornment variables value into a file using jython script and then read those value into ODI variable from the file.
BUt may I know why you want to read environment variable vaules in ODI, Dont you think this will make your application less portable
Regards,
Amit -
Can i pass parameter or global variable in view from 6i form
hi master
sir can i pass parameter or global variable in view from 6i form
i use view for some diff column calculation within the date then i use
where date between data1 and date2
in view but view not create
please give me idea how i pass external value in view
thank
aamirHi Antony!
I feel it may not produce the right results if you
dont include the where clause and using only group by
in view.You felt? Please clear, logical thoughts put here, not feelings.
(It may very well have all the Debit, Credit
for all the Accid where as the user wants only for
r some date range)Data range is determinated in Form by user, so if view should give final data set then you must back
on Ranjana first question: How to pass parameter or global variable to view from 6i form?
And also as Ranjit pointed out, If you have only
accid, sum(debit), sum(credit) in View, wheres this
enddate ??Of course, column entdate (or enddate?) must be included in view...
Cheers! -
How to use lengthy query in a "SQL Command from Variable"
My oracle SQL Query length is more than 14000 characters, so how can i use this for "SQL command from variable".
SarvanEither create a view or a table valued UDF. Using stored procedure in OLEDB source has some gotchas it will not pick up metadata information by default due to late binding.
http://consultingblogs.emc.com/jamiethomson/archive/2006/12/20/SSIS_3A00_-Using-stored-procedures-inside-an-OLE-DB-Source-component.aspx
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Problems in SQL transform with variable in statement
Hi,
I have an sql transform with a variable in the statement. It looks like this:
SELECT * FROM I.X where I.X.CUSTOMERNUMBER IN ([$variable])
I have a script running prior which sets the $variable = '\'366800\',\'000933\'';
(the CUSTOMERNUMBER field is a string)
The problem is when DI compiles the SQL with the variable value, it is replacing each single quote with two single quotes, and thus turning my list of values into a single string (as recognised by DB2).
How can I work around this? The CUSTOMERNUMBER field is indexed and the table is very large, so I want to use a very efficient statement to retrieve the data. I'm inserting this data into a different database, so I can't use the sql() function to execute the query and insert the rows into a new table in the same database (don't have authority to do that).
I also need the sql to be dynamic because the customer numbers required will change from time to time. They're listed in another database and I plan on writing a loop to set the $variable value to contain all values in the lookup table, but I can't use that in a join because its in a different database and would not be efficient.
Does anyone have any ideas? I'm literally all out, have tried a wide range of things to no avail, and none of my colleagues can work it out either.
Thanks very much,
-SteveI assume the SQL Transform is used only because of that in-list, not for other reasons....
In this book page here: https://boc.sdn.sap.com/node/20046 at the very bottom it isdescribed on how to use the pushdown_sql() function in a where clause to add *any* text of your choice into the select statement DI generates. In this example I used a "where exists" but you can easily change the text to
where key=5 and pushdown_sql('my_datastore', 'CUSTOMERNUMBER IN ([$variable])') and gender='M'
I used the key=5 and gender=M just to clarify the syntax (I hope).
For the SQL Transform, I wonder if you need the [$variable] syntax as well.... -
Dynamically Pass sql query in Database adapter
hi',
How can we dynamically pass sql query in Database adapter, is there any way, I am using SOA 11G.
Thanks
YatanHi,
Tried that too. No luck. Gives me this.
The selected operation process could not be invoked.
An exception occured while invoking the webservice operation. Please see logs for more details.
oracle.sysman.emSDK.webservices.wsdlapi.SoapTestException: Exception occured when binding was invoked.
Exception occured during invocation of JCA binding: "JCA Binding execute of Reference operation 'selectUsingIn' failed due to: Pure SQL Exception.
Pure SQL Execute of select interface_id, property_name, property_value from ( (?) ) failed.
Caused by java.sql.SQLSyntaxErrorException: ORA-00903: invalid table name
The invoked JCA adapter raised a resource exception.
Please examine the above error message carefully to determine a resolution.
Regards,
Neeraj Sehgal -
Passing SQL Server identity attributes values into adf entity objects
Hi all.
I'm using Jdeveloper 10g for developing an ADF Swing application based on MS SQL Server DB.
Does anyone know if it is possible to pass SQL Server identity attributes values into the correspondent attrributes of adf entity objects, like we do with Oracle DB Sequence.
The problem is that i should somhow implement cascade deleting of detail view objects, so i should use the composition association. But since i cant fill the primary key attribute with appropriate value (that is actually a ms sql server db sequence value) i always get
the following exception: oracle.jbo.InvalidOwnerException: JBO-25030 as i try to create a new pair of master/detail objects.
Thanks in advance.
Alex.The approach is good. but i still dont understand how i can address the sql server db sequence (identity field) programmatically...
The code offered
SequenceImpl sequence = new SequenceImpl("PRODUCTS_SEQ",getDBTransaction());
setProdId(sequence.getSequenceNumber());
generates something like this:
select deq_name.nextval from dual
but this syntax works for oracle only... and not for sql server...
Edited by: Timin on Mar 26, 2009 6:34 AM
Edited by: Timin on Mar 26, 2009 10:25 AM -
Can the output of a Generate Occurrence be passed in Local/Global Variable?
Can the output of a Generate Occurrence function, which is a refnum, be passed in Local/Global Variable so that it does not need to be wired to all parties directly?
Can more than one party be waiting on the same Occurrence and will all waiting function be released together?dbaechtel wrote:
Answer was not given:
Can the output of a Generate Occurrence function, which is a refnum, be passed in Local/Global Variable so that it does not need to be wired to all parties directly? Is this possible?
I am not worried about whether it is bad form or not, as yet. That is for me to decide on a case by case basis.
Yikes! That is not a very good way to learn.
Anyways, to avoid any more bold emphasis on words, I will answer your question. Locals can only be linked to controls/indicators not individual wires. If you want to get the effect of a local/global variable with a wire value, search the forum for action engines or functional globals. Those will work for passing a wire value between threads.
That said, what are you trying to use occurences for? There may be (and probably is) a more accepted way to implement what you are trying to do instead of using local variables
CLA, LabVIEW Versions 2010-2013 -
SQL*LOADER(8I) VARIABLE SIZE FIELD를 여러 TABLE에 LOAD하기 (FILLER)
제품 : ORACLE SERVER
작성날짜 : 2004-10-29
==================================================================
SQL*LOADER(8I) VARIABLE SIZE FIELD를 여러 TABLE에 LOAD하기 (FILLER)
==================================================================
PURPOSE
SQL*LOADER 에서 variable length record와 variable size field를 가진 data
file 을 여러 table에 load하는 방법을 소개하고자 한다.
( 8i new feature인 FILLER 절 사용)
Explanation
SQL*LOADER SYNTAX
여러 table에 load하고자 할때에는 control file에 아래와 같이 하면 된다.
INTO TABLE emp
INTO TABLE emp1
fixed length field을 가진 data file을 여러 table에 같은 data을 load하고자
한다면 아래와 같다.
INTO TABLE emp
(empno POSITION(1:4) INTEGER EXTERNAL,
INTO TABLE emp1
(empno POSITION(1:4) INTEGER EXTERNAL,
위와 같이 양쪽 table의 empno field에 각각의 load할 data로부터 1-4까지를
load 할수 있다. 그러나 field의 길이가 가변적이라면 위와 같이 POSITION 절을
각 field에 사용할 수 없다.
Example
예제 1>
create table one (
field_1 varchar2(20),
field_2 varchar2(20),
empno varchar(10) );
create table two (
field_3 varchar2(20),
empno varchar(10) );
load할 record가 comma로 나누어지며 길이가 가변적이라고 가정하자.
<< data.txt >> - load할 data file
"this is field 1","this is field 2",12345678,"this is field 4"
<< test.ctl >> - control file
load data infile 'data.txt'
discardfile 'discard.txt'
into table one
replace
fields terminated by ","
optionally enclosed by '"' (
field_1,
field_2,
empno )
into table two
replace
fields terminated by ","
optionally enclosed by '"' (
field_3,
dummy1 filler position(1),
dummy2 filler,
empno )
dummy1 field는 filler로 선언되었다. filler로 선언하면 table에 load하지 않는다.
two라는 table에는 dummy1이라는 field는 없으며 position(1)은 current record의
처음부터 시작해서 첫번째 field을 dummy1 filler item에 load한다는 것을 말한다.
그리고 두번째 field을 dummy2 filler item에 load한다. 세번째 field인, one이라는
table에 load되었던 employee number는 two라는 table에도 load되는 것이다,
<< 실행 >>
$sqlldr scott/tiger control=test.ctl data=data.txt log=test.log bindsize=300000
$sqlplus scott/tiger
SQL> select * from one;
FIELD_1 FIELD_2 EMPNO
this is field 1 this is field 2 12345678
SQL> select * from two;
FIELD_3 EMPNO
this is field 4 12345678
예제 2>
create table testA (c1 number, c2 varchar2(10), c3 varchar2(10));
<< data1.txt >> - load할 data file
7782,SALES,CLARK
7839,MKTG,MILLER
7934,DEV,JONES
<< test1.ctl >>
LOAD DATA
INFILE 'data1.txt'
INTO TABLE testA
REPLACE
FIELDS TERMINATED BY ","
c1 INTEGER EXTERNAL,
c2 FILLER CHAR,
c3 CHAR
<< 실행 >>
$ sqlldr scott/tiger control=test1.ctl data=data1.txt log=test1.log
$ sqlplus scott/tiger
SQL> select * from testA;
C1 C2 C3
7782 CLARK
7839 MILLER
7934 JONES
Reference Documents
<Note:74719.1>
Maybe you are looking for
-
I seriously have tried everything, from turning it on to plugging in the charger... It WON"T TURN ON and I am freaking out.
-
Applications Not Appearing in Workspace (9.3.1)
Hello all, We recently upgraded to system 9.3.1 and intermittently users are not seeing the applications when logging into Workspace. Example: USER A logs in to Workspace, is able to perform all necessary duties by logging on to the application for d
-
Create addon under bussiness partner menu
hi, i already created an addon. i want to install that addon under business partner meni item tab. its urgent. Regards, Puneeth S
-
MacBook Pro's Black Cleaning Cloth Dye Bleeding!
Been gently washing my black cleaning cloth which came with my 2011 MBP with lukewarm water and gentle dish soap for over a year now and it is still bleeding the black dye. I am a little concerned. For the premium price people pay for these noteboo
-
Changing account settings from G/L account into reconciliation account
Dear all, Could you please help me solve the following problem: We've got such settings in productive system so that open items were formed on GL account in spite of the fact that it was not a reconciliation account for creditors. Is there any way to