简体   繁体   English

获取 scala 中匿名 pl/sql 块的结果

[英]Get result of anonymous pl/sql block in scala

I am calling a function in scala to truncate table.我在 scala 中调用 function 来截断表。 I am able to call a function and able to truncate a table as well.我可以调用 function 并且也可以截断表格。 But, I would also print the value of result.但是,我也会打印结果的值。 If the truncate is successfully then the function is returning 1 as Int and I would to like to print this value to make sure the operation is successful but I am not sure how to do it?如果截断成功,则 function 返回 1 作为 Int 我想打印此值以确保操作成功但我不知道该怎么做?

Query to call function:查询调用function:

truncQuery = "declare
                  result number;
              begin
                  result := TRUNCATE_TABLE('PROV');
              end;"

The value is being stored in the result but how can I print the result in the scala code below?该值存储在结果中,但如何在下面的 scala 代码中打印结果?

Code:代码:

def truncateTbl (truncQuery : String ): Unit ={

    val con = oracleUtil.auxdbOracleUtil()
    val callableStatement  = con.prepareCall(truncQuery)
    callableStatement.execute()

    callableStatement.close()
    con.close()

Your TRUNCATE_TABLE function must be like:您的 TRUNCATE_TABLE function 必须像:

CREATE OR REPLACE FUNCTION (PARAM_TABLE IN VARCHAR2)
RETURN NUMBER
AS
BEGIN
    EXECUTE IMMEDIATE 'TRUNCATE TABLE ' || PARAM_TABLE;
    RETURN 0
EXCEPTION
WHEN OTHERS THEN
    RETURN 1
END;
/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM