Recursive functions in Oracle SQL.

OK,
Here is the pivot problem. Only this time were on an Oracle 11.1.0.7.0.
I've created a table called:
CREATE TABLE STAGING.MY_TAB_COLS
  TABLE_NAME   VARCHAR2(30 BYTE),
  COLUMN_NAME  VARCHAR2(30 BYTE)
)And I've put the following data into it:
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAEADP1', 'SSN_SOURCE');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAEADP1', 'FIRST_NAME_SOURCE');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAEADP1', 'LAST_NAME_SOURCE');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAEADP1', 'DOB_SOURCE');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAEADP1', 'EMP_SSN_SOURCE');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAEADP1', 'EMP_FIRST_NAME_SOURCE');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAEADP1', 'EMP_LAST_NAME_SOURCE');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAEADP1', 'EMP_DOB_SOURCE');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAEADP1', 'MPI');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAEADP1', 'SSN_STANDARDIZED');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAEADP1', 'FIRST_NAME_A_STANDARDIZED');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAEADP1', 'FIRST_NAME_B_STANDARDIZED');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAEADP1', 'LAST_NAME_A_STANDARDIZED');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAEADP1', 'LAST_NAME_B_STANDARDIZED');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAEADP1', 'EMP_SSN_STANDARDIZED');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAEADP1', 'EMP_FIRST_NAME_A_STANDARDIZED');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAEADP1', 'EMP_FIRST_NAME_B_STANDARDIZED');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAEADP1', 'EMP_LAST_NAME_A_STANDARDIZED');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAEADP1', 'EMP_LAST_NAME_B_STANDARDIZED');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAMAET1', 'MPI_OLD');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAMAET1', 'EMPLOYEE_SSN_SOURCE');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAMAET1', 'EMPLOYEE_LAST_NAME_SOURCE');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAMAET1', 'EMPLOYEE_FIRST_NAME_SOURCE');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAMAET1', 'EMPLOYEE_DOB');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAMAET1', 'PATIENT_SSN');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAMAET1', 'PATIENT_LAST_NAME_SOURCE');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAMAET1', 'PATIENT_FIRST_NAME_SOURCE');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAMAET1', 'PATIENT_DOB');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAMAET1', 'EMPLOYEE_NON_SSN_ID');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAMAET1', 'EMPLOYEE_SSN_STANDARDIZED');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAMAET1', 'PATIENT_FIRST_NAME_A_STD');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAMAET1', 'PATIENT_FIRST_NAME_B_STD');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAMAET1', 'PATIENT_LAST_NAME_A_STD');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAMAET1', 'PATIENT_LAST_NAME_B_STD');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAMAET1', 'EMPLOYEE_FIRST_NAME_A_STD');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAMAET1', 'EMPLOYEE_FIRST_NAME_B_STD');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAMAET1', 'EMPLOYEE_LAST_NAME_A_STD');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAMAET1', 'EMPLOYEE_LAST_NAME_B_STD');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAMAET1', 'PATIENT_SSN_STANDARDIZED');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAMAET1', 'MPI');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAPMED1', 'EMPLOYEE_SSN');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAPMED1', 'EMPLOYEE_FIRST_NAME');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAPMED1', 'EMPLOYEE_LAST_NAME');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAPMED1', 'EMPLOYEE_DATE_OF_BIRTH');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAPMED1', 'PATIENT_SSN');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAPMED1', 'PATIENT_FIRST_NAME_SOURCE');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAPMED1', 'PATIENT_LAST_NAME_SOURCE');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAPMED1', 'PATIENT_DOB');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAPMED1', 'PRESCRIBER_LAST_NAME');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAPMED1', 'MPI');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAPMED1', 'PATIENT_FIRST_NAME_A_STD');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAPMED1', 'PATIENT_FIRST_NAME_B_STD');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAPMED1', 'PATIENT_LAST_NAME_A_STD');
Insert into STAGING.MY_TAB_COLS
   (TABLE_NAME, COLUMN_NAME)
Values
   ('AAPMED1', 'PATIENT_LAST_NAME_B_STD');My task for this problem is pretty straight forward.
