Different plsql for different Oracle versions

Hi everyone,
I am working on a plsql script which may be run on multiple databases. Unfortunately, I have a need to run one query type if the version is 10g, and another if it is 9i. The 10g query is preferable for the type & amount of information it returns, but 9i does not have the same level of support. I wrote the below (dumbed down for posting purposes) to do this:
spool sqlLog.txt append
set heading off;
SET NEWPAGE 0;
SET SPACE 0;
SET LINESIZE 32767;
SET PAGESIZE 0;
--SET ECHO OFF;
SET FEEDBACK OFF;
SET VERIFY OFF;
SET HEADING OFF;
SET MARKUP HTML OFF;
SET TERMOUT OFF;
SET TRIMOUT ON;
SET TRIMSPOOL ON;
SET WRAP OFF ;
SET LONG 4000;
SET LONGCHUNKSIZE 500;
set serverout on;
set serveroutput on;
declare     
ver VARCHAR2(64);
BEGIN
select v.version into ver from product_component_version v where product like '%Oracle%';
ver:=substr(ver,0,2); --remove anything but the highest version number, a.k.a. 9 or 10.
dbms_output.put_line('ver: '||ver);
--10g
IF to_number(ver)>=10
THEN
     for csr_10g in (SELECT sql_fulltext, a.parsing_schema_name, b.name, b.value_string
                         FROM V$SQL a left outer join v$sql_bind_capture b ON a.SQL_ID = b.SQL_ID)
          loop
            dbms_output.put_line(csr_10g.sql_fulltext||';'|| csr_10g.parsing_schema_name||';'|| csr_10g.name||';'|| csr_10g.value_string);
         end loop;
