[英]how can i send an anonymous block to oracle and get result from oracle in coldfusion
In coldfusion, how can I send an anonymous block to oracle and get some response from oracle? 在Coldfusion中,如何将匿名块发送到oracle并从oracle得到一些响应? I tried cfquery , but it doesn't work.
我尝试了cfquery ,但它不起作用。 Great thanks.
万分谢意。
@Antony, I know i can write anonymous block in cfquery. @Antony,我知道我可以在cfquery中写匿名块。 Such as:
如:
<cfquery name="queryName" datasource="oracle11ghr" result="queryName_meta">
BEGIN
INSERT INTO npr_t_reservation(reservation_id) VALUES(33);
INSERT INTO npr_t_reservation(reservation_id) VALUES(34);
UPDATE npr_t_reservation set reservation_id=35 WHERE reservation_id=34;
COMMIT;
END;
</cfquery>
In fact what i did not know is how can i get some return value from sending anonymous block to oracle. 实际上,我不知道的是如何从将匿名块发送到oracle中获得一些返回值。
@Antony, Hi Antony, the upper code is just a demonstration. @Antony,嗨,安东尼,上面的代码只是一个演示。 In fact what I want to get from anomynous is of simple datatype, not collections or object type instance.
实际上,我想从无意识中获得的只是简单的数据类型,而不是集合或对象类型实例。 Such as VARCHAR2, NUMBER etc.
例如VARCHAR2,NUMBER等。
@APC, I don't use some kind of stored program because I'm not allowed to save it into the database. @APC,我不使用某种存储程序,因为不允许将其保存到数据库中。 So why I want to use an anonymous block to do the database work?
那么,为什么要使用匿名块来完成数据库工作呢? Because I need to do a lot of database related work.
因为我需要做很多与数据库相关的工作。 If I do these work in coldfusion it will be complicated and trivial.
如果我在Coldfusion中进行这些工作,将会变得复杂而琐碎。
Can you not include a SELECT query in there to return your value? 您不能在其中包含SELECT查询以返回您的值吗?
<cfquery name="queryName" datasource="oracle11ghr" result="queryName_meta">
BEGIN
INSERT INTO npr_t_reservation(reservation_id) VALUES(33);
INSERT INTO npr_t_reservation(reservation_id) VALUES(34);
UPDATE npr_t_reservation set reservation_id=35 WHERE reservation_id=34;
COMMIT;
SELECT myReturnValue AS RETURN_VALUE FROM dual;
END;
</cfquery>
<cfoutput>#queryName.RETURN_VALUE#</cfoutput>
There's no standard method that springs to mind to do this, though I can think of one really f****d up way of trying it that I would never put into production myself. 尽管我可以想到一种真正尝试过的方法,但我自己绝不会自己生产这种标准方法,但是没有想到的标准方法。 I think you might be stuck with using SQL to return your value, separate from the anonymous block.
我认为您可能会坚持使用SQL来返回您的值(与匿名块分开)。
It's a shame about the restrictions on stored procedures. 对存储过程的限制感到遗憾。 You might try making the case that your procedures could be in a different schema to the data so that they are logically isolated.
您可以尝试使过程与数据位于不同的架构中,从而使它们在逻辑上是隔离的。
if you are using a version of coldfusion that supports the cfide.adminapi you can do something like this: 如果您使用的是支持cfide.adminapi的Coldfusion版本,则可以执行以下操作:
<cfquery name="insData" datasource="datasourcename">
insert into maytable
(column1)
values
(42)
</cfquery>
<cfscript>
adminObj = createObject("component","cfide.adminapi.administrator");
adminObj.login("password");
adminDbugObj = createObject("component","cfide.adminapi.debugging");
// getDebugRecordset() returns a query object.
// "name", "datasource" and "body" are three of its columns.
q = #adminDbugObj.getDebugRecordset()#;
</cfscript>
<cfloop query="q">
<cfif name EQ "insData" and datasource EQ "datasourcename">
<cfoutput>#rowcount#</cfoutput>
<cfabort>
</cfif>
</cfloop>
I would also use the cftransaction/cftry/cfcatch tag with commit/rollback rather than an anonymous block and separate the queries into their own cfquery block. 我还将cftransaction / cftry / cfcatch标记与commit / rollback一起使用,而不是使用一个匿名块,并将查询分成各自的cfquery块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.