nesting queries on multiple sql files - possible?
HelloI was wondering if the following would be possible, and if so what the syntax in sqlplus?
Imagine I have a query that generates a table of data output. I can then refer to it and affix analytical functions on this one in a separate sql file?
For example if I have the query:
AB.sql
select count (*)
from (select sysdate from dual)
I could this split into two files sql A and B?A.SQL
select sysdate from dual
B.SQLselect count (*) from @C:\A.sql
the result of the execution of B.sql would be 1.for now I really wonder if this is doable on a conceptual level, anyone know?
Thank you
Jon
Yes, on the conceptual level, it is possible.
cat a.sql
select count (*)
from (
@b.sql
)
;
cat b.sql
select sysdate from dual
sqlplus scott
SQL*Plus: Release 11.2.0.1.0 Production on Fri Nov 12 13:13:58 2010
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Enter password:
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> set echo on
SQL> @a.sql
SQL> select count (*)
2 from (
3 @b.sql
3 select sysdate from dual
4 )
5 ;
COUNT(*)
----------
1
Best regards
Maxim
Tags: Database
Similar Questions
-
tablespace with multiple data files
Hi all
We have RHEL4 server with oracle 10 g 2 inside.
can we create a tablespace with multiple data files? I mean while creating a tablespace itself, we should be able to create two or more data files (should not use ALTER tablespace command).
If possible, please give me the SQL to do this (assume that I need to create a tablespace with two data files).
Thanks in advance...Not so difficult isn't it?
create tablespace datafile test
'1.dbf' size 1 m REUSE AUTOEXTEND ON NEXT 32 M MAXSIZE 1500 M,
'2.dbf' size 1 M REUSE AUTOEXTEND ON NEXT 32 M MAXSIZE 1500 M
EXTENT MANAGEMENT SEGMENT LOCAL SPACE MANAGEMENT AUTO; -
Select multiple PDF files and share them [iOS]
I use adobe Acrobat reader on my iPad and I would select several files and share them. Is this possible?
Hi davidw26200688,
I'm sorry ts not possible to share multiple PDF files at the same time in the iPad, however as a work around you can try to send the pdf by linking them directly to your email in PDF share also share the PDF by email.
Kind regards
Nicos
-
Nested queries in Apex/BEEP Source?
With the help of Apex 4.0.2.00.07, I have a master report / detail required that has a rather long header/footer and then lots of detail rows. The ideal ratio would eventually something like the following:
Paragraphs in header information
Line 1
....
Line 100
Info from footer paragraph
Is it possible for the Apex report queries to generate the XML to nest queries? I know that I can throw it all in a single record by joining tables, but then I have to generate all the header information for each line instead of once for each master record. I know that BEEP can handle it because I can do it for EBS by defining relationships of the query in the definition of data, but I can't seem to find a way to do it in the Apex report query. I've seen several comments on this issue, but no definitive answer. If anyone can help, I'd appreciate it.
Jessica,
You can not. If you decide to put all the data in a single line, you can build your model to break in the header data. The other option is to generate the report in the Pub BI and then call the report using webservice api bi pub.
Introduction to the Web Services BI Publisher - 11g Release 1 (11.1.1)
-
IDCS6 MACOSX JS: data merge multiple txt files one after the other
Hello everyone.
I have a situation where I have to data merge multiple text files to a single file indesign real "base". Databases formats are the same, the point of difference is a code in the second field of the database that refers to a postal box (not a zip/postal code, a code of 'distribution center' that has possibilities of 56 or greater). I would prefer data merge a file and then somehow split the PDF via Acrobat, but the length of postal areas resulting is incompatible and something that cannot be done if the document "split" feature in acrobat.
The database starts as one massive file but using a one line code, can be divided into postal areas in separate text files.
My last question: is it possible data merge several files at the same time (for example one after the other) and to give them their names based on the names of the input text file?
OLE Kvern had a script to merge the data to a file without the user interface. I changed the last line slightly so that it generates a PDF file based on [high quality]:
if(app.documents.length != 0){ var myDocument = app.activeDocument; app.dataMergeOptions.removeBlankLines = true; //Select a source file. var myDataFile = File.openDialog("Select a data file") var exported = "file location(redacted for the sake of this post)" if(myDataFile != ""){ myDocument.dataMergeProperties.selectDataSource(myDataFile,); myDocument.dataMergeProperties.exportFile(exported,"[High Quality Print]",); } }
I guess that the answer has to do with the variable "myDataFile" and rather than just being open a dialog box, it could be somehow by selecting a table of text files, but it is where I am out of my depth.
Ideas or thoughts which may not involve trying to do both the many mergers, but can somehow revolve around a great fusion of PDF?
Thank you very much
Colin
Since writing my last response, I realized there was a better answer. It is a scenario of Peter Kahrel and a modified version of a script by Olav Kvern. Details can be found here: batch of merge data | Adobe Community
I have since made other mods to the script is easier to understand:
if(app.documents.length != 0){ // make sure to use the document that is open var myDoc = app.activeDocument; // get the name of the document that is open for future naming purposes var myName = myDoc.name // get the location of the folder that contains both the indesign files and the text files var myLocation = "FULL PATH LOCATION OF FOLDER CONTAINING TEXT FILE AND DESTINATION FOR FINAL PDFS" // define the names of the data files to use based upon the names of the indesign files var myImport = myLocation + myName + ".txt" // define the names of the data merged PDFs to be created var myExport = myLocation + myName + ".pdf" // the actual engine for the merge, including DM instructions such as remove blank lines, object fitting etc. var myDataFile = myImport app.dataMergeOptions.removeBlankLines = true; if(myDataFile != ""){ myDoc.dataMergeProperties.selectDataSource(myDataFile,); myDoc.dataMergeProperties.exportFile(myExport, "[PDF/X-1a:2001]", ); } }
If this script will automatically merge a file which is open as LONG as the data file is the same name as the indesign file with .txt at the end for example
Woodward.indd (indesign file)
Woodward.indd.txt (used for merging text file)
This script does still not the original memory and who was using an indesign document, to browse for many text files and merging of PDF based on text files.
HOWEVER, I am sure that the answer to that is based only on the use of the script above (no need to Peter batch convert script) and changing the line 9 to be a loop for... but again, this is where I come to a grinding halt. Any help would be appreciated.
Colin
-
How to run multiple sql statements
Hi all
I wonder if I can run multiple sql statements in one shot with > >, immediate run
for example:
I set the variable as X: = sql statement
Y: = sql statement
z: = sql statement
can I execute immediate (X, Y, Z);
If yes how? and if not what other possible
Thank youBeginning with the codes of Ganesh
DECLARE l_statement VARCHAR2 (2000); v_passwd VARCHAR2 (200); v_username VARCHAR2 (200) := 'test'; v_pwd_key VARCHAR2 (200) := 'lwty23'; v_dblink_name VARCHAR2 (2000); v_dblink_drop VARCHAR2 (2000); v_dblink_create VARCHAR2 (2000); v_dblink_check_connection VARCHAR2 (2000); l_number NUMBER; BEGIN --<
> FOR c_instance IN (SELECT * FROM v_oracle_instances WHERE environment = 'Developement') LOOP SELECT encpwd_owner.display_db_encpwd (v_username, c_instance.host_name, c_instance.instance_name, v_pwd_key) INTO v_passwd FROM DUAL; v_dblink_name := c_instance.host_name || '_' || c_instance.instance_name; v_dblink_create := ' CREATE DATABASE LINK ' || v_dblink_name || ' CONNECT TO ' || v_username || ' ' || 'IDENTIFIED BY ' || v_passwd || ' USING' || ' ''(DESCRIPTION= (ADDRESS=(PROTOCOL=TCP)(HOST= ' || c_instance.host_name || ')(PORT=' || c_instance.LISTENER_PORT || '))(CONNECT_DATA=(SID=' || c_instance.instance_name || ')))'''; v_dblink_check_connection := 'select 1 from global_name@' || v_dblink_name || '.QCM'; --- Notice this change. I am simply selecting 1. That should be enough to test the database link. v_dblink_drop := 'drop database link ' || v_dblink_name || '.QCMTLAF'; -- l_statement := 'BEGIN ' || v_dblink_create ';' || v_dblink_check_connection ';' || v_dblink_drop '; END ;' BEGIN EXECUTE IMMEDIATE (v_dblink_create); DBMS_OUTPUT.PUT_LINE ('DB Link ' || v_dblink_name || ' Created'); EXCEPTION WHEN others THEN dbms_output.put_line( 'Failed to create the database link ' || v_dblink_name ); dbms_output.put_line( dbms_utility.format_error_backtrace() ); INSERT INTO error_table( column_list ) VALUES( < - > );
END;
EXECUTE IMMEDIATE (v_dblink_check_connection) INTO l_number; --- Notice this.
DBMS_OUTPUT.PUT_LINE ('DB Link ' || v_dblink_name || ' Tested');
BEGIN
EXECUTE IMMEDIATE (v_dblink_drop);
DBMS_OUTPUT.PUT_LINE ('DB Link ' || v_dblink_name || ' Dropped');
EXCEPTION
WHEN others THEN
dbms_output.put_line( 'Failed to drop the database link ' || v_dblink_name );
dbms_output.put_line( dbms_utility.format_error_backtrace() );
INSERT INTO error_table( column_list )
VALUES( <
- > );
END;
END LOOP;
END;
But I agree with the comment that others have grown up is not really wise to create and drop a database like that link.
Justin
-
Hello
I am trying to run a query on a request that I stored in a .sql file. I tried the following without success. It's a mad race or I just got the wrong syntax?
With some search terms such as "sql" and "file" I'm not having much luck Googling. Appreciate any advice.
Thank you
Jon
Does my sql query but I want to ask this in turn@G:\JFlett\PLSQLScripts\NewQPort_KTandMG.sql;
with t as ( @G:\JFlett\PLSQLScripts\NewQPort_KTandMG.sql; ) select deal_id from t
select deal_id from ( @G:\JFlett\PLSQLScripts\NewQPort_KTandMG.sql; )
It wouldn't CREATE TRIGGER but CREATE a TASK.
http://download.Oracle.com/docs/CD/B28359_01/server.111/b28310/schedover.htm#i1106753But you don't seem to have it.
Someone else could possibly create it for your schema/user if they had the privilege to CREATE ANY JOB. -
How to import the .sql file in oracle apex?
I am new to oracle apex...
How to import the .sql file in oracle apex?
I have to import a table in apex...
This script I have to write in the .sql file...
pls help...
Published by: 794244 on January 31, 2011 21:31Hi Manu
You can import and browse workshop SQL, SQL Scripts .sql files. If you have multiple SQL statements in your script, make sure that they are separated by the / character
Andy
-
Open multiple JPEG files in Camera RAW
I can open a single jpeg in Camera RAW by changing the Camera RAW format option. If I want to process multiple images at the same time, in Camera RAW, I lose the Camera RAW format option.
Is it possible, in the elements, open several JPEG files in Camera RAW format?
Mary Lou
Unfortunately, you can't open multiple JPEG files in camera raw at the same time
-
Multiple audio files in a single slide Captivate 5?
It is easy to add multiple audio files in Camtasia Studio: just drag gthem.
Captivate 5 asks me if I want to replace the current audio file. I don't. I just need - at the most - you short audio files that will play in order, perhaps with a short break between the two
Is this possible?
Welcome to our community
Captivate allows audio at three levels.
- Background - plays for the duration of the project
- Slide - plays when the slide plays
- Object - plays when the object appears
What you must do if you want multiple audio files to read is to insert objects and associate audio with objects. If you do not want to see the object and all what you want to do is to hear the audio, use a Transparent caption with no text or a box to highlight without color or a box click with no break and no action when you click it.
See you soon... Rick
Useful and practical links
Begin to learn Captivate 5 times now! $29.95
Captivate wish form/Bug report form
-
SQL file with block anonymous (main) and procedure
Can I have in a sql file? Ideally, I would like to use a procedure in my sql script. How is that possible? Thank you.
DECLARE
BEGIN
END;
-follow-up of a procedure block
BLANK test procedure
IS
BLANK END;How to define a procedure in the block of anonmymous and call it?
SQL> declare procedure blank as begin dbms_output.put_line ('Inside procedure blank'); end blank; begin blank; end; / Inside procedure blank
-
combinations, nested queries
Hello everyone,
We need to change technologies according to the needs of the company and we would like to understand request.
Select t1.fld1 as class, v2.section, v1.duration,
rownum, nest queries, dot operator and combinations make us confused.
T1.fld2 as start_date, end_date as t1.fld3,
(t1.fld2 + v2.section - 1) as sectiondate
Of
(select Fld1 as class, ((fld3-fld2) + 1) as the length)
from t1
) v1
, (select rownum as object section where rownum < 180) v2
t1
where t1.fld1 = v1.class
and v2.section < = v1.duration
We need help with this.
Thanks in advance,
NYHello
I don't have your question. In your request, that you do not use one of the columns object, you simply use a virtual column rownum to get an output of 180 lines with value 1-179. This array with the value 1 to 179 you set v2 table in your SQL.
Concerning
-
Call a script from a function sql file.
Hello
I need to call a script file sql from a user-defined function. Currently I am doing this in Oracle SQL Developer. I tried to call with
@ {filename}, EXECUTION IMMEDIATE etc, but nothing worked. I get the compile error.
Basically, my need is to call catldap.sql file so that DBMS_LDAP package gets loaded and then I can call this API functions.
Please let me know if this is possible to do in a PL/SQL function.
Thank you
NGOuser784520 wrote:
I need to call a script file sql from a user-defined function.
Not possible... and it seems that you do not fully understand the client-server in the context of Oracle.
All SQL and PL/SQL are parsed and executed by an Oracle server process. Engines SQL and PL/SQL is expecting a single command at a time block. Any of these can accept a series of commands in a single call and then runs them in turn. The SQL engine expects a single SQL statement at a time. PL engine provides an anonymous PL/SQL block for both.
This server process can not also enter the local file system to access the script files. Nor can he hack it on the network to access the script on the client files.
So that the server process to access local files, a Directory object must be created and the current Oracle schema must read or a write access to this directory object. Sound security principles apply.
There is no PL/SQL command to run a script. Do not confuse SQL * more (this customer has a very limited vocabulary) orders with PL/SQL commands. SQL * Plus runs its own orders... and send SQL and PL/SQL commands (a statement block a time) either repaired and running Oracle server process.
It's also a very bad idea to run the external script content from within an Oracle server process - as this script resides outside and so outside the Oracle security mechanisms. This means that it is fairly easy for a person to access this script, compromise and then you inject and execute the contents of this script in the database.
It is not good security.
Latest issue - it's even worse to have the PL/SQL application dynamically create (or try to create) parts of the Oracle data dictionary and calling PL/SQL interface.
The database must be installed correctly - and that includes loading and execution of the required rdbms/admin scripts during installation. It makes no sense at all for the application code to try to run these scripts. It raises many questions, including getting to allow the full application and full SYS code access to the instance database. A very serious breach of security.
I agree at all with the approach to use.
-
How can I execute commands stored in a sql file
Hello
I have a problem with the execution of one or two lines of a file after you save SQL and then brought back in SQL Developer. The sequence of what I do is
By selecting file > new > layer database > SQL file opens a file to me than I can name. In the window that appears, I can get into SQL, and then click the green arrow to run a line or I can run all of the script. I choose the database connection to use, and it works fine.
Now my problem is that I have after registration of this file and the setting again in SQL Developer I lose out on all the features that I had when the file was opened before.
Save the file, exit, start SQL Developer and select file > open. I choose the file and unlike before, it appears only in a regular window that does not allow me to run. I can't just choose a line to run all I can do is go run on the menu and run the entire file.
Is it possible that I can make in the file and opened it in a window which allows me to run commands as I could when I first created the file.
Thank you
Richard
Published by: user8662445 on August 29, 2009 05:21>
My question now is why it does not add a 'sql' file name? I was in the box to name a new sql file. It allowed me to enter a file name, but then instead of adding "sql" in the extension he just that added file name and does not itself give an extension.
Anyone who has tried this? Looks like a very unusual thing to do. I've never seen a request which just added "sql" in the name of the file when it should have given the file extension ".sql".
I have never tried before. I usually use "Save as" to a spreadsheet.
I just tried now and I can reproduce your problem. This is clearly a bug. If you have a support contract, you can trigger a SR in metalink, hope also one of here development team picks it up.
-
EXECUTE IMMEDIATE and multiple SQL
Hello
I get a string, say strSQL from an application.
for example:
strSQL: = "CREATE UNIQUE INDEX 'WEBDBTARGET'". "" PK_EMPID6"ON"WEBDBTARGET ". "" EMP_R1 "("EMPID")
PCTFREE, INITRANS 10 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645)
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 DEFAULT USER_TABLES)
TABLESPACE "TARGET_TS_01";
CREATING INDEX 'WEBDBTARGET '. "' MARK ' ON 'WEBDBTARGET '. "" EMP_R1 "("EMPNAME")
PCTFREE, INITRANS 10 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645)
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 DEFAULT USER_TABLES)
TABLESPACE «TARGET_TS_01 "«;»
I tried to run the strSQL using EXECUTE IMMEDIATE
get the error
* "PLS-00103: encountered the symbol"end-of-file"when it is waiting for one of the following values: *"
*; < an ID > < a between double quote delimited identifiers of > *.
* The symbol ";" was replaced by "end-of-file" continue. » *
I understand that the question is after the first SQL.
How to use EXECUTE IMMEDIATE if the input string contains multiple SQL?
Help, please.
TIA,
Newbieuser570138 wrote:
strSQL: = "CREATE UNIQUE INDEX 'WEBDBTARGET'". "" PK_EMPID6"ON"WEBDBTARGET ". "" EMP_R1 "("EMPID")
PCTFREE, INITRANS 10 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645)
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 DEFAULT USER_TABLES)
TABLESPACE "TARGET_TS_01";CREATING INDEX 'WEBDBTARGET '. "' MARK ' ON 'WEBDBTARGET '. "" EMP_R1 "("EMPNAME")
PCTFREE, INITRANS 10 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645)
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 DEFAULT USER_TABLES)
TABLESPACE 'TARGET_TS_01"';'You have extra quote (marked in red). But remove won't solve all of your problems. EXECUTE IMMEDIATE executes a SQL statement. You must divide in two strSQL:
strSQL:=' CREATE UNIQUE INDEX "WEBDBTARGET"."PK_EMPID6" ON "WEBDBTARGET"."EMP_R1" ("EMPID") PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "TARGET_TS_01"'; EXECUTE IMMEDIATE strSQL; CREATE INDEX "WEBDBTARGET"."SDSDSD" ON "WEBDBTARGET"."EMP_R1" ("EMPNAME") PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "TARGET_TS_01"'; EXECUTE IMMEDIATE strSQL;
SY.
P.S. in the majority of cases it IT not a good design of database to create objects dynamically.
Maybe you are looking for
-
Satellite P100 - v4.70 update BIOS stuttering in games
Hello I had a problem with the Bios v4.70. Since I flashed my BIOS I had regular stops in my games. Looks like the game crashes every 3 seconds for a short time. I got the BIOS v4.50 before without problem. I would use v4.70 because since the new ver
-
Where to save the backup to a key recovery?
When I try to back up using OKR partition by default drive Lenovo D is only about 1.5 GB so sure backup impossible as long as not enough space. So where can I save, is drive C ok or just stupid?
-
Slatebook: Order No. [redacted]
I bought a HP of Slatebook on 26.08.2014 with a 3 years, [redacted] number of order HP care pack. When I search this order on my account it is not found. Where is this order on the HP system?
-
Hello My laptop runs Windows Vista and it seems that whenever I download updates, it consumes space on my hard drive. I checked and there are too many updates installed on my laptop. Because I frequently download updates, - is it ok to uninstall the
-
2000-2d19WM HP laptop hard drive error
My HP 2000 is currently saying that a SMART disk check has detected an imminent failure. When running hardware diagnostics gave me a failure ID of: 6CX1VS-70P7AE-MFGJWK-60BA03 My product ID is: E0M17UA #ABA I wonder what my options are. My PC is stil