如何将代码格式化为'' || chr(10)||使用plsql开发人员

时间:2015-09-02 12:04:13

标签: oracle plsql formatting plsqldeveloper

我需要将大量代码转换为以下格式:

'MERGE INTO employees emp' || chr(10) ||    
'USING (SELECT * FROM (SELECT (SELECT VALUE 
FROM departments 
WHERE CNTRY_CDE = ''100'' 
AND NAME = ''Scott'') BATCH_ID, SUBJECT_ID,' || chr(10) ||  

因为此代码作为clob数据插入到表中。 有没有办法做到这一点?

以上给出的代码就是我的样本。

1 个答案:

答案 0 :(得分:0)

如果我理解正确,你有一个类似

的SQL语句
'MERGE INTO employees emp USING (SELECT * FROM (SELECT (SELECT VALUE FROM departments WHERE CNTRY_CDE = ''100'' AND NAME = ''Scott'') BATCH_ID, SUBJECT_ID,'

你希望它看起来像

'MERGE INTO employees emp' || chr(10) || 'USING (SELECT * FROM (SELECT (SELECT VALUE FROM departments WHERE CNTRY_CDE = ''100'' AND NAME = ''Scott'') BATCH_ID, SUBJECT_ID,' || chr(10) ||

尽管我对此的实用性存有疑虑,但我认为实现它的一种方法如下:

declare 
  strOldstmt VARCHAR2(2000) := 'MERGE INTO employees emp USING (SELECT * FROM (SELECT (SELECT VALUE FROM departments WHERE CNTRY_CDE = ''100'' AND NAME = ''Scott'') BATCH_ID, SUBJECT_ID,';
  strNewstmt VARCHAR2(2000);
begin
  -- Test statements here

  DBMS_OUTPUT.PUT_LINE('strOldstmt=''' || strOldstmt || '''');

  strNewstmt := REPLACE(strOldstmt, 'USING', ''' || CHR(10) || '' USING') || ''' || CHR(10) || ';

  DBMS_OUTPUT.PUT_LINE('strNewstmt=''' || strNewstmt || '''');
end;

这里的问题是这个特定的陈述非常具体,这可能不适用于其他陈述;但是,它确实适用于您已经给出的示例,而且我无法猜测您的更一般要求可能是什么。

祝你好运。