1

我有一个以下存储过程:

create or replace
PROCEDURE "SP_UTILITIES_LOG"
(
p_utility_name IN varchar2,
p_r_object_id IN varchar2,
p_platform_name IN varchar2,
p_exported_file_path IN varchar2,
p_Is_binary IN number,
p_extraction_status IN varchar2,
p_extraction_error IN varchar2,
p_extraction_datetime IN VARCHAR2,
p_schema_name IN varchar,
p_publication_path IN varchar,
p_schema_tcm_id IN varchar,
p_component_tcm_id IN varchar,
p_component_name IN varchar,
p_loading_status IN varchar,
p_transformed_file_path IN varchar,
p_transformed_status IN varchar,
p_import_status IN varchar,
p_loading_error IN varchar,
p_transform_error IN varchar,
p_import_error IN varchar,
p_loading_datetime IN TIMESTAMP,
p_transform_datetime IN TIMESTAMP,
p_import_datetime IN TIMESTAMP

)
   IS  
   BEGIN

    IF(p_utility_name ='EXTRACTION')
    THEN
    BEGIN
   INSERT INTO utilities_log(R_OBJECT_ID,
PLATFORM_NAME,
EXPORTED_FILE_PATH,
IS_BINARY,
EXTRACTION_STATUS,
EXTRACTION_ERROR,
EXTRACTION_DATETIME
)
   VALUES(p_r_object_id, p_platform_name,p_exported_file_path, p_is_binary, p_extraction_status, p_extraction_error, p_extraction_datetime); 

    END;
    END IF;


    IF(p_utility_name ='LOADING')
    THEN
    BEGIN

    UPDATE UTILITIES_LOG SET schema_name=p_schema_name,
    publication_path= p_publication_path,
    schema_tcm_id= p_schema_tcm_id,
    component_tcm_id= p_component_tcm_id,
    component_name= p_component_name,
    loading_status= p_loading_status,
    loading_error= p_loading_error,
    loading_datetime= current_timestamp
    WHERE
    r_object_id= p_r_object_id;

    END;
    END IF;


    IF(p_utility_name ='PRE-TRANSFORMATION')
    THEN
    BEGIN
    SELECT exported_file_path,component_tcm_id FROM utilities_log
    WHERE
    platform_name= p_platform_name and loading_status=p_loading_status
    and extraction_status=p_extraction_status;


    END;
    END IF;


    IF(p_utility_name ='TRANSFORMATION')
    THEN
    BEGIN
    UPDATE UTILITIES_LOG SET 
    transformed_file_path= p_transformed_file_path,
    transformed_status= p_transformed_status,
    transform_error= p_transform_error,
    transform_datetime= current_timestamp
    WHERE
    exported_file_path= p_exported_file_path;

    END;
    END IF;

    IF(p_utility_name ='RETRIEVE')
    THEN
    BEGIN
    execute immediate 'create global temporary table temp_import as SELECT transformed_file_path,publication_path
    FROM utilities_log
    WHERE
    platform_name= p_platform_name';

    END;
    END IF;

    IF(p_utility_name ='IMPORTER')
    THEN
    BEGIN
    UPDATE UTILITIES_LOG SET 
    import_status=p_import_status,
    import_error=p_import_error,
    import_datetime=current_timestamp
    WHERE
    publication_path= p_publication_path;
    END;
    END IF;


   END;

我收到错误“选择”语句中缺少“Into”子句...有什么帮助吗?谢谢

4

3 回答 3

1
IF(p_utility_name ='RETRIEVE') THEN
BEGIN
  execute immediate 'create global temporary table temp_import 
  as SELECT transformed_file_path,publication_path     
     INTO temp_import
     FROM utilities_log     
     WHERE platform_name= p_platform_name'
END     
END IF

我认为

于 2012-06-15T13:45:23.697 回答
1

正确的方法是(将一组查询结果从 sp 返回到 c#),是使用 oracle 提供的 Ref Cursor 类型。你可以在这里这里看到它是如何实现的

编辑:
它应该看起来像这样(我这里没有甲骨文,但你可以很容易地检查这个):

create or replace PROCEDURE "SP_UTILITIES_LOG" ( 
p_utility_name IN varchar2, 
p_r_object_id IN varchar2, 
/* your other parameters */
p_refcur out sys_refcursor /* notice the out parameter */
)
AS
BEGIN
/* one sample from your select*/
IF(p_utility_name ='PRE-TRANSFORMATION')
 THEN     
 BEGIN     
      OPERN p_refcur FOR 
      SELECT exported_file_path,component_tcm_id FROM utilities_log     
      WHERE     platform_name= p_platform_name 
     AND        loading_status=p_loading_status      
     AND extraction_status=p_extraction_status;       
 END;     
 END IF; 
END;
于 2012-06-15T13:52:53.227 回答
1

错误消息与此有关:

IF(p_utility_name ='PRE-TRANSFORMATION')
THEN
BEGIN
SELECT exported_file_path,component_tcm_id FROM utilities_log
WHERE
platform_name= p_platform_name and loading_status=p_loading_status
and extraction_status=p_extraction_status;
END;
END IF;

在 PL/SQL 块中,必须将数据选择到某些内容中,因此您需要声明一些变量,然后执行以下操作:

SELECT exported_file_path,component_tcm_id
INTO <local_exported_file_path_var>, <local_component_tcm_id_var>
FROM utilities_log
...

然后,您可以在 SP 的其他地方使用这些变量,目前您似乎不需要这些变量,因此完全不确定您为什么要选择这些变量。或者具有OUT可以选择它们的参数,以便调用者可以访问它们,但您也没有这样做。

不应在 Oracle 中动态创建临时表,因此整个概念似乎很混乱。如果您尝试将数据表返回给调用者,那么正如@YavgenyP 所说,请查看 ref 游标。不太确定你想要做什么。

于 2012-06-15T15:30:15.333 回答