Insert the result of a query select in another table
HelloI have a strange problem when I try to insert all the results of a query select in another table, using the declaration of the order.
With the declaration of COMMAND it works fine
Work:
------------------------------
INSERT INTO ADART01 (SELECT (codart)
"STOCK". "" CODART_STO ".
Of
"DB". ' ' 'ACTIONS');
------------------------------
But if I try to sort the result using the declaration of the ORDER, I have the following error:
Error: ORA-00907 missing right parenthesis
------------------------------
INSERT INTO ADART01 (SELECT (codart)
"STOCK". "" CODART_STO ".
Of
"DB". "" "ACTIONS"
ORDER BY
"STOCK". ("' CODART_STO ASC ');
------------------------------
Any idea?
Thank you for your help,
Angel.
delete "()" to select
create table test1 (a number, b varchar2(100));
insert into test1
(a, b)
select level, 'level ' || level from dual connect by level < 101;
insert into test1
(a, b)
select level, 'level ' || level from dual connect by level < 101 order by to_char(sysdate - level, 'D');
select * from test1;
drop table test1;
Tags: Database
Similar Questions
-
Need to print the results of a query in a CASE statement
I want to print the results of a query in a CASE statement:
SELECT RUN_STATUS
Of
(select check BOX WHEN COUNT (ROW_WID) = 0 THEN 'NO JOBS RAN AFTER' |) (select sysdate - XXAFL_MINUTES MINUTE)
END RUN_STATUS
of W_ETL_RUN_SDTL
where START_TS >
(sélectionnez sysdate-MINUTES de XXAFL_MINUTES)) where RUN_STATUS is not null; e
The query above subtracted 5 minutes from SYSDATE and he shoots XXAFL_MINUTES. I am doing this because we could change the number of minutes in the future. I want to print the number of minutes in the case statement.
If I execute this statement, it throws an error stating:
ORA-00937: not a single group group function
00937 00000 - 'not a single-group function.
* Cause:
* Action:
Error on line: 1 column: 96
How can I include "select sysdate - MINUTES of XXAFL_MINUTES" in the CASE that it calculates the number of minutes and it prints with the results.
Thanks in advance!
Hey guys,.
I found the solution:
SELECT
RUN_STATUS | TO_CHAR ((sélectionnez sysdate-MINUTES de XXAFL_MINUTES), 'HH24:MI:SS')
Of
(select check BOX WHEN COUNT (ROW_WID) = 0
THEN "NO JOB RAN.
END RUN_STATUS
of W_ETL_RUN_SDTL
where
START_TS > (select sysdate - XXAFL_MINUTES MINUTE))
where
RUN_STATUS is not null;
The output:
NO JOBS RAN AFTER 09:07:54
Thanks to you all!
-
defining the results of a query to a variable
Hi all
I'm having a problem affecting the results of a query to a variable. What I'm trying to do, is to do an AJAX call to a .cfc file and pass back the results of the function. The main problem is, I'm again moving a block of HTML (resulting from a cfquery in a cfoutput) stored in a variable. My code is something like...
< name cffunction = "getText" access = "remote" returntype = 'Cancel' >
< datasource = "" #request.dsn # cfquery "name ="queryTable">"
SELECT kort, infoBOf infoTable
< / cfquery >
< cfset result = ' <!-this is the part I'm stuck, I want the table go here. -> ">"< table >
< cfoutput query = "tablequery" >
< b >
< td > #infoA # < table > < td > #infoB # < table >
< /tr >
< / cfoutput >
< /table >
< cfwddx action = "cfml2js" input = "" # result # ' toplevelvariable 'o' = > "< / cffunction >
It is a simplified version of what I want to do, but you get the idea...
Is it still the right way to go about this? Thank you
That's what I get for trying the E-mail response feature! Are you not happy, that I double checked my post.
You could do a lot of string concatenation here to do stuff like
"& Kort &" "& infoB &" "> time and time again." But in reality the tagsis so much easier to use.
#infoA #. #infoB #.
-
I need to return the result of a query on a stored procedure
I need to return the result of a query to a stored procedure, I mean when I run a stored procedure it returns a result set in a select statement.
Best regards...Hello.
Do you really want a stored procedure for this?
Why not just a script that contains the query?Assuming that you don't really want a stored procedure, you'll have to decide what to do with the results.
An option is a slider.For example, you can write a procedure of this type to hold the query:
CREATE OR REPLACE PROCEDURE USP_TEST ( out_cursor OUT SYS_REFCURSOR ) IS BEGIN OPEN out_cursor FOR SELECT * FROM scott.emp; END USP_TEST; / SHOW ERRORS
You can move the cursor to another procedure for handling.
You could test this in SQL * more by creating a variable blond:
VARIABLE usp_test_cursor REFCURSOR; EXEC usp_test (:usp_test_cursor); PRINT :usp_test_cursor
-
Export the results of a query to a CSV file
Hello
My requirement is that I need to export the results of a query to a CSV file. Can someone please suggest a way to also include the names of columns in the CSV file?
Thanks in advance.
AnnieFollowing code comes from asktom. I changed to include the column header. This will get your CSV file desired for a given query.
create or replace function dump_csv( p_query in varchar2, p_separator in varchar2 default ',', p_dir in varchar2 , p_filename in varchar2 ) return number AUTHID CURRENT_USER is l_output utl_file.file_type; l_theCursor integer default dbms_sql.open_cursor; l_columnValue varchar2(2000); l_status integer; l_colCnt number default 0; l_separator varchar2(10) default ''; l_cnt number default 0; l_colDesc dbms_sql.DESC_TAB; begin l_output := utl_file.fopen( p_dir, p_filename, 'w' ); dbms_sql.parse( l_theCursor, p_query, dbms_sql.native ); for i in 1 .. 255 loop begin dbms_sql.define_column( l_theCursor, i, l_columnValue, 2000 ); l_colCnt := i; exception when others then if ( sqlcode = -1007 ) then exit; else raise; end if; end; end loop; dbms_sql.define_column( l_theCursor, 1, l_columnValue, 2000 ); l_status := dbms_sql.execute(l_theCursor); dbms_sql.describe_columns(l_theCursor,l_colCnt, l_colDesc); l_separator := ''; for lColCnt in 1..l_colCnt loop utl_file.put( l_output, l_separator || '"' || Upper(l_colDesc(lColCnt).col_name) || '"'); l_separator := p_separator; end loop; utl_file.new_line( l_output ); loop exit when ( dbms_sql.fetch_rows(l_theCursor) <= 0 ); l_separator := ''; for i in 1 .. l_colCnt loop dbms_sql.column_value( l_theCursor, i, l_columnValue ); utl_file.put( l_output, l_separator || '"' || l_columnValue || '"'); l_separator := p_separator; end loop; utl_file.new_line( l_output ); l_cnt := l_cnt+1; end loop; dbms_sql.close_cursor(l_theCursor); utl_file.fclose( l_output ); return l_cnt; end dump_csv;
The original link is below.
http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:95212348059
Thank you
Knani. -
assign the value to a selection of the result of a query control
I want to assign a value to my controls with the result of the query.
It works for CFINPUT TEXT, but it does not work to SELECT
I want to know are there any way tp affect my drop-down list value based on the result of questy.
I have CFSTOREPROC as follows:
< cfstoredproc procedure = "PSP" >
< cfprocparam value = '#form. "IDNumber #" CFSQLTYPE = "cf_sql_integer" >
< name cfprocresult = resultset "spResult" = "1" >
< / cfstoredproc >
< type CFINPUT = 'text' id = "txtIDNumber" value = "" #spResult.IDNumber # "/ >"
I am able to name a TEXT of ENTRY CF as above the code value,
< select id = "lstNumber" value = "#spResult.lstNumber #" > < / select >
but it does not affect the value of my result of the query to SELECT entry.
Is it possible to assign a value to the query result SELECTION control?
I tried to use JavaScript that works if I pass a number, but it does not work if I pass a query result,
Your help is very appreciated,
Kind regards
Iccsi,
@Iccsi,
My bad! Yes, you will either need to the CFOUTPUT tag (that you commented out in your code) but without specifying a query or change the CFLOOP query CFOUTPUT = "Notes". If one of these should work:
OR
-Carl V.
-
Insert the results of the query with constants
I need to select a table primary keys, then insert them into another table with a status value.
Select SQL would SELECT APP_ID OF PLAINTIFF WHERE LAST_NAME 'L % '.
I need all the APP_IDs insert into a table along a status of "in PROGRESS". The table has two columns; ID and the STATE.
How to combine these operations?You can try
Insert into your_table(ID,STATUS) SELECT APP_ID ID,'IN PROGRESS' STATUS FROM APPLICANT WHERE LAST_NAME LIKE 'L%'; commit;
-
Select from another table, when the query returns no result
Hello
I have a question where I'm supposed to retrieve the address of an account id-based billing. However, the table of billing may not have an address. There is a table of addresses that always has an address for an account. If the billing address exists, it should be used, so I can't use the address table. Is it possible in a select statement to query to the billing address and if it does not exist, use the address table.
SELECT * FROM accounts a, b billings WHERE a.accountid = b.accountid
Any help will be greatly appreciated.
Thank you.user10407139 wrote:
HelloI have a question where I'm supposed to retrieve the address of an account id-based billing. However, the table of billing may not have an address. There is a table of addresses that always has an address for an account. If the billing address exists, it should be used, so I can't use the address table. Is it possible in a select statement to query to the billing address and if it does not exist, use the address table.
SELECT * FROM accounts a, b billings WHERE a.accountid = b.accountid
Any help will be greatly appreciated.
I think you need to explain more clearly if
-you only have a couple of "billing" columns which is empty and in this case, you want to use the columns from the table 'accounts '.
- or you have a join with another table that doesn't return data, for example a foreign key "address_id" "billing" is zero and therefore the join to other tables 'address' will return all the data
In the first case, you have already been provided with some examples here, how to use NVL or similar functions to achieve, even if the first post first evaluates the information of 'accounts' and if it is white using information from "billing". According to your description you need the other way around. The second post a subquery recursive useless in my opinion.
In the latter case, you should probably use an "outer" join so that the data in your table "bills" are returned, even if the join to another table is not at all the lines.
SELECT NVL(AD1.ADDRESS_ATTR1, AD2.ADDRESS_ATTR1) as ADDRESS_ATTR1, NVL(AD1.ADDRESS_ATTR2, AD2.ADDRESS_ATTR2) as ADDRESS_ATTR2, NVL(AD1.ADDRESS_STREET, AD2.ADDRESS_STREET) as ADDRESS_STREET, ... FROM accounts a INNER JOIN billings b ON a.accountid = b.accountid LEFT OUTER JOIN address ad1 ON b.address_id = ad1.address_id INNER JOIN address ad2 ON a.address_id = ad2.address_id;
In this way you pick up the address stored in the "invoices" table, if it existed, otherwise you pick up the address assigned to the "accounts" table I used an inner for the second address join join because you said that the account always has an assigned address.
Kind regards
RandolfOracle related blog stuff:
http://Oracle-Randolf.blogspot.com/SQLTools ++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676 /.
http://sourceforge.NET/projects/SQLT-pp/ -
How to use the result of widget radio selection to 'show' a text box?
Hello again,
I have a question about widgets.
What I want to do is to take the result of radio button widgets (in this case 1 2 rather long sentences that were available) and which will display a text box on another screen.
Background: I have a series of slides where I ask the questions of the learner through Radio button widgets and so I get a number of variables (= penalty) they choose.
The question I have is that I want to display all the choices they made on 1 page. Because the possible answers are relatively long I have run out of space if I simply inserts
variables to shown as such and/or the police gets too small.
So my idea is to use the answer that they choose to make a text box with a shorter version of the same appearo of sentence on this slide 'results '.
So my idea is to have the learner to make their selection, then use a tip action to check what answer (= the option button), they clicked on.
What I would do through "If XYZ variable ' 'contains (a keyword of the long sentence)' then 'show textbox YZ' etc.
Question 1: Is this the most simple/more convenient way or I can save me time somwhow?
2 "contain" a medium of action adv. the exact text or it may be just one of the words (out of the long sentence that could be selected)? I ask because then I have to use the same long exact phrase in the NOA that seems awkward.
3. I need to create a separate fast action for each radio widget, I've used. Is this correct?
4 if I then say 5 adv. actions for different questions, I asked what should trigger these advanc. action? The goal is just to shorten the long sentences in the selections made?
If I use ' enter' for all the screen I just started one, I haven´t?
Many probably incorrect assumptions, on my part, I guess...
Any help is greatly appreciated!
In my example the var who will get the short sentence is v_class. It's always the variable associated with the interaction of radio buttons. You have as much of these variables to be inserted on the last slide you have interactions button radio please never enter the variable to insert, but use the X button in the role of composition of the properties panel for the text container. Variables are case sensitive, in this way, you will avoid typos.
-
Is it possible to put the results of a query in a variable to use in the bean class?
Hello, I am using JDeveloper 12.1.2.0.0
I like to keep the result of my queries (the method that I created in the AppModule) in a richeTableau or another type of variable, so I can get results and I don't have to make unnecessary after queries. I don't think that the query is the problem but keeping the results.
I tried to do in using this:
public String testVFactSales (String conditions) {}
PreparedStatement query = getDBTransaction () .createPreparedStatement ("" + "select * from v_fact_sales"+ conditions, 0 ");
ResultSet rs;
Outcome of the result set;
Result of the richeTableau;
String result = null;
try {}
query.setString (1, conditions);
Query.Execute ();
Query.Execute ();
result = query.getGeneratedKeys ();
Query.Close ();
System.out.println ("result:" + result.toString ());
return result.toString ();
} catch (SQLException e) {}
e.printStackTrace ();
}
Return ' ';
}
As you can see, I have already tried a few solutions, but so far I have only errors (cannot convert or null exception, when I try to put the result in a richeTableau in my bean class)
Any ideas?
It is very important for me, because it would improve the performance of my project a lot.
Kind regards
Frederico.
Although the issue is not 100% responded, I used the idea that Shay told me, where you can create a method in your AppModule to set your where clause!
Good luck to everyone who has the same problem.
As an attack similar to what I wanted in the first place, you can check this:
https://community.Oracle.com/thread/2619669
Kind regards
Frederico.
-
The results of F1-QUERY-how to restrict or to SQL with the role of access to the data?
Hello
With the help of CC & B 2.3.1.
I'm configuration of a Zone of F1-OF-QUERY to get and display customer information as level account; the filter criteria will be Geo val SP.
With our application, we use access to accounts and groups access to the data on users roles to restrict access to sensitive accounts, such as VIP.
What keywords should I use in the SQL statement to limit the results only for group accounts to which access is included in the Dar of the user?
Example: If the user has DAR 'STANDARD', it won't see accounts with group access 'VIP '.
I tried unsucessfully: USER: USER ID,: USER_ID.
Unsucessfull example:
Select dar_cd, user_id, expire_dt
of ci_dar_usr
Where user_id =: USER_ID
and expire_dt > =: F1
Thks,
FabienHi, Fabien,
If you are looking to determine the current user in the box,
the keyword to use is: USERIDYou can check the zone of F1 "F1-FAVSCR" for its use.
-
How to insert the comma (,) in a query
Hello all, I use Jdeveloper 11 g R1 and I have the following problem
I have a simple select statement inside my mind
What I want is to add a comma (,) to the COMPANY results, (it's a bit like County, city and State so all three are name).SELECT Opcine.SIFRA_OPCINA, Opcine.NAZIV, Opcine.SIFRA_KANTON, Opcine.RACUN_JAVNIH_PRIHODA, Kantoni.NAZIV NazivKantona, Entitet.NAZIV NazivEntiteta FROM OPCINE Opcine, KANTONI Kantoni, ENTITET Entitet WHERE Opcine.SIFRA_KANTON = Kantoni.SIFRA_KANTON AND Kantoni.SIFRA_ENTITET = Entitet.SIFRA_ENTITET
So in the results, I want it to be
Washington, Virginia, United States
Instead of
Washington, Virginia-UNITED STATES
I tried the LISTAGG and WM_CONCAT functions but without the use of group by (I don't want that) and it did not work.
I also tried | ',' | but this does not work, that's really what I want to use but without going all PL/SQL on it (you want to keep things simple).
I hope you guys can helpSELECT
CONCAT (Opcine.SIFRA_OPCINA, CONCAT (',', CONCAT (Opcine.NAZIV, CONCAT (', ', Opcine.SIFRA_KANTON))) such AS ADDRESS,)
Opcine.RACUN_JAVNIH_PRIHODA,
Kantoni.NAZIV NazivKantona,
Entitet.NAZIV NazivEntiteta
Of
OPCINE Opcine,
KANTONI Kantoni,
ENTITET Entitet
WHERE
Opcine.SIFRA_KANTON = Kantoni.SIFRA_KANTON AND Kantoni.SIFRA_ENTITET = Entitet.SIFRA_ENTITETI don't know, if I got your question right, but the above query should give u the output with required result m.
Thank you
-
Compare the result of a query with a number and return a message
Hello
I have the following query in oracle 9i:
SELECT COUNT (*)
OF hourly_files
WHERE date_received = TO_DATE ((SELECT TO_CHAR (SYSDATE - INTERVAL '1' DAY, 'DDMMYYYY')
(THE DOUBLE), 'DDMMYYYY');
This will produce a number of lines required
I need to compare the number of output with another number hardcoded (threshold) and print an appropriate example message
If the result of the query above is 18000 and the number of threshold is fixed at 20000, then output a meesage:
Number of files received less than 2000
Any help will be very appreciated!
Thank you.SQL> ed Wrote file afiedt.buf 1 SELECT CASE WHEN COUNT(*) >5 THEN 'Number is > than 5' 2 WHEN COUNT(*) <1 THEN 'Its less than 1' 3 ELSE 'Its in between' 4 END 5 FROM emp 6* WHERE deptno=20 SQL> / CASEWHENCOUNT(*)>5 ------------------ Its in between SQL> SELECT COUNT(*) FROM emp 2 WHERE deptno=10; COUNT(*) ---------- 3
-
Set a variable to the result of an instruction select
I create a list view of the numbers that I have in the system. I'm doing a table with only a list of numbers from 1 to whatever number max is in view. IIf 89 324 is so the last number in the system, so I want a table with 1 thru 89324. Then I can use the NOT EXIST to determine what numbers are miissing in the system. so, if 1 to 200 are not used, but by 89 324 201 is used, then I want the output to 1,2,3... 200.
The code to make the display works and the code to create the table is good, the loop works when I use a number defined for example 100. I just have problems affecting a variable in the number max.
Here's what I have (which of course does not)
Published by: james3302 on August 11, 2010 15:59CREATE OR REPLACE PROCEDURE test IS n number := 1; maxNum number; BEGIN execute immediate 'create view check_numbers as select num from table1 union select num from table2 union select num from table3'; maxNum := EXECUTE IMMEDIATE 'select max(num) from check_numbers'; --I also tried taking out the EXECUTE IMMEDATE here and it still did not work WHILE n <= maxIpid LOOP insert into numList values(n); n := n + 1; END LOOP; --Here I will put in the code to compare the two and display the numbers that are in numList but not in Check_numbers END; /
James,
The solution to your immediate problem to get the result of the immediate execution in a variable is to use
EXECUTE IMMEDIATE 'select max(num) from check_numbers' into maxNum;
You can also do without running to the immediate assistance
select max(num) into maxNum from check_numbers;
Of course, you should definitely consider using one of the other solutions already provided.
Depending on what you ultimately trying to reach, another option to consider is to get the list of discrepancies between the numbers to help
Method of Tabibitosan of Aketi ({: identifier of the thread = 1005478}).with t as ( select 1 as n from dual union all select 2 as n from dual union all select 7 as n from dual union all select 8 as n from dual union all select 11 as n from dual ) select * from ( select grp, n1, n2, 1+lag(n2,1,0) over(order by n1) as gap_n1, n1-1 as gap_n2 from ( select grp, min(n) as n1, max(n) as n2 from ( select n, n - row_number() over(order by n) as grp from t ) group by grp ) ) where grp>0 order by grp ; GRP N1 N2 GAP_N1 GAP_N2 ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- 4 7 8 3 6 6 11 11 9 10
Kind regards
BobPublished by: BobLilly on August 11, 2010 15:00
-
The Variable value based on the results of SQL query
With the help of OBIEE 11.1
Is it possible to set the value of a variable presentation of the results of a SQL statement?
Scenario:
I have 2 topics.
SubjectArea1
Text1
Date1
SubjectArea2
Field1
Field2
UpdateDate
I have an analysis that uses only the SubjectArea2.
Using a dashboard quickly, the user must be able to select Text1 in the other topic area (SubjectArea1).
Assuming that selection will be stored in a variable of presentation (SelectedText),
The filter in the analysis should be something like
Upper UpdateDate to @{SelectedDate}
How can I set a variable (SelectedDate) using a SQL statement?
Something like this:
SELECT "Date1" TO "SubjectArea1" WHERE "Text1" = @{SelectedText}
So the command prompt text selection should give a date that is used to filter the second review?
If so:
The prompt on SA1.textCol
hidden analysis who is invited on SA1.texCol has SA1.dateCol in the criteria
Analysis SA2.dateCol is filetered on basis of the results of another analysis (any value analysis hidden SA1.dateCol)
Maybe you are looking for
-
my external microphone does not work. My voice memo allows you to record, but I can't voice text or use siri. I can't hear it, and she doesn't hear me... Help!
-
How can access to about: support be blocked?
We want to block access to about: supports, because our public users can reset Firefox from the site.
-
Windows XP update problems: need to install before April 8, 2014, updated
I have a new PC Dell Optiplex 330 which have been stored since purchased. It was purchased as spare and never fed until last week. I've updated Internet Explorer to the version of Internet Explorer 8. I installed AVG Antivirus from 2014. Then I conne
-
Replacing the front fan is no longer functioning
Replacing my front fan, no longer works after removing the stock cooler to replace it with this -. who I couldn't screw at bottom, because the media have no hexagonal bolts, they just circles, which can be entered. After placing the return stock, and
-
Upgrade Windows 7 to win 10; Error code: 8007139F
The Windows 10 download process was simple, but now that I downloaded Windows 10 and chose to install it, my PC restarts and I get an error (Code 8007139F) and the installation of Windows 10 had failed. My OS has received all the necessary updates an