SQL scripts parser

I'm looking for Java open-source SQL script reader/parser.
That would allow me to find SQL comments about tables and columns, usually given in the neighbourhood of CREATE TABLE, ALTER TABLE commands.
Can you suggest me any such parser?
Best,
Maciej

>
http://search.cpan.org/~rehsack/SQL-Statement-1.23/lib/SQL/Statement.pm
BUGS AND LIMITATIONS ^
* currently we treat NULL and '' as the same - eventually fix
* No nested C-style comments allowed as SQL99 says
>
That's the reason why I want to use dedicated for 11g EE library ;-)
Thanks for quick reply

Similar Messages

  • IF Condition in a PL/SQL Script give a report error.

    Hello, I’m German and I hope you can unterstand my Question.
    First, I work with the HTML DB Version 1.6.0.0.0.87 and the Oracle Version 9.2.0.6.
    I create a SQL Report, where a PL/SQL Script return the SQL Statement for the Report. This is my source-code, I have short it...:
    Declare
    sql_str varchar(2000);
    sql_str_select varchar(1000) :=' select dim_sparte …... ';
    sql_str_from varchar(1000) := ' from faktentabelle,dim_sparte ';
    sql_str_where varchar(1000):= ' where … and faktentabelle.zeit_id = :POPUP_ZEIT ';
    sql_str_groupby varchar(1000):= ' group by dim_sparte.name, faktentabelle.zeit_id ';
    Begin
    If ( (V('POPUP_NETZGEBIET') is not NULL) and (V('POPUP_NETZGEBIET') <>
    'Alle Netzgebiete')) THEN
    sql_str_select := sql_str_select || ' ,dim_organisationseinheit.netzgebiet_name ';
    sql_str_from := sql_str_from || ' , dim_organisationseinheit ';
    sql_str_where := sql_str_where || ' and faktentabelle ... and
    dim_organisationseinheit.netzgebiet_name = :POPUP_NETZGEBIET';
    sql_str_groupby := sql_str_groupby || ' , dim_orga .... ';
    End IF;
    sql_str:= sql_str_select || sql_str_from || sql_str_where || sql_str_groupby;
    htp.print(sql_str);
    Return sql_str;
    End;
    This Script include a IF-THEN condition. The Condition is true and the sql-String-Variables are updatet.
    I can get the string with htp.print() and the Statement is OK.
    The report get a Error “report error: ORA-1403: no data found”. If I copy the printet sql String in a new Report Region with SQL String, the Report is OK. When I write IF(true) instead of IF( Condition) the Report is OK, too.
    I try ist with Varibalen V(‘name‘) and with :name. It’s always the same problem. I can’t use IF-THEN-Else Conditions in a Script.
    Please help me and say me what is the problem???
    Thanks,
    Simona

    Hi Simona,
    In the sql region below the region source see that you have " Use Generic Column Names (parse query at runtime only)" check and not " Use Query-Specific Column Names and Validate Query".
    This error you usually get when you have a mismatch in your report heading.
    Vivek
    [email protected]

  • Please help me resolve the Lync server 2013 deployment error: "An error occurred while applying SQL script for the feature BackendStore."

    I am getting an error in "Step 2 - Setup or Remove Lync Server Components" of "Install or Update Lync Server System" step.
    "An error occured while applying SQL script for the feature BackendStore. For details, see the log file...."
    Additionally, all previous steps such as: Prepare Active Directory, Prepare first Standard Edition server, Install Administrative Tools, Create and publish topology are done without any errors. The user that I used to setup the Lync server is member of:
    Administrators
    CSAdministrator
    Domain Admins
    Domain Users
    Enterprise Admins
    Group Policy Creator Owners
    RTCComponentUniversalServices
    RTCHSUniversalServices
    RTCUniversalConfigReplicator
    RTCUniversalServerAdmins
    Schema Admins
    I have tried to re-install all the things and started to setup a new one many times but the same error still occurred. Please see the log below and give me any ideas/solutions to tackle this problem.
    ****Creating DbSetupInstance for 'Microsoft.Rtc.Common.Data.BlobStore'****
    Initializing DbSetupBase
    Parsing parameters...
    Found Parameter: SqlServer Value lync.lctbu.com\rtc.
    Found Parameter: SqlFilePath Value C:\Program Files\Common Files\Microsoft Lync Server 2013\DbSetup.
    Found Parameter: Publisheracct Value LCTBU\RTCHSUniversalServices;RTC Server Local Group;RTC Local Administrators;LCTBU\RTCUniversalServerAdmins.
    Found Parameter: Replicatoracct Value LCTBU\RTCHSUniversalServices;RTC Server Local Group.
    Found Parameter: Consumeracct Value LCTBU\RTCHSUniversalServices;RTC Server Local Group;RTC Local Read-only Administrators;LCTBU\RTCUniversalReadOnlyAdmins.
    Found Parameter: DbPath Value D:\CsData\BackendStore\rtc\DbPath.
    Found Parameter: LogPath Value D:\CsData\BackendStore\rtc\LogPath.
    Found Parameter: Role Value master.
    Trying to connect to Sql Server lync.lctbu.com\rtc. using windows authentication...
    Sql version: Major: 11, Minor: 0, Build 2100.
    Sql version is acceptable.
    Validating parameters...
    DbName rtcxds validated.
    SqlFilePath C:\Program Files\Common Files\Microsoft Lync Server 2013\DbSetup validated.
    DbFileBase rtcxds validated.
    DbPath D:\CsData\BackendStore\rtc\DbPath validated.
    Effective database Path: \\lync.lctbu.com\D$\CsData\BackendStore\rtc\DbPath.
    LogPath D:\CsData\BackendStore\rtc\LogPath validated.
    Effective Log Path: \\lync.lctbu.com\D$\CsData\BackendStore\rtc\LogPath.
    Checking state for database rtcxds.
    Checking state for database rtcxds.
    State of database rtcxds is detached.
    Attaching database rtcxds from Data Path \\lync.lctbu.com\D$\CsData\BackendStore\rtc\DbPath, Log Path \\lync.lctbu.com\D$\CsData\BackendStore\rtc\LogPath.
    The operation failed because of missing file '\\lync.lctbu.com\D$\CsData\BackendStore\rtc\DbPath\rtcxds.mdf'
    Attaching database failed because one of the files not found. The database will be created.
    State of database rtcxds is DbState_DoesNotExist.
    Creating database rtcxds from scratch. Data File Path = D:\CsData\BackendStore\rtc\DbPath, Log File Path= D:\CsData\BackendStore\rtc\LogPath.
    Clean installing database rtcxds.
    Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
    ****Creating DbSetupInstance for 'Microsoft.Rtc.Common.Data.RtcSharedDatabase'****
    Initializing DbSetupBase
    Parsing parameters...
    Found Parameter: SqlServer Value lync.lctbu.com\rtc.
    Found Parameter: SqlFilePath Value C:\Program Files\Common Files\Microsoft Lync Server 2013\DbSetup.
    Found Parameter: Serveracct Value LCTBU\RTCHSUniversalServices;RTC Server Local Group.
    Found Parameter: DbPath Value D:\CsData\BackendStore\rtc\DbPath.
    Found Parameter: LogPath Value D:\CsData\BackendStore\rtc\LogPath.
    Trying to connect to Sql Server lync.lctbu.com\rtc. using windows authentication...
    Sql version: Major: 11, Minor: 0, Build 2100.
    Sql version is acceptable.
    Validating parameters...
    DbName rtcshared validated.
    SqlFilePath C:\Program Files\Common Files\Microsoft Lync Server 2013\DbSetup validated.
    DbFileBase rtcshared validated.
    DbPath D:\CsData\BackendStore\rtc\DbPath validated.
    Effective database Path: \\lync.lctbu.com\D$\CsData\BackendStore\rtc\DbPath.
    LogPath D:\CsData\BackendStore\rtc\LogPath validated.
    Effective Log Path: \\lync.lctbu.com\D$\CsData\BackendStore\rtc\LogPath.
    Checking state for database rtcshared.
    Reading database version for database rtcshared.
    Database version for database rtcshared - Schema Version5, Sproc Version 0, Update Version 1.
    Thanks and Regards,
    Thanh Le

    Thanks Lạc
    Phạm 2
    I Had similar issue i end up uninstalling and reinstallting but same issue, then i change the drive but same issue. It was I/O issue. After adjusting my I/O it fix our issue and installation went on without any issue. 
    If any one using KVM here is detail article 
    We just  give this option cache=‘writeback
    using this article http://www.ducea.com/2011/07/06/howto-improve-io-performance-for-kvm-guests/ and http://itscblog.tamu.edu/improve-disk-io-performance-in-kvm/ this fix my issue thanks 

  • How to use parameters in oracle SQL script????

    Right now I am writing a SQL script to create a schema and build the objects of this schema....
    I use a .net winform program to run sqlplus to parse this sql script ...
    The problem is that the schema name and the tablespace's location and the sys password must be input by the user, so my SQL script should use these runtime input parameters instead of const parameters....
    So, how to use parameter in SQL script ...........
    Are there some example scripts in oracle home directory for me to refer to????

    Hi,
    UNISTD wrote:
    thanks .....
    what's the difference between variable , define, accept in sqlplus ???VARIABLE declares (but does not assign a value to) a bind variable. Unlike substitution variables, bind variables are passed to the back end to be compiled, and they can only be values in certain data types. You can not use a bind vaiable in place of an identifier, so to do something like
    CREATE USER  &1 ...a bind variable won't work.
    "DEFINE x = y" sets the substitution variable &x to have the value y. There is no user interaction (unless x or y happen to contain undefined substtiution variables).
    "DEFINE x" shiows the value of the substitution variable &x, or, if it is undefined, raises a SQL*Plus error. I use this feature below.
    ACCEPT sets a substitution variable with user interaction.
    And if the user miss some parameters in “sqlplus /nolog ssss.sql par1 par2 par5 par6”, how to use default value of the miss parameters??Don't you need a @ befiore the script name, e.g.
    sqlplus /nolog @ssss.sql par1 par2 par5 par6Sorry, I don't know of any good way to use default values.
    The foloowing works, but, as you can see, it's ugly.
    "DEFINE 1" display a message like
    DEFINE 1            = "par1" (CHAR)if &1 is defined; otherwise,it will display a SQL*Plus error message like
    SP2-035: symbol 1 is UNDEFINEDNotice that the former contains an '=' sign, but the latter does not.
    The best way I know to use default values is to run the DEFINE command, save the output to a filee, read the file, and see if it's an error message or not.
    So you can use a script like this:
    --     This is  DEFINE_DEFAULT.SQL
    SPOOL     got_define_txt.sql
    DEFINE     &dd_old
    SPOOL     OFF
    COLUMN     dd_new_col     NEW_VALUE     &dd_new
    WITH     got_define_txt     AS
         SELECT  q'[
              @got_define_txt
    ]'               AS define_txt
         FROM    dual
    SELECT     CASE
             WHEN  define_txt LIKE '%=%'
             THEN  REGEXP_REPLACE ( define_txt
                               , '.+"
    ([^"]*)
                         , '\1'
             ELSE  '&dd_default'
         END        AS dd_new_col
    FROM     got_define_txt
    {code}
    and start your real script, ssss.sql, something like this:
    {code}
    DEFINE          dd_new     = sv1
    DEFINE          dd_old     = 1
    DEFINE          dd_default     = FOO
    @DEFINE_DEFAULT
    DEFINE          dd_new     = sv2
    DEFINE          dd_old     = 2
    DEFINE          dd_default     = "Testing spaces in value"
    @DEFINE_DEFAULT
    {code}
    when this finishes running, the substitution variable &sv1 will either have the value you passed in &1 or, if you didn't pass anything, the default value you specified, that is FOO.
    Likewise, &sw2 will have the value you passed, or, if you didn't pass anything, the 23-character string 'Testing spaces in value'.
    Here's how it works:
    Define_default.sql puts the output of the "DEFINE x" command into a column, define_txt, in a query.  That query displays either the existing value of the substitution variable indicated by &dd_old or, if it is undefined, the default value you want to use, which is stored in the substitution variable &dd_default.  The substitution variable named in &dd_new is always set to something, but that something may be its existing value.
    Notice that the paramerters to define_default.sql must be passed as global varibales.
    Why didn't I just use arguments, so that we could simply say:
    {code}
    @DEFINE_DEFAULT  sv1  1  FOO
    {code}
    ?  Because that would set the substitution variables &1, &2 and &3, which are miost likely the very ones in which you're interested.
    I repeat: there must be a better way, but I'm sorry, I don't know what it is.
    I usually don't do the method above.  Instead, I always pass the required number of parameters, but I pass dummy or plce-holder values.
    For example, if I wanted to call ssss.sql, but use defulat vlaues for &1 and &3, then I would say something like:
    {code}
    @ssss  ?  par2  ?
    {code}
    and, inside ssss.sql, test to see if the values are the place holder '?', and, if so, replace them with some real default value.  The use has  to remember what the special place holder-value is, but does not need to know anything more, and only ssss.sql itself needs to change if the default values change.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Tracking the order of execution of sql scripts in SQL*Plus

    In our production environment we sometimes have to run some .sql scripts in a particular order. Since the order of execution is important , i have created another .sql file caller caller.sql(shown at the bottom) which will call all the scripts in the right order.
    i thought of putting a exec DBMS_LOCK.SLEEP (5); after the end of every execution of the script so that i can see the
    'Ending script1'message .
    The spooling within the caller script(execute_stack.log) has become meaningless because each script has a spool <filename.log> and spool off within it. These spool logs (for every script) is important for tracking purposes as each script belongs to a different development team and i have to send them the spooled log file after the execution.
    I don't want to see the entire scripts running by in my screen. Since these scripts have their own spooling, i can later check the logs if the scripts where executed properly.
    So i need two things.
    1.I just need to see the following and nothing else in the screen.
    Ending script1
    Ending script2
    Ending script3
    .2. I need to log the order of execution. ie. the execute_stack.log should look like the above.Since there is a spool off within each script, this wouldn't be possible.Right?
    Ending script1
    Ending script2
    Ending script3
    .The caller.sql script which calls all the scripts in the right order
    alter session set nls_date_format = 'DD-MON-YYYY hh24:MI:SS';
    set serveroutput on
    set echo on;
    set feedback on;
    spool execute_stack.log
    @script1.sql
    exec dbms_output.put_line ('Ending script1');
    dbms_output.put_line(chr(10)||chr(10)||'.'||chr(10)||'.'||chr(10));
    exec DBMS_LOCK.SLEEP (5);
    @script2.sql
    exec dbms_output.put_line ('Ending script2');
    dbms_output.put_line(chr(10)||chr(10)||'.'||chr(10)||'.'||chr(10));
    exec DBMS_LOCK.SLEEP (5);
    @script3.sql
    exec dbms_output.put_line ('Ending script3');
    dbms_output.put_line(chr(10)||chr(10)||'.'||chr(10)||'.'||chr(10));
    exec DBMS_LOCK.SLEEP (5);
    @script4.sql
    dbms_output.put_line(chr(10)||chr(10)||'.'||chr(10)||'.'||chr(10));
    exec dbms_output.put_line ('Ending script3');
    commit;
    spool off;Is this a professional way of tracking the execution of .sql scripts?

    Pete_Sg1 wrote:
    Is this a professional way of tracking the execution of .sql scripts?No. There is very little professional about using .sql scripts on a production system - when stored procedures are safer, more robust, easier managed and controlled and secure.. and where a log table can be used to properly log the runtimes (and other stats) of each processing step.
    Let's just take a look at the number of moving parts you need to schedule and run a .sql script. A cron job needs to be configured with the proper environment setting. It needs to run a shell script. That shell script needs to load SQL*Plus. SQL*Plus needs to connect to the database (starting a dedicated server process most likely). SQL*Plus then needs to read a .sql file, parse these commands and either execute these locally (SQL*Plus commands) or remotely (PL/SQL and SQL commands).
    How can this be considered professional when the very same can be achieved with a
    - stored procedure
    - using DBMS_JOB to schedule the procedure for execution
    There are so many things that can go wrong with the first method. And so few things that could go wrong with the last one. No contest as to which method is not only better, but also professional.
    PS. See that you use Windows to run these scripts. It is even worse as it introduces another hardware and software layer making the scenario even more insecure & unsafe with more moving parts that can go wrong or simply fail.

  • AWM 11.1.0.7B question running global_11g_create_cubes.sql script

    Hi everybody,
    I installed AWM 11.1.0.7B and Oracle Database 11g software, version 11.1.0.6.0.
    I am trying to install Sample Schemas & Code.
    I got an error running global_11g_create_cubes.sql script that I downloaded from the http://www.oracle.com/technology/products/bi/olap/olap_downloads.html#software
    Here is an error:
    Begin installation
    ... deleting GLOBAL AW (if it exists)
    ... creating GLOBAL AW
    begin
    ERROR at line 1:
    ORA-37162: OLAP error
    XOQ-00506: Unable to parse XML string sent from the client to the server
    ORA-06512: at "SYS.DBMS_CUBE", line 88
    ORA-06512: at "SYS.DBMS_CUBE", line 134
    ORA-06512: at "SYS.DBMS_CUBE", line 154
    ORA-06512: at "SYS.DBMS_CUBE", line 144
    ORA-06512: at "SYS.DBMS_CUBE", line 181
    ORA-06512: at line 2
    The following line in the script gives an error:
    dbms_cube.import_xml('GLOBAL_INSTALL', 'GLOBAL_MV.XML');
    Any help will be greatly appretiated.
    Thank you.
    - t

    I suspect the problem is that you are using an 11.1.0.7 client to access an 11.1.0.6 server. This configuration should work, but there was a bug at some point with new clients and old servers. In any case you would be advised to upgrade your server to either 11.1.0.7 or, at least, the latest 11.1.0.6 OLAP patch.

  • Executing sql script from file, with multiple queries

    Hello,
    I am trying to load an SQL script from a file, parse the script into separate SQL statements, and execute each of them. The final statement will always be a query, and thus will return a result.
    Three problems arise:
    1. I don't know what TYPE of statement each one is (i.e. whether it is an UPDATE or a QUERY), which seems to be required in order to execute it in java (via executeQuery and executeUpdate).
    2. I am not sure of the best way to execute a series of statements (the Statement object has some "batch" functionality, but I'm not sure if there is a better way, or even of the proper way to use this).
    3. I need to be able to make sure the final statement is a QUERY, and thus will return a ResultSet. Otherwise I need to be able to throw an exception.
    This has been causing me a lot of trouble. Any help would be much appreciated.
    Thanks,
    Kevin

    Hi Kevin,
    Have you got any solution for your mentioned problem????
    I am facing almost the same kind of problem like I have some sql files containg simple sql statements as well as code for writting Procs , triggeres, index...functions..and so on. I need to execute this XYZ.sql file from Java side.
    Can you guide me about my problem?????
    Thanks in advance.............
    Mak

  • How to directly edit PL/SQL Scripts

    I can't open PL/SQL source files directly into a PL/SQL editor - they're opened as SQL scripts. The tool still seems targeted towards database maintenance rather than developing code held in a separate version control system.
    Whilst technically the PL/SQL source files are just SQL scripts this doesn't make for easy PL/SQL development.
    A change to a PL/SQL source file involves:
    - Open source file into SQL script tab.
    - Choose connection to run script against.
    - Run as a SQL script.
    - Close source file.
    - Navigate to package spec/body in tree browser and open read-only in a view tab.
    - Click to edit object source - opens in new tab.
    - Edit source and compile.
    - Add 'create or replace' at top and '/' at end.
    - Select 'Save As...' and navigate to original source file.
    - Close script window that this automatically opens for newly saved file, and close edit source tab. Same task in PL/SQL developer:
    - Open source file into a Program Window.
    - Edit source and compile.
    - Click save.
    Making a single change is bad enough - try it when you're making substantial changes to a source file and you want to regularly check compilation and save changes.
    Can anyone help make this easier ?

    The tool still seems targeted towards database maintenance rather than developing code held in a separate version control system.They'll get to it eventually...
    I can't open PL/SQL source files directly into a PL/SQL editor - they're opened as SQL scriptsIs the extension .sql? Change it to .pls or .pks/.pkb. They seem to use the dumb extension-based system to find out what files they are dealing with, instead of parsing the contents.
    If the code doesn't get syntax coloured, open a function or procedure from database first, that seems to wake him up.
    Also make sure the files are as the same as in the DB (with create or replace, without final slash), so you can compile them directly from the same file-based editor.
    You still have to assign connection and navigate to the PL/SQL in the DB to view compilation errors and run/debug though. There are some requests on the announced SQL Developer Exchange for these (http://htmldb.oracle.com/pls/otn/f?p=42626:37:260789750723810::NO:::). Please vote for them to see them implemented.
    K.

  • Difference between ';' and '/' in the SQL scripts

    Hi All,
    Could anyone please let me know the difference between placing ';' and '/' in the sql scripts.
    I am placing couple of insert statements in a textfile with .sql extension and running it from the sql prompt.
    Which one( ';' or '/') should be keep at the end of each statement in the script.
    SQL> SELECT SYSDATE FROM DUAL;
    SYSDATE
    12-MAY-13
    SQL> SELECT SYSDATE FROM DUAL
      2  /
    SYSDATE
    12-MAY-13Thanks,

    968217 wrote:
    My doubt is how it understands or the difference b/w the below two view statements one with ';' and another one with '/'. Sorry if i am unclear.They are identical in SQL*Plus. These characters mean "+send entered/buffered text to Oracle to parse and execute+".
    So - SQL*Plus sends "+create or replace view ev1 as select ename , sal from emp+" to the server (via a cursor execute):
    create or replace view ev1 as select ename , sal from emp
    /And again, SQL*Plus sends "+create or replace view ev1 as select ename , sal from emp+" to the server (via a cursor execute):
    create or replace view ev2 as select ename , sal from emp;These are identical statements.
    As I mentioned in the post I referred you to. Oracle also uses the ";" character in the PL/SQL language. So when you enter PL/SQL code in SQL*Plus, you do not want SQL*Plus to send each line of PL/SQL code to the server. Instead, you want it to wait till the last statement has been entered and then send the the whole block to the server to be parsed and executed,
    SQL*Plus has a basic parser itself. It uses that to figure out what you have entered, and whether a ";" you enter is an instruction from you to it, to send the text to the server - or when you enter a ";", it is part of the text for the server and that it should not react to it.
    Thus when you enter the following, SQL*Plus recognises that you are using the SQL language, and as this language does not use ";" characters, a ";" character when entered means that it needs to send the text to the server to be parsed and executed:
    SQL> select * from emp;
    // ; character instructs SQL*Plus to create and execute cursor "select * from emp"When you enter PL/SQL code, SQL*Pus recognises that and knows that ";" characters entered indicates end-of-statement for PL//SQL and that it should not act on that,
    SQL> begin
      2    null;
      3  end;
      4  /
    // SQL*Plus ignores the ";" character - and the "/" character is used to
    // instruct SQL*Plus to create and execute cursor"begin<LF>null;><LF>end;"

  • Convert SQL script from one dialect to another.

    Hi all,
    I am trying to convert an SQL script in MySQL dialect to one for
    Firebird (Interbase Open Source fork).
    I will show you the original MySQL script, (one table of 70), what I want it to
    become and then the Java program that I have written which has gone some of
    the way - but I'm not very experienced in Java and I think my approach
    needs to be fundamentally overhauled, it's just that I don't know
    exactly how to go about it - maybe treat the table as a unit and pass my
    file table by table to a/some processing function(s)?
    Here is the original script
    CREATE TABLE `analysis` (
      `analysis_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
      `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
      `logic_name` varchar(128) NOT NULL,
      `db` varchar(120) DEFAULT NULL,
      `db_version` varchar(40) DEFAULT NULL,
      `db_file` varchar(120) DEFAULT NULL,
      `type` enum('constitutive_exon','exon','flanking_exon') DEFAULT NULL,
      `program` varchar(80) DEFAULT NULL,
      `program_version` varchar(40) DEFAULT NULL,
      `parameters` text,
      `gff_feature` varchar(40) DEFAULT NULL,
       PRIMARY KEY (`analysis_id`),
       UNIQUE KEY `logic_name_idx` (`logic_name`)
    ) ENGINE=MyISAM AUTO_INCREMENT=261 DEFAULT CHARSET=latin1;I want this to become
    CREATE TABLE analysis
    (  -- ( on a separate line - have done this. Note also - got rid of funny quotes `
      analysis_id smallint(5),  -- see below for what happens to auto_increment
      created TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00', -- datetime now TIMESTAMP -- trivial
      logic_name varchar(128) NOT NULL,
      db varchar(120) DEFAULT NULL,
      db_version varchar(40) DEFAULT NULL,
      db_file varchar(120) DEFAULT NULL,
      type (CHECK TYPE IN ('constitutive_exon','exon','flanking_exon')) DEFAULT NULL,  -- emum becomes a CHECK constraint - parse the string in a function?
      program varchar(80) DEFAULT NULL,
      program_version varchar(40) DEFAULT NULL,
      parameters BLOB SUB_TYPE TEXT,  -- text becomes BLOB SUB_TYPE TEXT - trivial
      gff_feature varchar(40) DEFAULT NULL,
      -- PRIMARY KEY (analysis_id),  -- here's where the fun starts - see below.
      -- UNIQUE KEY logic_name_idx (logic_name) -- more fun here
    )  -- ) on new line
    -- ENGINE=MyISAM AUTO_INCREMENT=261 DEFAULT CHARSET=latin1; - this line gets obliterated - see below.
    -- only data of interest on this line is the AUTO_INCREMENT VALUE - 261
    ALTER TABLE ADD CONSTRAINT analysis_id_PK PRIMARY KEY(analysis_id) USING INDEX analysis_id_PK_IX
    ALTER SEQUENCE analysis_id_seq RESTART WITH 261 -- note auto_increment=261 at end
    -- note, take field name of AutoIncrement - add PK and PK_IX
    -- as required. I will also have to write something similar for the UNIQUE KEY - but
    -- if I can do it for PRIMARY KEY, then it should be easy...I have written a program which has started to do some of the easier stuff
    below - however, I now think that I should be treating a TABLE as a unit rather
    than the line by line processing which I have been doing so far. I would
    like some pointers as to how I could do this - the .sql file has about 70
    tables and I want to be able to process the file in one pass. Any hints,
    recommendations, URLs, tips or other help greatly appreciated - rgs,
    Paul...
    ============= Java listing so far (I have been trying 8-) ) ===========
    import java.io.*;
    import java.util.*;
    class FileProcess
      public static void main(String args[])
        try
          // Open the file that is the first
          // command line parameter
          FileInputStream fistream = new FileInputStream("analysis.sql");
          FileWriter fwstream = new FileWriter("nanalysis.sql");
          // Get the object of DataInputStream
          DataInputStream in = new DataInputStream(fistream);
          BufferedReader br = new BufferedReader(new InputStreamReader(in));
          BufferedWriter out = new BufferedWriter(fwstream);
          String strLine;
          String newLine = System.getProperty("line.separator");
          String newSQLText = "";
          String tblName = "";
          String recordDelims = "[ ]";
          Boolean inTable = false;
          String tableBegin = "(" + newLine;
          System.out.println("\nAnd tableBegin is *_" + tableBegin + "_*");
          //Read File Line By Line
          while ((strLine = br.readLine()) != null)      
            // if strLine.contains(
            // Print the content on the console
            System.out.println ("StrLine = " + strLine);
            newSQLText = getRidOfWierdQuotes(strLine);
            if(strLine.contains("CREATE TABLE"))
              StringTokenizer st = new StringTokenizer(newSQLText, "` ");
              st.nextToken();
              st.nextToken();
              tblName = st.nextToken();
              System.out.println("\nAnd the table name is *_" + tblName + "_*");
            if(strLine.contains(" (") && strLine.contains("CREATE TABLE"))
              System.out.println("\nAnd here's the start of a table!");
              newSQLText = newSQLText.replace(" (", newLine + "(");
             // br.readLine();
              //br.readLine();
            if(strLine.contains(" text,") || strLine.contains(" text "))
              newSQLText = newSQLText.replace(" text", " BLOB SUB_TYPE TEXT");
    //        String sqlTokens[] = newSQLText.split("\\s+");
    //       StringTokenizer stRecord = new StringTokenizer(newSQLText)
            System.out.println("\nNew strLine = " + newSQLText);
            out.write(newSQLText + "\n");
          //Close the input stream
          in.close();
          out.close();
        catch (Exception e)
          //Catch exception if any
          System.err.println("Error: " + e.getMessage());
      public static String getRidOfWierdQuotes(String iString)
        return iString.replace("`", "");
    } // End of class FileProcess

    >
    Your technique looks OK but I would avoid all the cosmetic changes. It doesn't make any
    difference to the script where the newline comes, and the back-quotes are legal SQL too.
    I would confine your activities to what is actually required. Otherwise you are just adding
    implementation difficulties and also running the risk of an ever-expanding scope of what
    the cosmetic improvements should include.Thanks for your reply - however, I would just make two points.
    1) The cosmetic changes are the easiest - and I've essentially implemented them already, and
    for myself, I find that when working on a system with many tables, the way they are presented
    by whatever tool one is using to modify/update/change/run various scripts is very important as
    an aid to organisation and ultimately understanding.
    2) Having essentially completed the cosmetic stuff, I now find myself turning to the group here
    for help with the real "meat" of the project - getting the PRIMARY KEYs and other INDEXES
    &c. into the mix - and this is tricky because of the significant differences between MySQL and
    Firebird SQL dialects - that and the fact that not all AUTO_INCREMENT fields are PRIMARY
    KEYs - so I am looking beyond the mere cosmetic.
    I think I said in my original post that I wanted to perform this task in "one pass". Perhaps what
    I should have said (and might have been clearer) is if I said that I just wanted to run one
    Java programme against the data.
    I now think that my Java programme will have to go through the data a couple of times - on
    the first pass - it will collect the names of those tables for which the AUTO_INCREMENT
    field is* the PRIMARY KEY - putting the name into a Vector (deprecated?) or similar
    and then go through my "cleaned up" sql file adding the KEYs/INDEXes &c. as I go.
    What do you think of this approach - or should I be looking at constructing "Table"
    objects (as arrays of String?) and manipulating those?
    This is my real question - what is the best approach to take - as a 36K guru level
    poster - you probably have an idea - I'm not asking for the work to be done for me,
    as you can see - I've made an effort myself, despite my Java not being to the highest
    pinnacle of coding perfection ;) - any snippets, help, anything appreciated (from
    anybody...) - TIA and rgs,
    Paul...

  • Calling a sql script file from a function.

    Hi,
    I need to call a sql script file from a user defined function. Currently i am trying to do this in Oracle SQL Developer. i tried calling with
    @ {filename}, EXECUTE IMMEDIATE etc, but nothing worked. I get the Compiler error.
    Basically my need is to call catldap.sql file so that DBMS_LDAP package gets loaded and then I can call the API functions from this.
    Please let me know if this is possible doing in a PL/SQL function.
    thanks,
    Naresh

    user784520 wrote:
    I need to call a sql script file from a user defined function. Not possible.. and it seems that you do not fully understand the client-server within the Oracle context.
    All SQL and PL/SQL are parsed and executed by an Oracle server process. The SQL and PL/SQL engines each expects a single command block at a time. Neither of these can accept a series of separate commands as a single call and then execute each in turn. The SQL engine expects a single SQL statement at a time. The PL engine expects a single PL/SQL anonymous block at a time.
    This server process also cannot break into the local file system to access script files. Nor can it hack across the network to access script files on the client.
    In order for the server process to access local files, a directory object needs to be created and the current Oracle schema needs read and/or write access on that directory object. As sound security principles apply.
    There's no PL/SQL command to execute a script. You must not mistake SQL*Plus commands (this client has a very limited vocabulary) with PL/SQL commands. SQL*Plus executes its own commands.. and send SQL and PL/SQL commands (a statement block a time) to the Oracle server process to be serviced and executed.
    It is also a very bad idea to execute external script contents from inside an Oracle server process - as that script resides externally and thus outside Oracle's security mechanisms. This means that is is pretty easy for someone to access that script, compromise it, and then have you inject and execute the contents of that script into the database.
    It is not sound security.
    Last issue - it is even worse to have application PL/SQL code dynamically creating (or trying to create) portions of the Oracle data dictionary and PL/SQL call interface.
    The database needs to be installed correctly - and this includes loading and executing the required rdbms/admin scripts during database installation. It does not make sense at all for application code to try and execute such scripts. It raises numerous issues, including having to allow that application code full and unrestricted SYS access to the database instance. A very serious security violation.
    I do not agree at all with the approach you want to use.

  • How to call SQL script from PL/SQL block

    Hi All,
    I have a pl/sql block from which i need to call a *.sql script file.
    Please tell me that how can i do this?
    Thanks and Regards.

    > Though just for knowledge sake, would you please tell if there is a way
    to call a sql script from a pl/sql block.
    This question stems usually from a confusion about client-server and which is which in Oracle.
    SQL*Plus is a client. PL/SQL is a server side language. SQL is a server side language.
    When entering either one of these two languages in SQL*Plus (or TOAD, SQL-Developer, etc), the content is shipped to an Oracle server process, is parsed there, and is executed there.
    The Oracle server process servicing the client can accept a single SQL statement or PL/SQL block at a time.
    It cannot accept a block of SQL statements delimited with a semicolon. That is a client concept where the client will read each delimited statement and send that, one after the other (in synchronous call mode) to the Oracle server for execution.
    The Oracle server does not have a "script parser". It understands SQL. It understands PL/SQL. And that is what it expects from the client.
    Whether the client supports the SET command, the HOST command, SPOOL command, ability to run scripts, and so... have no bearing on what the server itself is capable of doing. The server does not care what feature set the client has. It is tasked with servicing the client via SQL and PL/SQL.
    It is not tasked to support or emulate client features like running SQL scripts.
    Nor confuse PL/SQL with the very limited command set of SQL*Plus. The two has nothing in common. And just as PL/SQL cannot understand C# or Delphi commands, it cannot understand SQL*Plus commands.

  • Validate SQL Script

    Hi,
    I am working on a perl script to test if the sql script file prepared by the Dev team can be deployed to the DB without any issue or not. My intention is not to run the script but only to check if the script will run properly without any error at the time of actual deploy or not. Is there a way wherein I can mimic the execution of the script?
    consider, I has a script file CreateTable.sql which contains CREATE TABLE statement. I dont want the table to be created by mimic actual run of this script against the database. How do I do that?
    TIA
    -Onkar

    onkar.nath wrote:
    I am working on a perl script to test if the sql script file prepared by the Dev team can be deployed to the DB without any issue or not. My intention is not to run the script but only to check if the script will run properly without any error at the time of actual deploy or not. Is there a way wherein I can mimic the execution of the script?
    consider, I has a script file CreateTable.sql which contains CREATE TABLE statement. I dont want the table to be created by mimic actual run of this script against the database. How do I do that?Do that by being creative? ;-)
    Not possible using PL/SQL. PL/SQL has a a very flexible DBMS_SQL cursor interface - that amongst other things allow you to parse a statement into a cursor. However, a parse call also automatically executes if the parsed cursor is a DDL. With DML, you can parse and not execute.
    The only other way that comes to mind is using the EXPLAIN PLAN command in the SQL language. E.g.
    SQL> explain plan
      2          set statement_id = 'ddl.parse.1'
      3  for create table testtab2 nologging as select * from user_objects;
    Explained.
    SQL> --//object not created
    SQL> desc testtab2
    ERROR:
    ORA-04043: object testtab2 does not existThere could perhaps be a method using the OCI (Oracle Call Interface) to parse a DDL without executing it. Are you using Perl-DBI? In that case you may want to look at the OCI and how Perl-DBI exposes that - and whether a DDL can be parsed as cursor without executing it.

  • Change T-SQL Script

    I know that OMWB can convert the store procedure to oracle but how can i convert a T-SQL script to oracle?
    i know OMWB can eaily do it.
    i can make the t-sql script to store procedure but i don't want this..
    So is there any better way to change it?
    Anil

    Im afraid the OMWB does not have support for scripts yet.
    As noted you can cut and paste statements into the body of a stored procedure that is already captured by the OMWB and parse them. Unfortunately there is no other way to access the OMWB parser.
    Regards,
    Dermot.

  • IF statement syntax in SQL script view

    I need to include a "IF" condition in the "SELECT" section of my SQL script view.
    I tried the following syntax's but I get the error 'Incorrect SQL syntax near 'IF'
    1.  IF(Revenue <> '0' AND Quantity <> '0', Revenue/Quantity, '0') AS Gross Price
    2.  IF(Revenue != '0' AND Quantity != '0', Revenue/Quantity, '0') AS Gross Price
    3.  IF(Revenue <> '0' AND Quantity <> '0' THEN Revenue/Quantity ELSE  '0' END) AS Gross Price
    4.  IF(Revenue != '0' AND Quantity != '0' THEN Revenue/Quantity ELSE  '0' END) AS Gross Price
    My final SQL would read like follows:
    SELECT field1, field2, IF(......) AS field3
    FROM table1
    Can anybody please help with the correct IF statement syntax to be used in the SQL script based view?

    Hi Lakshmi,
    below is the syntax for IF statement.
    IF <bool_expr1> THEN
    <then_stmts1>
    ELSEIF <bool_expr2>
    THEN <then_stmts2>
    [ELSE <else_stmts3>]
    END IF
    eg :
    BEGIN
    DECLARE found INT := 1;
    SELECT count(*) INTO found FROM books WHERE isbn = :v_isbn;
    IF :found = 0 THEN
    INSERT INTO books VALUES (:v_isbn, 'In-Memory Data Management', 1, 1, '2011', 42.75, 'EUR');
    ELSE
    UPDATE books SET price = 42.75 WHERE isbn =:v_isbn;
    END IF;
    END;
    Sreehari

Maybe you are looking for

  • Open Interface Table for iExpense Template

    Where can I find the table name of the Open Interface for uploading master records of GL, AR, AP, FA? I can only find the name to upload journal entries and AR, AP Invoice. Can someone advise me where can I find the open interface tables list for mas

  • FTP Configuration

    HI Experts,                         i have assigned to following scnario, We are creating report level interfaces  from SAP to third party(no bdc,rfc,bapi, such methods) I want to know the FTP configuration bcos the flat files are send through FTP fr

  • ALE custom function module for IDOC_INPUT_COSTCENTER

    We are setting up an ALE to update cost centers in our HCM system from our ECC system.  In conjunction with the cost center update I need to convert the company code (it's not straight-forward enough to use a conversion rule) so I have created a cust

  • Xsl output attributes for cdata-section-elements and doctype-system

    I am using an xsl file to transform one xml document to another xml document. I want to use the xsl:output Element to do two things: 1.Generate CDATA sections for the text contained in an xml element,"Description" 2. Add the line "<!DOCTYPE PartInfor

  • How to replace hard drive on hp mini 110 - 1125nr

    HP mini 110 - 1125NR s/n [edited Serial Number by Moderator] P/N VM135UA#ABA trying to find out where the hard drive is located.