12.07.2015 Views

Oracle to Sybase ASE Migration Guide

Oracle to Sybase ASE Migration Guide

Oracle to Sybase ASE Migration Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong>MIGRATION GUIDE


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.36.4 Use a 3rd-party ETL <strong>to</strong>ol that supports both <strong>Oracle</strong> and <strong>Sybase</strong> <strong>ASE</strong> .......................................................................................... 326.5 <strong>Oracle</strong> datatypes requiring special attention for migration ................................................................................................................ 327 Migrating PL/SQL <strong>to</strong> Transact-SQL ....................................................................................................................................... 337.1 Locations of PL/SQL code ..................................................................................................................................................................... 337.2 3 rd -party <strong>to</strong>ols for PL/SQL migration <strong>to</strong> T-SQL ................................................................................................................................ 338 Transactions and Locking, <strong>Oracle</strong> vs. <strong>Sybase</strong> ......................................................................................................................... 358.1 <strong>Oracle</strong> MVCC vs. <strong>Sybase</strong> locking ........................................................................................................................................................... 358.28.3Transaction-related migration issues ...................................................................................................................................................... 35Using <strong>ASE</strong> implicit/chained transaction mode ................................................................................................................................... 368.3.1 Transactional DDL .............................................................................................................................................................................. 368.3.2 Transaction processing in s<strong>to</strong>red procedures ................................................................................................................................. 368.4 Using <strong>ASE</strong> explicit/unchained transaction mode ............................................................................................................................... 368.5 Using <strong>ASE</strong> transactional concurrency enhancements ........................................................................................................................ 368.6 Other transactional aspects ...................................................................................................................................................................... 379 Miscellaneous migration aspects ................................................................................................................................................ 399.1 Cursors ......................................................................................................................................................................................................... 399.2 Sequences .................................................................................................................................................................................................... 399.3 Error/Exception handling ....................................................................................................................................................................... 419.4 Outer join limitations ................................................................................................................................................................................ 419.5 Migrating JDBC/ODBC/… Applications ........................................................................................................................................... 429.5.1 JDBC ...................................................................................................................................................................................................... 429.6 <strong>Oracle</strong> Forms .............................................................................................................................................................................................. 4210 DBA Tasks Cross-Reference ..................................................................................................................................................... 4311 <strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>Migration</strong> Cross-Reference ......................................................................................................................... 4711.1 <strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>ASE</strong> migration: category "Simple Conversion" ................................................................................................... 4711.2 <strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>ASE</strong> migration: category "Partial Rewrite" ........................................................................................................... 5611.3 <strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>ASE</strong> migration: category "Major Rewrite" ........................................................................................................... 64Revision his<strong>to</strong>ry:Rev.1.0: September 2011: initial versionRev.1.1: November 2011: expanded the <strong>to</strong>pic on case-sensitivity; various other additionsRev.1.2: Oc<strong>to</strong>ber 2012: many extensions <strong>to</strong> chapters 3 & 11; added example of sequence equivalent in <strong>ASE</strong>Rev.1.3: December 2012: replaced PowerDesigner and ECDA examples by pointers <strong>to</strong> a separate document© 2011-2012 <strong>Sybase</strong>, Inc.<strong>Sybase</strong>, Transact-SQL, Adaptive Server Enterprise and Replication Server are registered trademarks of <strong>Sybase</strong>, Inc.Other product or brand names may be (registered) trademarks of their respective owners.Introduction 3


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.31 INTRODUCTIONThis <strong>Migration</strong> <strong>Guide</strong> aims <strong>to</strong> provide guidance and assistance with the migration process from an <strong>Oracle</strong> database <strong>to</strong><strong>Sybase</strong> <strong>ASE</strong> (Adaptive Server Enterprise). By "migration" we mean the process of changing a client-server applicationcurrently using the <strong>Oracle</strong> database as its RDBMS, such that it uses the <strong>Sybase</strong> <strong>ASE</strong> database instead.This <strong>Migration</strong> <strong>Guide</strong> has as its primary focus <strong>to</strong> migrate functionality from <strong>Oracle</strong> <strong>to</strong> <strong>Sybase</strong> <strong>ASE</strong>. Performance-relatedaspects of <strong>Sybase</strong> <strong>ASE</strong> are not covered (also see section 2.4).1.1 Intended AudienceThis <strong>Migration</strong> <strong>Guide</strong> is intended for anyone involved in migrating an <strong>Oracle</strong> database <strong>to</strong> <strong>Sybase</strong> Adaptive ServerEnterprise (<strong>ASE</strong>).1.2 What You Should Already KnowThe reader is expected <strong>to</strong> be familiar with relational database concepts, and with <strong>Oracle</strong> in particular. In addition,introduc<strong>to</strong>ry knowledge of the <strong>Sybase</strong> <strong>ASE</strong> RDBMS is required.For a database migration <strong>to</strong> be successful, there should be a detailed understanding of the current <strong>Oracle</strong>-based system,including its high- and low-level architecture, as well as the interaction between the client application and the <strong>Oracle</strong>database.1.3 About <strong>Sybase</strong> <strong>ASE</strong><strong>Sybase</strong> <strong>ASE</strong> is the database that powers Wall Street. <strong>ASE</strong> has been delivering rock-solid reliability and <strong>to</strong>p-levelperformance for the past 25 years. <strong>Sybase</strong> <strong>ASE</strong> has a lower <strong>to</strong>tal cost of ownership than <strong>Oracle</strong>, and delivers betterperformance on the same hardware. <strong>Sybase</strong> <strong>ASE</strong> is ready <strong>to</strong> be the database in any application that runs on <strong>Oracle</strong> <strong>to</strong>day.1.4 <strong>Oracle</strong> systems targeted by this <strong>Guide</strong>This <strong>Migration</strong> <strong>Guide</strong> can be used for migrations of any type of <strong>Oracle</strong>-based system. While it does not focus on aspecific type of application, workload or system design, the majority of <strong>Oracle</strong>-based migration candidate systems areexpected <strong>to</strong> be transactional systems.This <strong>Migration</strong> <strong>Guide</strong> specifically does not aim at migrating SAP Business Suite installations currently running on<strong>Oracle</strong>, <strong>to</strong> run on <strong>Sybase</strong> <strong>ASE</strong> instead. Since such migrations are covered by product and service offerings by SAP,interested cus<strong>to</strong>mers should contact SAP directly.1.5 <strong>Oracle</strong> products vs. <strong>Sybase</strong> productsBoth <strong>Oracle</strong> and <strong>Sybase</strong> provide a range of database-related products. The following list illustrates how the main highlevel<strong>Oracle</strong> products compared <strong>to</strong> <strong>Sybase</strong> products. While this list is deliberately kept brief, it provides some basicguidance on how <strong>Oracle</strong> and <strong>Sybase</strong> can be aligned.The focus of this <strong>Migration</strong> <strong>Guide</strong> is on migration from <strong>Oracle</strong> Database Server <strong>to</strong> <strong>Sybase</strong> <strong>ASE</strong>. These are usuallyexpected <strong>to</strong> be OLTP-oriented systems, though this is not required.<strong>Oracle</strong><strong>Oracle</strong> Database Server<strong>Oracle</strong> OLAP and DW<strong>Oracle</strong> RAC<strong>Oracle</strong> Times Ten<strong>Oracle</strong> Streams<strong>Sybase</strong><strong>Sybase</strong> <strong>ASE</strong> (Adaptive Server Enterprise)<strong>Sybase</strong> IQ<strong>Sybase</strong> <strong>ASE</strong> Cluster Edition<strong>Sybase</strong> <strong>ASE</strong> In-Memory Database<strong>Sybase</strong> Replication ServerIntroduction 4


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.31.6 <strong>Oracle</strong> / <strong>Sybase</strong> database versions coveredThis document pertains <strong>to</strong> <strong>Oracle</strong> versions 9i, 10g and 11g.The migration target is assumed <strong>to</strong> be <strong>Sybase</strong> <strong>ASE</strong> version 15.7 (or later). <strong>Migration</strong> <strong>to</strong> earlier <strong>ASE</strong> versions is notrecommended and not covered by this <strong>Migration</strong> <strong>Guide</strong>.If not otherwise specified all references <strong>to</strong> "<strong>ASE</strong>" or "Adaptive Server" are considered references <strong>to</strong> "<strong>Sybase</strong> AdaptiveServer Enterprise".1.7 <strong>Sybase</strong> <strong>ASE</strong> documents and referencesFor more detailed information about <strong>Sybase</strong> <strong>ASE</strong> , see http://www.sybase.com/ase for general documents andwhitepapers.See http://www.sybase.com/support/techdocs/migration for resources specifically focused at (different types of)migrations. These include the document you are currently reading, as well as “Migrating an <strong>Oracle</strong> Database <strong>to</strong> SAP <strong>Sybase</strong><strong>ASE</strong> with PowerDesigner and ECDA (A Step-By-Step Practical <strong>Guide</strong>)” .For <strong>ASE</strong> documentation and product manuals, see http://infocenter.sybase.com . Specifically, the following <strong>ASE</strong>documents are relevant:Transact SQL User's <strong>Guide</strong>Reference ManualSystem Administration <strong>Guide</strong>Utility <strong>Guide</strong>Performance and Tuning <strong>Guide</strong>In addition, <strong>Sybase</strong> provides technical training for <strong>ASE</strong>. For details on courses and availability, seehttp://www.sybase.com/education.Introduction 5


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.32 HOW TO USE THIS MIGRATION GUIDEThe focus of this <strong>Migration</strong> <strong>Guide</strong> is on the database-specific technical aspects of an <strong>Oracle</strong> <strong>to</strong> <strong>Sybase</strong> databasemigration project. In particular, it aims <strong>to</strong> help identify and assess the complexity of the migration when scoping out amigration project, so as <strong>to</strong> avoid overlooking or underestimating potentially difficult aspects of the system <strong>to</strong> bemigrated. In addition, it helps establish a migration approach by providing and suggesting technical options for variousaspects of the migration process.2.1 <strong>Migration</strong> process outlineThis <strong>Migration</strong> <strong>Guide</strong> recommends a phased approach <strong>to</strong>wards migrating from <strong>Oracle</strong> <strong>to</strong> <strong>Sybase</strong> <strong>ASE</strong>. The followingphases can be identified, in order of importance and priority:1. Before starting the actual migration project, assess the complexity of the migration using the checklist inchapter 3. This activity involves identifying specific <strong>Oracle</strong> features used in the current system which may nothave a direct <strong>Sybase</strong> equivalent.It is strongly recommended <strong>to</strong> pay sufficient attention <strong>to</strong> this activity, as this helps <strong>to</strong> avoidoverlooking or underestimating the most difficult parts of a migration.2. Migrating the database schema is the necessary first step of an actual migration (described in chapter 4).This <strong>Migration</strong> <strong>Guide</strong> recommends using <strong>Sybase</strong> PowerDesigner <strong>to</strong> reverse-engineer the <strong>Oracle</strong> schema andconvert it <strong>to</strong> the <strong>Sybase</strong> <strong>ASE</strong> equivalent.3. Migrating server-level aspects such as users (described in chapter 5).4. Migrating the data itself (described in chapter 6). The approach chosen <strong>to</strong> perform the data migration is usuallydriven by the maximum <strong>to</strong>lerable downtime allowed for the application.It is recommended <strong>to</strong> consider using 3 rd -party <strong>to</strong>ols for extracting data from <strong>Oracle</strong>. If minimal applicationdowntime is crucial, consider <strong>Sybase</strong> Replication Server <strong>to</strong> reduce this downtime <strong>to</strong> minutes rather than hours.5. Migrating <strong>Oracle</strong> PL/SQL code <strong>to</strong> <strong>Sybase</strong> Transact-SQL (also see chapter 7). This needs <strong>to</strong> be performed bothfor SQL located in the database (i.e. s<strong>to</strong>red procedures, triggers, SQL functions) as well as for SQL code inclient applications. This step tends <strong>to</strong> be the most complex part of a migration.To assist with this migration step, chapter 11 contains cross-reference between <strong>Oracle</strong> features and their <strong>Sybase</strong><strong>ASE</strong> equivalent, in the three categories "Simple conversion possible", "Partial rewrite required" and "Majorrewrite required". This cross-reference is an extended version of the <strong>Oracle</strong> checklist in chapter 3.6. <strong>Migration</strong> of vendor-specific infrastructural components, such as JDBC drivers (see section 9.5).7. Convert the maintenance, administration and moni<strong>to</strong>ring tasks. Since these aspects are highly specific for eachdatabase brand, "migration" would be a misnomer.Chapter 10 contains a cross-reference of some common DBA aspects. This is however not sufficient forperforming a migration, and specific DBA skills, both for <strong>Oracle</strong> and <strong>Sybase</strong>, will be required.8. The primary focus of this <strong>Migration</strong> <strong>Guide</strong> is <strong>to</strong> help achieve functional equivalence of the <strong>Oracle</strong> system afterbeing migrated <strong>to</strong> <strong>Sybase</strong> <strong>ASE</strong>.As a next step, <strong>Sybase</strong> <strong>ASE</strong>-specific optimization and tuning will likely be required in order <strong>to</strong> achieve desiredperformance levels. <strong>Sybase</strong> <strong>ASE</strong>-specific tuning is not covered by this <strong>Migration</strong> <strong>Guide</strong>; see section 2.4.2.2 Success fac<strong>to</strong>rsDatabase migrations can be complex, and costly migration failures need <strong>to</strong> be avoided. The following success fac<strong>to</strong>rsapply <strong>to</strong> any <strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> database migration project:How <strong>to</strong> use this <strong>Migration</strong> <strong>Guide</strong> 6


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3Domain knowledge of the business application(s), system and environment. It is essential <strong>to</strong> have a full andcomplete understanding of all applications that access the <strong>Oracle</strong> database being migrated. This includes theclient applications that connect <strong>to</strong> the <strong>Oracle</strong> database directly, but also applications that indirectly access thedatabase, for example through an application server.For all these applications, it needs <strong>to</strong> be unders<strong>to</strong>od which data the application accesses in the database, andhow it modifies such data. Any SQL code submitted <strong>to</strong> the database by the application must be identified, aswell as how such SQL code can be changed.Availability of sufficient <strong>Oracle</strong> expertise <strong>to</strong> analyze all aspects of the database is an absolute requirement. Akey activity is <strong>to</strong> identify which specific <strong>Oracle</strong> features are used (as per the checklists in chapter 3), especiallythose which do not have a direct <strong>Sybase</strong> equivalent.Full access <strong>to</strong> all <strong>Oracle</strong> PL/SQL code being used, both in the database and in all client applications.As a minimum, sufficient understanding of <strong>Sybase</strong> <strong>ASE</strong> in order <strong>to</strong> create a functionally working migrateddatabase system. At a later stage in the migration project, more specialized <strong>Sybase</strong> expertise will likely beneeded for <strong>Sybase</strong> <strong>ASE</strong>-specific performance tuning and optimization. Having such expertise available at anearly stage may be helpful.A comprehensive testing process and production-like environment for validating the migration approach andthe affected software applications against the migrated <strong>Sybase</strong> database. For best results, it is highlyrecommended <strong>to</strong> use a copy of production data (as close as possible) as well as hardware which is similar in size<strong>to</strong> production.2.3 Not covered by this guide: Project aspectsThis <strong>Migration</strong> <strong>Guide</strong> does not prescribe or suggest how <strong>to</strong> organize a migration project in terms of preparation, settingup testing procedures, validating the migrated components, etc. These aspects of a migration project are left <strong>to</strong>requirements, standards, best practices and preferences of the organization undertaking the emigration effort.Please note that the absence of specific recommendations for testing and validation of migrated components does notmean that such activities should not be performed. On the contrary, these activities are essential, and it is recommended<strong>to</strong> follow generally accepted best practices with respect <strong>to</strong> software testing and validation.2.4 Not covered by this guide: <strong>Sybase</strong> <strong>ASE</strong>-specific tuningThe primary purpose of this <strong>Migration</strong> <strong>Guide</strong> is <strong>to</strong> assist in creating a functionally equivalent <strong>Sybase</strong> <strong>ASE</strong>-based systemcompared with the original <strong>Oracle</strong>-based system. The purpose of this <strong>Migration</strong> <strong>Guide</strong> is not <strong>to</strong> provide guidance forarriving at an optimally tuned <strong>Sybase</strong> <strong>ASE</strong> system; while <strong>Sybase</strong> <strong>ASE</strong>-specific tuning will likely be necessary as part of amigration project, this <strong>Migration</strong> <strong>Guide</strong> deliberately makes no attempt <strong>to</strong> cover such tuning aspects.Since <strong>ASE</strong>-specific tuning is considered <strong>to</strong> be mostly unrelated <strong>to</strong> any <strong>Oracle</strong>-specific aspects or considerations, thereader is referred <strong>to</strong> the <strong>Sybase</strong> <strong>ASE</strong> documentation for background and recommendations about <strong>Sybase</strong> <strong>ASE</strong> tuning.,specifically the System Administration <strong>Guide</strong> and the Performance and Tuning manuals.How <strong>to</strong> use this <strong>Migration</strong> <strong>Guide</strong> 7


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.33 PRE-MIGRATION COMPLEXITY ASSESSMENTFor a database migration project, it is crucial <strong>to</strong> have an accurate assessment of the complexity of the migration ahead oftime. Here, "complexity" refers <strong>to</strong> how <strong>Oracle</strong>-specific features can be mapped <strong>to</strong> the feature set of <strong>Sybase</strong> <strong>ASE</strong>.Before starting the actual migration effort, the current <strong>Oracle</strong> system should be closely inspected and a list should bedrawn up of all types of <strong>Oracle</strong>-specific features being used, and how many times these occur.For each feature used, it should be determined in which of the following three categories it falls:Simple conversion possibleAn <strong>Oracle</strong> feature or statement can be mapped and converted directly <strong>to</strong> a (nearly) identical <strong>Sybase</strong> <strong>ASE</strong>feature, requiring no syntax changes or only simple, local syntax changes only.Examples: most datatype mappings (<strong>Oracle</strong> VARCHAR2 <strong>Sybase</strong> VARCHAR); simple SELECT statementsPartial rewrite requiredAn <strong>Oracle</strong> feature or statement can be mapped <strong>to</strong> a partly equivalent <strong>Sybase</strong> <strong>ASE</strong> feature, requiring potentiallysignificant syntax changes and possibly partial rewriting of algorithms.Example: <strong>Oracle</strong> sequences <strong>Sybase</strong> <strong>ASE</strong> identity columnsMajor rewrite requiredAn <strong>Oracle</strong> feature or statement has no directly equivalent <strong>Sybase</strong> <strong>ASE</strong> feature, requiring rewriting orredesigning of algorithms or parts of applications.Example: <strong>Oracle</strong> Flashback; <strong>Oracle</strong> row-level triggers.Categorizing the <strong>Oracle</strong> features used by the system being migrated helps <strong>to</strong> identify the areas where most migrationcomplexity is likely <strong>to</strong> occur. Before deciding <strong>to</strong> start the migration project, there should be a clear view of the numberof occurrences of the features in the categories "Partial rewrite required" and "Major rewrite required" above, and of theeffort <strong>to</strong> migrate these, especially those in the Major rewrite required" category.To assist with this complexity assessment, below are three checklists, corresponding <strong>to</strong> the categories above, listing arange of <strong>Oracle</strong> features. Note that additional <strong>Oracle</strong> features may occur in your system that are not in these checklists;these should be taken in<strong>to</strong> account just as well.The checklists below list the <strong>Oracle</strong> features only very briefly. Chapter 11 contains extended versions of these checklistswith the corresponding <strong>Sybase</strong> <strong>ASE</strong> equivalent for each <strong>Oracle</strong> feature.3.1 <strong>Oracle</strong> checklist: datatypesVerify the datatypes used in the current <strong>Oracle</strong> application; see section 4.7.Also see:section 4.7.1 for considerations that apply when migrating data rows whose length exceed an <strong>Oracle</strong> disk block;section 6.5 for considerations that apply when migrating particular datatypes.3.2 <strong>Oracle</strong> checklist: category "Simple Conversion"#cases found<strong>Oracle</strong> checklist: category "Simple Conversion"Connecting <strong>to</strong> an <strong>Oracle</strong> schemaThe <strong>Oracle</strong> SQL*Plus “slash” character sends preceding PL/SQL text <strong>to</strong> the <strong>Oracle</strong> server.Semicolon (as a statement delimiter in PL/SQL)Pre-migration complexity assessment 8


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3#cases found<strong>Oracle</strong> checklist: category "Simple Conversion"The <strong>Oracle</strong> DUAL tableSET SAVEPOINT savepoint-nameVariable/Parameter declarations; naming syntaxAssign default value in variable declarationMultiple variable declarations with a single DECLARE keywordDeclarations without DECLARE keyword in declaration section of s<strong>to</strong>red procedures/functionsVariable assignmentTransferring table data in<strong>to</strong> a variableConstants%TYPE denotes the datatype of a column in an existing tableDynamic SQL (Execute-immediate)Loops with LOOP/END LOOPFOR loopsCURSOR loops<strong>Oracle</strong> Outer join syntaxSET TRANSACTION READ WRITEALTER TABLE mytable TRUNCATE PARTITION partition_nameCREATE OR REPLACE PROCEDURE (or FUNCTION)ALTER PROCEDURE (or FUNCTION)CREATE PROCEDURE… IS…S<strong>to</strong>red procedure execution with named parameters (param => value)S<strong>to</strong>red procedure execution with positional parameters (:var)S<strong>to</strong>red procedure executionSQL Function declaration with DETERMINISTIC keywordExecution of a SQL FunctionDECLARE CURSOR cursor-name IS…<strong>Oracle</strong> cursorsPre-migration complexity assessment 9


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3#cases found<strong>Oracle</strong> checklist: category "Simple Conversion"Cursor Attribute %ISOPENCursor Attributes %FOUND, %NOTFOUNDCursor Attribute %ROWCOUNTAFTER triggers (on statement level)INSTEAD OF triggers (on views)SQL%ROWCOUNTBOOLEAN datatype (for PL/SQL variables only)MERGE statementPartitioned tables with composite partitioningPerformance-optimized native PL/SQL datatypes (for PL/SQL variables only)BINARY_INTEGERBINARY_DOUBLEBINARY_FLOATIF-THEN-ELSEMultiple statements in an IF-THEN-ELSE branchConditional test based on EXISTS subqueryString concatenation opera<strong>to</strong>r: ||userenv('sessionid')MOD(X,Y)CEIL()TRUNC(number)SUBSTR()SUBSTR() function with two parametersLENGTH()CHR()REPLACE()TO_CHAR(expression)TO_CHAR(expression, datepart)Pre-migration complexity assessment 10


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3#cases found<strong>Oracle</strong> checklist: category "Simple Conversion"TO_CHAR(expression, format-string)TO_NUMBER(expression)Date/time functions and calculationsSYSDATE, SYSTIMESTAMPTRUNC(date/time [,unit])LAST_DAY()NVL() functionInconsistent use of upper/lowercase for identifiers (<strong>Oracle</strong> is case-insenstive for identifiers)Identifiers that are <strong>Sybase</strong> <strong>ASE</strong> reserved words (see section 4.8)INSTR() function with two parametersDerived tables (also known as "inline views") without correlation nameALTER TABLE … SPLIT PARTITION…ALTER TABLE … MERGE PARTITIONS…Quoted identifiers. <strong>Oracle</strong> allows using quoted identifiers by enclosing an identifier in doublequotes.<strong>Oracle</strong> hintsPre-migration complexity assessment 11


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.33.3 <strong>Oracle</strong> checklist: category "Partial Rewrite"For the <strong>Oracle</strong> features listed below, migration <strong>to</strong> partly equivalent <strong>Sybase</strong> <strong>ASE</strong> features is possible, although potentiallysignificant syntax changes and possibly partial rewriting of algorithms may be required.#cases found<strong>Oracle</strong> checklist: category "Partial Rewrite"Database linksExternal tablesSequencesTable-valued User-defined SQL FunctionsPipelined Table FunctionsSynonymsComments on database objectsBitmap indexesTemporary tablesIS TABLE OF, AS VARRAY(n)OFNested tablesObject tables%ROWTYPEDefine a PL/SQL record type by enumerating the fields with IS RECORD OF or TYPE…ISRECORDNon-integer RETURN value in s<strong>to</strong>red procedureUser-defined PackagesOverloaded s<strong>to</strong>red proceduresPL/SQL Exception handling; defining exception handlersSQLCODE, SQLERRMRAISE_APPLICATION_ERRORColumn EncryptionLOB loca<strong>to</strong>rsPre-migration complexity assessment 12


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3#cases found<strong>Oracle</strong> checklist: category "Partial Rewrite"Data compressionRetrieving data <strong>to</strong> the client in s<strong>to</strong>red procedures usingDBMS_OUTPUT packageDBMS_*, UTL_* package calls (excl. DBMS_OUTPUT)SDO_* package callsSQL*Loader (sqlldr)Materialized ViewsGlobal variables (in a PL/SQL package)INTERSECT constructMINUS constructSpecific SQL clausesAS OFAS OF TIMESTAMPCONNECT BYDIMENSIONDIMENSION BYEXCLUDEGROUPING SETSINCLUDEMEASURESRETURN ALL ROWSRETURN UPDATED ROWSPARTITION BYREFERENCESYSTIMESTAMPCROSSCUBEFORKEEPMAINMODELNAVNOCYCLENOWAITONONLYRULESSAMPLESEEDSKIPIGNOREITERATENATURALNULLSNULLS FIRSTNULLS LASTROLLUPSIBLINGSSINGLEREFERENCELOCKEDSTART WITHUNIQUEUNPIVOTWAITINITCAP( string-expression )INSTR() function with three or four parametersNVL2() functionDECODE() functionPrimary key and foreign key with different datatypes, different precision/scale (for numericdatatypes) or different length (for character datatypes)Cluster (as created with CREATE CLUSTER)Pre-migration complexity assessment 13


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3#cases found<strong>Oracle</strong> checklist: category "Major Rewrite"<strong>Oracle</strong> Flashback<strong>Oracle</strong> Snapshot Standby<strong>Oracle</strong> SQL Plan ManagementAWR (Au<strong>to</strong>matic Workload Reposi<strong>to</strong>ry)<strong>Oracle</strong> Advanced QueuingPackages for PL/SQL web accessOWA_CUSTOM, OWA_CX, OWA_OPT_LOCK, OWA_SEC, OWA_TEXT, OWA_UTIL<strong>Oracle</strong> FormsPre-migration complexity assessment 16


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3etc, and au<strong>to</strong>matically convert the <strong>Oracle</strong> datatypes in<strong>to</strong> their <strong>ASE</strong> equivalent, this is the fastest and most efficientschema migration method available.Section 4.2 describes how <strong>to</strong> use PowerDesigner for this purpose.Section 4.3 describes a possible approach <strong>to</strong> reverse-engineer the schema without PowerDesigner.4.2 Using <strong>Sybase</strong> PowerDesigner for database schema migration<strong>Sybase</strong> PowerDesigner is arguably the most advanced data modeling <strong>to</strong>ol in the market. It is a stand-alone <strong>to</strong>ol, runningon Windows. PowerDesigner supports over 30 database types, including <strong>Oracle</strong> and <strong>Sybase</strong> <strong>ASE</strong>.For more information on PowerDesigner, see http://www.sybase.com/powerdesigner .With PowerDesigner it is relatively straightforward <strong>to</strong> reverse-engineer most of the <strong>Oracle</strong> schema and convert it <strong>to</strong><strong>Sybase</strong> <strong>ASE</strong>. The central concept used by PowerDesigner is the PowerDesigner Physical Data Model (PDM). This is adatabase-independent model which can be converted <strong>to</strong> the SQL DDL dialect of each supported database.4.2.1 PowerDesigner schema conversion stepsFor detailed, step-by-step instructions on how <strong>to</strong> use PowerDesigner <strong>to</strong> convert the database schema from <strong>Oracle</strong> <strong>to</strong><strong>Sybase</strong> <strong>ASE</strong>, see the document “Migrating an <strong>Oracle</strong> Database <strong>to</strong> SAP <strong>Sybase</strong> <strong>ASE</strong> with PowerDesigner and ECDA (A Step-By-Step Practical <strong>Guide</strong>)” at http://www.sybase.com/support/techdocs/migration.Once the schema is reverse-engineered, run the completed DDL script in <strong>Sybase</strong> <strong>ASE</strong> and check for any errors.Note that some aspects of schema migration cannot be handled by PowerDesigner and will have <strong>to</strong> be handleddifferently. These aspects are described in section 4.4.4.3 Reverse-engineering the <strong>Oracle</strong> schema without <strong>Sybase</strong> PowerDesignerWithout using <strong>Sybase</strong> PowerDesigner, reverse-engineering the schema can be done in a number of ways:Use the <strong>Oracle</strong> SQL*Plus DESC command on all database objects, and process the output so that they arevalid DDL statements. This is likely <strong>to</strong> require significant manual script coding.Use the <strong>Oracle</strong> DBMS_METADATA package <strong>to</strong> extract DDL for the <strong>Oracle</strong> objects. This involves SQLstatements such as the following (for <strong>Oracle</strong> table 'MY_TABLE', in schema/user 'SALESAPP'). Note thatthese are only examples, this is not a complete list of all statement required <strong>to</strong> perform full reverse-engineering:SELECT DBMS_METADATA.GET_DDL('TABLE', 'MY_TABLE', 'SALESAPP') FROM DUAL;SELECT DBMS_METADATA.GET_DEPENDENT_DDL('INDEX', 'MY_TABLE', 'SALESAPP') FROMDUAL;SELECT DBMS_METADATA.GET_GRANTED_DDL('OBJECT_GRANT', 'SALESAPP') FROM DUAL;Use <strong>Oracle</strong> SQL Developer (a free Java-based <strong>to</strong>ol, downloadable from oracle.com). This uses theDBMS_METADATA package (see previous bullet).Use TOAD (a low-cost <strong>to</strong>ol, commonly used in many <strong>Oracle</strong> environments) <strong>to</strong> extract the object definitions,and then manually convert the <strong>Oracle</strong> datatypes in<strong>to</strong> their <strong>ASE</strong> equivalent. This could be cumbersome whenlarge numbers of tables are involved.Once the <strong>Oracle</strong> schema has been reverse-engineered, the <strong>Oracle</strong> DDL needs <strong>to</strong> be converted <strong>to</strong> <strong>Sybase</strong> <strong>ASE</strong> syntax,including conversion from the <strong>Oracle</strong> datatypes <strong>to</strong> <strong>Sybase</strong> <strong>ASE</strong> datatypes. Section 4.7 describes the mapping from<strong>Oracle</strong> datatypes <strong>to</strong> <strong>Sybase</strong> <strong>ASE</strong>.In addition, some aspects of the <strong>Oracle</strong> schema require special attention; see section 4.4.4.4 Special cases in schema migrationThe following schema aspects require special attention:Database Schema <strong>Migration</strong> 18


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3<strong>Oracle</strong> allows more columns per table than <strong>Sybase</strong> <strong>ASE</strong> (the limit depends on the <strong>ASE</strong> server's page size andon the table's lock scheme). If the limit in <strong>Sybase</strong> <strong>ASE</strong> is exceeded, an error will be raised when trying <strong>to</strong> createthe table. If this occurs, either the <strong>ASE</strong> server's page size will need <strong>to</strong> be increased, or the table needs <strong>to</strong> besplit vertically in<strong>to</strong> multiple tables and all queries referencing the table likely have <strong>to</strong> be modified accordinglyIf the length of a column exceeds the maximum allowed length in <strong>Sybase</strong> <strong>ASE</strong> (the limit depends on the <strong>ASE</strong>server's pagesize and on the table's lock scheme), such columns will have <strong>to</strong> be split in<strong>to</strong> multiple columns andplaced in additional tables. All queries referencing the column likely have <strong>to</strong> be modified accordingly.PowerDesigner converts the <strong>Oracle</strong> BFILE datatype <strong>to</strong> the <strong>Sybase</strong> <strong>ASE</strong> image datatype. Since BFILE is adatatype used <strong>to</strong> s<strong>to</strong>re a loca<strong>to</strong>r (link) <strong>to</strong> an external binary file s<strong>to</strong>red outside of the database, this is notfunctionally equivalent so application changes may be required. If a different <strong>ASE</strong> datatype is required, forexample, <strong>to</strong> hold the name of an externally s<strong>to</strong>red file, change it manually.PowerDesigner 15.x cannot au<strong>to</strong>matically convert the <strong>Oracle</strong> timestamp datatype <strong>to</strong> bigdatetime in<strong>ASE</strong>, so this needs <strong>to</strong> be done manually. PowerDesigner 16.0 (release expected in August 2011) does not havethis limitation and will perform the conversion au<strong>to</strong>matically. PowerDesigner 15.x cannot reverse-engineer <strong>Oracle</strong> users or security details (permissions). PowerDesigner 16.0(release expected in August 2011) does not have this limitation and is capable of handling these aspects.Since the SQL reserved words are different between <strong>Oracle</strong> and <strong>Sybase</strong> <strong>ASE</strong>, before attempting a databaseschema migration, all <strong>Oracle</strong> objects need <strong>to</strong> be checked against the <strong>Sybase</strong> <strong>ASE</strong> reserved words. Any <strong>Oracle</strong>identifiers that are also <strong>Sybase</strong> <strong>ASE</strong> reserved words, need <strong>to</strong> be changed first. For a complete list of reservedwords in <strong>Sybase</strong> <strong>ASE</strong>, see “Adaptive Server Enterprise->Reference Manual: Building Blocks->Reserved Words”.Also see section 4.8 for queries that can be used <strong>to</strong> search for the occurrence of keywords in the <strong>Oracle</strong>database.The mapping of <strong>Oracle</strong> user-defined datatypes <strong>to</strong> <strong>ASE</strong> can be difficult and may require extensive manualintervention. The key <strong>to</strong> user-defined datatype migration is <strong>to</strong> fully understand the underlying base datatype.Note that user-defined datatypes can be nested. For <strong>Oracle</strong>, user-defined datatypes is an add-on option <strong>to</strong> thedatabase and is not widely used.4.5 Mapping the <strong>Oracle</strong> schema <strong>to</strong> <strong>Sybase</strong> <strong>ASE</strong> databases<strong>Sybase</strong> <strong>ASE</strong> does not have an identical interpretation of the concept of "schema" as the "<strong>Oracle</strong> schema". Whenmigrating an <strong>Oracle</strong> schema <strong>to</strong> <strong>Sybase</strong> <strong>ASE</strong>, there are two basic options <strong>to</strong> map the <strong>Oracle</strong> schema <strong>to</strong> <strong>Sybase</strong> <strong>ASE</strong>.For the sake of example, let's assume there are two <strong>Oracle</strong> users john and bill who own an <strong>Oracle</strong> schema, and eachschema has a table named salesdetails.The options are:Perhaps the most straightforward way <strong>to</strong> migrate, is <strong>to</strong> map each <strong>Oracle</strong> schema <strong>to</strong> a separate <strong>ASE</strong> database,where each database is owned ('dbo') by the corresponding user. This would result in two <strong>ASE</strong> databasesnamed john_db and bill_db (different names may of course be chosen), owned by <strong>ASE</strong> logins john andbill respectively; each database has table named salesdetails, owned by the dbo database user (the fulltable name would be dbo.salesdetails).However, this results in as many <strong>ASE</strong> databases as there are users owning an <strong>Oracle</strong> schema, of which theremight be many. While an <strong>ASE</strong> server can hold up <strong>to</strong> 32786 databases, it is highly impractical from a DBAperspective <strong>to</strong> have more than 20-50 databases.Map all <strong>Oracle</strong> schemas <strong>to</strong> a single <strong>ASE</strong> database with a multi-tenancy model. This means that the <strong>ASE</strong>database user (which is linked <strong>to</strong> the <strong>ASE</strong> server login, which is the equivalent of an <strong>Oracle</strong> user) is used withinthe database <strong>to</strong> identify each object's owner. This will result in a more manageable <strong>ASE</strong> system since there willbe less <strong>ASE</strong> databases.In this case, the example would result in a single <strong>ASE</strong> database, let's say sales_db, in which <strong>ASE</strong> logins johnDatabase Schema <strong>Migration</strong> 19


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3and bill have been added as database users. Under each user, a salesdetails table is created, which willhave the full name john.salesdetails and bill.salesdetails.Either option is possible; technically <strong>ASE</strong> does not favor one over the other, but the multi-tenancy model fits best with<strong>ASE</strong>'s methods for backup and res<strong>to</strong>re.It should be noted that multi-tenancy models are sometimes incorrectly seen as security weaknesses since it would beeasier for user bill <strong>to</strong> access john's tables, since they are located in the same <strong>ASE</strong> database. This is however not justified:if standard best practices around <strong>ASE</strong> security are followed, then security can be fully guaranteed.One consideration around multi-tenancy databases is that a backup of a database contains the data from all users in thatdatabase. If this is undesirable, for example because each user wants <strong>to</strong> have a backup copy of his own database, thenthe first option above (separate <strong>ASE</strong> databases for each user) should be followed instead.Lastly, it may also be the case that there is only one <strong>Oracle</strong> schema. In that case, there is no need <strong>to</strong> qualify the <strong>ASE</strong>tables with the owner name since they will all be owned by the dbo user.4.6 Schema-related <strong>Oracle</strong>-<strong>Sybase</strong> terminologyFollowing is the high-level terminology mapping of <strong>Oracle</strong> concepts <strong>to</strong> <strong>Sybase</strong> concepts. This table is not intended <strong>to</strong> beused for direct migration purposes, but only as high-level terminology guidance.<strong>Oracle</strong>DatabaseSchemaTablespaceSegmentUndo/rollback tablespaceOnline redo logs<strong>Sybase</strong> <strong>ASE</strong>Database ServerDatabase and objects owned by the same user.Aspects of <strong>ASE</strong> database and/or database device and/orsegment(system/sysaux tablespace<strong>ASE</strong> master database;temporary tablespace<strong>ASE</strong> tempdb database;user-defined tablespacedatabase device and/or segment)A database object that has space allocated (table, index,materialized view)Transaction logTransaction logUser User, Login (see section 5.5)RoleTableTemporary tableRoleTableTemporary tableViewMaterialized ViewClusterIndexIndex-organized tableColumn-level check constraintViewNo direct equivalentNo direct equivalentNon-unique indexTable with clustered indexColumn-level check constraintDatabase Schema <strong>Migration</strong> 20


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3<strong>Oracle</strong>Column defaultUnique keyPrimary keyForeign keyConstraintsCollectionsPL/SQL ProcedurePL/SQL FunctionTriggersPackageSequencesSnapshotDatabase links, External tablesProcedureSynonym<strong>Sybase</strong> <strong>ASE</strong>Column defaultUnique key or identity property for a columnPrimary keyForeign keyConstraintsIn PL/SQL, a collection is an ordered group of elementsof the same type, such as VARRAYs or nested tables.Transact-SQL s<strong>to</strong>red procedureT-SQL user-defined SQL function (SQL UDF)TriggersNo direct equivalentPartly covered by the identity property for a column ordedicated key value tableNo direct equivalentProxy Tables and Remote ServersS<strong>to</strong>red procedureSimilar functionality with views for table and viewsynonyms. All other synonym references must be replacedwith fully qualified object strings (database.owner.object)or proxy tables (for synonyms <strong>to</strong> remote objects).4.7 Mapping <strong>Oracle</strong> Datatypes <strong>to</strong> <strong>Sybase</strong> <strong>ASE</strong>The table below describes how <strong>Oracle</strong> datatypes can be mapped <strong>to</strong> <strong>Sybase</strong> <strong>ASE</strong> datatypes. In most cases the mapping ofdatatypes is straightforward.For the <strong>Oracle</strong> datatypes CHAR, VARCHAR2 and RAW, the <strong>ASE</strong> server page size determines whether or not themapping can take place; the technical background is that <strong>ASE</strong> requires a row, and therefore every column, <strong>to</strong> fit on an<strong>ASE</strong> database page. By default, <strong>ASE</strong> uses a 2KB server page size, but 4KB, 8KB and 16KB are also possible.The maximum allowed column length for a column for each <strong>ASE</strong> server page size depends on various fac<strong>to</strong>rs such aswhether the column is fixed- or variable length and the <strong>ASE</strong> table's lock scheme. To display full details, run thecommand dbcc serverlimits in <strong>ASE</strong>.<strong>Oracle</strong> Description <strong>Sybase</strong> <strong>ASE</strong> Comments / When <strong>to</strong> useNUMBER(x) <strong>Oracle</strong> NUMBER(x) datatypeswith 0 decimals can be convertedin<strong>to</strong> an equivalent <strong>Sybase</strong> <strong>ASE</strong>datatypes.BIGINT length of NUMBER datatype > 10INTEGERSMALLINTlength of NUMBER datatype between6 and 10 and data values


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3<strong>Oracle</strong> Description <strong>Sybase</strong> <strong>ASE</strong> Comments / When <strong>to</strong> use32767NUMBER(x,y)FLOATCHAR(x)VARCHAR2(x)DATETIMESTAMP[WITH [LOCAL]TIME ZONE]alternatively <strong>to</strong> the mapping pathabove, these <strong>Sybase</strong> <strong>ASE</strong>datatypes can be used.maximum FLOAT precision in<strong>Oracle</strong> is approx. 38maximum CHAR size in <strong>Oracle</strong>is 2000 bytesmaximum VARCHAR2 size in<strong>Oracle</strong> is 4000 bytes for columns(for PL/SQL variables, the max.size is 32767)date/ time precision in <strong>Oracle</strong> isup <strong>to</strong> one second.precision of <strong>Oracle</strong>‟sTIMESTAMP is 1/100000000thof a secondTINYINTlength of NUMBER datatype between2 and 3 and data values 15FLOAT precision of actual values


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3<strong>Oracle</strong> Description <strong>Sybase</strong> <strong>ASE</strong> Comments / When <strong>to</strong> useLONG RAW <strong>Oracle</strong>‟s max. s<strong>to</strong>rage capacity for IMAGELONG RAW is 2GBCHAR(1)BFILE4.7.1 Chained <strong>Oracle</strong> data rowsif this is a packed bit columnmaintained by a PL/SQLfunction set / unset / retrieve /query on them.BFILE s<strong>to</strong>res a loca<strong>to</strong>r (link) <strong>to</strong> abinary file outside of the databaseBITno direct equivalent<strong>Oracle</strong> allows long data rows <strong>to</strong> exceed the size of a disk block. This is known as 'chained rows'. It is possible that suchchained data rows, if they exist in the <strong>Oracle</strong> database, are <strong>to</strong>o long <strong>to</strong> be s<strong>to</strong>red in <strong>Sybase</strong> <strong>ASE</strong>, which requires that adata rows fits on a data page (which is 2KB, 4KB, 8KB or 16KB; use dbcc serverlimits <strong>to</strong> find the net max rowlength allowed in <strong>ASE</strong>). Also, for tables with more than 255 columns, the rows will always be chained.It is important <strong>to</strong> identify tables that have chained rows before starting the migration. To find how many chained rowsoccur in a table, run this <strong>Oracle</strong> query:SELECT owner, table_name, chain_cntFROM dba_tables WHERE chain_cnt > 0If chained rows are found, the <strong>Oracle</strong> command ANALYZE TABLE table-name LIST CHAINED ROWSINTO chained-row-table can be used <strong>to</strong> identify the actual chained rows.If chained rows are found, it may be needed <strong>to</strong> modify the data model <strong>to</strong> ensure that rows are short enough <strong>to</strong> fit on an<strong>ASE</strong> page.4.8 Search for <strong>Sybase</strong> <strong>ASE</strong> reserved words and keywords in <strong>Oracle</strong>Before you can migrate an <strong>Oracle</strong> schema or <strong>Oracle</strong> s<strong>to</strong>red procedure, function or trigger, there needs <strong>to</strong> be a check forreserved words (keywords) that are already identified as either problematic or non-migratable. <strong>Oracle</strong> allows SQLkeywords <strong>to</strong> be used as identifiers whereas this is not allowed in <strong>ASE</strong>. For example, the following is valid PL/SQL:CREATE TABLE case (begin VARCHAR2(100), when INT)The following query finds all object names within the <strong>Oracle</strong> database that are <strong>ASE</strong> keywords:select owner, object_name, object_typeFROM sys.dba_objectsWHERE object_name = UPPER('')The following query scans any PL/SQL object within the <strong>Oracle</strong> database for certain keywords and returns the nameand owner of the object as well as the object type for objects containing <strong>ASE</strong> keywords. This query retrieves the exactcode and line number of the occurrence within a s<strong>to</strong>red procedure, function or trigger. Note that this could potentiallyreturn a lot of output since the 'line' column may be long. Also note that these keywords could be part of comments orstring constants, in which case they can be ignored:SELECT owner, name, type, line, textFROM sys.dba_sourceWHERE instr(UPPER(text), UPPER('')) > 0The queries above should be run for all <strong>Sybase</strong> <strong>ASE</strong> reserved words and keywords. The most practical way of runningthese queries for all <strong>ASE</strong> keywords is <strong>to</strong> insert the <strong>ASE</strong> keywords in an <strong>Oracle</strong> table, and then run the above queries as ajoin with this table.For a complete list of reserved words and keywords in <strong>Sybase</strong> <strong>ASE</strong>, see “Adaptive Server Enterprise->Reference Manual:Building Blocks->Reserved Words”. Reserved words can also be displayed with the following <strong>ASE</strong> query (but checkcompleteness against the <strong>ASE</strong> documentation!):Database Schema <strong>Migration</strong> 23


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3SELECT name FROM master..spt_values WHERE type = 'W'4.9 Choosing a lock scheme for <strong>Sybase</strong> <strong>ASE</strong> tables<strong>ASE</strong> offers a choice of three lock schemes for each database table: allpages, datapages or datarows.allpages is the oldest lock scheme, as well as the out-of-the-box <strong>ASE</strong> default. It is slightly more efficient for sometypes of operations. The datapages, and especially datarows, lock schemes provide fundamentally betterconcurrency characteristics. The concurrency benefits are likely <strong>to</strong> be relevant when migrating from <strong>Oracle</strong> <strong>to</strong> <strong>Sybase</strong><strong>ASE</strong> due <strong>to</strong> the difference in transaction handling (as described in chapter 8).It is recommended <strong>to</strong> configure datapages or datarows as the default lock scheme in <strong>Sybase</strong> <strong>ASE</strong>. datapages ismore efficient, but datarows provides better concurrency (datarows locking is also known as row-level locking).Changing between datarows and datapages for an existing table is instantaneous. In contrast, large tables with theallpages lock scheme may require long downtimes <strong>to</strong> if their lock schemes need <strong>to</strong> be changed <strong>to</strong> datarows ordatapages since this requires a full conversion of the table and all its indexes.4.10 The <strong>Oracle</strong> DUAL TableIn <strong>Oracle</strong>, a SELECT statement must always be executed against a table, even when retrieving system information, suchas the current date/time. For this purpose, <strong>Oracle</strong> created the DUAL table. Retrieving the system date via SQL lookslike this in <strong>Oracle</strong>:SELECT sysdate FROM DUAL<strong>Sybase</strong> <strong>ASE</strong> supports SELECT statements that do not have a FROM clause. The same query in <strong>Sybase</strong> <strong>ASE</strong> would looklike this:SELECT getdate()To avoid rewriting existing SELECTs that use the DUAL table, it is possible <strong>to</strong> create a table named DUAL in <strong>ASE</strong>,which must always contain one and only row:create table DUAL (dummy_col char(1) unique check (dummy_col='X'))insert DUAL values ('X')goIf <strong>Sybase</strong> <strong>ASE</strong> is created case-sensitive (see section 5.2), you may need <strong>to</strong> create additional tables named dual, Dual,etc, depending on how disciplined the <strong>Oracle</strong> developers were in using a consistent spelling for the DUAL table.Alternatively, consider editing the <strong>Oracle</strong> PL/SQL source code <strong>to</strong> use only "DUAL", or <strong>to</strong> remove all references <strong>to</strong>DUAL completely.Database Schema <strong>Migration</strong> 24


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.35 MIGRATING SERVER-LEVEL ASPECTSThe architecture of the database server, and the way it is configured and managed, are quite different between <strong>Oracle</strong>and <strong>Sybase</strong> <strong>ASE</strong>. This chapter lists some migration aspects that require attention, but without claim for completeness.The reader is urged <strong>to</strong> consult the <strong>Sybase</strong> documentation, specifically the "System Administration <strong>Guide</strong>", for full details.5.1 Character setWhen creating a new <strong>Sybase</strong> <strong>ASE</strong> server, the character set <strong>to</strong> be used by the <strong>ASE</strong> server must be chosen. It isrecommended <strong>to</strong> use the same character for <strong>ASE</strong>, as is being used for the <strong>Oracle</strong> database.While the character set in <strong>ASE</strong> can be changed at a later point in time, it is strongly recommended <strong>to</strong> avoid this, and <strong>to</strong>pick the right character set before migrating any <strong>Oracle</strong> aspects <strong>to</strong> <strong>ASE</strong>.5.2 Database server case sensitivity ('sort order')A difference between <strong>Oracle</strong> and <strong>Sybase</strong> <strong>ASE</strong> is that <strong>Oracle</strong> is not case-sensitive, whereas <strong>Sybase</strong> <strong>ASE</strong> is case-sensitiveby default. <strong>ASE</strong> can be configured <strong>to</strong> be case-insensitive, by installing a case-insensitive 'sort order'.Moreover, there is also a difference in the scope of case-insensitivity between <strong>Oracle</strong> and <strong>ASE</strong>:In a case-insensitive <strong>ASE</strong> server, case-insensitivity applies <strong>to</strong> both identifiers and <strong>to</strong> data comparisons; SQLkeywords are always case-insensitive in <strong>ASE</strong>.In <strong>Oracle</strong>, case-insensitivity applies only <strong>to</strong> identifiers (table names, column names, etc), but, by default, not <strong>to</strong>data comparisons; it is likely that existing <strong>Oracle</strong> systems use this default. Note that the above applies only <strong>to</strong>unquoted identifiers; quoted identifiers are case-sensitive in <strong>Oracle</strong>, though these are not used often.As a result, the following two queries will retrieve different data in a case-insensitive <strong>Oracle</strong> system, but retrieve the samedata in a case-insensitive <strong>Sybase</strong> <strong>ASE</strong>:select * from Employees where Name = 'Johnson'select * from Employees where Name = 'JOHNSON'Also, existing <strong>Oracle</strong> SQL code refers <strong>to</strong> the table TEST in different ways - the following all refer <strong>to</strong> the same table.Inconsistent use of upper- and lower-case spelling for identifiers is not uncommon <strong>to</strong> occur in practical <strong>Oracle</strong> systems:select * from TESTselect * from Testselect * from testWhen using a case-insensitive sort order for <strong>Sybase</strong> <strong>ASE</strong>, such SQL statements do not need <strong>to</strong> be changed. When usingthe default case-sensitive <strong>ASE</strong> sort order, all references <strong>to</strong> a table must use the exact same upper/lowercase spelling, or"table not found" errors will result.Whether the <strong>ASE</strong> server should be case-sensitive or case-insensitive is a decision <strong>to</strong> be made. For <strong>ASE</strong>, there is nooverriding technical advantage <strong>to</strong> either option.In practice, the decision probably depends on whether query results may be affected by using a case-insensitive <strong>ASE</strong>server. If this is the case, then the default case-sensitive <strong>ASE</strong> configuration should be used, and any <strong>Oracle</strong> SQLstatements referring <strong>to</strong> identifiers in mixed-case spelling (i.e. TEST and Test) should be changed <strong>to</strong> use one consistentspelling for the identifiers.Migrating server-level aspects 25


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.35.3 Server configuration parametersIn <strong>Oracle</strong>, the configuration parameters for the server and database are s<strong>to</strong>red in the initialization file (init.ora) orserver parameter file (spfile). These parameters cover a diverse set of resources, such as memory, processes, network,disk, I/O, connections, files, character set, and so on.It is unlikely that <strong>Oracle</strong> configuration parameters can be mapped directly <strong>to</strong> corresponding configuration parameters for<strong>Sybase</strong> <strong>ASE</strong>. It may however be useful <strong>to</strong> be aware of <strong>Oracle</strong>-specific configuration settings since in some cases somekind of <strong>Sybase</strong> <strong>ASE</strong> equivalent could be required.The non-default values of the <strong>Oracle</strong> parameters can be obtained using one of the following options:Convert the server parameter file (spfile) <strong>to</strong> an initialization parameter file as follows:CREATE pfile FROM spfileQuery the database by executing the following statement:SELECT name, value FROM sys.v$spparameterWHERE isspecified = 'TRUE'5.4 S<strong>to</strong>rageMost <strong>Oracle</strong> installations enlist the help of <strong>Oracle</strong>‟s Au<strong>to</strong>mated S<strong>to</strong>rage Manager (ASM). <strong>Sybase</strong> <strong>ASE</strong> does not have theequivalent of ASM. S<strong>to</strong>rage must be managed through T-SQL commands, <strong>Sybase</strong> Control Center , or via <strong>Sybase</strong> Central(the <strong>Sybase</strong> database admin GUI <strong>to</strong>ol).Generally speaking, <strong>Sybase</strong> <strong>ASE</strong> recommends the following high-level guidelines for s<strong>to</strong>rage:For user databases, use raw devices or filesystem devices with directio=true. Never use filesystem devices withdsync=false for user databases; filesystem devices with dsync=true can be used but carry a potentiallysignificant performance penaltyFor temporary databases, filesystem devices with dsync=false are generally recommended.For the underlying s<strong>to</strong>rage layer, RAID 0+1 or RAID 1+0 is recommended. Avoid RAID 5 for write-intensivepurposes such as the <strong>ASE</strong> transaction log, unless the s<strong>to</strong>rage solution provides a non-volatile write cache <strong>to</strong>buffer the writes.To achieve maximum disk I/O bandwidth, read- and write-intensive data should preferably be spread over asmany physical spindles as possible.Many additional considerations with respect <strong>to</strong> s<strong>to</strong>rage configuration apply. Please refer <strong>to</strong> the <strong>Sybase</strong> <strong>ASE</strong> "SystemAdministration <strong>Guide</strong>" for details.5.5 Migrating the User LoginsThere are some differences in terminology between <strong>Oracle</strong> and <strong>Sybase</strong> <strong>ASE</strong> around the concept of a "user".In <strong>Oracle</strong>, on instance level: a user is used for authentication, and can also be a schema owner (and thus owndatabase objects, and have permissions on database objects)In <strong>Sybase</strong> <strong>ASE</strong>, on server level: a login is used for authentication, but does not own any objects or haveobject access permission.A special <strong>ASE</strong> login is sa - this is the 'super user' in <strong>Sybase</strong> <strong>ASE</strong>, comparable <strong>to</strong> the SYS account in <strong>Oracle</strong>.This user has access permissions on all database objects and should be restricted <strong>to</strong> the DBA. For securityreasons, applications should never use the sa login <strong>to</strong> connect <strong>to</strong> the <strong>ASE</strong> server.Migrating server-level aspects 26


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3In <strong>Sybase</strong> <strong>ASE</strong>, on database level: a user, which maps <strong>to</strong> a login, can own database objects and havepermissions on database objects.When migrating from <strong>Oracle</strong> <strong>to</strong> <strong>Sybase</strong> <strong>ASE</strong>, the most likely scenario is <strong>to</strong> migrate all <strong>Oracle</strong> application users <strong>to</strong> anidentically named <strong>Sybase</strong> <strong>ASE</strong> login. For each <strong>ASE</strong> login, a corresponding database user (typically with the same name asthe login) is then created <strong>to</strong> allow that login <strong>to</strong> access an <strong>ASE</strong> user database. A login can be given access <strong>to</strong> multiple <strong>ASE</strong>databases by creating a corresponding database user in each <strong>ASE</strong> database.Alternatively, the guest database user can be created in each <strong>ASE</strong> user database. However, related security implicationsshould be carefully assessed first.The resulting structure of <strong>ASE</strong> logins and database users depends on decisions about how an <strong>Oracle</strong> schema is migrated<strong>to</strong> <strong>ASE</strong> (see section 4.5).5.5.1 User passwordsEach <strong>Oracle</strong> user has a password. In <strong>ASE</strong>, a login has a password. If the <strong>Oracle</strong> user passwords are known, they can beset identically in <strong>ASE</strong>; otherwise, new passwords must be set for the <strong>ASE</strong> logins. <strong>ASE</strong> login passwords cannot be set <strong>to</strong>blanks.5.6 PermissionsIt is recommended <strong>to</strong> use PowerDesigner 16 <strong>to</strong> reverse-engineer the permissions for accessing (objects in) the <strong>Oracle</strong>database. If PowerDesigner 16 cannot be used, the permissions will likely have <strong>to</strong> be converted manually <strong>to</strong> the <strong>Sybase</strong><strong>ASE</strong> equivalent.Migrating server-level aspects 27


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.36 DATA MIGRATIONThis section describes the methods for migrating data from <strong>Oracle</strong> <strong>to</strong> <strong>Sybase</strong> <strong>ASE</strong>. It is assumed that the schema hasalready been migrated.The main complicating fac<strong>to</strong>r is that <strong>Oracle</strong> provides no <strong>to</strong>ols <strong>to</strong> unload a table <strong>to</strong> a flat file in a format that can be readby non-<strong>Oracle</strong> <strong>to</strong>ols.Data migration can be performed in a number of ways. Therefore, when choosing an approach, various fac<strong>to</strong>rs need <strong>to</strong>be considered, including:- the complexity of the chosen solution- the volume of data being migrated- the available system downtime <strong>to</strong> perform the data migration during cu<strong>to</strong>ver- the need <strong>to</strong> become familiar with new software or <strong>to</strong>ols for the purpose of migrating the data- additional software license costsIn essence, the following options are available for data migration:Unload <strong>Oracle</strong> data in<strong>to</strong> ASCII-formatted flat files, and load these files in<strong>to</strong> <strong>ASE</strong> with the <strong>Sybase</strong>"bcp" utility.If <strong>Oracle</strong> data can be exported in<strong>to</strong> an ASCII-formatted flat file, then <strong>ASE</strong>'s high-speed loading <strong>to</strong>ol "bcp" canload it in<strong>to</strong> <strong>ASE</strong>. Since <strong>Oracle</strong> does not provide a way <strong>to</strong> achieve this, the user must either use a 3 rd -party <strong>to</strong>olfor this purpose, or create his own PL/SQL utility <strong>to</strong> essentially spool the data from the database in<strong>to</strong> a flat file.Considerations: This option is often seen as attractive due <strong>to</strong> the transparency of the migration process: allsteps are clearly visible and can be individually developed and tested. Developing your own PL/SQL <strong>to</strong>ol <strong>to</strong>unload <strong>Oracle</strong> data is simple, but will perform slowly, thus making it unsuitable for anything but relatively smalldata volumes. Using a 3 rd -party <strong>to</strong>ol adds software license costs.Use <strong>Sybase</strong>'s Enterprise Connect Data Access (ECDA) Option for <strong>Oracle</strong>.ECDA is a connectivity product by <strong>Sybase</strong> that enables direct connections from an <strong>ASE</strong> database in<strong>to</strong> an<strong>Oracle</strong> database, making it possible <strong>to</strong> transfer <strong>Oracle</strong> data directly in<strong>to</strong> <strong>ASE</strong>. ECDA hooks in<strong>to</strong> the <strong>ASE</strong>mechanism of "proxy tables".Considerations: This option can be used when the data volume is such that the data can be transferred in theavailable migration window. It is unlikely <strong>to</strong> be suitable for very large data volumes. An advantage is thatECDA takes care of mapping <strong>Oracle</strong> datatypes <strong>to</strong> <strong>ASE</strong> datatypes, and that the migration can be fullyperformed through SQL.Using this option requires purchasing <strong>Sybase</strong>'s ECDA product.Use <strong>Sybase</strong> Replication Server Heterogeneous Edition (RSHE) for <strong>Oracle</strong><strong>Sybase</strong> Replication Server captures database transactions in <strong>Oracle</strong> and applies these <strong>to</strong> <strong>ASE</strong>, thus keeping the<strong>ASE</strong> database continuously up-<strong>to</strong>-date. In addition, Replication Server can also initially copy the full contentsof the <strong>Oracle</strong> tables in<strong>to</strong> <strong>ASE</strong>, in order <strong>to</strong> initialize the data replication ("materialization of the replicationsystem").Considerations: Using transactional replication is the only data migration solution where activity on the <strong>Oracle</strong>database can continue while the data migration is in progress. This means that the migration downtime, duringwhich applications are not available because they must switch from the <strong>Oracle</strong> database <strong>to</strong> the <strong>ASE</strong> database, isindependent of the data volume being migrated; this downtime could potentially be very short (e.g. minutesrather than hours).Using this option requires purchasing <strong>Sybase</strong>'s Replication Server product, as well as learning how <strong>to</strong> useReplication Server.Letting Replication Server perform the initial data copy from <strong>Oracle</strong> <strong>to</strong> <strong>ASE</strong> may not be realistic for large datavolumes. In this case, the initial materialization of the replication system might be better performed with one ofthe other options mentioned here.Use a 3 rd -party ETL <strong>to</strong>ol that supports both <strong>Oracle</strong> and <strong>Sybase</strong> <strong>ASE</strong>.Data <strong>Migration</strong> 28


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3Considerations: This option is most attractive if the ETL <strong>to</strong>ol is already in use so that no additional softwareneeds <strong>to</strong> be purchased for the migration alone.an be used when the data volume is such that the data can be transferred in the available migration window. Itcan be used for very large data volumes, but a sizeable migration window may be required.6.1 Unload <strong>Oracle</strong> data in<strong>to</strong> ASCII files; load in<strong>to</strong> <strong>ASE</strong> with "bcp" utility<strong>ASE</strong>'s high-speed data loading utility "bcp" is capable of loading almost any type of appropriately formatted ASCII datafile in<strong>to</strong> <strong>ASE</strong>. However, since <strong>Oracle</strong> does not provide any <strong>to</strong>ols <strong>to</strong> export <strong>Oracle</strong> data in<strong>to</strong> an ASCII-formatted file, theuser must either use a 3rd-party <strong>to</strong>ol for this purpose, or create his own PL/SQL utility <strong>to</strong> essentially spool the data fromthe database in<strong>to</strong> a flat file. FACT is an example of such a 3-rd party <strong>to</strong>ol.6.1.1 Loading in<strong>to</strong> <strong>ASE</strong> with "bcp"This is an example of loading data from an ASCII file in<strong>to</strong> an <strong>ASE</strong> table (named mydb..mytable) with bcp:bcp mydb..mytable in mytable.txt –Ulogin –Ppassword –Sserver –cIn practical situations, bcp should also specify which row- and column delimiters are used (bcp -r and -t options) sincethe defaults (CR and tab) could also occur in the actual data file (which is ASCII, after all). When unloading data in<strong>to</strong> flatASCII files, proper delimiters should be chosen.Bcp-in performance is best when all indexes on the tables being loaded, are dropped first. Of course, , depending on thesize and number of indexes and the width of the base tables, recreating them afterwards could take a long time on largetables, so this may not be realistic for all cases.It is usually best <strong>to</strong> use a large network packet size with bcp (the –A option; also requires configuring the network packetsize on the <strong>ASE</strong> server).For large tables, it may be advisable <strong>to</strong> use the bcp –b option <strong>to</strong> break the load in<strong>to</strong> multiple database transactions. Thisis typically combined with enabling the "trunc log on checkpt" database option in <strong>ASE</strong> <strong>to</strong> avoid the transaction logfilling up.To load only part of a data file, or <strong>to</strong> load columns in a different order than in the file, a so-called "bcp format file" maybe used. For more information on format files, as well as on bcp in general, see the Utility <strong>Guide</strong> in the <strong>ASE</strong>documentation set (http://tinyurl.com/6883kx4).It is highly recommended <strong>to</strong> perform multiple bcp operations in parallel (one for each table being loaded). The optimalnumber of concurrent bcp operations will be determined by the hardware capabilities. If there is only one (or few) largetables that need <strong>to</strong> be loaded, these can still be loaded using in multiple BCP operations by adding partitioning the tableusing round robin partitioning and specifying the start and last rows of the data file being loaded in<strong>to</strong> a particularpartition number of the table.Lastly, note that, on Unix/Linux, bcp can read from a "named pipe" (created with the "mkfifo" command). If the utilitythat extracts the data in<strong>to</strong> a file can write <strong>to</strong> a named pipe as well, then a lot of time can potentially be saved as follows:1. Create a named pipe with the Unix/Linux "mkfifo" command2. Extract the data from <strong>Oracle</strong>, writing it <strong>to</strong> the named pipe.3. Without waiting for the data extraction <strong>to</strong> complete, start bcp <strong>to</strong> load the data from the same named pipe. Bcpwill read data from the named pipe once it is delivered by the extraction utility, and immediately insert it in<strong>to</strong><strong>ASE</strong>.Instead of first extracting the data and then loading it, the time <strong>to</strong> transfer the data is now reduced <strong>to</strong> the longer of(extracting the data, loading the data). This can represent significant time gain.For more information on bcp and named pipes, please refer <strong>to</strong> http://tinyurl.com/5urcfrt .6.1.2 Unloading from <strong>Oracle</strong>: FACT (3rd-party <strong>to</strong>ol)FACT ("Fast Extract") is a 3 rd -party high speed <strong>Oracle</strong> data export <strong>to</strong>ol that allows ASCII flat file creation, also inparallel mode. These files can be used as input for the <strong>Sybase</strong> <strong>ASE</strong> utility bcp.Data <strong>Migration</strong> 29


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3For more information about FACT, see http://www.iri.com/products/FACT.6.1.3 Unloading from <strong>Oracle</strong>: Roll-your-own PL/SQL utility <strong>to</strong> export <strong>Oracle</strong> dataIf you want <strong>to</strong> unload data from <strong>Oracle</strong> tables in<strong>to</strong> ASCII flat files using only <strong>Oracle</strong> features, you must create your ownPL/SQL utility that essentially spools the data from the database in<strong>to</strong> a flat file. This uses the DBMS_OUTPUT.put_linecommand in PL/SQL. Here's an example of exporting two columns of table emp using "~" as a column delimiter andCR as a row delimiter. The output from this PL/SQL code should be captured in a flat file:DECLARE CURSOR emp_cur IS SELECT ename, sal FROM emp;BEGINFOR emp_rec IN emp_curLOOPDBMS_OUTPUT.PUT_LINE (emp_rec.ename || '~' || TO_CHAR (emp_rec.sal) );END LOOP;END;/The downside is that this method is likely <strong>to</strong> be very slow, making it unsuitable for anything but relatively small datavolumes. In addition, care must be taken <strong>to</strong> correctly format/convert each column datatype management.6.1.4 Unloading from <strong>Oracle</strong>: use <strong>Oracle</strong> SQL Developer<strong>Oracle</strong> SQL Developer is a free Java-based <strong>to</strong>ol, downloadable from oracle.com. This can be used <strong>to</strong> create a logicalexport of the data, whereby a SQL INSERT statement is created for every row.The downside is that this method is likely <strong>to</strong> be relatively slow in exporting as well as importing the extracted data, sincethis is all done on a single-row basis. This may make it unsuitable for large data volumes.6.2 Use <strong>Sybase</strong>'s Enterprise Connect Data Access (ECDA) Option for <strong>Oracle</strong>ECDA is a connectivity product by <strong>Sybase</strong> that acts as a gateway between <strong>Oracle</strong> and <strong>Sybase</strong> <strong>ASE</strong>. With ECDA, directconnections can be made from an <strong>ASE</strong> database in<strong>to</strong> an <strong>Oracle</strong> database, making it possible <strong>to</strong> transfer <strong>Oracle</strong> datadirectly in<strong>to</strong> <strong>ASE</strong> using only SQL.The ECDA functionality is exposed as an <strong>ASE</strong> "proxy table", which maps <strong>to</strong> the actual <strong>Oracle</strong> table. By selecting fromthe proxy table, data is retrieved from the <strong>Oracle</strong> table and can be inserted directly in<strong>to</strong> an <strong>ASE</strong> table. Also, it is possible<strong>to</strong> do things like joining <strong>Oracle</strong> tables (though their proxy table) with tables in <strong>Sybase</strong> <strong>ASE</strong>.The main advantage of using ECDA is that takes care au<strong>to</strong>matically of the datatype conversions from <strong>Oracle</strong> <strong>to</strong> <strong>Sybase</strong><strong>ASE</strong> when the data is retrieved. It also offers the flexibility and control of using the SQL language <strong>to</strong> access <strong>to</strong> proxytables.ECDA involves starting a separate process outside the <strong>ASE</strong> server.6.2.1 ECDA ExampleFor examples of how <strong>to</strong> use ECDA in an <strong>Oracle</strong> migration context, see the document “Migrating an <strong>Oracle</strong> Database <strong>to</strong>SAP <strong>Sybase</strong> <strong>ASE</strong> with PowerDesigner and ECDA (A Step-By-Step Practical <strong>Guide</strong>)” athttp://www.sybase.com/support/techdocs/migration.6.3 Use <strong>Sybase</strong> Replication Server Heterogeneous Edition (RSHE) for <strong>Oracle</strong><strong>Sybase</strong> Replication Server is often used by <strong>Sybase</strong> cus<strong>to</strong>mers <strong>to</strong> facilitate migrations between databases. The mainattraction is that the required downtime for curring over from the "old" <strong>to</strong> the "new" database can in principle be veryshort as far as the database side of things is concerned.6.3.1 Minimal migration downtime with ReplicationReplication Server captures database transactions in <strong>Oracle</strong> by reading the <strong>Oracle</strong> redo logs, and then applies thesetransactions <strong>to</strong> <strong>ASE</strong>, thus keeping the <strong>ASE</strong> database continuously up-<strong>to</strong>-date. In addition, Replication Server can alsoData <strong>Migration</strong> 30


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3initially copy the full contents of the <strong>Oracle</strong> tables in<strong>to</strong> <strong>ASE</strong>, in order <strong>to</strong> initialize the data replication ("materialization ofthe replication system"). When large tables are involved, a main decision <strong>to</strong> be made is whether this initial materializationneeds <strong>to</strong> be performed through Replication Server or through an external unload-and-load mechanism.When using Replication Server for data migration, the objective is <strong>to</strong> reach a state where the <strong>ASE</strong> database is completelyin synch with the <strong>Oracle</strong> database, at which point the applications can switch from the <strong>Oracle</strong> database <strong>to</strong> the <strong>ASE</strong>database (after the cu<strong>to</strong>ver, the replication setup can be removed). The system downtime needs <strong>to</strong> be only as long as thisapplication cu<strong>to</strong>ver takes, which would typically rather be minutes rather than hours.It is essential <strong>to</strong> observe that replication is application-transparent: applications can keep working normally on the <strong>Oracle</strong>database until the moment of cu<strong>to</strong>ver comes (obviously, the applications themselves likely require modifications <strong>to</strong> runon an <strong>ASE</strong> database instead of <strong>Oracle</strong>, but that is outside the scope of this <strong>to</strong>pic of data migration).Other data migration solutions than transactional replication will require significantly more downtime. This is becauseReplication Server provides a mechanism <strong>to</strong> incrementally upload data changes from <strong>Oracle</strong> <strong>to</strong> <strong>ASE</strong> allowingapplications continue <strong>to</strong> work normally. In contrast, most other migration methods essentially take a copy of an entiretable which usually requires applications <strong>to</strong> be shut down or in read-only mode since it can be very difficult <strong>to</strong> reconcileany data changes <strong>to</strong> the copied afterwards. For those other migration methods, the required system downtime istherefore roughly identical <strong>to</strong> the time required <strong>to</strong> copy the data out of <strong>Oracle</strong> and in<strong>to</strong> <strong>Sybase</strong>.6.3.2 Initial materialization for the replication setupReplication Server can au<strong>to</strong>matically copy the full contents of the <strong>Oracle</strong> tables in<strong>to</strong> <strong>ASE</strong>, in order <strong>to</strong> initialize the datareplication ("materialization of the replication system"). However, for very large tables, this may take unacceptably long.An alternative approach may therefore be <strong>to</strong> take an initial copy from these large tables through other means, like one ofthe other options described in this section on data migration (for example, unload in<strong>to</strong> an ASCII flat file and load in<strong>to</strong><strong>ASE</strong> with bcp). With Replication Server, changes made <strong>to</strong> the table afterwards will be synch'd afterwards. The high-levelapproach would be as follows:1. Set up table replication for all <strong>Oracle</strong> tables <strong>to</strong> <strong>ASE</strong> tables, but do not au<strong>to</strong>-materialize the large tables.Optionally, enable "au<strong>to</strong>correction" for the large tables (depending on your understanding of the type of datachanges that may be made; see the Replication Server documentation for details).2. Suspend the DSI connection by Replication Server <strong>to</strong> the <strong>ASE</strong> database. Any future changes <strong>to</strong> the <strong>Oracle</strong>tables will be picked up by Replication Server and are accumulated in Replication Server's "stable queues". At alater point, these changes will be applied <strong>to</strong> <strong>ASE</strong>.3. For the large tables, take a copy and load this in<strong>to</strong> <strong>ASE</strong> (using your preferred method).4. Once the loading of the large tables in<strong>to</strong> <strong>ASE</strong> is complete, resume the connection from Replication Server <strong>to</strong>the <strong>ASE</strong> database. This will push out the changes that were accumulated in Replication Server's "stablequeues", and apply these <strong>to</strong> the <strong>ASE</strong> tables.5. Once all accumulated changes are pushed out <strong>to</strong> <strong>ASE</strong>, the <strong>ASE</strong> database should be in the same state as the<strong>Oracle</strong> database and the applications can switch over <strong>to</strong> complete the migration.When the tables are not <strong>to</strong>o large <strong>to</strong> perform au<strong>to</strong>matic materialization, or when it is acceptable that such materializationtakes a long time (since the <strong>Oracle</strong> applications keep functioning normally anyway), then the above steps can be replacedby simple setting up table replication from <strong>Oracle</strong> <strong>to</strong> <strong>ASE</strong> using au<strong>to</strong>matic materialization.6.3.3 Other considerationsUsing this option requires purchasing <strong>Sybase</strong>'s Replication Server Heterogeneous Edition (RSHE) for <strong>Oracle</strong>, as well aslearning how <strong>to</strong> use Replication Server. Letting Replication Server perform the initial data copy from <strong>Oracle</strong> <strong>to</strong> <strong>ASE</strong>may not be realistic for large data volumes. In this case, the initial materialization of the replication system might bebetter performed with one of the other options mentioned here.Before using <strong>Sybase</strong> Replication Server <strong>to</strong> replicate out of an <strong>Oracle</strong> database, verify whether this complies with theavailable <strong>Oracle</strong> licenses. If a full <strong>Oracle</strong> license is used, there should be no restrictions; if a more restricted <strong>Oracle</strong>Data <strong>Migration</strong> 31


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3license is used (like a run-time only license), this might legally prohibit use of Replication Server and additional <strong>Oracle</strong>licensing might be needed. This is a matter outside the scope of <strong>Sybase</strong>, and should be addressed with <strong>Oracle</strong>.<strong>Oracle</strong> GoldenGate can also provide transactional replication between <strong>Oracle</strong> and <strong>Sybase</strong> <strong>ASE</strong>. If the cus<strong>to</strong>mer alreadyhas this product available, in principle this can also be used as part of a migration, in similar ways as described above for<strong>Sybase</strong> Replication Server.6.4 Use a 3rd-party ETL <strong>to</strong>ol that supports both <strong>Oracle</strong> and <strong>Sybase</strong> <strong>ASE</strong>If an ETL <strong>to</strong>ol is already in use which supports both <strong>Oracle</strong> and <strong>Sybase</strong>, it may be attractive <strong>to</strong> use it <strong>to</strong> perform the datamigration. Typically this would require system downtime for the duration of transferring the data from <strong>Oracle</strong> <strong>to</strong> <strong>Sybase</strong>,unless the ETL <strong>to</strong>ol is capable of sorting out any changes <strong>to</strong> the data that are made during the transfer process.Please make sure that you adhere <strong>to</strong> any license restrictions and clear the use of this <strong>to</strong>ol <strong>to</strong> move data from <strong>Oracle</strong> <strong>to</strong><strong>Sybase</strong> <strong>ASE</strong> with this vendor.6.5 <strong>Oracle</strong> datatypes requiring special attention for migrationThe following <strong>Oracle</strong> datatypes require special attention when migrating the data. <strong>Oracle</strong> TIMESTAMP <strong>Sybase</strong> BIGDATETIME<strong>Oracle</strong>‟s TIMESTAMP datatype has a granularity of 1/100000000 th of a second. This exceeds the precision of<strong>Sybase</strong>‟s BIGDATETIME datatype which has a granularity of 1 microsecond. When migrating data with bcp,TIMESTAMP data may need <strong>to</strong> be edited <strong>to</strong> remove the last 3 digits <strong>to</strong> avoid bcp throwing an error. <strong>Oracle</strong> BLOB/CLOB/NCLOB <strong>Sybase</strong> IMAGE/TEXT /UNITEXT<strong>Oracle</strong> s<strong>to</strong>res large binary objects in the BLOB datatype and large character objects in the CLOB datatype. Bothdatatypes can s<strong>to</strong>re up <strong>to</strong> 128TB (4GB * database block size) of data, as of <strong>Oracle</strong> 11g. When migrating, data from<strong>Oracle</strong>‟s BLOB datatype should be mapped <strong>to</strong> <strong>Sybase</strong> IMAGE datatype and CLOB <strong>to</strong> the TEXT datatype. Themaximum size for an individual column value of the IMAGE or TEXT datatype in <strong>Sybase</strong> <strong>ASE</strong> is 2GB. If theactual <strong>Oracle</strong> data values are larger than this maximum, <strong>ASE</strong> is unable <strong>to</strong> s<strong>to</strong>re these values. In this case, <strong>Sybase</strong> IQmight be a solution since it supports a maximum varying between 512TB <strong>to</strong> 2PB per column value. <strong>Oracle</strong> BFILEThe <strong>Oracle</strong> BFILE datatype is used <strong>to</strong> s<strong>to</strong>re a loca<strong>to</strong>r (link) <strong>to</strong> an external binary file s<strong>to</strong>red outside of the database.<strong>Sybase</strong> <strong>ASE</strong> has no direct functional equivalent, so application changes may be required.Data <strong>Migration</strong> 32


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.37 MIGRATING PL/SQL TO TRANSACT-SQLPL/SQL is <strong>Oracle</strong>'s implementation of the SQL language. Transact-SQL (T-SQL) is <strong>Sybase</strong> <strong>ASE</strong>'s SQL dialect.Both SQL versions are mostly ANSI-92 entry-level compliant, but both vendors have implemented extensive non-ANSI-compliant vendor-specific enhancements and extensions.In many cases both dialects will still have equivalent functionality in their vendor-specific extensions, but syntax changesor varying amounts of code changes may be required when migrating from PL/SQL <strong>to</strong> T-SQL. In cases where T-SQLdoes not have a direct equivalent of a particular PL/SQL construct, larger amounts of code rewrite or even applicationrewrite could be required.While the incompatibilities between <strong>Oracle</strong> and <strong>Sybase</strong> are quite limited when it comes <strong>to</strong> schema migration and datamigration, there is much more potential for migration complexity between the two SQL dialect. Consequently, migratingPL/SQL <strong>to</strong> T-SQL is probably the most involved part of any <strong>Oracle</strong> <strong>to</strong> <strong>Sybase</strong> migration, and will typically requiremanual conversion/migration activity.A key fac<strong>to</strong>r for a successful migration –or, for that matter, for avoiding a failed migration- is a realistic assessment ofthe SQL-related complexities <strong>to</strong> be migrated before starting the migration project. Chapter 3 provides checklists for thispurpose.To assist with the actual migration of PL/SQL <strong>to</strong> T-SQL, chapter 11 contains a cross-reference between <strong>Oracle</strong> featuresand their <strong>Sybase</strong> <strong>ASE</strong> equivalents, in three categories of complexity. This cross-reference is an extended version of the<strong>Oracle</strong> checklist in chapter 3 but provides more detail and provides specific suggestions on how <strong>to</strong> migrate a specific<strong>Oracle</strong> feature <strong>to</strong> <strong>ASE</strong>.7.1 Locations of PL/SQL codePL/SQL code can be found in the following locations:S<strong>to</strong>red procedures (in the database server)Triggers (in the database server)SQL functions (in the database server)SQL queries (submitted <strong>to</strong> the database server by client applications, for example as anonymous PL/SQLblocks)PL/SQL objects in the database server can be reverse-engineered, or, if present and up-<strong>to</strong>-date, reposi<strong>to</strong>ry scripts thatwere used <strong>to</strong> create these PL/SQL objects can be taken as a starting point.PL/SQL code located in client applications needs <strong>to</strong> be identified in a different way, for example source code inspectionWhen it comes <strong>to</strong> using existing scripts or reverse-engineering the PL/SQL objects from the database server, the sameconsiderations apply as with respect <strong>to</strong> the database schema; see the pros and cons discussed in section 4.1.<strong>Sybase</strong> PowerDesigner may also be used <strong>to</strong> reverse-engineer PL/SQL objects (see section 4.2); however PowerDesignerdoes not perform any conversion <strong>to</strong> T-SQL (for this, evaluate <strong>to</strong>ols as in section 7.2 below).Since the majority of PL/SQL is typically located in s<strong>to</strong>red procedures and triggers, "migrating PL/SQL" is oftenequated <strong>to</strong> "migrating s<strong>to</strong>red procedures and triggers". While that definition is not formally correct (there are otherplaces where PL/SQL occurs, as shown above), it does reflect the area where most migration issues are typicallyencountered.7.2 3 rd -party <strong>to</strong>ols for PL/SQL migration <strong>to</strong> T-SQLTools for migrating from PL/SQL <strong>to</strong> T-SQL would be a welcome help when undertaking <strong>Oracle</strong> <strong>to</strong> <strong>ASE</strong> migrations.However, it is unlikely that any au<strong>to</strong>mated <strong>to</strong>ol will be capable of perfectly migrating all of the PL/SQL code in any reallife<strong>Oracle</strong> system <strong>to</strong> <strong>ASE</strong>'s T-SQL. Yet, it may well be possible that a substantial percentage can be handled by a <strong>to</strong>ol,but a certain amount of manual conversion/migration should be expected.Migrating PL/SQL <strong>to</strong> Transact-SQL 33


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3SwisSQL and SQLWays (both 3 rd -part <strong>to</strong>ols) are among the few <strong>to</strong>ols that provide assistance with au<strong>to</strong>matic migrationof <strong>Oracle</strong> PL/SQL code <strong>to</strong> <strong>Sybase</strong> T-SQL. For more information, see www.swissql.com (SwisSQL) andwww.ispirer.com (SQLWays).It should be noted that for both <strong>to</strong>ols, support for <strong>ASE</strong> features in general, and new features in <strong>ASE</strong> 15.0 and later inparticular, appears <strong>to</strong> be limited. It is recommended <strong>to</strong> carefully evaluate these <strong>to</strong>ols before using them for PL/SQLmigration.Please note that the above neither constitutes an endorsement by SAP/<strong>Sybase</strong> of either SwisSQL or SQLWays, nor astatement about the suitability of these <strong>to</strong>ols for any specific project or purpose.Migrating PL/SQL <strong>to</strong> Transact-SQL 34


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.38 TRANSACTIONS AND LOCKING, ORACLE VS. SYB<strong>ASE</strong>The <strong>to</strong>pic of transaction handling, transaction isolation and locking is probably where the most profound differencesbetween <strong>Oracle</strong> and <strong>Sybase</strong> <strong>ASE</strong> occur. For this reason a separate chapter is dedicated <strong>to</strong> this <strong>to</strong>pic.8.1 <strong>Oracle</strong> MVCC vs. <strong>Sybase</strong> lockingThe purpose of transactions in the database is <strong>to</strong> take the database from one consistent state <strong>to</strong> the next. Databasetransactions, both in <strong>Oracle</strong> and <strong>Sybase</strong> <strong>ASE</strong>, guarantee all of the ANSI-defined ACID characteristics. ACID is anacronym for:A<strong>to</strong>mic: Either all of the modifications in the transaction are applied or none is applied.Consistent: A transaction takes the database from one consistent state <strong>to</strong> the next, observing referentialintegrity constraints.Isolated: The effects of a user's transaction are not visible <strong>to</strong> other users until the transaction is committed.Durable: Once the transaction is successfully committed, it is permanent.<strong>Oracle</strong>'s implementation of the "Isolation" aspect of transactions is different from <strong>Sybase</strong> <strong>ASE</strong>'s. <strong>Oracle</strong> uses MVCC(multi-version concurrency control) where an open transaction creates a new version of the data it is modifying, suchthat other sessions reading the same data will read the unmodified version, and thus are not blocked ("writers don‟tblock readers and readers don't block writers"). In contrast, <strong>Sybase</strong> <strong>ASE</strong> maintains only a single version of the data, anduses blocking locks <strong>to</strong> implement transaction isolation.<strong>Oracle</strong> also uses locking in addition <strong>to</strong> MVCC, but <strong>Oracle</strong>'s locking concept is rather different from <strong>ASE</strong>'s.8.2 Transaction-related migration issuesThe different approaches <strong>to</strong>wards transaction isolation by <strong>Oracle</strong> and <strong>Sybase</strong> <strong>ASE</strong> may bring up the following issueswhen migrating from <strong>Oracle</strong> <strong>to</strong> <strong>ASE</strong>:<strong>Oracle</strong> applications and queries may rely, knowingly or unknowingly, on <strong>Oracle</strong> MVCC's "writers don't blockreaders and readers don't block writers" behavior. When migrating such queries unchanged <strong>to</strong> <strong>Sybase</strong> <strong>ASE</strong>,concurrency problems (blocking) may result. In addition, since MVCC has the effect that the result of an<strong>Oracle</strong> query is essentially defined at the moment then the query starts, different results could potentially bereturned.Long-running transactions: these are fine, and indeed common, in <strong>Oracle</strong> where MVCC allows transactions <strong>to</strong>remain open for longer times with fewer adverse effects (though naturally, this also has its limits; for examplewriters still block writers). With <strong>Sybase</strong> <strong>ASE</strong> designed specifically for high-performance OLTP, transactionsshould be kept as short as possible in <strong>ASE</strong> for best concurrency and performance. Long transactions in <strong>ASE</strong>can quickly lead <strong>to</strong> issues around concurrency (blocking) and resource consumption which also affectsunrelated transactions by other users (transaction log full).<strong>Oracle</strong> uses implicit transactions (also called "chained transactions"). This means a transaction is startedau<strong>to</strong>matically whenever a SELECT, INSERT, UPDATE or DELETE statement is executed. By default <strong>Sybase</strong><strong>ASE</strong> uses explicit transactions ("unchained"), though it also supports the ANSI-compliant implicit/chainedmode as well. When migrating <strong>to</strong> <strong>ASE</strong>, it may be needed <strong>to</strong> run some transactions in chained mode whichcould involve making changes <strong>to</strong> the way some transactions are handled, notably changing the transactionmode at session or client level, or by adding explicit BEGIN TRANSACTION statements (which <strong>Oracle</strong> doesnot support nor require).Transactions and Locking, <strong>Oracle</strong> vs. <strong>Sybase</strong> 35


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3For a successful migration <strong>to</strong> <strong>Sybase</strong> <strong>ASE</strong>, it is crucial <strong>to</strong> have a thorough understanding of the behavior of the <strong>Oracle</strong>application on the above aspects, and of the assumptions behind the design of queries and transaction handling in the<strong>Oracle</strong> application.8.3 Using <strong>ASE</strong> implicit/chained transaction modeThe most straightforward migration option with respect <strong>to</strong> <strong>Oracle</strong>'s implicit/chained transaction mode is <strong>to</strong> retain thetransactional structure of the <strong>Oracle</strong> application, and operate <strong>Sybase</strong> <strong>ASE</strong> in chained transaction mode.In <strong>Sybase</strong> <strong>ASE</strong>, implicit/chained transaction mode can be achieved by:Running the T-SQL command SET CHAINED ON before starting a transaction. This statement can also beexecuted in an <strong>ASE</strong> login trigger.Setting the OpenClient connection attribute CS_OPT_CHAINXACTS <strong>to</strong> true (default=false) in the clientapplication before connecting <strong>to</strong> the <strong>ASE</strong> server (With the isql utility, this attribute is set by specifying the -Ycommand-line flag).Since some operations in <strong>Sybase</strong> <strong>ASE</strong> may not work in chained mode, for example administration procedures such assp_configure, always enabling chained mode for all connections may not be practical (although <strong>ASE</strong> 15.7 allowsvarious system sp_* procedures <strong>to</strong> run in chained mode). It is recommended <strong>to</strong> only enable chained mode for thoseconnections or s<strong>to</strong>red procedures that really require it. For connections by the DBA (typically, the 'sa' user), thedefault unchained mode should always be used instead.8.3.1 Transactional DDLWhen running <strong>Sybase</strong> <strong>ASE</strong> in chained mode, it is possible that, with a straightforward migration from <strong>Oracle</strong>, DDLstatements are executed inside a transaction. By default, this will cause an error in <strong>Sybase</strong> <strong>ASE</strong>. To allow DDLstatements in a transaction in <strong>ASE</strong>, run: sp_dboption database_name,'ddl in tran', true . Note that this is notpossible for some types of DDL.In addition, <strong>Oracle</strong> issues an implicit COMMIT after each DDL statement. In <strong>ASE</strong>, an explicit COMMIT statementshould be inserted after each DDL statement that runs in a transaction <strong>to</strong> avoid concurrency issues. Alternatively,chained mode should temporarily be turned off at session level when DDL is executed.8.3.2 Transaction processing in s<strong>to</strong>red proceduresIf transaction processing is performed inside s<strong>to</strong>red procedures, and the transaction mode (chained/unchained) matters,<strong>Sybase</strong> <strong>ASE</strong> optionally allows enforcing that a s<strong>to</strong>red procedure is executed only in chained or unchained mode (oreither mode). This can be achieved with sp_procxmode:sp_procxmode proc_name, { 'chained' |'unchained' | 'anymode' }8.4 Using <strong>ASE</strong> explicit/unchained transaction modeIf it appears that running <strong>ASE</strong> in implicit/chained transaction mode leads <strong>to</strong> <strong>to</strong>o many concurrency issues, considerusing the default <strong>ASE</strong> explicit/unchained mode instead for all transaction or only for selected transactions.When using unchained transaction mode, a BEGIN TRAN[SACTION] statement needs <strong>to</strong> be added <strong>to</strong> all transactionsthat will run in unchained mode (this statement is not required in chained mode where transactions start implicitly). Todetermine the best location <strong>to</strong> add BEGIN TRANSACTION requires detailed understanding of the transaction inquestion. In general it is recommended <strong>to</strong> keep transaction in <strong>ASE</strong> as short as possible.8.5 Using <strong>ASE</strong> transactional concurrency enhancements<strong>Oracle</strong>'s MVCC feature tends <strong>to</strong> be seen, especially by <strong>Oracle</strong> itself, as a vastly superior and irreplaceable transactionhandling model, compared with other database brands.Transactions and Locking, <strong>Oracle</strong> vs. <strong>Sybase</strong> 36


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3In reality, much of the concurrency benefits of MVCC can be achieved in <strong>Sybase</strong> <strong>ASE</strong> by using <strong>ASE</strong>-specific features.What is true is that concurrency issues caused by sub-optimal transaction/query design will be less immediately visible in<strong>Oracle</strong> than in <strong>ASE</strong>; consequently, discipline in transaction programming is more important in <strong>Sybase</strong> <strong>ASE</strong> than in<strong>Oracle</strong> since sloppy transaction handling backfires quicker in <strong>Sybase</strong> <strong>ASE</strong> than in <strong>Oracle</strong>.When migrating from <strong>Oracle</strong>, it is recommended <strong>to</strong> consider the use of the following <strong>ASE</strong> features:Choose the datapages or datarows lock scheme for database tables. These lock schemes provide betterconcurrency than the default of allpages which is likely <strong>to</strong> be relevant when migrating from <strong>Oracle</strong> <strong>to</strong> <strong>ASE</strong> (alsosee section 4.9). When using datarows locking, uncommitted inserts do not block readers; in addition, "pseudocolumn-levellocking" behavior will au<strong>to</strong>matically apply in certain scenarios (see the <strong>ASE</strong> Performance and Tuningmanual, volume "Locking and Concurrency Control" for details).Consider using the readpast feature in queries. When reading data, this lets the query skip over locks that wouldotherwise have blocked the read operation. For example:select * from mytable readpast where mykey = 123When using readpast, the data page (with datapages lock scheme) or data row (with datarows) being lockedand skipped over, will not be read. In many cases however, this may be acceptable because the nature or timing ofthe query is such that the data being looked for is known not <strong>to</strong> be accessed by other users anyway. Or the skippeddata is known not <strong>to</strong> have any impact on the query result anyway.Consider using the ANSI transaction isolation level 0 (ANSI READ UNCOMMITTED) in SELECT queries. Whilereading, this lets the SELECT query read data that is currently locked, and potentially being updated, by anotheruser's transaction. On the default ANSI transaction isolation level 1 (READ COMMITTED), the SELECT querywould be blocked instead.When using ANSI isolation level 0, it is important <strong>to</strong> be aware of the implications and potential downsides, such asrequirements for unique indexing, the risk of isolation level 0 select queries being aborted in certain scenarios (seethe see the <strong>ASE</strong> Performance & Tuning manual, volume "Locking and Concurrency Control" for details).Also, since isolation level 0 does not provide true transaction isolation, there is the risk of reading data that iscurrently being updated and which may be updated again, or rolled back, after being read. However, this may beacceptable because the uncommitted data being read is known not <strong>to</strong> have any impact on the query result anyway.When using transaction isolation level 0, it is strongly recommended not <strong>to</strong> set this as the default isolation level for asession, but <strong>to</strong> add the clause AT ISOLATION READ UNCOMMITTED or AT ISOLATION 0 only <strong>to</strong> those SELECTstatements where isolation level 0 is required.8.6 Other transactional aspectsSavepoints: <strong>Sybase</strong> <strong>ASE</strong> supports savepoints in the same way as <strong>Oracle</strong> though with slightly different syntax.By default, <strong>Oracle</strong> operates on transaction isolation level 1 (READ COMMITTED), which is the same as <strong>Sybase</strong><strong>ASE</strong>. <strong>Oracle</strong> also supports transaction level 3 (SERIALIZABLE). <strong>Sybase</strong> <strong>ASE</strong> supports both isolation levels as well.(Note that <strong>Oracle</strong> does not support isolation levels 0 and 2).SQL*Plus commit behavior:o <strong>Oracle</strong>'s SQL*Plus always commits when exiting normally. <strong>Sybase</strong>'s isql client does not commit when itexits, and consequently the effect would be that any open transaction is rolled back – which is the oppositeof <strong>Oracle</strong>'s SQL*Plus behavior.o <strong>Oracle</strong>'s SQL*Plus can be configured <strong>to</strong> au<strong>to</strong>commit after every statement with SET AUTOCOMMIT ON;by default, this is disabled.<strong>Sybase</strong>'s isql client does not support au<strong>to</strong>commit; <strong>to</strong> achieve the same effect, explicit COMMITstatements should be inserted.Transactions and Locking, <strong>Oracle</strong> vs. <strong>Sybase</strong> 37


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3<strong>Oracle</strong> supports the syntax SET TRANSACTION READ ONLY, which makes the data read during the transactiontransactional data read-only, thus achieving the almost the same effect as transaction isolation level 3(SERIALIZABLE).In <strong>Sybase</strong> <strong>ASE</strong>, this should be changed <strong>to</strong> using transaction isolation level 3 (SERIALIZABLE). This can be achievedwith either of the following syntax:o SET TRANSACTION ISOLATION LEVEL 3o SELECT … AT ISOLATION LEVEL 3Instead of ISOLATION LEVEL 3, ISOLATION LEVEL SERIALIZABLE can also be used.<strong>Oracle</strong> also supports the syntax SET TRANSACTION READ WRITE; this can be removed when migrating <strong>to</strong> <strong>Sybase</strong><strong>ASE</strong> since it is the default transactional behavior.Deadlocks: <strong>Oracle</strong> sometimes pictures other database brands that do not support MVCC, as a source of 'deadlocks',perhaps aiming <strong>to</strong> use this somewhat scary-sounding terminology as an argument against their competi<strong>to</strong>rs.Indeed, deadlocks are rare in an <strong>Oracle</strong> environment, although it should be noted (consult any computer sciencetextbook on concurrent computing) that the possibility of deadlocks can never be excluded in a multi-userenvironment – which includes <strong>Oracle</strong> databases.When following some elementary best practices, deadlocks typically do not occur at all, or very rarely at worst, in<strong>Sybase</strong> <strong>ASE</strong>. The main guideline <strong>to</strong> avoid deadlocks is that when different transactions each access multiple tables,they should always do so in the same order. In addition, using the <strong>ASE</strong> datarows lock scheme will help <strong>to</strong> reducethe chance of deadlocks occurring. Finally, in the rare occasion that deadlocks do occur, it is recommended <strong>to</strong>implement deadlock retry logic in<strong>to</strong> the application where possible.In summary, deadlocks need not be a major point of concern when migrating from <strong>Oracle</strong> <strong>to</strong> <strong>Sybase</strong> <strong>ASE</strong>.Transactions and Locking, <strong>Oracle</strong> vs. <strong>Sybase</strong> 38


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.39 MISCELLANEOUS MIGRATION ASPECTS9.1 CursorsA main difference between <strong>Oracle</strong> and <strong>Sybase</strong> <strong>ASE</strong> is on how the systems handle query results. In <strong>Sybase</strong> <strong>ASE</strong>, resultsets are handles using „set processing‟, meaning that in a s<strong>to</strong>red procedure result sets are typically s<strong>to</strong>red in temporarytables and then further refined, whereas <strong>Oracle</strong> is based on cursor processing navigating through result sets. Theunderlying reason is that <strong>Oracle</strong> maintains the versioning of its transactions and guarantees data integrity throughcursors. By using insensitive cursors in <strong>Sybase</strong> <strong>ASE</strong>, the same effect for the cursor result set is closest <strong>Oracle</strong>‟s cursorimplementation.Both <strong>Oracle</strong> and <strong>Sybase</strong> <strong>ASE</strong> support cursors, with some –mostly small- differences in syntax and semantics.<strong>Oracle</strong> PL/SQL is implemented with an implicit cursor deallocation process. When you close an <strong>Oracle</strong> cursor, it getsau<strong>to</strong>matically deallocated. <strong>Sybase</strong> <strong>ASE</strong> requires an explicit deallocate cursor statement <strong>to</strong> do so."REF CURSOR" is an <strong>Oracle</strong> datatype. Parameters and variables can be created with this datatype (called "cursorvariables"). A cursor variable acts as a pointer <strong>to</strong> a result set, and can be associated with different queries at run-time andpassed around between s<strong>to</strong>red procedures, functions etc. Thus a cursor variable can be opened in one s<strong>to</strong>red procedure,and the results fetched in another s<strong>to</strong>red procedure, whereby the cursor variable is passed between both procedures.Since <strong>ASE</strong> does not have the REF CURSOR concept, PL/SQL using REF CURSOR needs <strong>to</strong> be rewritten, for exampleby rewriting all s<strong>to</strong>red procedures involved, or by putting query results in (temporary) tables and let the different s<strong>to</strong>redprocedures access these.9.2 Sequences<strong>Sybase</strong> <strong>ASE</strong> does not have a full equivalent of <strong>Oracle</strong> Sequences, but in most cases similar functionality can be achievedby using either an <strong>ASE</strong> identity column or a key counter table.A main criterium is whether the sequence values must be transactional (i.e. the sequence-generated value is rolled backwhen the enclosing transaction rolls back). If such transactionality is required, a key counter table must be used.If this is not required, then an identity column can be used.<strong>Oracle</strong> code:CREATE SEQUENCE test_seqMINVALUE 1STARTWITH 1INCREMENTED by 1CACHE 20;INSERT INTO m_table VALUES (test_seq.nextval,…);Equivalent <strong>Sybase</strong> <strong>ASE</strong> code with identity column:-- this example uses an int as the sequence counter. Use numeric or bigint as needed.CREATE PROCEDURE init_seq_nr (@seqtab varchar(30), @startwith int=1, @cache int=100)ASBEGINset nocount onDECLARE @s varchar(100), @v intif object_id('seqtab') is not nullbeginset @s = 'drop table seqtab'exec (@s)endset @s = 'create table ' + @seqtab + '(seq int identity) with identity_gap = ' +convert(varchar, @cache)Miscellaneous migration aspects 39


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3EXEC (@s)if @startwith > 1beginselect @v = convert(int, reserve_identity (@seqtab, @startwith - 1))endendgo-- you can use either the output parameter or the return value,-- though the return value can only be an 'int' datatype-- NB: the values generated here are not transactional (they cannot be rolled back)CREATE PROCEDURE get_seq_nr (@seqtab varchar(30), @incremented_by int, @v_out int output)ASBEGINset nocount onDECLARE @s varchar(100), @v intset @v = convert(int, reserve_identity (@seqtab, @incremented_by))set @v_out = @vreturn @vendgo-- Initialize the sequence tableEXEC init_seq_nr 'myseqtab', 1, 20go-- Now get the next sequence number-- you can use either the output parameter or the return value,-- though the return value can only be an 'int' datatype-- NB: the values generated here are not transactional (they cannot be rolled back)-- variant 1: use output parameterDECLARE @p_out intEXEC get_seq_nr 'myseqtab', 1, @p_out outputINSERT INTO my_table VALUES (@p_out,…)go-- variant 2: use return valueDECLARE @ret intDECLARE @p_notused intEXEC @ret = get_seq_nr 'myseqtab', 1, @p_notusedINSERT INTO my_table VALUES (@ret,…)goEquivalent <strong>Sybase</strong> <strong>ASE</strong> code with key counter table:-- create tableCREATE TABLE my_seq (seq int)go-- initialize the sequenceINSERT INTO my_seq select 0go-- create s<strong>to</strong>red procedure <strong>to</strong> increment and return the value–- note that this can also be done with an OUTPUT parameterCREATE PROCEDURE get_seq (@incr int)ASUPDATE my_seq SET seq = seq + @incrSELECT @seq = seq FROM my_seqRETURN @seqgo-- execute the procedure <strong>to</strong> get the next sequence numberDECLARE @seq intMiscellaneous migration aspects 40


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3EXEC @seq = get_seq 1INSERT INTO m_table VALUES (@seq,…)goNotes: When using a step count > 1 in ORacle (= 'incremented by' > 1), the <strong>ASE</strong> configuration parameter 'identityreservation size' must be set <strong>to</strong> the maximum block size (with sp_configure) The <strong>Oracle</strong> sequence attributes 'cycle', 'minvalue', 'maxvalue' and 'noorder' are not easy <strong>to</strong> support in <strong>ASE</strong>. Toimplement 'cycle', the identity counter can be set backwards with sp_chgattribute ..., 'identity_burn_max'. Yet another approach is <strong>to</strong> replace the sequence functionality with a static Java function which is visible across allprocesses (i.e. loaded by the system ClassLoader). This is not discussed further in this <strong>Guide</strong>.9.3 Error/Exception handlingIn <strong>Oracle</strong>, each SQL statement is au<strong>to</strong>matically checked for errors before proceeding with the next statement. If an erroroccurs, control immediately jumps <strong>to</strong> an exception handler if one exists. PL/SQL supports the creation of cus<strong>to</strong>mexception handlers <strong>to</strong> deal with different types of errors. <strong>Sybase</strong> <strong>ASE</strong> passes the control from one SQL statement <strong>to</strong>another without checking for errors. This means that in <strong>Sybase</strong> <strong>ASE</strong>, error checks must be performed after every SQLstatement.The <strong>Oracle</strong> built-in procedure RAISE_APPLICATION_ERROR notifies the client of the server error condition andreturns immediately <strong>to</strong> the calling routine. <strong>Oracle</strong> places an implicit SAVEPOINT at the beginning of a procedure. Thebuilt-in RAISE_APPLICATION_ERROR procedure rolls back <strong>to</strong> this SAVEPOINT or <strong>to</strong> the last committedtransaction within the procedure. Control is then returned <strong>to</strong> the calling routine.<strong>Sybase</strong> <strong>ASE</strong>‟s equivalent <strong>to</strong> <strong>Oracle</strong>‟s RAISE_APPLICATION_ERROR is called RAISERROR. Unlike <strong>Oracle</strong>,RAISERROR does not return the controls <strong>to</strong> the calling routine.The first step in the conversion is <strong>to</strong> replace all RAISE_APPLICATION_ERROR calls with RAISERROR calls,followed immediately with a RETURN statement <strong>to</strong> emulate the <strong>Oracle</strong> exception handling.The second step is <strong>to</strong> handle the implicit SAVEPOINTs that <strong>Oracle</strong> creates at the beginning of each procedure. If thetransaction is within one procedure this is relatively simple. But if the code uses nested s<strong>to</strong>red procedures this becomesmore complex and may require additional flow-control logic.9.4 Outer join limitations<strong>Sybase</strong> <strong>ASE</strong> does not allow another join relationship on a table that already has an outer join (see example #1 below). Inaddition, for a query with an outer join and a qualification on a column from the inner table of the outer join, the resultsmay be different than expected (example #2). Ideally, the database design should be de-normalized <strong>to</strong> remove the needfor these relationships. It is generally recommended <strong>to</strong> use the ANSI outer join syntax in <strong>Sybase</strong> <strong>ASE</strong> rather than the T-SQL style syntax (*=. =*).<strong>Oracle</strong>Example #1:SELECT DISTINCT a.id, b.name, c.descFROM a, b, cWHERE a.id = b.id (+)and b.id2 = c.id2 (+) ( or b.id = c.id2 )and a.code = 1ORDER BY b.nameExample #2:SELECT a.id, b.name<strong>Sybase</strong> <strong>ASE</strong>Example #1:SELECT a.id, b.name, c.descFROM a, b, cWHERE a.id = b.idand b.id2 *= c.id2and a.code = 1UNIONSELECT a.id, '', ''FROM aWHERE a.code = 1and ( NOT EXISTS ( SELECT 'X'FROM bWHERE a.id = b.id ))ORDER BY 2Example #2:SELECT a.id, b.nameMiscellaneous migration aspects 41


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3<strong>Oracle</strong>FROM a, bWHERE a.id = b.id (+)AND b.name LIKE 'Bill%'<strong>Sybase</strong> <strong>ASE</strong>FROM a, bWHERE a.id *= b.idAND b.name LIKE 'Bill%'9.5 Migrating JDBC/ODBC/… ApplicationsThe data and any SQL code that are s<strong>to</strong>red in the database (e.g., s<strong>to</strong>red procedures and triggers) are migrated with thesteps in Section 5. This section describes the following different types of client database applications that need <strong>to</strong> bemigrated from <strong>Oracle</strong> <strong>to</strong> <strong>Sybase</strong> <strong>ASE</strong>.Embedded SQL applicationODBC client applicationJDBC client applicationDatabase-specific library applicationC Applications<strong>Oracle</strong> formsIn all cases, conversion of one type of application <strong>to</strong> any of the other types of applications is possible. For example,instead of converting your <strong>Oracle</strong> Embedded SQL application <strong>to</strong> a <strong>Sybase</strong> Embedded SQL application, you can convertyour <strong>Oracle</strong> Embedded SQL application <strong>to</strong> a JDBC client application.9.5.1 JDBCMigrating JDBC connections from <strong>Oracle</strong> <strong>to</strong> <strong>Sybase</strong> requires understanding how <strong>Oracle</strong> manages JDBC drivers vs.<strong>Sybase</strong> <strong>ASE</strong>. This will determine your approach on how <strong>to</strong> migrate JDBC.<strong>Oracle</strong> provides the following JDBC drivers:Thin driver: a pure Java driver used on the client-side, without an <strong>Oracle</strong> client installation. It can be used withboth applets and applications.<strong>Oracle</strong> Call Interface (OCI) driver: used on the client-side with an <strong>Oracle</strong> client installation. It can be used onlywith applications.<strong>Oracle</strong> recommends the use of its Thin JDBC driver in all and any cases when connections are made through TCP/IP.<strong>Sybase</strong> <strong>ASE</strong> provides its own JDBC driver, named jConnect.9.6 <strong>Oracle</strong> Forms<strong>Oracle</strong> Forms, a component of the <strong>Oracle</strong> Developer Suite, is <strong>Oracle</strong>'s approach <strong>to</strong> design and build enterpriseapplications quickly and efficiently. <strong>Oracle</strong> Forms-based applications can retrieve and manipulate data in <strong>Oracle</strong>databases. Applications developed with <strong>Oracle</strong> Forms are unlikely <strong>to</strong> run well, or run at all, against <strong>Sybase</strong> <strong>ASE</strong>.<strong>Sybase</strong> PowerBuilder is an enterprise development <strong>to</strong>ol that allows you <strong>to</strong> build many types of applications andcomponents. It is one of a group of <strong>Sybase</strong> products that <strong>to</strong>gether provide the <strong>to</strong>ols <strong>to</strong> develop client/server, multi-tier,and Internet applications.<strong>Oracle</strong> Forms applications can be rewritten using PowerBuilder. Most of the functionality provided by <strong>Oracle</strong> forms canbe also be created by using PowerBuilder with <strong>Sybase</strong> <strong>ASE</strong>.<strong>Migration</strong> of <strong>Oracle</strong> Forms application <strong>to</strong> PowerBuilder application is not straightforward. The "form" is the basis ofuser interface (UI) in <strong>Oracle</strong> Forms while the "datawindow" is the basis of UI in PowerBuilder. Both are graphical innature and are used <strong>to</strong> present data and accept user input. Both can contain elements graphical and non-graphical innature.For more information on PowerBuilder, see http://www.sybase.com/powerbuilder .Miscellaneous migration aspects 42


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.310 DBA TASKS CROSS-REFERENCEThis chapter seeks <strong>to</strong> provide some starting points with respect <strong>to</strong> mapping DBA tasks and concepts in <strong>Oracle</strong> <strong>to</strong> theirequivalent in <strong>ASE</strong>. However, the <strong>to</strong>ols and methods used for database administration and moni<strong>to</strong>ring are very differentas these are highly specific <strong>to</strong> each database brand. This makes it impossible <strong>to</strong> provide more than a loose mapping.For a successful migration, availability of sufficient DBA skills will be important.Description <strong>Oracle</strong> <strong>Sybase</strong> <strong>ASE</strong>Home Direc<strong>to</strong>ry $ORACLE_HOME $SYB<strong>ASE</strong>Default Database/Instance $ORACLE_SID $DSQUERYCommand-line <strong>to</strong>ol for SQLSQL*Plus in$ORACLE_HOME/bin/sqlplusisql in $SYB<strong>ASE</strong>/OCS-15_x/bin/isqlImport/export dataLoading data from external filesimp / exp command or impdp/expdp command for data pumplocated in $ORACLE_HOME/bin<strong>Oracle</strong> imports and exports the dataand the DDL definitions, plus all otherobjects like type definitions, indexes,procedure and views.Data exported with exp can only beimported with imp.SQL*Loader is <strong>Oracle</strong>‟s high-speedloader. It loads data in<strong>to</strong> <strong>Oracle</strong> veryfast, but it cannot unloading <strong>Oracle</strong>database data in<strong>to</strong> files.For data import and export:bcp command located in$SYB<strong>ASE</strong>/OCS-15_x/binFor the definition import andexport:defncopy command in$SYB<strong>ASE</strong>/OCS-15_x/binTo reverse engineering the DDL <strong>to</strong>be recreated in anotherenvironment:ddlgen command in$SYB<strong>ASE</strong>/<strong>ASE</strong>P/binbcp command located in$SYB<strong>ASE</strong>/OCS-15_x/bin(bcp can also unload data in<strong>to</strong>files)Create a new databasedbca command in$ORACLE_HOME/bin<strong>Sybase</strong> Central or SQL commandcreate databaseCreate new network connectionnetca command in$ORACLE_HOME/bindsedit in $SYB<strong>ASE</strong>/OCS-15_x/binDBA Tasks Cross-Reference 43


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3Description <strong>Oracle</strong> <strong>Sybase</strong> <strong>ASE</strong>Setup new <strong>Oracle</strong> EnterpriseManager (OEM) serveremca command in$ORACLE_HOME/bin<strong>Sybase</strong> Central in combination with<strong>Sybase</strong> Control Center is equivalent<strong>to</strong> OEM.Setup <strong>Sybase</strong> Central: installedau<strong>to</strong>matically when <strong>Sybase</strong> <strong>ASE</strong> isinstalled. Installs as part of theclient installation.Setup <strong>Sybase</strong> Control Center:Install the software with thesupplied <strong>Sybase</strong> Installer.Load data in<strong>to</strong> the databaseSQL*LOADER in$ORACLE_HOME/bin/sqlldrbcp command located in$SYB<strong>ASE</strong>/OCS-15_x/binusing bcp inStart database serverManual:Start SQL*Plus as sysdbaSQL> STARTUPStarts the instance, , mounts thedatabase and opens the database.Script:dbstart command in$ORACLE_HOME/binBoth commands are using the spfileslocated in $ORACLE_HOME/dbs inthe following order:1. spfile$ORACLE_SID.ora2. spfile.ora3. init$ORACLE_SID.orastartserver command in$SYB<strong>ASE</strong>/<strong>ASE</strong>-15_x/installstartserver –fRUN_$DSQUERYThe RUN_$DSQUERY file is thespfile equivalent.Start backup server N/A startserver command in$SYB<strong>ASE</strong>/<strong>ASE</strong>-15_x/installstartserver –fRUN_$DSQUERY_BSThe RUN_$DSQUERY_BS filecontains the startup parameters.Start moni<strong>to</strong>r serveremctl command in$ORACLE_HOME/binemctl start dbconsolestartserver command in$SYB<strong>ASE</strong>/<strong>ASE</strong>-15_x/installstartserver –fRUN_$DSQUERY_MSThe RUN_$DSQUERY_MS filecontains the startup parameters.DBA Tasks Cross-Reference 44


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3Description <strong>Oracle</strong> <strong>Sybase</strong> <strong>ASE</strong>Show running processesUnix:ps –aef | grep$ORACLE_SIDWindows:pslist –d oracleshowserver command in$SYB<strong>ASE</strong>/<strong>ASE</strong>-15_x/installS<strong>to</strong>p database serverLogin <strong>to</strong> SQL*Plus and execute:SQL>shutdownFor normal shut downSQL>shutdown immediate;For immediate shut downSQL>shutdown abort;For emergency shut downLogin via isql and execute thecommand:shutdowngoWithout parameters the server willwait for all transactions <strong>to</strong> finish.Adding „with nowait‟ will terminateall sessions and shut down theserver immediately.S<strong>to</strong>p backup server<strong>Oracle</strong> does not have a concept of aBackup Server.Login via isql in<strong>to</strong> the <strong>Sybase</strong> <strong>ASE</strong>database server and execute thecommand:shutdownBackup_Server_namegoBy default this waits for all currentbackups <strong>to</strong> finish. Adding „withnowait‟ will terminate all sessionsand shut down the backup serverimmediately.DBA Tasks Cross-Reference 45


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3Description <strong>Oracle</strong> <strong>Sybase</strong> <strong>ASE</strong>Database BackupInformation about systemperformanceInformation about schema<strong>Oracle</strong> has the following ways ofperforming a database backup:imp / exp commands: this canimport/export the entire database(including all data), individualschemas or a single table.Data Pump: new import / exportfeature since <strong>Oracle</strong> 10g. The basicfunctionality is identical <strong>to</strong> the oldimp and exp commands, butData Pump is faster.RMAN: The <strong>Oracle</strong> RecoveryManager (RMAN), command-lineas well as Enterprise Managerbased,is the <strong>Oracle</strong>-preferredmethod of efficiently backing upand res<strong>to</strong>ring an <strong>Oracle</strong> database.Various backup options exist,some of which require the <strong>Oracle</strong>database <strong>to</strong> be shut down first.<strong>Oracle</strong> dynamic performance views<strong>Oracle</strong> static data dictionary views<strong>Sybase</strong> <strong>ASE</strong> always performs a hotbackup; this requires hardly anyconfiguration. This is the samefunctionality as <strong>Oracle</strong>‟s ArchiveLog backup, but no archive filecleanup is necessary.The command dump databasebacks up an entire database (fulldump); dump transactiononly backs up the transaction logsince the previous dump(incremental backup).The command load databaseres<strong>to</strong>res a full backup; loadtransaction loads anincremental backup following loadsof earlier backups.For these dump/load commands,Backup Server must be running.MDA tablesSystem tables (catalogs) and systems<strong>to</strong>red procedures (sp_*)DBA Tasks Cross-Reference 46


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.311 ORACLE-TO-SYB<strong>ASE</strong> MIGRATION CROSS-REFERENCEThis chapter provides specific suggestions on how <strong>to</strong> migrate a <strong>Oracle</strong> feature <strong>to</strong> <strong>Sybase</strong> <strong>ASE</strong>. This cross-reference is anextended version of the <strong>Oracle</strong> checklist in chapter 3. Much of this type of conversion can in principle be done using atext edi<strong>to</strong>r with search-and-replace commands, or with <strong>to</strong>ols like 'sed'.11.1 <strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>ASE</strong> migration: category "Simple Conversion"<strong>Oracle</strong>Connecting <strong>to</strong> an <strong>Oracle</strong> schemaCONNECT user_name/passwordSET ROLEThe <strong>Oracle</strong> SQL*Plus “slash” character sends precedingPL/SQL text <strong>to</strong> the <strong>Oracle</strong> server./The semicolon is a statement delimiter in PL/SQL;The <strong>Oracle</strong> DUAL tableSELECT sysdate FROM DUALSET SAVEPOINT savepoint-nameVariable/Parameter declarations; naming syntaxDECLARE count NUMBERAssign default value in variable declarationDECLARE blood_type char(2) := 'O';Multiple variable declarations with a single DECLAREkeywordDECLAREV1 NUMBER(10,0);V2 CHAR(20);CURSOR mycursor ISSELECT * FROM mytable;<strong>Sybase</strong> <strong>ASE</strong> ("simple conversion")Connecting <strong>to</strong> a <strong>Sybase</strong> database; also see section 4.5USE database_nameEquivalent <strong>to</strong> the ISQL go command at the end of abatch of SQL statementsgoNo statement delimiters; remove <strong>Oracle</strong> delimitersemicolonsShould be removed completely from queries in <strong>Sybase</strong><strong>ASE</strong>; but if it occurs many times in <strong>Oracle</strong> queries, itmay also be created as a dummy table in <strong>ASE</strong>; seesection 4.10SAVE TRAN[SACTION] savepoint-nameIn <strong>Sybase</strong> <strong>ASE</strong>, variable/parameter names must startwith the character @. In <strong>ASE</strong>, the maximum length is30 bytes; in <strong>Oracle</strong>, longer names are allowed.DECLARE @count INTExplicitly assign value after variable declarationDECLARE @blood_type CHAR(2)SET @blood_type = 'O'When declaring multiple variables with oneDECLARE keyword, the variables must be commaseparated<strong>ASE</strong>. Cursors must be declared separatelywith DECLARE…CURSORDECLARE@v1 int,@v2 char(20)<strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>Migration</strong> Cross-Reference 47


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3<strong>Oracle</strong>Declarations without DECLARE keyword in declarationsection of s<strong>to</strong>red procedures/functionsCREATE PROCEDURE pASV1 NUMBER(10,0);V2 CHAR(20);CURSOR mycursor ISSELECT * FROM mytable;BEGIN…statements…END;Variable assignmentmyvar := expression;Transferring table data in<strong>to</strong> a variableSELECT my_col INTO my_variableFROM my_table WHERE id = 123;Constants%TYPE denotes the datatype of a column in an existingtable<strong>Sybase</strong> <strong>ASE</strong> ("simple conversion")DECLARE keyword is required in <strong>Sybase</strong> <strong>ASE</strong>.Cursors must be declared separately withDECLARE…CURSORCREATE PROCEDURE pASBEGINDECLARE@v1 int,@v2 char(20)DECLARE mycurs CURSOR ASSELECT * FROM mytable…statements…ENDgoSET @myvar = expressionSELECT @myvar = expressionDirectly select in<strong>to</strong> the variableSELECT @my_variable = my_col FROMmy_table WHERE id = 123Redefine as variables and check scope of usage (localor global).Explicitly declare the variable with the column's actualdatatypeDECLARE count my_table.id%TYPEDynamic SQLEXECUTE IMMEDIATE '…sql…';Optional clauses:EXECUTE IMMEDIATE '…sql…' USING …;EXECUTE IMMEDIATE '…sql…' INTO …;EXECUTE IMMEDIATE '…sql…' BULK COLLECTINTO …;Use <strong>Sybase</strong> <strong>ASE</strong> execute-immediateSET @cmd = '…sql…'EXECUTE (@cmd)or:EXECUTE ('…sql…')With the clauses USING (specifies parameters <strong>to</strong> thedynamic SQL), INTO (puts results in<strong>to</strong> variables forsingle-row results), BULK COLLECT INTO (s<strong>to</strong>resresults in<strong>to</strong> <strong>Oracle</strong> collections), the query should berewritten <strong>to</strong> achieve the same effect in <strong>ASE</strong>.<strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>Migration</strong> Cross-Reference 48


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3<strong>Oracle</strong>Loops with LOOP/END LOOP:LOOP…statements…;EXIT [WHEN …condition…]; /*exit loop*/…statements…;/* back <strong>to</strong> <strong>to</strong>p for next iteration: */CONTINUE [WHEN …condition…];…statements…;END LOOP;<strong>Sybase</strong> <strong>ASE</strong> ("simple conversion")Convert <strong>to</strong> WHILE-loops. <strong>Oracle</strong>'s EXIT andCONTINUE corresponds <strong>to</strong> <strong>ASE</strong>'s BREAK andCONTINUE though <strong>ASE</strong> cannot have a conditionassociated with these statements.WHILE 1=1BEGIN…sql……conditional exit…ENDOr:WHILE BEGIN…statements…ENDFOR loopsFOR i IN 1..5LOOP…statements…END LOOP;CURSOR loopsConvert <strong>to</strong> WHILE; use variables <strong>to</strong> implement FORDECLARE @i int, @i_start int, @i_endintSET @i_start = 1, @i_end = 5SET @i = @i_startWHILE @i


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3<strong>Oracle</strong><strong>Oracle</strong> Outer join syntax<strong>Sybase</strong> <strong>ASE</strong> ("simple conversion")Translates <strong>to</strong> <strong>Sybase</strong> <strong>ASE</strong> T-SQL outer join syntax or<strong>to</strong> ANSI outer join syntax (preferred). Somerestrictions apply in <strong>Sybase</strong>, see section 9.4.// right outer joinSELECT * FROM t1, t2WHERE t1.col1 = t2.col2(+)SELECT * FROM t1, t2WHERE t1.col1 =* t2.col2syntax)(T-SQLSELECT * FROM t1 RIGHT [OUTER] JOIN t2ON t1.col1 = t2.col2 (ANSI syntax)// left outer joinSELECT * FROM t1, t2WHERE t1.col1(+) = t2.col2SELECT * FROM t1, t2WHERE t1.col1 *= t2.col2syntax)(T-SQLSELECT * FROM t1 LEFT [OUTER] JOIN t2ON t1.col1 = t2.col2 (ANSI syntax)SET TRANSACTION READ WRITE Remove in <strong>Sybase</strong> <strong>ASE</strong>; see chapter 8ALTER TABLE mytable TRUNCATE PARTITIONpartition_nameCREATE OR REPLACE PROCEDURE (orFUNCTION)ALTER PROCEDURE (or FUNCTION)CREATE PROCEDURE… IS…S<strong>to</strong>red procedure OUT/IN OUT parametersCREATE PROCEDURE p(a IN number, b OUT number, c IN OUT number)IS …Replace by TRUNCATE TABLE mytablePARTITION partition_nameReplace by DROP PROCEDURE (or FUNCTION)followed by CREATE PROCEDURE (orFUNCTION)Replace by DROP PROCEDURE (or FUNCTION)followed by CREATE PROCEDURE (orFUNCTION)Change <strong>to</strong> CREATE PROCEDURE… AS…<strong>Sybase</strong> <strong>ASE</strong> supports input and input+outputparameters, but no output-only parameters. Inaddition, the output keyword must be specified whencalling the procedureCREATE PROCEDURE p@a int, @b int output, @c int outputAS …EXEC p @var1, @var2 output, @var3 outputS<strong>to</strong>red procedure execution with named parameters(param => value)result := proc_name(param1 => my_var, param2=> 123);Convert <strong>to</strong> <strong>ASE</strong> syntax with named parameters:EXEC @result = proc_name @param1 = @my_var,@param2 = 123<strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>Migration</strong> Cross-Reference 50


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3<strong>Oracle</strong>S<strong>to</strong>red procedure execution with positional parameters(:var)VAR a NUMBER;VAR b NUMBER;VAR c NUMBER;EXEC proc_name (:a, :b, :c)Procedure executionIn <strong>Oracle</strong>, the EXEC[UTE] keyword is not usedCREATE PROCEDURE p1ASBEGIN…statements…END;CREATE PROCEDURE p2ASBEGINp1;END;SQL Function declaration with DETERMINISTICkeyword<strong>Sybase</strong> <strong>ASE</strong> ("simple conversion")Convert <strong>to</strong> <strong>ASE</strong> syntax with named parameters:declare @a int,@b int,@c int,@return_statusEXEC @return_status = proc_name @a, @b, @cIn <strong>ASE</strong>, the EXEC[UTE] keyword is manda<strong>to</strong>ry(except when the procedure is the first statement inthe batch)CREATE PROCEDURE p1ASBEGIN…statements…ENDgoCREATE PROCEDURE p2ASBEGINEXECUTE p1ENDgoIn <strong>Sybase</strong> <strong>ASE</strong>, remove DETERMINISTICCREATE FUNCTION f_func (p NUMBER)RETURN NUMBERDETERMINISTICIS…Execution of a SQL Functionselect myfunc(123);DECLARE CURSOR cursor-name IS…<strong>Oracle</strong> cursorsIn <strong>Sybase</strong> <strong>ASE</strong>, the name of the executed SQL functionmust always be preceded by the owner's nameselect dbo.myfunc(123)select jsmith.yourfunc(456)Change <strong>to</strong> DECLARE cursor-name INSENSITIVECURSOR AS…<strong>ASE</strong>'s insensitive cursor is closest <strong>to</strong> <strong>Oracle</strong>'s cursorimplementation<strong>Oracle</strong> cursors are au<strong>to</strong>matically deallocated whenclosed.<strong>ASE</strong> cursors must be deallocated explicitly withDEALLOCATE CURSOR cursor-name. This shouldbe added after every cursor CLOSE.Cursor Attribute %ISOPEN No equivalent in <strong>ASE</strong>, remove .Cursor Attributes %FOUND, %NOTFOUNDConvert <strong>to</strong> using @@sqlstatusCursor Attribute %ROWCOUNTConvert <strong>to</strong> using @@rowcount<strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>Migration</strong> Cross-Reference 51


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3<strong>Oracle</strong>AFTER triggers (on statement level)INSTEAD OF triggers (on views)SQL%ROWCOUNTIndicates the number of rows affected by the mostrecently executed PL/SQL statementSELECT * FROM mytable WHERE id = 1234;IF SQL%ROWCOUNT = 0 THENDBMS_OUTPUT.PUT_LINE('No rowsfound.');END IF;BOOLEAN datatype (for PL/SQL variables only)Allowed values are TRUE, FALSE and NULL.MERGE statementPartitioned tables with composite partitioningCREATE TABLE mytable(...columns...)PARTITION BY RANGE(ptn_key_col)SUBPARTITION BY HASH(subptn_key_col)[...]Performance-optimized native PL/SQL datatypes (forPL/SQL variables only)<strong>Sybase</strong> <strong>ASE</strong> ("simple conversion")Similar <strong>to</strong> <strong>Sybase</strong> <strong>ASE</strong> table triggersSimilar <strong>to</strong> <strong>Sybase</strong> <strong>ASE</strong> INSTEAD-OF triggersReplace by @@rowcountDECLARE @rc INT, @err INTSELECT * FROM mytable WHERE id = 1234SELECT @rc = @@rowcount, @err = @@errorIF @rc = 0print 'No rows found.'Convert <strong>to</strong> variables of type BIT (allows only 0 and 1;NULL = 0) or TINYINT NULL. Decide on astandard encoding like 0=false; 1=true.Instead of using the numeric literals 0 and 1 in testsand assignments, two variables named @true and@false could be defined (and set <strong>to</strong> 1 and 0), so as <strong>to</strong>use these names instead.Migrate <strong>to</strong> <strong>ASE</strong> 15.7, which supports MERGE<strong>ASE</strong> supports partitioned tables, but no compositepartitioning. Remove the SUBPARTITION clause.Convert <strong>to</strong> INTEGER, DOUBLE, FLOAT datatypesBINARY_INTEGERBINARY_DOUBLEBINARY_FLOATIF-THEN-ELSEIF expressionTHENstatement;ELSEstatement;END IF;In <strong>Sybase</strong> <strong>ASE</strong>, there is no THEN or END IF, soremove themIF expressionstatementELSEstatement<strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>Migration</strong> Cross-Reference 52


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3<strong>Oracle</strong>Multiple statements in an IF-THEN-ELSE branchIF expressionTHENstatement;statement;ELSEstatement;statement;END IF;Conditional test based on EXISTS subqueryDECLAREv_x NUMBER(10,0);v_temp NUMBER(1, 0) := 0;SELECT 1 INTO v_tempFROM DUALWHERE EXISTS ( …subquery… );<strong>Sybase</strong> <strong>ASE</strong> ("simple conversion")In <strong>Sybase</strong> <strong>ASE</strong>, there can be only a single statementexpression in each branch; multiple statements mustbe grouped in a BEGIN- END block.IF expressionBEGINstatementstatementENDELSEBEGINstatementstatementENDCan be kept identical in <strong>ASE</strong>, but this can also besimplified greatly in <strong>ASE</strong>:DECLARE @x intSET @x = 0IF EXISTS ( …subquery… )SET @x = -1ENDIF v_temp = 1 THENv_x := -1;String concatenation opera<strong>to</strong>r: ||userenv('sessionid')MOD(X,Y)CEIL()TRUNC(number)SUBSTR()SUBSTR() function with two parametersSELECT substr('John', 2) returns 'ohn'LENGTH()CHR()REPLACE()<strong>Sybase</strong> <strong>ASE</strong> supports + as the string concatenationopera<strong>to</strong>r; it also supports || though this is formallyundocumented.Equivalent <strong>to</strong> session-specific global variable @@spid(since @@spid values are re-used, thesysprocesses.kpid value can also be used <strong>to</strong> create abetter uniqueness)X % YCEILING()CONVERT(INT,..)SUBSTRING()Rewrite with the length of the expression as the 3rdparameterSELECT substring ('John', 2, len('John'))CHAR_LENGTH() or LEN() or DATALENGTH()CHAR()STR_REPLACE()<strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>Migration</strong> Cross-Reference 53


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3<strong>Oracle</strong>TO_CHAR(expression)TO_CHAR(expression, datepart)TO_CHAR(sysdate, 'dd')TO_CHAR(expression, format-string)TO_CHAR(some-number, '999D99')TO_CHAR(some-number, '999')TO_NUMBER(expression)Date/time functions and calculationsSELECT add_months( xyz ,3 ) FROM dualSELECT nr_days := DateEnd - DateStartSYSDATE, SYSTIMESTAMPTRUNC(date/time [,unit])LAST_DAY()<strong>Sybase</strong> <strong>ASE</strong> ("simple conversion")CONVERT(VARCHAR(n), expression)Convert <strong>to</strong> use the <strong>ASE</strong> datepart() functionCONVERT(VARCHAR,datepart(dd,getdate()))Implement the formatting explicitly with <strong>ASE</strong>functionsCONVERT(VARCHAR,ROUND(some-number,2))CONVERT(VARCHAR,CONVERT(INT,somenumber))CONVERT([BIG|SMALL|TINY]INT,expression)CONVERT(NUMERIC(n,m), expression)Rewrite with <strong>ASE</strong> date/time functions likeDATEADD(), DATEDIFF(), DATEPART(),DATENAME()SELECT DATEADD(month, 3, xyz)SELECT @nr_days = datediff(dd, DateStart,DateEnd)Replace by CURRENT_BIGDATETIME()Replace by CONVERT() with the date/timeformatting stylesLast day of a month function based on a date value;rewrite using <strong>ASE</strong> SQL functionsNVL() functionNVL(a,b)Inconsistent use of upper/lowercase for identifiers(<strong>Oracle</strong> is case-insensitive for identifiers)Identifiers that are <strong>Sybase</strong> <strong>ASE</strong> reserved words (seesection 4.8)INSTR() function with two parametersSELECT INSTR('abcabc', 'ab')Replace by ISNULL() functionISNULL(a,b)Either use a case-insensitive sort order in <strong>ASE</strong>, or useconsistent upper/lowercase spelling for identifiers (seesection 5.2)Change such identifiers so that they are not a reservedword.Replace by charindex()SELECT CHARINDEX('abcabc', 'ab')<strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>Migration</strong> Cross-Reference 54


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3<strong>Oracle</strong>Derived tables (also known as "inline views") withoutcorrelation nameselect afrom (select b as a, d as b from mytab)where b > 0ALTER TABLE … SPLIT PARTITION…ALTER TABLE … MERGE PARTITIONS…Quoted identifiers. <strong>Oracle</strong> allows using quoted identifiersby enclosing an identifier in double quotes. Quotedidentifiers are case-sensitive, unlike unquoted identifierswhich are case-insensitive.CREATE TABLE "mytable" ("mycol" NUMBER);Note that all-uppercase quoted identifiers do not need <strong>to</strong>be quoted: "MYTABLE" (quoted) is identical <strong>to</strong>MYTABLE (without quotes) in <strong>Oracle</strong>.<strong>Oracle</strong> hints; indicated by a special comment directlyfollowing the SELECT:<strong>Sybase</strong> <strong>ASE</strong> ("simple conversion")<strong>ASE</strong> always requires a correlation name for a derivedtableselect afrom (select b as a, d as b from mytab)[as] somenamewhere b > 0Migrate <strong>to</strong> <strong>ASE</strong> 15.7 ESD#2 which supports thesestatements.<strong>Sybase</strong> <strong>ASE</strong> also allows quoted identifiers delimited bydouble quotes, but this is disabled by default. To usequoted identifiers, the command setquoted_identifiers on must be executed first. Thiscommand affects only the session executing it.Ignore quotes for all-uppercase quoted identifiers.Remove all <strong>Oracle</strong> hintsSELECT /*+ INDEX (C) */NAMEFROM CUSTOMERS CWHERE ZIPCODE = 54321Hint keywords:ALL_ROWSAPPENDCACHECLUSTERFACTFIRST_ROWSFULLHASHINDEXINDEX_ASCINDEX_DESCINDEX_FFSINDEX_JOININDEX_SSLEADINGMERGEMONITORNO_EXPANDNO_FACTNO_INDEXREWRITEUNNESTUSE_CONCATCURSOR_SHARING_EXACTDRIVING_SITEDYNAMIC_SAMPLINGMODEL_MIN_ANALYSISNATIVE_FULL_OUTER_JOINNO_NATIVE_FULL_OUTER_JOINNO_PARALLELNO_PARALLEL_INDEXNO_PUSH_PREDNO_PUSH_SUBQNO_PX_JOIN_FILTERNO_QUERY_TRANSFORMATIONNO_RESULT_CACHENO_REWRITENO_STAR_TRANSFORMATIONNO_UNNESTNO_USE_HASHNO_USE_MERGENO_USE_NLNO_XML_QUERY_REWRITENO_XMLINDEX_REWRITESTAR_TRANSFORMATIONUSE_NL_WITH_INDEXNOPARALLEL_INDEXNOAPPENDNOCACHENOPARALLELNOREWRITEOPT_PARAMORDEREDPARALLELPARALLEL_INDEXPQ_DISTRIBUTEPUSH_PREDPUSH_SUBQPX_JOIN_FILTERQB_NAMERESULT_CACHEINDEX_COMBINEINDEX_SS_ASCINDEX_SS_DESCNO_INDEX_FFSNO_INDEX_SSNO_MERGENO_MONITORUSE_HASHUSE_MERGEUSE_NL<strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>Migration</strong> Cross-Reference 55


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.311.2 <strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>ASE</strong> migration: category "Partial Rewrite"For the <strong>Oracle</strong> features listed below, migration <strong>to</strong> partly equivalent <strong>Sybase</strong> <strong>ASE</strong> features is possible, although potentiallysignificant syntax changes and possibly partial rewriting of algorithms may be required.<strong>Oracle</strong>Database linksCREATE DATAB<strong>ASE</strong> LINK SALES.PROD[ CONNECT TO CURRENT_USER ] using'SALES';SELECT * FROM salesdata@SALES;External tablescreate table my_external_tab( ...columns...)organization external( default direc<strong>to</strong>ry external_data_diraccess parameters( records delimited by newlinefields terminated by ','location ('...pathname...') )<strong>Sybase</strong> <strong>ASE</strong> ("partial rewrite")Equivalent <strong>to</strong> <strong>ASE</strong> proxy tables, mapping <strong>to</strong> a remotetablecreate proxy_table sales_proxyat SALES.salesdb..salesdataselect * from your_proxyEquivalent <strong>to</strong> <strong>ASE</strong> proxy tables, mapping <strong>to</strong> an O/Sfilecreate proxy_table my_external_tab( ...columns...)external file at '...pathname...'column delimiter ','SequencesGenerate unique numbers, for example for primarykeysTable-valued User-defined SQL FunctionsPipelined Table Functions ( a special case of TablevaluedUser-defined SQL Functions)FUNCTION my_funcRETURN my_out_tab PIPELINED;SynonymsComments on database objectsCOMMENT ON TABLE mytab IS "This is my table";In some cases, this can be replaced by using <strong>ASE</strong>identity columns. In other cases, the sequencefunctionality must be emulated with a key countertable and a s<strong>to</strong>red procedure. See section 9.2.<strong>ASE</strong> only supports scalar User-defined SQLfunctions. Rewrite with temporary tables.Rewrite with cursors or with an <strong>ASE</strong> proxy tablemapping <strong>to</strong> a s<strong>to</strong>red procedure (though theperformance of <strong>Oracle</strong> Pipelined Table Functions canprobably not be achieved)For synonyms for tables or views, replace by an <strong>ASE</strong>view; for table/view synonyms at dblinks, replace byan <strong>ASE</strong> proxy table.For synonyms for s<strong>to</strong>red procedures or functions,replace by a wrapper s<strong>to</strong>red procedure/function; fors<strong>to</strong>red procedure synonyms at dblinks, replace by aremote procedure call.For other synonyms, application changes are required.No direct equivalent. An method for s<strong>to</strong>ring objectcomments in <strong>ASE</strong> is describedin http://www.sybase.com/detail?id=607<strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>Migration</strong> Cross-Reference 56


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3<strong>Oracle</strong>Bitmap indexesCREATE BITMAP INDEX my_ix ON mytable(…)Temporary tablesCREATE GLOBAL TEMPORARY TABLE temptab[…] [ON COMMIT {PRESERVE|DELETE} ROWS]<strong>Sybase</strong> <strong>ASE</strong> ("partial rewrite")<strong>ASE</strong> does not support bitmap indexes. RemoveBITMAP and create a regular index.<strong>Sybase</strong> IQ supports bitmapped indexes.Replace by <strong>ASE</strong> temporary tables whose names startwith the # character:CREATE TABLE #temptab […]SELECT * INTO #temptab FROM my_tableNote that there are differences in scope between an<strong>Oracle</strong> temporary table and a <strong>Sybase</strong> #temporarytable: an <strong>Oracle</strong> temporary table is visible by all users(though a user can only see his own data rows in thetable) whereas a <strong>Sybase</strong> #temp table is visible only <strong>to</strong>the session that created it. In addition, an <strong>Oracle</strong>temporary table is a permanent table that must bedropped explicitly (only the data in the <strong>Oracle</strong>temporary table is au<strong>to</strong>matically deleted); a <strong>Sybase</strong>#temp table is au<strong>to</strong>matically dropped at the end of theprocedure or session that created it.IS TABLE OF or AS VARRAY(n)OFdefine a PL/SQL "table" (= non-database table, array).Also known as a "collection" (various types of <strong>Oracle</strong>collections exist).Rewrite algorithm with a temporary table and useFETCH or SELECT <strong>to</strong> process rows. Alternatively,convert the table <strong>to</strong> a Java object with different dataelements, which can be s<strong>to</strong>red in a table column.<strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>Migration</strong> Cross-Reference 57


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3<strong>Oracle</strong>Nested tablesAllow a column <strong>to</strong> be defined as a table, that can holdN rows (=N column values)Also known as a "collection" (various types of <strong>Oracle</strong>collections exist).<strong>Sybase</strong> <strong>ASE</strong> ("partial rewrite")Change <strong>to</strong> use a separate table for the nested table inthe column, with a primary key-foreign keyrelationship.CREATE TYPE address_t AS OBJECT (street VARCHAR2(30),city VARCHAR2(20),state CHAR(2),zip CHAR(10),country CHAR(30));CREATE TYPE address_tab IS TABLE OFaddress_t;CREATE TABLE cus<strong>to</strong>mers (custid NUMBER,address address_tab )NESTED TABLE address STORE AScus<strong>to</strong>mer_addresses;INSERT INTO cus<strong>to</strong>mers VALUES (654,address_tab(address_t('148 Oak Drive','Dallas', 'TX', '75240', 'USA'),address_t('561 VirginiaRoad', 'Concord', 'MA', '01742','USA')));NB: cus<strong>to</strong>mer_addresses is an object table as wellas a nested table at the same time.Object tablesCREATE TYPE person_type AS OBJECT (name VARCHAR2(30), addressVARCHAR2(100));Either replace with regular tables and columns, or usea Java class <strong>to</strong> define a column as a complex datatypecontaining different fields.CREATE TABLE person_obj_table OFperson_type;%ROWTYPE declares a PL/SQL record with thesame columns as a particular tableDECLARE cust cus<strong>to</strong>mer%ROWTYPEDefine a PL/SQL record type by enumerating thefields with IS RECORD OF or TYPE…IS RECORDNon-integer RETURN value in s<strong>to</strong>red procedure<strong>Oracle</strong> s<strong>to</strong>red procedures can return a scalar value ofany datatype.Declare each field as an individual variable and modifyall references accordingly. Alternatively, convert therecord <strong>to</strong> a Java object with different data elements,which can be s<strong>to</strong>red in a table column.Declare each field as an individual variable and modifyall references accordingly. Alternatively, convert therecord <strong>to</strong> a Java object with is treated as an array.<strong>Sybase</strong> <strong>ASE</strong> s<strong>to</strong>red procedures can only return aninteger value.When a different datatypes is returned, rewrite byusing an output parameter or rewrite with a SQLfunction<strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>Migration</strong> Cross-Reference 58


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3<strong>Oracle</strong>User-defined PackagesOverloaded s<strong>to</strong>red procedures(multiple procedures with identical names but differentparameter datatypes or different number of parameters)PL/SQL Exception handling; defining exceptionhandlers<strong>Sybase</strong> <strong>ASE</strong> ("partial rewrite")Translate packages <strong>to</strong> the individual objects that thepackage consists of (s<strong>to</strong>red procedures, data types,etc.)Translate <strong>to</strong> a single s<strong>to</strong>red procedures or split in<strong>to</strong>separate s<strong>to</strong>red proceduresRewrite and perform checks on @@error and@@rowcount after every SQL statement.EXCEPTION WHEN ZERO_DIVIDE THEN-- handles 'division by zero' error[…]EXCEPTION WHEN TOO_MANY_ROWS-- handle case that > 1 row affected[…]EXCEPTION WHEN NO_DATA_FOUND-- handle case that no rows affected[…]EXCEPTION WHEN DUP_VAL_ON_INDEX-- handle case for duplicate index key[…](etc… other conditions existSQLCODE, SQLERRMIndicates the error status and error message text of themost recently executed PL/SQL statement; used withthe exception handling sectionEXCEPTIONWHEN OTHERS THENerror_code := SQLCODE;error_msg := substr(SQLERRM, 1, 200);INSERT INTOaudit_table(err_no,err_msg)VALUES (error_code, error_msg);END;RAISE_APPLICATION_ERRORIn s<strong>to</strong>red procedures, this also rolls back until theimplicit savepoint at the start of the procedure (or afterthe last committed transaction in the procedure)Column EncryptionLOB loca<strong>to</strong>rsReplace SQLCODE by @@error. <strong>ASE</strong> has noequivalent of SQLERRMDECLARE @rc INT, @err INTSELECT * FROM mytable WHERE id = 1234SELECT @rc = @@rowcount, @err = @@errorIF @err = 0BEGININSERT INTOaudit_table(err_no,err_msg)VALUES (@err, '');ENDRecode with <strong>Sybase</strong> <strong>ASE</strong> functions such asRAISERROR or PRINT immediately followed by aRETURN in s<strong>to</strong>red proceduresRewrite with <strong>ASE</strong> column encryptionMigrate <strong>to</strong> <strong>ASE</strong> 15.7, which supports LOB Loca<strong>to</strong>rs<strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>Migration</strong> Cross-Reference 59


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3<strong>Oracle</strong>Data compression<strong>Sybase</strong> <strong>ASE</strong> ("partial rewrite")Migrate <strong>to</strong> <strong>ASE</strong> 15.7, which supports datacompressionRetrieving data <strong>to</strong> the client in s<strong>to</strong>red procedures usingDBMS_OUTPUT packageDBMS_OUTPUT.PUT_LINEDBMS_*, UTL_* package calls(excl. DBMS_OUTPUT)SDO_* package callsSQL*Loader (sqlldr)<strong>Oracle</strong>‟s high-speed data loader utility (only loading, nounloading).Materialized ViewsReplace by direct SELECT or PRINT statementsRecode with <strong>Sybase</strong> <strong>ASE</strong> features if possible,otherwise removeSpatial data features, remove/recodeRewrite using the <strong>Sybase</strong> bcp utility.Migrate <strong>to</strong> <strong>ASE</strong> 15.7 ESD#2 which supportsmaterialized views (a.k.a. "precomputed result sets").Global variables (in a PL/SQL package)INTERSECT constructSELECT a FROM tab1 WHERE b > 10INTERSECTSELECT c FROM tab2 WHERE d = 0MINUS constructSELECT a,b,c FROM tab1 WHERE …MINUSSELECT d,e,f FROM tab2 WHERE …Global variables are not supported; either pass allvariables around as parameters, or s<strong>to</strong>re such values ina table and read/update that table as needed.Alternatively, Java static classes can be used.Rewrite as a joinSELECT tab1.a FROM tab1, tab2WHERE tab1.a = tab2.cAND tab1.b > 10 AND tab2.d = 0Rewrite with NOT IN (single column) or NOTEXISTS (multiple columns)SELECT a,b,c FROM tab1WHERE NOT EXISTS(SELECT * from tab2WHERE tab2.d = tab1.aAND tab2.e = tab1.bAND tab2.f = tab1.c)<strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>Migration</strong> Cross-Reference 60


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3<strong>Oracle</strong><strong>Sybase</strong> <strong>ASE</strong> ("partial rewrite")Specific SQL clausesAS OFAS OF TIMESTAMPCONNECT BYDIMENSIONDIMENSION BYEXCLUDEGROUPING SETSINCLUDEMEASURESRETURN ALL ROWSRETURN UPDATEDROWSPARTITION BYREFERENCESYSTIMESTAMPCROSSCUBEFORKEEPMAINMODELNAVNOCYCLENOWAITONONLYRULESSAMPLESEEDSKIPIGNOREITERATENATURALNULLSNULLS FIRSTNULLS LASTROLLUPSIBLINGSSINGLEREFERENCELOCKEDSTART WITHUNIQUEUNPIVOTWAITReplace by corresponding <strong>Sybase</strong> <strong>ASE</strong> functionality, ifavailable. Otherwise, rewriting the SQL is required.Capitalize first letter of all words in a stringINITCAP( string-expression )INSTR() function with three or four parameters(3=start position, 4=n th occurrence)SELECT INSTR('abcabc', 'ab', 2)SELECT INSTR('abcabcabc', 'ab', 2, 2)NVL2() functionSELECT NVL2(salary,salary*2, 123) FROM…DECODE() functionUsed <strong>to</strong> evaluate with „if-else‟ type logicSELECTDECODE(T1.C1, 'ABC',T1.C2,T1.C3) as P_IDFROM T1Primary key and foreign key with different datatypes,different precision/scale (for numeric datatypes) ordifferent length (for character datatypes)Cluster (as created with CREATE CLUSTER)Rewrite with s<strong>to</strong>red procedures or SQL functionsCreate a SQL function <strong>to</strong> perform the advancedsearches.Note that charindex() accepts a 3 rd paramter in<strong>ASE</strong> 15.7, but this cannot have a negative value (forbackward search) as is allowed in <strong>Oracle</strong>Convert <strong>to</strong> a C<strong>ASE</strong> expressionSELECTC<strong>ASE</strong> WHEN salary = NULL OR salary = ''THEN 123ELSE salary * 2 ENDFROM…Convert <strong>to</strong> a C<strong>ASE</strong> expressionSELECTcase T1.C1when 'ABC' then T2.C2 else T3.C3end as P_IDFROM T1Unlike <strong>Oracle</strong>, <strong>ASE</strong> requires that a foreign key andprimary key have identical datatypes. Modify thedatatypes accordingly.Change the data model <strong>to</strong> use individual tables;consider using views <strong>to</strong> avoid making changes <strong>to</strong>existing SQL code<strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>Migration</strong> Cross-Reference 61


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3<strong>Oracle</strong>VARCHAR2 variables longer than 16384 bytesDECLARE msg VARCHAR2(32767)(for columns, VARCHAR2 cannot be longer than 4000bytes)SQL functions where the last statement is notRETURNDerived tables (also known as "inline views") using"with" syntax<strong>Sybase</strong> <strong>ASE</strong> ("partial rewrite")The maximum length of string variables is 16384bytes; rewrite code, either using shorter <strong>ASE</strong> varcharstrings, or use ASSE LOB variables or LOB loca<strong>to</strong>rsin <strong>ASE</strong> 15.7<strong>ASE</strong> requires that a SQL function has RETURN as itslast statement. This may require some re-coding of theflow control.Rewrite with <strong>ASE</strong> derived table syntaxwith x as (select b as a, d as b from mytab)select a from x where b > 0UNIONs in cursorsPRAGMA directivesAu<strong>to</strong>nomous transactions(AUTONOMOUS_TRANSACTION)ON DELETE CASCADE constraintsXMLTYPE (XML data type)XML functions extract(), existsnode(), xmlexists(), etcROWIDAn <strong>Oracle</strong> table always contains a ROWID columnwith a unique identifier for each row, even if noprimary key was defined for the table. The ROWID canbe referenced in queries.SELECT last_name, ROWIDINTO var_lname, var_rowidFROM empWHERE empid = 98765A cursor with a UNION cannot be updatable in <strong>ASE</strong>;such code may need <strong>to</strong> be rewritten.Rewrite with <strong>ASE</strong> syntax/functionality.<strong>ASE</strong> does not support au<strong>to</strong>nomous transactions;rewrite with <strong>ASE</strong> transactional semantics.Rewrite with <strong>ASE</strong> triggersRewrite with TEXT, IMAGE or VARCHARdatatatypes and with <strong>ASE</strong> functions xmlextract(),xmltable(), etc.A similar effect can be achieved by add an identitycolumn <strong>to</strong> each table, and name the column"ROWID".There can be only one identity column per table. Ifthere is already an identity column for the primarykey, for example <strong>to</strong> replace an <strong>Oracle</strong> sequence, add avirtual computed column named "ROWID", equal <strong>to</strong>the identify column. This method can also be usedwhen existing <strong>Oracle</strong> code uses a different spelling,like "rowid":CREATE TABLE mytab(ROWID NUMERIC IDENTITY, rowid ASROWID,…other columns…)<strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>Migration</strong> Cross-Reference 62


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3<strong>Oracle</strong>ROWNUMFor each row returned by a query, the ROWNUMpseudocolumn returns a number indicating the order ofthe row in the result set. This can be used in queries,for example <strong>to</strong> select only a subset of the result set.SELECT * FROM empWHERE state = 'CA'AND ROWNUM > 9 AND ROWNUM < 21ORDER BY last_name;<strong>Sybase</strong> <strong>ASE</strong> ("partial rewrite")When the objective is <strong>to</strong> select the <strong>to</strong>p N rows, thiscan be achieved with select <strong>to</strong>p N …from…When more complex selections are done (e.g. only getrows 10-20) , the an identity column (which shouldprobably be named "ROWNUM") can be added <strong>to</strong>the result set with the identity() function, whichassigns a sequence number <strong>to</strong> every row in the resultset. This column can then be used in queries. Notethat this requires one extra query step:SELECT *, ROWNUM=identity(int)INTO #t FROM empWHERE state = 'CA'ORDER BY last_nameSELECT FROM #tWHERE ROWNUM > 9 AND ROWNUM < 21<strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>Migration</strong> Cross-Reference 63


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.311.3 <strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>ASE</strong> migration: category "Major Rewrite"For the <strong>Oracle</strong> features listed below, no direct equivalent is available in <strong>Sybase</strong> <strong>ASE</strong>. Consequently, rewriting orredesigning algorithms or parts of applications will be required.<strong>Oracle</strong><strong>Oracle</strong> MVCC (Multi-Version Concurrency Control;"writers don‟t block readers, readers don't blockwriters")Relevant aspects:Applications or queries relying on nonblockingMVCCLong-running transactionsDDL in transactionsSET TRANSACTION READ ONLYSQL*Plus au<strong>to</strong>commit/commit-on-exit<strong>Sybase</strong> <strong>ASE</strong> ("major rewrite")No direct equivalent of MVCC. Some aspects may beaddressed by using DATAROWS locking, using theREADPAST option., or running SELECT queries atisolation level 0 (READ UNCOMMITTED).For other cases, the application may need <strong>to</strong> bemodified, for example by keeping transactions as shortas possible.See section 8 for details.SQL*PlusThe <strong>Sybase</strong> <strong>ASE</strong> counterpart for SQL*Plus is theisql utility. SQL*Plus allows for more complexconfiguration settings and SQL*Plus-specific (i.e.non-PL/SQL) client-side commands insideSQL*Plus. Existing SQL*Plus-based functionalitymust be rewritten for <strong>ASE</strong>.BEFORE triggersNo direct equivalent. Some aspects of thefunctionality (like domain integrity) may be covered byrules or CHECK constraints at the table definition level;however an <strong>Oracle</strong> BEFORE trigger can perform farmore complex processing than can be handled byrules or constraints. If this functionality cannot beimplemented with <strong>Sybase</strong> <strong>ASE</strong> "after" triggers, theapplication may need <strong>to</strong> be changed <strong>to</strong> apply thefunctionality in a different way.Triggers on row level (BEFORE and AFTER)No direct equivalent; some logic may be changed <strong>to</strong>operate on the <strong>ASE</strong> pseudo-tables inserted anddeleted; otherwise, see BEFORE triggers above.Multiple triggers for a DML type on a tableNo direct equivalent; if the functionality cannot beconsolidated in a single <strong>ASE</strong> trigger, the applicationmay need <strong>to</strong> be changed <strong>to</strong> apply the functionality in adifferent way.<strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>Migration</strong> Cross-Reference 64


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3<strong>Oracle</strong>REF CURSOR<strong>Sybase</strong> <strong>ASE</strong> ("major rewrite")No direct equivalent. In <strong>ASE</strong>, REF CURSORs need<strong>to</strong> be rewritten, for example by rewriting all s<strong>to</strong>redprocedures involved, or by putting query results in(temporary) tables and let the different s<strong>to</strong>redprocedures access these. Also see section 9.1.Regular Expressions; functions REGEXP_LIKE(),REGEXP_SUBSTR(), REGEXP_REPLACE(),REGEXP_INSTR()No direct equivalent since <strong>ASE</strong>does not supportregular expressions.Rewrite with <strong>ASE</strong> SQL usingcus<strong>to</strong>m processing instead of RegExWindowing queries (SELECT…OVER(…) …)SELECT name, salary,NTILE(4) OVER (ORDER BY salary DESC)AS quartileFROM empWHERE dept_id = 123;No equivalent in <strong>Sybase</strong> <strong>ASE</strong>. Rewrite with classic<strong>ASE</strong> features, possibly requiring breaking up a queryin multiple steps. Alternatively. Use <strong>Sybase</strong> IQ whichdoes support windowing queries as well as manyanalytic functions.SQL function OUT/IN OUT parameters<strong>Sybase</strong> <strong>ASE</strong> supports only input parameters for SQLfunctions. If output parameters are used, rewrite withs<strong>to</strong>red proceduresNon-deterministic SQL Functions (functions whoseresult may be independent of the function inputparameters)This cannot be concluded from PL/SQL keywordssince <strong>Oracle</strong> supports only the keywordDETERMINISTIC <strong>to</strong> indicate that a function isdeterministic. Non-determinism cannot be indicatedexplicitly, but only from code inspection.<strong>Sybase</strong> <strong>ASE</strong> supports only deterministic SQLfunctions. DML, DDL, procedure calls, executeimmediate,certain function calls and utilitycommands are not allowed in a SQL function.If these occur in an <strong>Oracle</strong> SQL Function, rewritewith <strong>ASE</strong> s<strong>to</strong>red proceduresSQL Aggregate FunctionsCREATE FUNCTION f_aggr (p NUMBER)RETURN NUMBERAGGREGATE USING object-type;No direct equivalent. Rewrite using available <strong>ASE</strong>features.BFILE datatypeA BFILE column s<strong>to</strong>res a loca<strong>to</strong>r (link) <strong>to</strong> a binary fileoutside of the databaseNo direct equivalent<strong>Oracle</strong> Streams; <strong>Oracle</strong> Data GuardUse <strong>Sybase</strong> Replication Server.<strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>Migration</strong> Cross-Reference 65


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3<strong>Oracle</strong><strong>Oracle</strong> RAC for high-availability<strong>Sybase</strong> <strong>ASE</strong> ("major rewrite")Use <strong>Sybase</strong> <strong>ASE</strong> Cluster Edition<strong>Oracle</strong> Flashback<strong>Oracle</strong> flashback-related pseudocolumnsORA_ROWSCN, VERSION_XID,VERSION_STARTSCN, VERSION_ENDSCN,VERSION_STARTTIME, VERSION_ENDTIME,VERSION_OPERATIONNo direct equivalent. Some aspects may be covered byusing the <strong>ASE</strong> "auditing" feature, by using <strong>ASE</strong>"archive databases", and by using the until_timeoption when loading a transaction log dump.For other cases, old data values can be retained bymeans of triggers.See "<strong>Oracle</strong> Flashback" above<strong>Oracle</strong> Snapshot Standby (combination of datareplication and Flashback)No direct equivalent. Similar functionality can beachieved with Replication Server.<strong>Oracle</strong> SQL Plan ManagementS<strong>to</strong>res and maintains query plans <strong>to</strong> support the queryoptimizer <strong>to</strong> make better decisions: every time a querygets executed, the query optimizer compares thecurrent query plan with the s<strong>to</strong>red query plan andchooses the better plan au<strong>to</strong>matically.(for DBA/tuning purposes, not affecting applicationquery syntax)Some aspects are covered by abstract query planassociation ('abstract plan load') as well as by theQPTune utility. However, <strong>ASE</strong> does not supportau<strong>to</strong>matic evaluation of newly generated plans versuscaptured past plans.AWR (Au<strong>to</strong>matic Workload Reposi<strong>to</strong>ry)S<strong>to</strong>res every query with corresponding performanceindica<strong>to</strong>rs and metrics in a reposi<strong>to</strong>ry, allowingidentifying the <strong>to</strong>p poorly performing queriesau<strong>to</strong>matically (for which query plans managed by<strong>Oracle</strong> SQL Plan Management will be used when thequery are being executed again)(for DBA/tuning purposes, not affecting applicationquery syntax)<strong>Oracle</strong> Advanced QueuingQuery metrics are captured in <strong>ASE</strong>'ssysquerymetrics with the 'metrics capture'feature, or through the MDA tables.<strong>ASE</strong> does not support au<strong>to</strong>matic actions based oncaptured dataSimilar concept as <strong>ASE</strong>'s Real-Time MessagingService (RTMS), which allows direct interfacing fromSQL with message bus products like Tibco and MQSeries.Packages for PL/SQL web accessOWA_CUSTOM, OWA_CX, OWA_OPT_LOCK,OWA_SEC, OWA_TEXT, OWA_UTILNo equivalent. Cus<strong>to</strong>m implementation in <strong>ASE</strong>required.<strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>Migration</strong> Cross-Reference 66


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3<strong>Oracle</strong><strong>Sybase</strong> <strong>ASE</strong> ("major rewrite")<strong>Oracle</strong> Forms Rewrite with <strong>Sybase</strong> PowerBuilder. See section 9.2.<strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>Migration</strong> Cross-Reference 67


ORACLE TO SYB<strong>ASE</strong> <strong>ASE</strong> MIGRATION GUIDERev.1.3CONTACT INFORMATIONFor Europe, Middle East,or Africa inquiries:+(31) 34 658 2999For Asia-Pacific inquiries:+852 2506 8900 (Hong Kong)For Latin America inquiries:+770 777 3131 (Atlanta, GA)SYB<strong>ASE</strong>, INC.WORLDWIDE HEADQUARTERSONE SYB<strong>ASE</strong> DRIVEDUBLIN, CA 94568-7902 USATel: 1 800 8 SYB<strong>ASE</strong>www.sybase.comCopyright © 2012 <strong>Sybase</strong>, Inc. All rights reserved. Unpublished rights reserved under U.S.copyright laws. <strong>Sybase</strong>, and the <strong>Sybase</strong> logo are trademarks of <strong>Sybase</strong>, Inc. or its subsidiaries.All other trademarks are the property of their respective owners. ® indicates registration in theUnited States. Specifications are subject <strong>to</strong> change without notice.<strong>Oracle</strong>-<strong>to</strong>-<strong>Sybase</strong> <strong>Migration</strong> Cross-Reference 68

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!