ELSE
--9i
     for csr_9i in (SELECT a.sql_Text, b.Schemaname
                         FROM v$sqlarea a left outer join v$session b ON a.parsing_schema_id=b.schema#
          loop
            dbms_output.put_line(csr_9i.sql_text||';'|| csr_9i.schemaname||';');
         end loop;
END IF;
END;
--run;
spool off;
exit;If I run this on a 10g database, it works correctly, spooling the query return to a file.
If I run this on a 9i database, it will not run, and i get these errors:
                         FROM V$SQL a left outer join v$sql_bind_capture b ON a.SQL_ID = b.SQL_ID --combine to also find the bound variables used
ERROR at line 13:
ORA-06550: line 13, column 35:
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 12, column 17:
PL/SQL: SQL Statement ignored
ORA-06550: line 27, column 30:
PLS-00364: loop index variable 'CSR_10G' use is invalid
ORA-06550: line 27, column 9:
PL/SQL: Statement ignored
Am I doing something wrong with my syntax, or is there another way to go about this?
Thanks!

Hi,
Dynamic SQL, like John suggested, might be the most elegant solution, but here are some others to consider:
(1) Create dummy objects. Your code guarantees that you'll never get a run-time error trying to query v$sql in Oracle 9, but the problem is that you're getting a compile-time error just by referencing it. So create a v$sql: a dummy table in your own schema, a synonym to the Oracle 10 data dictionary via a database link, anything just so it compiles.
(2) Create real objects. For example, in your Oracle 9 database, create a view called v$sql, based on v$sqlarea and v$session, that has all the same columns you use in Oracle 10. If you can do this, you won't even need an IF statement in your PL/SQL; the same code that runs against the data dictionary v$sql in Oracle 10 will run against your own schema's v$sql in Oracle 9.
(3) Isolate the problems. Write two different versions of a package, one for each version, and put all version-dependent code in the package. In most of your code, call the procedure to do the version-dependent stuff. For example, don't open a cursor in your program: instead, call the package to open a cursor.
(4) Comment Out. Klugy but cute. Write your PL/SQL without IF statements, like this:
BEGIN
&v10     for csr_10g in (SELECT sql_fulltext, a.parsing_schema_name, b.name, b.value_string
&v10                         FROM V$SQL a left outer
&v9     for csr_9i in (SELECT a.sql_Text, b.Schemaname
&v9                         FROM v$sqlarea a left outer join v$session b ON a.parsing_schema_id=b.schema#
&v9                                                                                  join v$sql_bind_capture b ON a.SQL_ID = b.SQL_ID)
          loop
&v10            dbms_output.put_line(csr_10g.sql_fulltext||';'|| csr_10g.parsing_schema_name||';'|| csr_10g.name||';'|| csr_10g.value_string);
&v9            dbms_output.put_line(csr_9i.sql_text||';'|| csr_9i.schemaname||';');
         end loop;
END;Compile your PL/SQL in SQL*Plus.
Define two substitution variables: v10 and v9.
In Oracle 10, v10 make " " and make v9 "--".
In Oracle 9, v10 make "--" and make v9 " ".
You can do the assignments on the fly with the SQL*Plus "COLUMN ... NEW_VALUE" command.
In either database, code that only works in the other version will be commented out. Your code will look like hell (good spacing and comments will make it less hard to read), but it will compile and work.
None of these ideas are mutually exclusive. You might want to do dynamic SQL in some places, and use on dummy objects in others, for example.

Similar Messages

  • DBConnect with two different oracle versions

    Hullo folks,
    I've been looking for threads concerning the use of SAP BI's DBConnect tool with multiple external oracle databases.
    My client is currently using BI 3.5 and we have successfully used DBConnect to extract information from an external Oracle 9.2.0.5.0 database (btw BW uses the same oracle version).
    Currently my customer requests to extract information from a new external non-sap application. This application will be using an oracle database as well, but it will use the latest oracle version, 10.
    I know that in the past it wasn't possible to use DBConnect with different oracle versions as the differences were to big. I wonder whether this is also the case with the oracle 9 and 10 versions. Would it be possible to use both versions and extract the data with DBConnect? Or are the changes too big and SAP BW can only pick one of these versions? Perhaps there's a workaround? I don't know, and I'm hoping some of you know something.
    Thanks in advance.

    Thanks for your answer,
    though this doesn't answer my question. Yes, I know I'll have to create a different sourcesystem for the new oracle database.
    However, I can only use one ini file for Oracle in DBConnect. In the past it wasn't possible to have active connections with different versions of oracle databases (you can only have one file for oracle installed in DBConnect).
    The question is, whether it's possible to have a connection with two source systems where one uses Oracle 10 and the other Oracle 9... and if it's possible which file should be used in DBConnect...
    Remi

  • Different Oracle versions Replication?

    Hello,
    We want to create a replication in our laptop.
    The server has oracle 9i rel.1. In the laptop we want to install oracle 9i rel. 2.
    Can we replicate part of the database using different Oracle DBMS versions?
    As a comment: The replication is SDE information.
    Thanks,

    Hi;
    Please see:
    Client / Server / Interoperability Support Between Different Oracle Versions [ID 207303.1]
    Re: Replication between 8i and 10g
    Regard
    Helios

  • Transportable tablespace accross different oracle versions

    Hi
    Do I need same oracle versions if I want to transport tablespaces ?
    i.e Can I transport tablespaces from oracle9i to oracle 11g ? or from oracle 10g to oracle 11g ?
    I read the documents however Im still confused.

    Thanks, I have read the document and notice that from oracle 10g and onwards I can transport tablespaces accross different oracle versions.
    I think we can change the endian format via rman hence no need to have same endian format
    "Beginning with the Oracle10g database, a tablespace can always be transported to a database with the same or higher compatibility setting, whether the target database is on the same or a different platform."

  • Dbstart & different oracle versions

    I have a couple different versions of oracle running on one box (9.2.0.4, 9.2.0.7 & 10.2.0.2).
    The dbstart being called is in the 9.2.0.4 directory. It failed to start the instances in 9.2.0.7 when the machine was last restarted.
    If I call the 10.2.0.2 dbstart, will it start all the instances (for all 3 versions)?
    Also, is it true that 9.2.0.4 dbstart will not start 9.2.0.7?
    I don't have a reliable way to test this as I can't restart nodes.
    Thanks!

    Which ever dbstart you call, it will look for oratab to choose the correct ORACLE_HOME, ORACLE_SID etc..
    Therefore, all dbstart should work for all instances on the server, if you make the oratab entry correct.
    # On Solaris
    # ORATAB=/var/opt/oracle/oratab
    # All other UNIX platforms
    # ORATAB=/etc/oratab
    # Entries are of the form:
    # $ORACLE_SID:$ORACLE_HOME:<N|Y>:
    # The first and second fields are the system identifier and home
    # directory of the database respectively. The third filed indicates
    # to the dbstart utility that the database should , "Y", or should not,
    # "N", be brought up at system boot time.
    #

  • ORA-00979: not a GROUP BY expression on different oracle version

    Hi,
    I tried below sql on different database and I'm having a strange result.
    error is ORA-00979: not a GROUP BY expression
    SELECT COUNT(*) OVER() CNT,
    COUNT(member_id) AS cnt2,
    etoc_type,
    journal_id,
    volume_id,
    issue_id,
    current_registered_users,
    date_sent,
    date_order,
    (COUNT(member_id) -
    (Select Count( *)
    FROM oracjoc.email_alert_bounce_backs bb
    WHERE aa.journal_id = bb.journal_id
    AND aa.volume_id = bb.volume_id
    AND aa.issue_id = bb.issue_id
    AND aa.etoc_type = bb.etoc_type
    AND aa.date_sent = TO_CHAR(bb.date_sent, 'ddMonYYYY')
    )) delivered
    FROM
    (SELECT member_id,
    etoc_type,
    journal_id,
    volume_id,
    issue_id,
    current_registered_users,
    TO_CHAR(date_sent, 'ddMonyyyy') date_sent,
    To_Number(To_Char(Date_Sent, 'yyyymmdd')) Date_Order
    FROM oracjoc.Report_Issue_Alert
    WHERE Etoc_Type = '1'
    ) Aa
    GROUP BY Journal_Id,
    Volume_Id,
    Issue_Id,
    Etoc_Type,
    Current_Registered_Users,
    Date_Order,
    Date_Sent
    ORDER BY date_order DESC
    Oracle version:
    Oracle Database 11g Release 11.1.0.7.0 - 64bit Production: I got failed result on this one
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production: sql was successfully executed.
    Can someone explain is this still a part of bug on non enterprise edition?, TIA!

    919272 wrote:
    Hi,
    I tried below sql on different database and I'm having a strange result.
    error is ORA-00979: not a GROUP BY expressionRead the full error message. It has also a row and a column number specified. Use this number to find out which column gives you the trouble.
    I see that there are several not needed date to char conversions. I could imaging that they confuse the query merge mechanism. Other than that: try to strip down the query to the smallest posisble set of colum combination. So that you can see where the error comes from.
    SELECT COUNT(*) OVER() CNT,
    COUNT(*) AS cnt2,
    etoc_type,
    journal_id,
    volume_id,
    issue_id,
    current_registered_users,
    date_sent2,
    (COUNT(*) -
      (Select Count( *)
        FROM oracjoc.email_alert_bounce_backs bb
        WHERE aa.journal_id = bb.journal_id
        AND aa.volume_id = bb.volume_id
        AND aa.issue_id = bb.issue_id
        AND aa.etoc_type = bb.etoc_type
        AND aa.date_sent2 = trunc(bb.date_sent)
        )) delivered
    FROM  (SELECT member_id, etoc_type, journal_id, volume_id, issue_id, current_registered_users,
           trunc(date_sent) date_sent2,
    FROM oracjoc.Report_Issue_Alert
    WHERE Etoc_Type = '1'
    ) Aa
    GROUP BY Journal_Id, Volume_Id, Issue_Id, Etoc_Type, Current_Registered_Users, Date_Sent2
    ORDER BY Date_Sent2 DESC

  • Dbms_xmldom.writetoclob.different result on different oracle version.

    Hi all,
    I have a problem using dbms_xmldom.
    please give me an advise.
    take a look here.
    ora-06502 when using xmltype
    thanks

    Thasleem;
    This will depend upon type of Standby.
    For Logical is is possible, for Physical no.
    Here's a supporting MOS document :
    Mixed Oracle Version support with Data Guard Redo Transport Services [ID 785347.1]
    Best Regards
    mseberg

  • Dataguard between different oracle versions

    Can I dataguard an 11.1.0.6 database to a backup 11.2.0.1 database

    For rolling upgrade purposes yes. But only to a Logical standby. And you can also use the transient Logical standby rolling upgrade as well if you are a Physical standby user.
    See the following:
    Mixed Oracle Version support with Data Guard Redo Transport Services (Doc ID 785347.1) on Oracle Support
    MAA Rolling Upgrade paper at http://www.oracle.com/technology/deploy/availability/maa/maa_wp_11g_upgrades_made_easy.pdf
    Transient Logical Standby Rolling Upgrade MAA paper at http://www.oracle.com/technology/deploy/availability/pdf/maa_wp_11g_transientlogicalrollingupgrade.pdf
    Larry

  • Transports between different Oracle versions

    Hello Experts,
    Is it possible to have DEV, QAS on Oracle 10.2.0.2 and PRD on Oracle 9.2.0.8? Will the transports work?
    Thanks & Regards,
    tamilboyus

    > Is it possible to have DEV, QAS on Oracle 10.2.0.2 and PRD on Oracle 9.2.0.8? Will the transports work?
    Sure - the whole transport thing works database independently.
    But you should really move on with your Oracle versions there - 10.2.0.2: old, 9.2.0.8: damn old...
    regards,
    Lars

  • Install client for two different oracle versions

    hello, right now I'm involved in two different projects, which work with Oracle 9i and 10g, and I need to access both databases from the same computer. My question is if it's possible to install the client software for both versions without problems.
    Thank you

    The problem is that the client for 9i is already installed in that machine, and it can't be uninstalled. So I need to install 10g client software, but without uninstalling the other one, only if this operation doesn't generate any conflicts. Is there an official Oracle document or somethign similar about this topic?

  • Shared Listener with different oracle versions

    Hi,
    I have configured the following shared listener for two databases running with different versions.
    I have started the O02TXN3-9i along with the shared listener and then listener was started with 9i version and then I brought up the O01TXN3 -10g.
    Please let me know whether I can connect to the 10g database O01TXN3 remotely with shared listener.
    Note: Please find listener and oratab files below.
    Your early response is much appreciated.
    Database O01TXN3 with 10g
    Database O02TXN3 with 9i
    ==== Listener.ora File ======
    TNS_DTXN03 =
    (ADDRESS_LIST =
    (ADDRESS=
    (PROTOCOL=IPC)
    (KEY= O01TXN3.world)
    (ADDRESS=
    (PROTOCOL=IPC)
    (KEY= O01TXN3)
    (ADDRESS=
    (PROTOCOL=IPC)
    (KEY= O02TXN3.world)
    (ADDRESS=
    (PROTOCOL=IPC)
    (KEY= O02TXN3)
    (ADDRESS =
    (COMMUNITY = tcpcom)
    (PROTOCOL = TCP)
    (Host = dtxn03)
    (Port = 1525)
    STARTUP_WAIT_TIME_TNS_DTXN03 = 0
    CONNECT_TIMEOUT_TNS_DTXN03 = 10
    LOG_DIRECTORY_TNS_DTXN03 =/dtxn03/txn/oracle/admin
    TRACE_LEVEL_TNS_DTXN03 = OFF
    SID_LIST_TNS_DTXN03 =
    (SID_LIST =
    (SID_DESC =
    (SID_NAME = O01TXN3)
    (ORACLE_HOME = /dtxn03/txn/oracle/10.2.0-64)
    (SID_DESC =
    (SID_NAME = O02TXN3)
    (ORACLE_HOME = /dtxn03/txn/oracle/9.2.0-64)
    # Added to get rid of the "inbound connection timed out (ORA-3136)"
    INBOUND_CONNECT_TIMEOUT_TNS_DTXN03 = 180
    ==
    Oratab:
    #LISTENER:/dtxn03/txn/oracle/9.2.0-64
    O01TXN3:/dtxn03/txn/oracle/10.2.0-64:Y
    O02TXN3:/dtxn03/txn/oracle/9.2.0-64:Y

    As a general rule, only one listener is required for a machine as long as all database versions are currently supported. (In other words one listener for Oracle7 and Oracle11g will not work.)
    As a general rule, an old listener MAY not be able to handle the features of the newer database (such as transferring blobs was a limitation in Oracle8). Therefore use the newest listener to handle all the databases.
    As a general rule, listeners can be considered independent of databases in a sense similar as ASM. Therefore it's not a bad idea to have a separate ORACLE_HOME specifically to install the listener. This is especially useful if you have multiple databases with differing service level agreements,
    I'd want to see
    1) the output of lsnrctl status
    2) any console session stuff and copy/paste to be surrounded by preview tages as described in the FAQ (http://www.oracle.com/technology/forums/faq.html#q14)

  • Install media for older Oracle version (10gR2)

    Hello,
    I need to find an install image for Oracle 10gR2 Client for AIX - I have the DB Engine and Companion disk images I just don't have the client. That version is old enough that it's no longer available from the standard Oracle Download page. I've checked Oracle Support and the Software Delivery cloud but no luck either place. Does anyone know if that is available for download anywhere?
    Thanks in advance.

    user5699590 wrote:
    Hello damorgan,
    I actually do have an extended support agreement and access to MOS but when I've looked there I haven't been able to find the base install for the client - patches yes but not the original install - maybe I just haven't been using the right search terms - could you suggest how I might find that on MOS?submit a Service Request & the software will be made available to you.

  • Specifying Different Oracle Drivers

    I'm having some issues using some Oracle drivers versions in different applications that use different Oracle versions (8 and 9), is there a way to define for one Connection Pool one version and for another a different one but still have XA support?
    Thanks,
    Johann

    johann renck wrote:
    I'm having some issues using some Oracle drivers versions in different applications that use different Oracle versions (8 and 9), is there a way to define for one Connection Pool one version and for another a different one but still have XA support?
    Thanks,
    JohannHi, nope. The whole JVM will only load one version of a given class.
    I would do everything you need to do to use the 10.2.0.3 thin
    driver in all cases.
    Joe

  • Data Guard with diff Oracle Versions??

    Hi,
    I have one query on Data Guard.
    Can I config. data guard with two different Oracle versions?
    i.e Primary=> 8i
    stand by=> 10g
    OR either way. Pls post your comments
    JAI HIND
    Darshan

    Some of the parameters that you need to have with Physical standby database are :
    *.background_dump_dest='/ford/app/oracle/admin/xchbot1/bdump'
    *.compatible='9.2.0.7'
    *.control_files='/home30/oradata/xchange/xchbot1/control01.ctl','/home30/oradata/xchange/xchbot1/control02.ctl','/home30/orad
    ata/xchange/xchbot1/control03.ctl'
    *.core_dump_dest='/ford/app/oracle/admin/xchbot1/cdump'
    *.db_block_buffers=1024
    *.db_block_size=8192
    *.db_file_multiblock_read_count=8# SMALL
    *.db_files=1000# SMALL
    *.db_name='xchbot1'
    *.global_names=TRUE
    *.log_archive_dest_1='LOCATION=/home30/oradata/xchange/xchbot1/archivelog'
    *.log_archive_dest_2='SERVICE=standby'
    *.log_archive_dest_state_2='ENABLE'
    *.log_archive_format='arch_%t_%s.arc'
    *.log_archive_start=true
    *.log_buffer=16384000# SMALL
    *.log_checkpoint_interval=10000
    *.max_dump_file_size='10240'# limit trace file size to 5 Meg each
    *.parallel_max_servers=5
    *.parallel_min_servers=1
    *.processes=50# SMALL
    *.rollback_segments='rbs01','rbs02','rbs03','rbs04','rbs05','rbs06','rbs07','rbs08','rbs09','rbs10'
    *.shared_pool_size=67108864
    *.sort_area_retained_size=2048
    *.sort_area_size=10240
    *.user_dump_dest='/ford/app/oracle/admin/xchbot1/udump'

  • ACCESS 97 & ORACLE VERSION 7

    Two questions really :
    1. Is there a migration tool for any oracle version prior to 7.3.
    We're moving to 7.3 within the next two months but need to
    investigate migration before then.
    2. When performing a link table / attach table from access the
    list we get list all possibilities of users and tables blowing
    the list and taking a long time to come back. we're using
    microsofts OBDC driver on this one and attaching to oracle
    version 7.1
    null

    The two lines you quote aren't errors, they're warnings and they're pretty standard fare. If there isn't anything else in the ODBC log, then the driver isn't returning any errors. I'm not sure why Access is failing, so let's look at the client configuration first.
    - I assume you've successfully installed the 8.1.6 client on the machine with Access. Were there any errors during the install?
    - You say you're using the 8.1.6 version of the Oracle ODBC driver-- can you look to see what the last digit of the version is? If possible, I'd start by downloading the most recent 8.1.6.x ODBC driver from OTN.
    - Check which version of the MDAC you have installed (new versions & a version checker are available from Microsoft at <http://www.microsoft.com/data>.
    - The ODBC driver you download above will list which versions of the MDAC it is expected to work with. Make sure your version is one of the listed versions.
    Justin

Maybe you are looking for

  • Installing a new hard drive and using Time Machine to Restore system

    I just upgraded a Macbook (2006) hard drive and had problems importing the Time Machine backup. The problem was that the initial install discs were for Tiger, which did not support Time Machine. After numerous attempts at a work-around I solved this

  • Dnt want Auto Multiple Ship Costs items for Same Vendor

    Hi All, I have a problem.. In my shipment my header as well as Legs are cost relevant. And i have given automatic determination of item categories in my shipment costs. Now the problem is when i have say 2 stages in my route den in my shipment costs

  • AS: InDesign CS4: contents only returns displayed text

    Hello, I realize that the function "contents" returns only the text displayed within the text frame. If the text exceeds the frame (because the frame is too small), the text that exceeds is not included in the text returned by contents of text frame

  • Restrict skills in ESS

    Hi, I have a requirement where in ESS learning page -> skills profile  i want the user to be able to select only one skill. We thought of disabling the "add new skill button" in portal but that would need logic to be written incase of a user without

  • Sales Order and obligatory material's parameter fields - help!!!

    Hi, My problem is: I've got to create material in MM by using BAPI_MATERIAL_SAVEDATA, so that this material can be later used as an item in Sales Order (SD). Do you know what parameter fields from which structures are obligatory in my case? I've alre