Mittwoch, 10. September 2014

Example: Kopieren einer Tabelle per PL/SQL-Block

DECLARE
  l_sql           varchar2(32767);
  c_tab_comment   varchar2(32767);
  PROCEDURE run(p_sql varchar2) AS
  BEGIN
    execute immediate p_sql;
 
  END;
BEGIN
  run('create table EMP_TMP as select * from EMP where ' || 11 ||
      ' = 1');
  select comments
    into c_tab_comment
    from sys.all_TAB_comments
   where owner = 'TEST'
     and table_name = 'EMP'
     and comments is not null;
  run('comment on table TEST.EMP is ' || '''' || c_tab_comment || '''');

  for tc in (select column_name
               from sys.all_tab_cols
              where owner = 'TEST'
                and table_name = 'EMP') loop
    for c in (select comments
                from sys.all_col_comments
               where owner = 'TEST'
                 and table_name = 'EMP'
                 and column_name = tc.column_name) loop
      run('comment on column TEST.EMP.' || tc.column_name ||
          ' is ' || '''' || c.comments || '''');
    end loop;
  end loop;
EXCEPTION
  WHEN OTHERS THEN
    NULL;
END;

########################################################

CREATE TABLE new_table
  AS (SELECT *
      FROM old_table WHERE 1=2);

aus:
[http://www.techonthenet.com/sql/tables/create_table2.php]

APEX als Rapid Application Development Tool

http://www.heise.de/developer/artikel/Oracle-APEX-Rapid-Application-Development-Werkzeug-fuer-Webanwendungen-227214.html

https://blogs.oracle.com/apexcommunity_deutsch/de/


Freitag, 29. August 2014

Error Handling / Exceptions

Oracle® Database PL/SQL Language Reference 11g Release 2 (11.2)

http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/errors.htm#LNPLS007

Uni Potsdam - Wiki (Stefan Uhlmann)

http://fara.cs.uni-potsdam.de/~uhlmann/19/ch09.html


Freitag, 22. August 2014

For Cursor Loop - Example

  set serveroutput on;
  --
  DECLARE
    v_anzahlDS NUMBER(20);
  BEGIN
    FOR n IN (SELECT owner, table_name
                FROM all_tables
               WHERE owner = 'SCOTT' order by 1)
    LOOP
      execute immediate 'select count(*) from '|| n.owner ||'.'|| n.table_name INTO v_anzahlDS;
      dbms_output.put_line(n.table_name || '   ' || v_anzahlDS);
    END LOOP;
  END;