Using the ALL_TAB_COLS table I want to list out certain fields for each table name specified.
All the tables have fields that are similar. I just want these table names to go across the top.
And the field names to list out under each table.
So you would have something like:
AAEADP1                         AAMAET1                     AAPMED1
SSN_SOURCE                      MPI_OLD                     EMPLOYEE_SSN
FIRST_NAME_SOURCE               EMPLOYEE_SSN_SOURCE         EMPLOYEE_FIRST_NAME
LAST_NAME_SOURCE                EMPLOYEE_LAST_NAME_SOURCE   EMPLOYEE_LAST_NAME
DOB_SOURCE                      EMPLOYEE_FIRST_NAME_SOURCE  EMPLOYEE_DATE_OF_BIRTH
EMP_SSN_SOURCE                  EMPLOYEE_DOB                PATIENT_SSN
EMP_FIRST_NAME_SOURCE           PATIENT_SSN                 PATIENT_FIRST_NAME_SOURCE
EMP_LAST_NAME_SOURCE            PATIENT_LAST_NAME_SOURCE    PATIENT_LAST_NAME_SOURCE
EMP_DOB_SOURCE                  PATIENT_FIRST_NAME_SOURCE   PATIENT_DOB
MPI                             PATIENT_DOB                 PRESCRIBER_LAST_NAME
SSN_STANDARDIZED                EMPLOYEE_NON_SSN_ID         MPI
FIRST_NAME_A_STANDARDIZED       EMPLOYEE_SSN_STANDARDIZED   PATIENT_FIRST_NAME_A_STD
FIRST_NAME_B_STANDARDIZED       PATIENT_FIRST_NAME_A_STD    PATIENT_FIRST_NAME_B_STD
LAST_NAME_A_STANDARDIZED        PATIENT_FIRST_NAME_B_STD    PATIENT_LAST_NAME_A_STD
LAST_NAME_B_STANDARDIZED        PATIENT_LAST_NAME_A_STD     PATIENT_LAST_NAME_B_STD
EMP_SSN_STANDARDIZED            PATIENT_LAST_NAME_B_STD   
EMP_FIRST_NAME_A_STANDARDIZED   EMPLOYEE_FIRST_NAME_A_STD   
EMP_FIRST_NAME_B_STANDARDIZED   EMPLOYEE_FIRST_NAME_B_STD   
EMP_LAST_NAME_A_STANDARDIZED    EMPLOYEE_LAST_NAME_A_STD   
EMP_LAST_NAME_B_STANDARDIZED    EMPLOYEE_LAST_NAME_B_STD   
                                PATIENT_SSN_STANDARDIZED   
                                MPI         Where each table name lists across with all of their column names under each table.
The query that I have so far is The following:
  SELECT   T1.TABLE_NAME, T1.COLUMN_NAME
    FROM   my_tab_cols t1, (  SELECT   DISTINCT UPPER (SOURCE_TABLE) TABLE_NAME
                                 FROM MPI_DEMOGRAPHICS_TEST
                             ORDER BY UPPER (SOURCE_TABLE)) tn
   WHERE   T1.TABLE_NAME = tn.TABLE_NAME
           AND (   T1.column_name LIKE '%MPI%'
                OR T1.column_name LIKE '%SSN%'
                OR T1.column_name LIKE '%E%SSN%'
                OR T1.column_name LIKE '%R%SSN%'
                OR T1.column_name LIKE '%P%SSN%'
                OR T1.column_name LIKE '%BIRTH%'
                OR T1.column_name LIKE '%DOB%'
                OR T1.column_name LIKE '%FIRST%NAME%'
                OR T1.column_name LIKE '%LAST%NAME%'
                OR T1.column_name LIKE '%CLIENT%NAME%'
                OR T1.column_name LIKE '%SOURCE_TABLE%'
                OR T1.column_name LIKE '%TABLE%')
ORDER BY   T1.TABLE_NAME, t1.column_id; It just list everything straight down.
Where the MPI_DEMOGRAPHIES_TEST table feeds the relevant table names to the ALL_TAB_COLS table.
It can just be substituted with a list of the values, AAEADP1, AAMAET1, AAPMED1.
Is there a 'pivot' function in Oracle 11.1 that I can use to list these column names out sideways as opposed to what I did before?
Thanks,

Hi,
Here's one way to get results like that using the Oracle 11 SELECT ... PIVOT feature:
WITH     got_nums     AS
     SELECT     column_name
     ,     ROW_NUMBER () OVER ( PARTITION BY  table_name
                               ORDER BY          column_name
                       )                    AS r_num
     ,     DENSE_RANK () OVER ( ORDER BY      table_name)     AS c_num
     FROM     my_tab_cols
        WHERE   column_name     LIKE '%MPI%'
        OR     column_name     LIKE '%SSN%'
--      OR     column_name     LIKE '%E%SSN%'          -- Included in '%SSN% above
--      OR     column_name     LIKE '%R%SSN%'          -- Included in '%SSN% above
--      OR     column_name     LIKE '%P%SSN%'          -- Included in '%SSN% above
        OR     column_name     LIKE '%BIRTH%'
        OR     column_name     LIKE '%DOB%'
        OR     column_name     LIKE '%FIRST%NAME%'
        OR     column_name     LIKE '%LAST%NAME%'
        OR     column_name     LIKE '%CLIENT%NAME%'
--      OR     column_name     LIKE '%SOURCE_TABLE%'     -- Included in %TABLE% below
        OR     column_name     LIKE '%TABLE%'
    UNION
        SELECT  table_name                         AS colum_name
     ,     0                              AS r_num
     ,     DENSE_RANK () OVER ( ORDER BY      table_name)     AS c_num
     FROM     my_tab_cols
