Code Monkey home page Code Monkey logo

Comments (3)

mickeypearce avatar mickeypearce commented on June 2, 2024

@Danieleeee , Oradew uses DBMS_METADATA.get_ddl function to import objects by default. This functionality can be customized with setting "import.getDdlFunction" in oradewrc.json in a way that you write your own function on DB that will be used by Oradew to import objects. This function should have 3 parameters - first 3 paramaters of DBMS_METADATA.get_ddl (example bellow).

To add a terminator at the end of each imported object you could make a function on your DB as follows, for example:

FUNCTION my_get_ddl (
  object_type         IN VARCHAR2,
  name                IN VARCHAR2,
  schema              IN VARCHAR2 DEFAULT NULL
RETURN CLOB
is
begin
  -- transform parameter to add / terminator at the end
  DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'SQLTERMINATOR', true);
  -- call get_ddl to return object ddl
  return DBMS_METADATA.get_ddl(object_type, name, schema);
end;

and then add a property with "import.getDdlFunction": "my_get_ddl" to your oradew project (oradewrc.json).

Similiarly you could eliminate "EDITIONABLE" from packages, if a transform parameter exists, otherwise replace content returned by get_ddl function with:
replace(l_ddl, 'create or replace editionable', 'create or replace') or something similar as a last resort. :)

from oradew-vscode.

Danieleeee avatar Danieleeee commented on June 2, 2024

I used your procedure inserted in the code generator, very useful.

function getDdl(
    object_type IN VARCHAR2, 
    name IN VARCHAR2, 
    schema IN VARCHAR2 DEFAULT NULL
  ) return clob is
    l_clob    clob := NULL;
    l_clob_header clob := 'CREATE OR REPLACE ';
    l_name VARCHAR2(100) := name;
    l_object_type VARCHAR2(100) := case object_type 
      when 'PACKAGE_SPEC' then 'PACKAGE' 
      when 'PACKAGE_BODY' then 'PACKAGE BODY' 
      when 'TYPE_SPEC' then 'TYPE' 
      when 'TYPE_BODY' then 'TYPE BODY' 
      else object_type
    end;
  begin
  
    -- dbms_metadata.get_ddl doesn't return objects outside my home schema
    -- all_source does (?)
    -- this is why we are going down this path
    
    dbms_lob.createtemporary(l_clob,true);      
    if l_object_type in ('VIEW', 'TRIGGER', 'TABLE') then         
      /*for rec in (
        select text
        from all_views
        where
          view_name = l_name
          and owner = schema    
      )loop    
        l_clob := rec.text;
       end loop;  */
       -- too hard !! for now as these object has different headers
       l_clob := dbms_metadata.get_ddl(l_object_type, name, schema);
    else
      for rec in (
        select text, line
        from all_source
        where
        name = l_name
        and owner = schema
        and type = l_object_type
        order by line      
      )loop      
        if rec.line = 1 then        
          --Add "create or replace" and schema
          --\s* - white spaces  
          l_clob := REGEXP_REPLACE (rec.text, '^(' || l_object_type|| '\s*)', l_clob_header || l_object_type|| ' "' || schema || '".', 1, 0, 'i'); 
          --Add " to object name, if it doesn't exists already
          --  1, 0,'i' - case insensitive
          l_clob := REGEXP_REPLACE (l_clob, '"?' || l_name || '"?', '"' || l_name || '"', 1, 0, 'i');         
        else
          dbms_lob.writeappend(l_clob, length(rec.text), rec.text);
        end if;
      end loop;    
    end if;
    dbms_lob.writeappend(l_clob, length('/'), '/');
    return l_clob;
  end getDdl;

from oradew-vscode.

mickeypearce avatar mickeypearce commented on June 2, 2024

Ow, I forgot about this one!

from oradew-vscode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.