How to concatenate two sql statements?
HelloHow can I combine the following two sql statements so that the result of a line of the first statement appears before the lines of my second sql statement. The reason I need it is to order the lines correctly.
Select the username, id
some abusers
where id = 0
Select the username, id
some abusers
where id! = 0
order by username
Thank you
j
You should ask in the forum of the Apex:
Oracle Application Express (APEX)
Nicolas.
Tags: Database
Similar Questions
-
How to combine towing sql statements.
Hi all
I try to combine the two sql statements. but it is giving error 907, I can't stand no less. Please correct me if am wrong.
Here's my query
Select a.A1, b.C1, a.B1 in)
(select C1, sum (s.amount_sold) cust_first_name
customers c, s sales where c.cust_id = s.cust_id
C.cust_first_name group),
(select t.calendar_year A1, sum (c.unit_cost) B1
the time period t, cost c where
t.TIME_ID = c.TIME_ID and t.calendar_year
((1998,1999) group by t.calendar_year) b) order of 1, 2
Thank you
SreeI found two [a start and closing] and additional fasteners - from parentheses after FROM and closing introductory "order by".
Try this:
SELECT a.A1, b.C1, a.B1 FROM ( SELECT cust_first_name C1, SUM (s.amount_sold) FROM customers c, sales s WHERE c.cust_id = s.cust_id GROUP BY c.cust_first_name) a, (select t.calendar_year A1,sum(c.unit_cost) B1 from times t,costs c where t.time_id=c.time_id and t.calendar_year in (1998,1999) group by t.calendar_year) b order by 1,2
Published by: user130038 on Sep 1, 2011 08:19
-
How to run a SQL statement to use a specific implementation plan
Hi all
I have a SQL that has recently been run badly. I tried the Advisor tuning SQL for the given SQL query and it gives the following information:
GENERAL INFORMATION SECTION
-------------------------------------------------------------------------------
Name of the task of tuning: 2q94zb7djr2xn
The owner task of tuning: LMDBPROD
Type of work: single SQL statement
County of execution: 2
The current run: EXEC_8869
Type of execution: TUNE SQL
Scope: COMPLETE
Time Limit (seconds): 60
Status: COMPLETED
Started on the: 03/02/2014-20:43:39
To the: 03/02/2014 20:44:25
-------------------------------------------------------------------------------
Name of the schema: LMDBPROD
SQL ID: 2q94zb7djr2xn
SQL text: SELECT NPCOMMON. FGET_ACTION_CODE (ORDNUM) ACTIONCODE, STATUS,
SUMA COUNT (*) FROM SORDER, WHERE HEADORDNUM IS NOT NULL AND
NPCOMMON. FGET_PRODUCTOFFER4ORDER (ORDNUM) IN (SELECT ID FROM)
PRODUCTOFFER WHERE PPSPECIFICATION_ID IN (SELECT ID FROM)
PPSPECIFICATION WHERE PCLASS_CODE IN (SELECT PCLASS_CODE FROM)
ARUSERGROUP WHERE CODE IN (SELECT ARUSERGROUP_CODE FROM)
ARUSER_ARUSERGROUP WHERE ARUSER_USERNAME =: B1 AND STATUS = '1')
AND STATUS = '1'))) GROUP BY NPCOMMON. FGET_ACTION_CODE (ORDNUM),
STATUS
-------------------------------------------------------------------------------
RESULTS SECTION (1 result)
-------------------------------------------------------------------------------
1-alternative Plan conclusion
---------------------------
Some implementation plans alternative for this statement was found by searching
performance data in real-time and historical of the system.
The following table lists these plans sorted by their average time.
See "SECTION of ALTERNATIVE PLANS" section for detailed information on each
plan.
plan ID hash last visit elapsed note of origin (s)
-- ---------- -------------------- ------------ --------------- ----------------
1 617797893 2013-07-11/07: 45:20 9.555 no reproducible STS
2 1311086720 2014-01-31/04: 00:44 19.569 AWR
3 1226863820 2014-01-31/18: 00:24 AWR 21.158
4 1359606848 2014-02-03/16: 00:34 21.492 AWR original plan
The plan with hash 617797893 seems the most efficient one and is based on some specific SQL Tuning Set I ran on this time. But the note says that the plan is not reproducible. Is there anyway how can I force the SQL statement to execute the plan? The database version is Standard Edition 11.2.0.1.0
Best regards
Rodriguez
Hello
I think you can use this
before 11 g, we used to create an outline stored for this.
concerning
-
How to execute a SQL statement that is stored within a SQL Table
Hello
If someone please help me with the following problem I would be eternally grateful
I have a SQL statement that is stored inside a certain SQL table, I want to use this SQL statement inside my PL/SQL procedure.
Thought a simple solution was to get the SQL statement in a table, and then run it, but how could I do so exactly with PL/SQL? I only started to play with PL/SQL in the last days.
Thanks in advance!
This is what it looks like more or less:
Display result for:
---------------------
SELECT TRIM (OBJ_VALU_TXT)
OF OBJ_VALU_DOC
WHERE TYPE_OBJET = 'FLD '.
AND OBJECT_CODE = 15443
AND OBJ_VALU_CD = 'CAB '.
ORDER BYDOC_SEQ_NO
00001
------------------------------------------------------------------
SELECT
VALUE (MAX (RECEIPT_NO) + 1,: OUT-COMP-FACTOR)
THE FRONT DESK
WHERE (RECEIPT_NO BETWEEN
(: OUT-COMP-FACTOR AND: OUT TO A NUMBER) OR
(RECEIPT_NO >: OUT-COMP-FACTOR AND)
(: OUT-TO-NUMBER = 0)
Here's a demo of your condition.
create table t (col1 varchar2 (200));
table created
insert into values t ('select * from double ');
1 row inserted
declare
v_col varchar2 (200);
v_val varchar2 (200);
StartSelect col1 in t v_col;
run immediately v_col in v_val;
dbms_output.put_line (v_val);
end;-----
XUse in the clause, you can use as many variables as needed. But the basic approach remains the same.
But storage in DB SQL is not an efficient design.
Ishan
-
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
-
How to run grid sql statements
Hello
I would like to run some of the grid control sql statements as tablespace freespace check.
Grid options could there be to execute the sql statement?
If so, how to set up the output of the sql for E-mail
Please I need your suggestion to proceed.
Version of the grid: 10.2.0.5.0
Platform: Sun
Thank you.Hello
no need to run the sql statement of the grid, instead of that you can configure the threshold values.
for example, if your tablespace capacity 85% complete and then he will send you the email alert that you configured in notifications.
you will find on the home page - bottom of the page - > manage settings...
check http://download.oracle.com/docs/cd/B19306_01/server.102/b14196/montune001.htm#CACCIHAB
http://download.Oracle.com/docs/CD/B19306_01/EM.102/b40002/notification.htm#sthref995
Thank you
-
How to execute the SQL statement in the Application Module
Hi people
I´d would like to know how I can execute a SQL statement like "remove user" in the Module to request... prepareSession method...
I m using Jdev 10 with ADF Faces
Thank youThis is possible, but you should think twice about it.
If this can be done with an EO/VO do in this way.
If you can't do it with an EO/VO you can yourself the DB operation (ApplicationModule.getDBTransaction ()) and use a call of createStatement (...) do what you want.Timo
-
How to concatenate two strings
Hi all
I have two Xml String
<? REQUISITION_NUMBER? > and <? LINE_NO? > and values like this req_no-13091 and Line_no-2
So how do you concatenate like this 13091-2
I tried likethis <? REQUISITION_NUMBER | » -'|| LINE_NO? >
But it gives error
Thanks and greetings
SrikkanthYou can use
-
How to execute the sql statement in the file beats?
I want to execute after the statement
C:\ > sqlplus/nolog
SQL > conn scott/tiger
SQL > select * from tab;
I know I can achieve it following test.bat and testdb.sql file
test.bat is:
sqlplus/nolog @testdb.sql
TestDB.SQL is:
Conn scott/tiger
Select * from tab;
Now I don't want to use the sql file, I want only use bat file, as follows:
test.bat is:
sqlplus/nolog
Conn scott/tiger
Select * from tab;
When I run test.bat, I find only one sqlplus /nolog execute statement, do not execute other statements.
(1) I want to know if there is a method to run the SQL file by fighting without a sql file? How to make it happen?
(2) if I call the sql file, how to hide the password of user? Because I don't want other people to know scott password, if I use conn scott/tiger in testdb.sql, other person can see testdb.sql and the password. Is there a good way to avoid?
Thank you!It works a bit different in Windows. Create a file is like this:
( echo conn scott/tiger@orcl echo spool c:\temp\list.txt echo select sysdate from dual; echo spool off echo exit ) | sqlplus -s -l /nolog
-
Dear friends,
As I recently started working with SQL more, I realized that my opinion on this has changed.
andselect first_name, last_name from personal_details
andselect first_name, last_name from personal_details, education_details
andselect first_name, last_name from personal_details a , education_details b where a.id =b.id
is it different? or make the same result?select first_name, last_name from personal_details a , education_details b where b.id =a.id
Won't return the same result.
Just started to wonder, how it actually works of in.
Can anyone shine some light on this issue?
Thank you.
Benard>
...By default, I think that oracle starts executing the last where condition and so queries can take different time, depending on which is the primary key, or if any column index created on this subject.
This statement is almost always wrong. Oracle evaluates what query condition is the best to run first. This is done by the optimizer cost based using statistical information about the tables, columns and the indexec on these columns. There had been questions back in the day Oracle 7 and the RBO (rule based optimizer) where the order in the clause from and where clause was important. But in general, do not care anymore to this topic.
-
I have 2 questions,
Query1 - SELECT A1, B1, C1 OF TAB1
A1 B1 C1
10 5 6
Query-2 SELECT A2, B2, C2 OF the TAB2
A2 B2 C2
5-7-4
How to find
A1 - A2, B1 - B2, C1 - C2
EXPECTED
A1 - A2, B1 - B2, C1 - C2
5 -2 2
Help, please
Hello
If tab1 and tab2 will always be exactly 1 row of each, then you can make a cross join:
SELECT tab1.a1 - tab2.a2 AS a_dif
, tab1.b1 - tab2.b2 AS b_dif
, tab1.b1 - tab2.c2 AS c_dif
OF tab1
CROSS JOIN tab2
;
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
-
How to generate the SQL statement
Hello
Here is the table and the data, and I did the solution using a pl/sql cursor.
This is possible in a SQL statemnt?
create the table TEMP_DISTINCT
(
NUMBER of allocation A_ID not null,
B_ID NUMBER not null,
C_VAL VARCHAR2 (30)
)
INSERT INTO TEMP_DISTINCT(A_ID,B_ID,C_VAL) VALUES(111,2222,'One')
INSERT INTO TEMP_DISTINCT(A_ID,B_ID,C_VAL) VALUES(111,2222,'Two')
INSERT INTO TEMP_DISTINCT(A_ID,B_ID,C_VAL) VALUES(112,2222,'Three')
INSERT INTO TEMP_DISTINCT(A_ID,B_ID,C_VAL) VALUES(112,2222,'Four')
INSERT INTO TEMP_DISTINCT(A_ID,B_ID,C_VAL) VALUES(112,2221,'Five')
INSERT INTO TEMP_DISTINCT(A_ID,B_ID,C_VAL) VALUES(112,2221,'Six')
declare
vorgid varchar2 (30);
CUR cursor is
Select distinct A_ID, B_ID from TEMP_DISTINCT
order by A_ID, B_ID;
Start
for the curs in news
loop
Select C_VAL
in TEMP_DISTINCT vorgid
where curs. A_ID = A_ID
and curs. B_ID = B_ID
and rownum = 1;
dbms_output.put_line (curs. A_ID | ' : ' || curs. B_ID | ':' || substr (vorgid, 1, 22));
end loop;
end;
Output
-------------
111: 2222:One
112: 2221:Five
112: 2222:ThreeHello
When you use ROWNUM directly on a table or a set of view or a result that is not an ORDER BY clause, results are for an indefinite period, in other words, there is no guarantee that you will get the same results every time that you run the query, even if the table has not changed.
The ROW_NUMBER analytic function can be used instead of ROWNUM. ROW_NUMBER can be calculated several different sequences (on different partitions of the result set) at the same time, like this:
WITH got_rnum AS ( SELECT a_id , b_id , c_val , ROW_NUMBER () OVER (PARTITION BY a_id, b_id ORDER BY ROWID ) AS rnum FROM temp_distinct ) SELECT a_id , b_id , c_val FROM got_rnum WHERE rnum = 1 ;
When you use ROW_NUMBER, you have to ORDER SOMETHING. In a very small table, like the sample, arbitrary results could come in the ROWID in your PL/SQL code order, so I used "ORDER OF ROWID" above. I could have used a constant, for example "ORDER OF 0.
-
How to rewrite the sql statement?
Hello my query goes like this:
Select a, b, c
from (select 5A, b null, null double c
Union of all the
Select null, 4, the double null
Union of all the
Select 10, 3, double null) test_tab;
and I want to get the result
5 null null
null null 4
10 null null
3 null null
How can I rewrite the query without changing the structure of a table?
Kind regards
IgorHello
A way
select a, null b, null c from test_tab where a is not null union all select null, b, null from test_tab where b is not null union all select null, null, c from test_tab where c is not null
Concerning
Anurag -
How to remove the sql statement in the output of the coil?
Hi gurus,
If my spool request is like that
I get my file csv as like this:set feedback off set verify off set trimspool on set heading off spool c:\test\test.csv select * FROM test; spool off
What should I change in my SQL query such that I won't include these lines:SELECT * FROM test1 SSO -------------------- shsrgh dehrerdh wtw55hd dhdfhdfh hdhdh SET SPOOL OFF;
Thank youSELECT * FROM test1 SSO -------------------- SET SPOOL OFF;
user10679113 wrote:
What should I change in my SQL query such that I won't include these lines:
SELECT * FROM test1 SSO -------------------- SET SPOOL OFF;
You cannot change anything in your SQL query to exclude these lines.
These lines refer to the client you are using i.e. SQL * more and have nothing to do with the SQL language as such.You could put all of these SQL * more commands in a script file and run this SQL script file *, as shown below:
test@ORA10G> test@ORA10G> -- show contents of the script: c:\test.sql test@ORA10G> host type c:\test.sql set feedback off set trimspool on set heading off set echo off spool c:\test.log select ename from emp; spool off set echo on set heading on set feedback on test@ORA10G> test@ORA10G> -- run the script test@ORA10G> @c:\test.sql SMITH ALLEN WARD JONES MARTIN BLAKE CLARK SCOTT KING TURNER ADAMS JAMES FORD MILLER test@ORA10G> set heading on test@ORA10G> set feedback on test@ORA10G> test@ORA10G> -- show contents of the spooled file: c:\test.log test@ORA10G> host type c:\test.log SMITH ALLEN WARD JONES MARTIN BLAKE CLARK SCOTT KING TURNER ADAMS JAMES FORD MILLER test@ORA10G>
HTH,
isotope -
How to get the create view sql statement
I have a technical problem
There is a view in the database, for example "topstudentsview" and sql statement is ' select * student where scores > 90;
My question is how to get the sql statement of the view. I want to get the sql statement in the topstudentsview
Is the equivalent in MS Sql
sp_helptext 'topstudentsview '.
How in Oracle?
Thank youuser10182401 wrote:
My question is how to get the sql statement of the view.Simple answer: use a tool. Almost every development tool will give you an option for this requirement.
In Oracle SQL Developer (free), it's as simple as:
Connect to the database with the user and click on "views".
Select the appropriate view, and then click the SQL tab.
Maybe you are looking for
-
Satellite P870 constantly re - starts
Have a new P870 Satellite which continue to re - start, no matter what happens. All the drivers are updated, settings adjusted, etc., but unless you let the battery go flat it just new guard start after about 5 minutes to be stop. Any ideas?
-
I MESSED UP A FEW DISPLAY SETTINGS AND NOW I'M HAVING TROUBLE IN THE EYES AND EYE FATIGUE. I HAVE NOT USED TO ARRIVE EARLY ITS HAPPENING BEGAN AFTER THE CHANGE. SO HOW RESET DEFAULT DISPLAY?
-
window focus issues Windows 7 (x 64 pro)
Hello When I open a program window /, it always opens in the background instead of foreground. When I open a program window /, it always opens in the background instead of foreground and I have to click on the program window to make it active. I tri
-
# Problem in borrowed Inspiron N5010 to Wi - fi networks...
Hello! This is my first post in this forum. I am confronted with problem with my WiFi network to a modem connection broadband Wi - fi. I have an Inspiron N5010 laptop with original Win7 Home Premium installed. I installed "Intel WiFi Link 1000 BGN" f
-
Variable commandline plugin Adobe Reader
Hello.For the work I do an Adobe read pluging.Is it possible to pass a textstring to the executable of adobe reader and the search for this string of text with my own plugin and to highlight these instances on the first page of the pdf document?My pl