I have multiple select statements and I have to execute a particular select statement based on parameter we passed to script in Exasol.
This is pretty known to me in SQL server where we can achieve this functionality using inline function or stored procedure.
Exasol has a similar facility - it is called scripting in Exasol and is described in detail (with examples) in Section 3.5 of the Exasol User Manual. The manual can be downloaded from the Exasol website here :
https://www.exasol.com/portal/display/DOC/User+Manual+6.0
Related
I'm running a complicated SQL script in Oracle SQL Developer. The query starts with
DEFINE custom_date = "'22-JUL-2016'"
While this works fine in Oracle SQL Developer I get an error in jetbrains:
<statement> expected got DEFINE
Also when I run the query it says:
ORA-00919: invalid function
even though it all works fine in Orace SQl Developer.
Is there anything specific I need to configure in Jetbrains Pycharm to be able to execute Oracle SQL queries correctly?
DEFINE isn't a core feature of the database, instead it's a command in SQL*Plus.
SQL Developer has as script engine which supports all of the SQL*Plus commands, including DEFINE, which is why it works when you run it there.
DEFINE just creates a variable and assigns a text value to it. You'll need to re-write your code to declare the variable and assign values to it instead.
Docs for DEFINE
I have been researching the names of the SQL versions used by different DBMSs.
So far I have:
Microsoft SQL -> Transact SQL
PostgrSQL -> PL/pgSQL
MySQL -> standard SQL (ANSI)
Oracle -> PL/SQL
Firebird -> ?
I haven't found anything about this. I read somewhere that it's PSQL, but I'm not sure if that is true, since the search results for it return many pages about postgres...
Firebird simply has SQL, which is very close to standard SQL (probably closer than MySQL), it then discerns a number of different variants:
SQL, the basic variant (although some of the old InterBase documentation seems to use this to refer to ESQL as well)
ESQL (or Embedded SQL) which allows use of SQL directly in code (using a preprocessor), not used much these days
DSQL (or Dynamic SQL), this is what you usually use when executing queries against Firebird from a programming language
PSQL (or Procedural SQL) is the extension for stored procedures, stored functions, triggers and execute block
What is a dynamic SQL query, and when would I want to use one? I'm using SQL Server 2005.
Here's a few articles:
Introduction to Dynamic SQL
Dynamic SQL Beginner's Guide
From Introduction to Dynamic SQL:
Dynamic SQL is a term used to mean SQL code that is generated programatically (in part or fully) by your program before it is executed. As a result it is a very flexible and powerful tool. You can use dynamic SQL to accomplish tasks such as adding where clauses to a search based on what fields are filled out on a form or to create tables with varying names.
Dynamic SQL is SQL generated by the calling program. This can be through an ORM tool, or ad-hoc by concatenating strings. Non-dynamic SQL would be something like a stored procedure, where the SQL to be executed is predefined. Not all DBA's will let you run dynamic SQL against their database due to security concerns.
A dynamic SQL query is one that is built as the program is running as opposed to a query that is already (hard-) coded at compile time.
The program in question might be running either on the client or application server (debatable if you'd still call it 'dynamic') or within the database server.
I have a database schema generated in a text file (DDL - MS Access compliant).
Where is the option in MS Access to import that schema into an empty database ?
I'm not aware of any import for DDL.
However, DDL contains the definition for the schema.
You simply have the execute DDL as you would any query.
Either create a query, put it in sql mode, paste your ddl, and execute
or....
Create a VBA Sub to essentially do the same: currentdb.execute SQL
Good Luck
To execute a SQL DDL in the SQL View of a Query object, you may need to change the Access user interface to ANSI-92 Query Mode. While the 'traditional' query mode (ANSI-89 Query Mode) supports a SQL DDL syntax it is very limited.
The Access database engine can only execute one SQL statement (DML, DDL or DCL) at a time. To execute a SQL script consisting of multiple SQL statement, you need something to parse individual SQL statements, so it really helps if your script has semicolon ; characters separating them, then execute each statement on at a time i.e. synchronously. If you are doing this in VBA code you are better off using ADO because it always uses ANSI-92 Query Mode.
See if this helps: http://support.microsoft.com/kb/180841
I have been very succesful with reverse / forward engineering MS Access databases with Dezign for Databases by Datanamic. It reads all kinds of DDL scripts (from almost all available database) and can translate between different databases. There is a free trial available.
Does anyone know how to generate SQL scripts from a query?
For example,
Script some tables.
Do custom action 1.
Script the views.
Do custom action 2.
Etc.
It sounds like you want to write a cursor to execute custom SQL. This is common and easy to do. What you need to do is specify a few things to help us more completely answer your question:
What type of SQL server are you using? (MSSQL, Oracle, MySQL)
What language are you writing in? (Java, C++, PL/SQL, TSQL)
You can either write code (Java / C++) to generate SQL from a query, or possibly use a cursor to iterate over recordsets (PL/SQL / TSQL). You can use the results to give you information that can then be executed as SQL via an exec (of some kind depending on the language).
... but please investigate SQL injection before implementing dynamic SQL. Look into Parameterized Queries...
With Microsoft Sql Server, the best way to script database objects is to use SMO. Sql Management Objects is a c# api, but you could always execute t-sql scripts from c# using a SqlClient.
You could want something like
select 'UPDATE '+table_name+ ' SET description=''(new!) ''+description WHERE description_date>''2008-11-01'''
from information_schema.tables where table_name like '%Description'
(this query generates queries which prepend value of description column with '(new!) ' for each recent row in each table which name ends with 'Description' in a fictional database).
The system view INFORMATION_SCHEMA.TABLES contains data about all database tables, there are also INFORMATION_SCHEMA.VIEWS, INFORMATIONS_CHEMA.COLUMNS and other system views in INFORMATION_SCHEMA table schema.
Hope this will help.