SELECT       *
FROM       got_nums
PIVOT       (   MIN (column_name)
       FOR c_num     IN ( 1     AS table_1
                        , 2     AS table_2
                  , 3     AS table_3
ORDER BY  r_num
;Output:
R_NUM TABLE_1                        TABLE_2                        TABLE_3
    0 AAEADP1                        AAMAET1                        AAPMED1
    1 DOB_SOURCE                     EMPLOYEE_DOB                   EMPLOYEE_DATE_OF_BIRTH
    2 EMP_DOB_SOURCE                 EMPLOYEE_FIRST_NAME_A_STD      EMPLOYEE_FIRST_NAME
    3 EMP_FIRST_NAME_A_STANDARDIZED  EMPLOYEE_FIRST_NAME_B_STD      EMPLOYEE_LAST_NAME
    4 EMP_FIRST_NAME_B_STANDARDIZED  EMPLOYEE_FIRST_NAME_SOURCE     EMPLOYEE_SSN
    5 EMP_FIRST_NAME_SOURCE          EMPLOYEE_LAST_NAME_A_STD       MPI
    6 EMP_LAST_NAME_A_STANDARDIZED   EMPLOYEE_LAST_NAME_B_STD       PATIENT_DOB
    7 EMP_LAST_NAME_B_STANDARDIZED   EMPLOYEE_LAST_NAME_SOURCE      PATIENT_FIRST_NAME_A_STD
    8 EMP_LAST_NAME_SOURCE           EMPLOYEE_NON_SSN_ID            PATIENT_FIRST_NAME_B_STD
    9 EMP_SSN_SOURCE                 EMPLOYEE_SSN_SOURCE            PATIENT_FIRST_NAME_SOURCE
   10 EMP_SSN_STANDARDIZED           EMPLOYEE_SSN_STANDARDIZED      PATIENT_LAST_NAME_A_STD
   11 FIRST_NAME_A_STANDARDIZED      MPI                            PATIENT_LAST_NAME_B_STD
   12 FIRST_NAME_B_STANDARDIZED      MPI_OLD                        PATIENT_LAST_NAME_SOURCE
   13 LAST_NAME_A_STANDARDIZED       PATIENT_DOB                    PATIENT_SSN
   14 LAST_NAME_B_STANDARDIZED       PATIENT_FIRST_NAME_A_STD       PRESCRIBER_LAST_NAME
   15 LAST_NAME_SOURCE               PATIENT_FIRST_NAME_B_STD
   16 MPI                            PATIENT_FIRST_NAME_SOURCE
   17 SSN_SOURCE                     PATIENT_LAST_NAME_A_STD
   18 SSN_STANDARDIZED               PATIENT_LAST_NAME_B_STD
   19                                PATIENT_LAST_NAME_SOURCE
   20                                PATIENT_SSN
   21                                PATIENT_SSN_STANDARDIZEDIf you don't want to see the r_num column, use your front-end to hide it (e.g., in SQL*Plus: "COLUMN r_num NOPRINT"), or do the pivot in a sub-query, and only select table_1, table_2 and table_3 in the main query.
As with all pivots, you have to hard-code an upper bound to the number of pivoted columns. I used 3 above. You could use 4, or 5, or 45, but you must specify exactly how many columns to display.
If you say there will be 3 tables, and there actually are more than 3, then the query will still run, but all the tables after the first 3 will be ignored.
If you say there will be 3 tables, and there actually are fewer, then the query will still run, but you will have NULL columns at the end of each output row.
This sorts the output alphabetically by table_name and column_name. You can sort by anything you want by changing the analytic ORDER BY clauses. For example, if you are using all_tabl_columns and you want the columns to appear in order by column_id, then you would say:
,     ROW_NUMBER () OVER ( PARTITION BY  table_name
                          ORDER BY          column_id     -- instead of column_name
                  )                    AS r_num

Similar Messages

  • Convert columns to row equivalent to stragg function in oracle sql

    Hi,
    Sorry i forgot my Oracle version :
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for 64-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - ProductionI searched in google but i didn't found the solution.
    I looking for a function in discoverer equivalent to stragg sql function.
    Note : stragg function convert columns to rows.
    Thanks
    SELECT   deptno, stragg ('-' || ename)
        FROM emp_test
    GROUP BY deptno;
        DEPTNO STRAGG_STR                                                 
            10 -CLARK-KING-MILLER                                         
            20 -SMITH-FORD-ADAMS-SCOTT-JONES                              
            30 -ALLEN-BLAKE-MARTIN-TURNER-JAMES-WARD                      
    3 rows selected.Edited by: Salim Chelabi on 2010-01-29 08:32

    Hi again,
    *1- I created  my function in my schema.*
    CREATE OR REPLACE TYPE t_string_agg AS OBJECT
      g_string  VARCHAR2(32767),
      STATIC FUNCTION ODCIAggregateInitialize(sctx  IN OUT  t_string_agg)
        RETURN NUMBER,
      MEMBER FUNCTION ODCIAggregateIterate(self   IN OUT  t_string_agg,
                                           value  IN      VARCHAR2 )
         RETURN NUMBER,
      MEMBER FUNCTION ODCIAggregateTerminate(self         IN   t_string_agg,
                                             returnValue  OUT  VARCHAR2,
                                             flags        IN   NUMBER)
        RETURN NUMBER,
      MEMBER FUNCTION ODCIAggregateMerge(self  IN OUT  t_string_agg,
                                         ctx2  IN      t_string_agg)
        RETURN NUMBER
    SHOW ERRORS
    CREATE OR REPLACE TYPE BODY t_string_agg IS
      STATIC FUNCTION ODCIAggregateInitialize(sctx  IN OUT  t_string_agg)
        RETURN NUMBER IS
      BEGIN
        sctx := t_string_agg(NULL);
        RETURN ODCIConst.Success;
      END;
      MEMBER FUNCTION ODCIAggregateIterate(self   IN OUT  t_string_agg,
                                           value  IN      VARCHAR2 )
        RETURN NUMBER IS
      BEGIN
        SELF.g_string := self.g_string || ',' || value;
        RETURN ODCIConst.Success;
      END;
      MEMBER FUNCTION ODCIAggregateTerminate(self         IN   t_string_agg,
                                             returnValue  OUT  VARCHAR2,
                                             flags        IN   NUMBER)
        RETURN NUMBER IS
      BEGIN
        returnValue := RTRIM(LTRIM(SELF.g_string, ','), ',');
        RETURN ODCIConst.Success;
      END;
      MEMBER FUNCTION ODCIAggregateMerge(self  IN OUT  t_string_agg,
                                         ctx2  IN      t_string_agg)
        RETURN NUMBER IS
      BEGIN
        SELF.g_string := SELF.g_string || ',' || ctx2.g_string;
        RETURN ODCIConst.Success;
      END;
    END;
    SHOW ERRORS
    CREATE OR REPLACE FUNCTION string_agg (p_input VARCHAR2)
    RETURN VARCHAR2
    PARALLEL_ENABLE AGGREGATE USING t_string_agg;
    SHOW ERRORS
    *2- I ran my query in my schema with sqlplus.*
    SELECT deptno,ename,sal, string_agg(ename)over(partition by deptno) AS employees
    FROM   emp_test
    order by deptno;
        DEPTNO ENAME             SAL EMPLOYEES                                        
            10 CLARK            2450 CLARK,KING,MILLER                                
            10 KING             5000 CLARK,KING,MILLER                                
            10 MILLER           1300 CLARK,KING,MILLER                                
            20 JONES            2975 JONES,FORD,ADAMS,SMITH,SCOTT                     
            20 FORD             3000 JONES,FORD,ADAMS,SMITH,SCOTT                     
            20 ADAMS            1100 JONES,FORD,ADAMS,SMITH,SCOTT                     
            20 SMITH             800 JONES,FORD,ADAMS,SMITH,SCOTT                     
            20 SCOTT            3000 JONES,FORD,ADAMS,SMITH,SCOTT                     
            30 WARD             1250 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN             
            30 TURNER           1500 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN             
            30 ALLEN            1600 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN             
            30 JAMES             950 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN             
            30 BLAKE            2850 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN             
            30 MARTIN           1250 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN             
    14 rows selected.
    *3- I import this function in discoverer administration*
    4- My problem :When i use the function string_agg(ename)over(partition by deptno) in discover deskto i got the error you can't use over in this place.
    Any ideas.
    Thank in advance.
    Regards Salim.

  • MySQL functionality within Oracle SQL Developer Data Modeler

    Hi all,
    I've read a few forum posts here that lead me to believe that MySQL is not currently supported by the data modeler tool (Link #1 I got to by clicking on the Statement Of Direction link on the main page SQL Developer Data Modeler</title><meta name="Title" content="SQL Developer Data Modeler"&g… Link #2 I got to by doing a search on the word MySQL within the forum search):
    Link 1:
    SQL Developer Data Modeler Statement of Direction
    Link 2:
    Can datamodeler be used with MySQL?
    SQL Developer (not the Data Modeler tool, but the database admin-type tool not for modeling) does support MySQL using the latest MySQL Connector J 5.1 driver but, strangely,  it doesn't seem the Data Modeler supports it, though.  Can anyone please confirm that MySQL is currently unsupported for the Data Modeler tool?  Thanks in advance.

    Hi,
    it doesn't seem the Data Modeler supports it, though.
    Data Modeler doesn't have specific support for MySQL - i.e you cannot generate DDL for MySQL. Though you can import form MySQL server using JDBC connection in standalone DM or using created MySQL connection if you are using DM inside SQL Developer.
    You can import definitions for tables(columns, PK and UK constraints, indexes, foreign keys) and views.
    Philip

  • T-SQL functions in ORACLE

    Use T-SQL functions in ORACLE too, so you can write one script version that works in SYBASE, SQLSERVER and ORACLE when need to use the following functions:
    ceiling, charindex, dateadd, datediff, datename, datepart, day, db_id, db_name, getdate, host_id, host_name, left, len, month, replicate, right, space, str, str_replace, stuff, substring, suser_id, suser_name, user_id, user_name and year.
    The file [comp_tsql_ORA_schema.txt|http://forums.databasejournal.com/attachment.php?attachmentid=564&d=1258547015] creates the tablespace and schema to put the objects, and the file [comp_tsql_ORA.txt|http://forums.databasejournal.com/attachment.php?attachmentid=569&d=1259256898] creates the functions into the new schema. They will be avaliable for any schema of the oracle instance.
    Hope this help!
    Any suggestion please contact.
    aklein2003
    Edited by: user1958693 on 26/11/2009 10:16

    jgarry wrote:
    J2EE beta released around 1999. Religious programming wars far preceded that. Here's but [one example|http://groups.google.com/group/comp.lang.lisp/browse_thread/thread/1c50bc13e9302f00/34bb8f3ac77e2388?q=programming+language+religion#34bb8f3ac77e2388] from a quick google. I'm no longer convinced that elegance is a desirable trait for a language. So call me a heretic.
    Ever tried XLISP? :-)
    It's different. Back then it was simply the language itself. And it was not really a religious kind of battle, but more a mine-is-bigger-and-better-than-yours one.
    With Java, it is all about The Acrhitecture and the blessed language of Java. ;-)
    I wouldn't so much blame J2EE believers for that. I think there is a fundamental complexity to web type paradigms that hasn't been described in a precise and encompassing enough manner to enable correct project planning.The basic problem is that the database is treated as a persistent storage layer only. A bit bucket. And that is exactly what a database is not.
    But as it is used that, loads of database features now need to be duplicated in the application layer. Which is done. Very poorly.
    Heck, I've even been told that J2EE's 3-tier architecture is not client server. Such ignorance is really unbelievable. Or is it pure stupidity?Until you just made me look it up, I would have thought that too, I'm sure I saw client/server defined as two-tier in the last century. But I have much more stupid misdefinitions to deal with on a daily basis, simply from the multiplicity of paradigms. I tend to retreat into my shell. Hehehe. Know that feeling... These days I rather run away, or set shields to full power, than try to get in yet another frustrating, fruitless and futile discussion with a Java head about the wonders of the J2EE architecture. Or trying to explain that this "new" architecture is predated with what we used in the 80's on mainframe systems with transaction monitors, block devices (the 80's web browsers) and databases - which software layer for software layer was almost identical to "+The Great Architecture+" of today. (and we did it without buzzwords too) ;-)
    Client-server is a software architecture and in essence describes 3 basic software components. The User Interface (UI), the Application (APP) and the Database (DB). And there are various ways to put these components together in a client-server architecture. The mistake that the Java fanbois make is thinking that client-server means having the client as the UI and APP as a single component (so-called fat client) and then the DB component as the server.
    There are numerous versions of these - including the APP component being a server component (as we now these days more commonly used in over the web).
    My beef with the J2EE "+religion+" always has been that client-server is client-server. The fundamentals stay the same.

  • Oracle SQL Functions

    There's a function that does what I need.
    Can I pass parameters from ODI to Oracle SQL?
    Jz

    I will have to find out. The initial approach was to create a view and import via Knowledge Module...
    Do you think that would be a better approach?
    Jz

  • SQL Devloper Migration from SQL SerProcedurs created as Functions in Oracle

    Hi All,
    This is the first time I am using SQL Deveoper to migrate SQL Server database to Oracle.
    I have SQL Developer 3 and I did migration from SQL Sever 2008 to Oracle 10g using online migration.
    Everything was done perfectly, but there are some extra tables created in Oracle which are not present in SQL Server database.
    And also I observed lot of programs which are stored procedures in SQL Server are converted as functions in Oracle.
    Does someone knows how to fix this problem.
    Thanks

    Hi,
    A SQL*Server stored procedure can be converted to an Oracle function depending on how it is written and what it is doing. In the documentation -
    Oracle® SQL Developer
    Supplementary Information for Microsoft SQL Server and
    Sybase Adaptive Server Migrations
    In Chapter 3 in the section -
    3.4.2 Function
    It says under Table 3-6 -
    In Microsoft SQL Server or Sybase
    Adaptive Server, you can convert a stored
    procedure to a function in Oracle because
    the stored procedure in Microsoft SQL
    Server or Sybase Adaptive Server can
    RETURN an integer value to the calling
    routine using a RETURN statement. A
    stored procedure returns a status value to
    the calling routine even in the absence of
    a RETURN statement. The returned status
    is equal to ZERO if the procedure
    execution is successful or NON-ZERO if
    the procedure fails for some reason. The
    RETURN statement can return only
    integer values
    And what tables do you see in oracle that are not there in SQL*Server ? Some tables are created as part of the migration as they are needed to have the same functionality as in SQL*Server.
    Does your migrated Oracle database work in the same way as the SQL*Server database ? If not, then please give use specific examples and we can follow up.
    Regards,
    Mike

  • Need a function name for Sql and Oracle

    Retrieving value of next line by doing opteration in previous row.

    Can you rephrase the question? Or better yet, provide an example? I'm not sure I understand what you are asking.
    My best guess is that you are looking for the analytic functions LEAD or LAG in Oracle, assuming you are on a relatively recent Oracle version. If by "SQL and Oracle" in your subject you mean "SQL Server and Oracle" (SQL is a language that all relational databases implement, SQL Server is Microsoft's relational database), I have no idea how (or if) you can do something similar with a built-in function in SQL Server. You would want to post in a SQL Server group to see how they handle that sort of thing.
    Justin

  • Using an Oracle SQL Function from JPA/TopLink

    How do I get the return value from a simple (one string input parameter, returns a string) Oracle SQL Function?
    Thanks!

    If you mean calling a stored function in Oracle, you might try something like:
        ValueReadQuery vrq = new ValueReadQuery();
        SQLCall call = new SQLCall("begin ###res := pkg.funcInp(#inp); end;");
        vrq.setCall(call);
        Query q = em.createNativeQuery("");   // we need a Query; any query would do; we replace its contents below
        ((EJBQuery)q).setDatabaseQuery(vrq);
        q.setParameter("inp", "paramValue");
        String result = (String)q.getSingleResult();
        // #=input; ###=output; ####=input/output;
        // if you want to explicitly specify the type of an output parameter, use #### instead of ###,
        // because pure "output" parameters are always treated as java.lang.StringThis will only work in TopLink Essentials, though. I don't know how to do it in Hibernate. I have dealt mainly with TopLink, and just a little with Hibernate.
    In my opinion, it's a HUGE omission not to have support for stored procedures in JPA. Virtually every project I have worked on (in two large companies) has consisted of a large portion of code in stored procedures (sometimes as much as 50% of the overall code). It's a pain to have to go through all that trouble to call the stored procedures.
    Also, pay special attention to TopLink's shared L2 cache. If a stored procedure changes something in the database, TopLink won't know about it and chances are that you will end up with stale objects in the cache which you will either have to refresh, or you'd have to invalidate TopLink's cache for these objects.
    Best regards,
    Bisser

  • Oracle sql function to find VARCHAR2 data is numeric

    Hi Everyone,
    Is there oracle sql function to find whether the VARCHAR2 data is numeric?
    Thanks

    hi,
    see the below example .
    with t as
    (select '12'  as col from dual union all
    select '1 2'  as col from dual union all
    select '2 1 3'  as col from dual union all
    select 'abcde'  as col from dual union all
    select '12345'  as col from dual union all
    select '1a4A5'  as col from dual union all
    select '12a45'  as col from dual union all
    select '12aBC'  as col from dual union all
    select '12abc'  as col from dual union all
    select '12ab5'  as col from dual union all
    select '12aa5'  as col from dual union all
    select '12AB5'  as col from dual union all
    select 'ABCDE'  as col from dual union all
    select '123-5'  as col from dual union all
    select '12.45'  as col from dual union all
    select '1a4b5'  as col from dual union all
    select '1 3 5'  as col from dual union all
    select '1  45'  as col from dual union all
    select '1   5'  as col from dual union all
    select 'a  b  c  d'  as col from dual union all
    select 'a b  c   d    e'  as col from dual union all
    select 'a              e'  as col from dual union all
    select 'Steven'  as col from dual union all
    select 'Stephen'  as col from dual union all
    select '111.222.3333'  as col from dual union all
    select '222.333.4444'  as col from dual union all
    select '333.444.5555'  as col from dual union all
    select 'abcdefabcdefabcxyz'  as col from dual union all
    select 'aaa'  as col from dual union all
    select 'ddd'  as col from dual union all
    select 'ccc'  as col from dual union all
    select 'aaaaa'  as col from dual union all
    select 'aaaaaaaa'  as col from dual
    select * from t where regexp_like(col,'[1-9]')
    Result
    COL
    12
    1 2
    2 1 3
    12345
    1a4A5
    12a45
    12aBC
    12abc
    12ab5
    12aa5
    12AB5
    123-5
    12.45
    1a4b5
    1 3 5
    1  45
    1   5
    111.222.3333
    222.333.4444
    333.444.5555Thanks,
    P Prakash

  • How can i migrate Power Builder 8.0 Function into oracle PL/SQL

    Hi Oracle Experts...
    How can i migrate Power Builder 8.0 Function into oracle PL/SQL.. I had migrate some of the coding from PB to PL/SQL. But i don't know how can i convert PB structure(here structure is a data type) into oracle PL/SQL.
    Instead of structure what is the equivalent in oracle plsql
    Below i pasted my POWER BUILDER FUNCTION:
    Long ll_perd,ll_lnperd,ll_mon,ll_effmon,ll_instno,ll_odno
    Decimal{5} ldl_actual,ldl_diff,ldl_inst
    Datetime ldt_first,ldt_exp,ldt_oddt, ldt_lastprod
    String ls_instmode,ls_inst
    str_batch lstr_od //Structure to store odamt and oddate
    Select pay_c_final,lon_d_expiry, lon_d_lastprod
    Into     :ls_inst,:ldt_exp, :ldt_lastprod
    From      loan_mast
    Where branch_c_code = :gs_branch and
              act_c_type      = :as_actype and
              act_c_no           = :as_acno;
    If Sqlca.Sqlcode = -1 Then
         f_message('FT-0189',Sqlca.Sqlerrtext)
         lstr_od.batchslno = -1
         Return lstr_od
    End If
    If adt_prodt > ldt_exp Then
         Select Ceil(months_between(:adt_prodt,:ldt_exp)) Into :lstr_od.batchslno From dual;
         lstr_od.cheqdt = ldt_exp
         lstr_od.batchslno = DaysAfter(Date(ldt_lastprod), Date(adt_prodt))
    Else
         If ls_inst = 'N' Then
              If adt_prodt > ldt_exp Then
                   Select Ceil(months_between(:adt_prodt,:ldt_exp)) Into :lstr_od.batchslno From dual;
                   lstr_od.cheqdt = ldt_exp
              Else
                   lstr_od.batchslno = 1
              End If
         ElseIf ls_inst = 'Y' Then
              Select first_d_due,lon_c_instperd,lon_n_perd
              Into     :ldt_first,:ls_instmode,:ll_lnperd
              From     loan_mast
              Where branch_c_code = :gs_branch and
                        act_c_type      = :as_actype and
                        act_c_no          = :as_acno;
              If Sqlca.Sqlcode = -1 Then
                   f_message('FT-0189',Sqlca.Sqlerrtext)
                   lstr_od.batchslno = -1
                   Return lstr_od // Return Structure
              End If
              Select Ceil(months_between(:adt_prodt,:ldt_first)) Into :ll_mon from dual;
              If ll_mon > 0 Then
                   Select Nvl(ln_n_balance,0),Nvl(ln_n_instlamt,0),Nvl(ln_n_instlno,0)
                   Into     :ldl_actual,:ldl_inst,:ll_instno
                   From     loan_inst_sch
                   Where act_c_type = :as_actype and
                             act_c_no     = :as_acno and
                             ln_d_effdate = (Select Max(ln_d_effdate)
                                                           From     loan_inst_sch
                                                           Where act_c_type = :as_actype and
                                                                     act_c_no     = :as_acno and
                                                                     ln_d_effdate < :adt_prodt);
                   If Sqlca.Sqlcode = -1 Then
                        f_message('FT-0224', Sqlca.Sqlerrtext)
                        lstr_od.batchslno = -1
                        Return lstr_od
                   ElseIf Sqlca.Sqlcode = 100 Then
                        lstr_od.batchslno = 1
    *                    Return lstr_od*
                   End If
                   If adl_bal > ldl_actual Then
                        If ldl_inst > 0 Then
                             lstr_od.batchslno = (adl_bal - ldl_actual) / ldl_inst
                        End If
                   Else
                        lstr_od.batchslno = 1
                   End If     
                   If lstr_od.batchslno = 0 Then lstr_od.batchslno = 1
                   //For full OD
                   If ll_mon > ll_lnperd Then
                        lstr_od.batchslno = (ll_mon - ll_lnperd) + lstr_od.batchslno
                   End If
                   If ls_instmode = 'Q' Then
                        lstr_od.batchslno = lstr_od.batchslno * 3
                   ElseIf ls_instmode = 'H' Then
                        lstr_od.batchslno = lstr_od.batchslno * 6
                   ElseIf ls_instmode = 'Y' Then
                        lstr_od.batchslno = lstr_od.batchslno * 12
                   End If
                   Select :adt_prodt - :lstr_od.batchslno Into :lstr_od.cheqdt From dual;
                   If ls_instmode = 'M' Then
                        ll_odno = ll_instno - lstr_od.batchslno // To get OD Date
                        Select ln_d_effdate
                        Into     :lstr_od.cheqdt
                        From     loan_inst_sch
                        Where act_c_type = :as_actype and
                                  act_c_no     = :as_acno and
                                  ln_n_instlno = :ll_odno;
                        If Sqlca.Sqlcode = -1 Then
                             f_message('FT-0224', + Sqlca.Sqlerrtext)
                             lstr_od.batchslno = -1
                             Return lstr_od
                        End If
                   End If
              Else
                   lstr_od.batchslno = 1
              End If
         End If
    End if
    Return lstr_od
    Thanks in adance
    Arun M M

    What are you going to return the structure to? What I would normally use here if the code was going to be used by other PL/SQL would be a PL/SQL object type.
    However, if PowerBuilder is still in the equation (you're moving the logic to PL/SQL but keeping PowerBuilder for the GUI ), then you'll have to return something else, because PowerBuilder doesn't understand PL/SQL object types. Perhaps passing a REF CURSOR as a OUT argument and populating it from the procedure. PowerBuilder could then retrieve the result of the procedure using a stored procedure based DataWindow.

  • Calling SQL Server Function from Oracle Database link

    Hi ,
    i have some data from a old SQL server i would i can access with a database link but i cant call function from my database link.
    i would like to do something like
    @SPAN_PROD = Database link
    _EnerttObtApReelBassSys is a Table function from my SQL server
    SELECT *
    FROM "_EnerttObtApReelBassSys('20120504',4,1)"@SPAN_PROD
    WHERE DateEffectiveDebut <= GetDate()
    AND DateEffectiveFin > GetDate()
    any help ?
    Thnx

    951879 wrote:
    I have a SP in SQL Server which will return a Result Set.
    My requirement is to call that procedure in ORACLE using DB Link and insert that resultset(Data) in the temp table.First you need to setup Oracle to SQL Server connectivity. To do that you can either use HS - heterogeneous connectivity which comes for free or use Oracle Transparent Gateway which is not free. HS uses ODBC, so if your Oracle database in not on windows, you'll have to get ODBC SQL Server driver for Unix/Linux (e.g. from EasySoft). Since SQL Server selecting from table function syntax is different from Oracle's you will have to, if you use HS, to use DBMS_HS_PASSTHROUGH package. I never worked with Oracle Transparent Gateway to SQL Server, so I don't know if and how it supports selecting from SQL Server table function.
    SY.

  • How to call java function from PL/sql in oracle applications

    I am trying to call a java function from plsql procedure. Can any one explain how to call java function, and in which directory I have to store my java function in oracle applications. Do I need to register that java function from Application developer.
    Thanks
    Kranthi

    http://www.oracle.com/technology/tech/java/jsp/index.html
    Good Luck,
    Avi.

  • How I work with MS-SQL function in oracle

    I’m working in oracle now but I don’t know how can I use following function in oracle.
    convert, dateadd, datediff, fetch_status, isnumeric, reverse, str and stuff

    Also available in 10g, the model clause version, taken from this How to display text in reverse order ?.
    WITH t AS (SELECT 'abcdefg' col1
                 FROM DUAL
                UNION
               SELECT ''
                 FROM DUAL   )
    SELECT col1
         , new_col1
      FROM t       
    MODEL
       PARTITION BY (ROWNUM rn)
       DIMENSION BY (0 dim)
       MEASURES     (col1, CAST ('' AS VARCHAR2(255)) new_col1)
       RULES ITERATE(99) UNTIL (LENGTH(new_col1[0]) = LENGTH(col1[0]))
          (new_col1[0] = SUBSTR(col1[0], ITERATION_NUMBER + 1, 1) || new_col1[0])
    COL1    NEW_COL1
    abcdefg gfedcbaC.

  • Error of passing of oracle.sql.ARRAY in PL/SQL function at work under OC4J

    Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)
    Error occured at working with DataSource based on com.evermind.sql.DriverManagerDataSource and oracle.jdbc.pool.OracleDataSource.
    Error:
    java.lang.AbstractMethodError: com.evermind.sql.OrclCMTConnection.physicalConnectionWithin()Loracle
    /jdbc/internal/OracleConnection;
    at oracle.sql.TypeDescriptor.setPhysicalConnectionOf(TypeDescriptor.java:660)
    at oracle.sql.TypeDescriptor.<init>(TypeDescriptor.java:212)
    at oracle.sql.ArrayDescriptor.<init>(ArrayDescriptor.java:376)
    at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:237)
    at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:192)
    at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:177)
    at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:114)
    What to do?
    Thank you.

    The issue is resolved by change classes12dms.jar for OC4J. The jdbc driver was changed from version (read from manifest):
    Manifest-Version: 1.0
    Specification-Title: Oracle JDBC driver classes for use with JDK12
    Created-By: 1.4.2_08 (Sun Microsystems Inc.)
    Implementation-Title: classes12dms_g.jar
    Specification-Vendor: Oracle Corporation
    Specification-Version: Oracle JDBC Driver version - "10.2.0.1.0"
    Implementation-Version: Oracle JDBC Driver version - "10.2.0.1.0"
    Implementation-Vendor: Oracle Corporation
    Implementation-Time: Wed Jun 22 19:11:35 2005
    to:
    Manifest-Version: 1.0
    Name: javax/sql/ConnectionEvent.class
    Digest-Algorithms: SHA MD5
    SHA-Digest: GQ5KFq39ybZzmgVThMOVSb6DDL8=
    MD5-Digest: uryrGtwsbgYBwoQDl0I85A==
    Name: javax/sql/ConnectionEventListener.class
    Digest-Algorithms: SHA MD5
    SHA-Digest: gh9/m94g05tRid8f4mhmEnJ5als=
    MD5-Digest: x63DZ5tPqdiCaLP0z1GHew==
    Probably the Oracle has compiled OC4J with other version of this library.

  • Function sequence error / Recursive functions error

    Hi! I've a little problem over here. I have an application (servlet) that makes recursive functions with DB access. This function contains a resultset that calls the same function again until no more data is found. The problem, is that I'm using JDBC-ODBC bridge (because this must work in SQL Server, Informix, Sybase, Access and Oracle), so I need to make commit of the connection in every resultset. If I make the commit inside the resultset, I got a "Function Sequence error" exception. Of course, I can't close every statement inside the resultset (or at least I don't know how). My code looks like this:
    public void myfunction(String odbc,String data1,String data2) throws SQLException,Exception{
         //this class, myclassDB, just return a established connection with the DB
         Connection connection = myclassDB.connect(odbc);
         Statement statement = connection.createStatement();
         ResultSet rs = statement.executeQuery("query");
         while(rs.next()){
              //do something with the information
              //make recursive
              connection.commit();
              myfunction(odbc,data1,data2);
         statement.close();
         connection.close();
    }Hope you can help me!
    Feel free to email me at [email protected]
    Regards!     

    I am not really sure what the question is but...
    Presuming that there isn't something wrong with your design (which recursive calls suggest) then you need to extract all of the data, close the resultset/statement then do the recursive calls. If you do processing first then you can still commit on the connection.

Maybe you are looking for