Use cursor Fetch to return multiple columns of data
HelloThis is my Table:
SQL > select * connection;
USERNAME PASSWORD CONFIRMPASSWORD
--------------- --------------- ---------------
Happy SAI SAI
Kiran keyboard keyboard
JAINA JAINA VARNU
It's my stored procedure for this Table, it works very well there, Fetch it has the cursor returns only a single column of data.
CREATE OR REPLACE PROCEDURE getEmpName (EMP_ID IN VARCHAR2)
IS
EMPNAME VARCHAR2 (50);
CURSOR MYCUR
IS
SELECT a connection username where USERNAME = EMP_ID;
BEGIN
MYCUR OPEN;
LOOP
EXTRACT MYCUR IN EMPNAME;
DBMS_OUTPUT. PUT_LINE (EMPNAME);
WHEN THE OUTPUT MYCUR % NOTFOUND;
END LOOP;
close MYCUR;
END;
Now, I have a requirement, I need to get the password also with user name,
Please tell me how to use FETCH from cursor to fill in the details in the declared Variables
EXTRACT MYCUR IN EMPNAME;
CREATE OR REPLACE PROCEDURE getEmpName (EMP_ID IN VARCHAR2)
IS
EMPNAME VARCHAR2 (50);
VARCHAR2 (50) PASSWORD.
CURSOR MYCUR
IS
SELECT username, PASSWORD of connection where USERNAME = EMP_ID;
BEGIN
MYCUR OPEN;
LOOP
FETCH IN EMPNAME MYCUR; / / Need help here *.
DBMS_OUTPUT. PUT_LINE (EMPNAME);
WHEN THE OUTPUT MYCUR % NOTFOUND;
END LOOP;
close MYCUR;
END;
Published by: user10503747 on October 14, 2010 11:51
Published by: user10503747 on October 14, 2010 11:52
EXTRACT MYCUR IN EMPNAME, PASSWORD;
SY.
Tags: Database
Similar Questions
-
How to concatenate values based on multiple columns of data duplicate in the loop
Hi all
Select '100' col_1, '111111' col2 of double
Union of all the
Select '100' col_1, '222222' col2 of double
Union of all the
Select '101' col_1, '333333' col2 of double
Union of all the
Select '102' col_1, '333333' col2 of double
I need to write by using cursor loop (configurable) so, it must concatenate col_1 or col_2
If,
In the table
col_1, col_2
100 111111
100 222222
101 333333
102 333333
Then
col_1, col_2
100 111111,222222
333333 101 102
Is it possible to compare and concatenate values in the loop
I have more than 4,000 bytes in the table of col_1,col_2 data values
Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production
Ok then:
create a type that makes "grouped" clob
CREATE or REPLACE TYPE clob_obj IS OBJECT
(
CLOB theClob
ORDER MEMBER FUNCTION equals (in_clob_obj IN clob_obj) RETURN NUMBER
member function getClobVal return clob)
/CREATE or REPLACE TYPE clob_obj BODY
IS
FUNCTION MEMBER ORDER is equal to (in_clob_obj IN clob_obj)
RETURN NUMBER
IS
BEGIN
RETURN sys.dbms_lob.compare (SELF.theClob, in_clob_obj.theClob);
END;
Member return clob getClobVal function
is
BEGIN
Return self.theClob;
end;
END;
/WITH conc_table AS (SELECT 1111 cust_id, cust_no 'ABC', '101010' ordr_no OF DOUBLE UNION ALL
SELECT 2222 cust_id, cust_no 'ABC', '101010' ordr_no OF DOUBLE UNION ALL
SELECT 3333 cust_id, cust_no 'ABC', '101010' ordr_no OF DOUBLE UNION ALL
SELECT cust_id 4444, "CCC" cust_no, ordr_no ' 123456' OF DOUBLE UNION ALL
SELECT cust_id 5555, "CCC" cust_no, '454545' ordr_no OF DOUBLE UNION ALL
Select cust_id 66666, "CCC" cust_no, ordr_no ' 77777' DOUBLE UNION ALL
SELECT cust_id, "CCC" cust_no, ordr_no ' 77777 66666' FROM DUAL)
SELECT rtrim (XMLAGG (XMLELEMENT (E, cust_id_no, ',')). EXTRACT ('customer_id //text()').getClobVal (),',')
clob_obj (ord_number) .getClobVal)
cust_num
FROM (SELECT cust_id_no
cust_num
rtrim (XMLAGG (XMLELEMENT (E, ord_num, ",")). EXTRACT ('//text ()') .getClobVal (), ',') ord_number
FROM (SELECT DISTINCT cust_id_no, cust_num, ordr_no AS conc_table FROM ord_num cust_no cust_id)
GROUP BY cust_id_no
cust_num)
GROUP BY clob_obj (ord_number)
cust_num;
I got the distinct in the select more intimate for no duplicate of the basetable is only sent to reunification of...
HTH
-
Group by returning multiple columns in a single request
Hello
Sorry to ask this simple question, I suppose, but here's my problem.
I am building a query to get to say the smallest user_id of workers in society by Department.
The query goes like:
Select emp... Department,
min (EMP.user_id)
employee emp
Emp.department group
It gives me the smallest user by Department id, which is what I want. But how can I also get the name of this person?
I know that the condition of 'min' distinguishes a single record (there are no two people with the same user_id in the Department).
But how can I also get the name without turning the query above in a subquery that I would like to once again a link to the table of employees?
I know that the following works, but I don't think it's the best option:
Select v1.department,
v1.user_id,
Emp1.name
employee emp1.
(select emp... Department,
min (EMP.user_id)
employee emp
Group emp.department) v1
where emp1.user_id = v1.user_id
This is just one example of data. This is the principle which I don't understand.
Any advice would be much appreciated.
CyrilHi, Cyril.
To find the name of the person who has the lowest user_id
SELECT department , MIN (user_id) AS lowest_user_id , MIN (name) KEEP (DENSE_RANK FIRST ORDER BY user_id) AS person_with_lowest_user_id FROM emp GROUP BY department;
'MIN (name)' above means that if there is a link for the lowest user_id, you will choose the candidate with the first name.
If you want to display several columns in the row with the lowest user_id, you must have an expression of 'KEEP (DENSE_RANK...)' separate for each column. In this case, you will find may be easier to use the RANK or the analytical ROW_NUMBER in a subquery, like this:
WITH sub_query AS ( SELECT department , user_id , name , col2, col3, col4, col5 , RANK () OVER ( PARTITION BY department ORDER BY user_id ) AS r_num FROM emp ) SELECT * -- or list all columns EXCEPT r_num FROM sub_query WHERE r_num = 1;
-
Return multiple values from a function in a SELECT statement
I hope I've provided enough information here. If not, let me know what I'm missing.
I create a view that will combine the information from several tables. Most are pretty simple, but there are a couple of columns in the view that I need to get by running a function within a package. Even if this is quite simple (I have a function named action_date in a package called rp, for example, that I can use to return the date that I need through SOME rp.action_date (sequence_number).
Here is the question: I really need to return several bits of information of the same record (not only action_date, but also action_office, action_value, etc.)-a join of the tables will work not here, as I will explain below. I can, of course, perform a function separate for each statement, but this is obviously inefficient. Within the select statement of the view, however, I don't know how each of the values that I need to get back.
For example, right now, I have:
Table 1:
sequence_number NUMBER (10),
name varchar (30),
...
Table2:
Table1_seq NUMBER (10),
action_seq NUMBER (10),
action_date DATE,
action_office VARCHAR (3),
action_value VARCHAR (60),
...
I can't just simply join Table1 and Table2 because I have to perform processing in order to determine the rows returned matching, I really need to select. If the package opens a cursor and treats each line until it finds the one I need.
The following works but is ineffective since all calls to the package returns the columns of the same record. I don't know how to put all the values that I need in the SELECT statement.
CREATE VIEW all_this_stuff AS
SELECT sequence_number, name,
RP.action_date (sequence_number) action_date,
RP.action_office (sequence_number) action_office,
RP.action_value (sequence_number) action_value
FROM table1
Is there a way to return multiple values in my SELECT statement or I'm going about this all wrong?
Any suggestions?
Thank you very much!Hello
What you want is a Query of Top - N , what you can do using the ROW_NUMBER analytic function in a subquery, like this:
WITH got_rnum AS ( SELECT action_seq, action_dt, action_office, action_type, action_value , ROW_NUMBER () OVER ( ORDER BY action_date , action_seq , action_serial ) AS rnum FROM table2 WHERE action_code = 'AB' AND action_office LIKE 'E' -- Is this right? ) SELECT action_seq, action_dt, action_office, action_type, action_value FROM got_rnum WHERE rnum = 1 ;
As written, this returns a single line (at most).
I suspect you'll actually get a rank for each group , where a group is defined by a value in a table in which you join.
In this case, add a PARTITION BY clause to the ROW_NUMBER function.
If post you a small example of data (CREATE TABLE and INSERT statements), I could show you exactly how.
As I don't have your tables, I'll show you the use of the tables in the scott schema.
This is a view containing data in the scott.dept table and also to scott.emp, but only for the highest employee in each Department (in other words, the employee whose oldest hire date). If there be a tie for the first hire date, while the candidate with the lowest empno is selected.CREATE OR REPLACE VIEW senior_emp AS WITH got_rnum AS ( SELECT d.deptno , d.dname , e.empno , e.ename , e.hiredate , ROW_NUMBER () OVER ( PARTITION BY d.deptno ORDER BY e.hiredate , e.empno ) AS rnum FROM scott.dept d JOIN scott.emp e ON d.deptno = e.deptno ) SELECT deptno , dname , empno , ename , hiredate FROM got_rnum WHERE rnum = 1 ; SELECT * FROM senior_emp ;
Output:
. DEPTNO DNAME EMPNO ENAME HIREDATE ---------- -------------- ---------- ---------- --------- 10 ACCOUNTING 7782 CLARK 09-JUN-81 20 RESEARCH 7369 SMITH 17-DEC-80 30 SALES 7499 ALLEN 20-FEB-81
Moreover, one of the conditions to the query you posted has been
action_office LIKE 'E'
which equals
action_office = 'E'
(AS is always equivalent to = if the string that follows AS does not contain the winning cards.)
Did you mean say that or did you mean something like this:action_office LIKE 'E%'
Instead?
-
Help in the treatment of "subquery returns multiple rows.
Appreciate your help on this.
I have under sql query fails with the error "ORA-01427: einreihig subquery returns multiple lines"
WITH t AS (SELECT 'A' Col1, 'B' Col2, 'C' Col3 FROM DUAL UNION SELECT 'D', 'E', 'F' FROM DUAL UNION SELECT 'E', 'F', 'G' FROM DUAL UNION SELECT 'A', 'T', 'U' FROM DUAL), t1 AS (SELECT 'A' Col1, 'B' Col2, 'C' Col3 FROM DUAL UNION SELECT 'D1', 'E1', 'F1' FROM DUAL UNION SELECT 'D', 'E', 'F' FROM DUAL UNION SELECT 'S', 'V', 'W' FROM DUAL), t2 AS (SELECT 'A' Col1, 'B' Col2, 'C' Col3 FROM DUAL UNION SELECT 'A', 'E1', 'F1' FROM DUAL UNION SELECT 'D', 'E', 'F' FROM DUAL) SELECT t.col1, (SELECT distinct col2 FROM t2 WHERE t2.col1 = t.col1) RND_COL FROM t, t1 WHERE t.col1 = t1.col1 WhenI checked the count using below query WITH t AS (SELECT 'A' Col1, 'B' Col2, 'C' Col3 FROM DUAL UNION SELECT 'D', 'E', 'F' FROM DUAL UNION SELECT 'E', 'F', 'G' FROM DUAL UNION SELECT 'A', 'T', 'U' FROM DUAL), t1 AS (SELECT 'A' Col1, 'B' Col2, 'C' Col3 FROM DUAL UNION SELECT 'D1', 'E1', 'F1' FROM DUAL UNION SELECT 'D', 'E', 'F' FROM DUAL UNION SELECT 'S', 'V', 'W' FROM DUAL), t2 AS (SELECT 'A' Col1, 'B' Col2, 'C' Col3 FROM DUAL UNION SELECT 'A', 'E1', 'F1' FROM DUAL UNION SELECT 'D', 'E', 'F' FROM DUAL) SELECT t.col1, (SELECT count(col2) FROM t2 WHERE t2.col1 = t.col1) RND_COL FROM t, t1 WHERE t.col1 = t1.col1 (+) it shows as below ----------------- COL1 RND_COL A 2 A 2 D 1 E 0 My Requirement is for all the values in the column 'RND_COL' > 1 it should display text as 'Multiple', for 'RND_COL' = 1 display actual value returned by sub query and 'RND_COL' = 0 display it as NULL. expected output ------------------- COL1 RND_COL A Multiple A Multiple D E E NULL
Hello
Here's another way. It's like the solution in response #1, but it does not use a subquery:
SELECT t.col1
CASE
WHEN COUNT (DISTINCT t2.col2) > 1
THEN "Multiple."
For ANOTHER MIN (t2.col2)
END AS rnd_col
T
LEFT OUTER JOIN t2 ON t2.col1 = t.col1
GROUP OF t.col1, t.col2, t.col3
ORDER BY t.col1
;
This assumes that in table t (col1, col2, col3) combination is unique. If theat is not the case, change the GROUP BY clause, but you need to ensure that all lines of t becomes a separate group.
-
Web service PLSQL returning multiple records
Hello
I am creating a web service using oracle 11 g, which should be able to return multiple records.
Based on the code and the advice of the samples found on the internet, here is my code:
CREATE OR REPLACE TYPE test_rec is OBJECT ( s_nume_adre NUMBER , c_eta_civi VARCHAR2(4 BYTE), l_nom1_comp VARCHAR2(40 BYTE), l_nom2_comp VARCHAR2(40 BYTE), l_nom3_comp VARCHAR2(40 BYTE), l_pren_comp VARCHAR2(30 BYTE), d_date_nais DATE); CREATE OR REPLACE TYPE test_array AS TABLE OF test_rec; */ CREATE OR REPLACE PACKAGE test_pkg AS function get_rows(snume_adre in number) return test_array; END; / CREATE OR REPLACE PACKAGE BODY test_pkg AS function get_rows(snume_adre in number) return test_array is v_rtn test_array := test_array(null); v_first boolean := true; cursor c_get_rows(snume_adre in number) is SELECT a.s_nume_adre, nvl(a.c_eta_civi, '') c_eta_civi, nvl(a.l_nom1_comp, '') l_nom1_comp, nvl(a.l_nom2_comp, '') l_nom2_comp, nvl(a.l_nom3_comp, '') l_nom3_comp, nvl(a.l_pren_comp, '') l_pren_comp, nvl(a.d_date_nais, to_date('01.01.1900', 'dd.mm.yyyy')) d_date_nais FROM bro.z45 a where a.s_nume_adre = snume_adre or snume_adre is null; begin for rec in c_get_rows(snume_adre) loop if v_first then v_first := false; else v_rtn.extend; end if; v_rtn(v_rtn.last) := test_rec(rec.s_nume_adre, rec.c_eta_civi, rec.l_nom1_comp, rec.l_nom2_comp, rec.l_nom3_comp, rec.l_pren_comp, rec.d_date_nais); end loop; return v_rtn; end; END; / --select * from table (test_pkg.get_rows(null));
I am able to retrieve data using select.
However, when I try to access its wsdl I get an error:
< envelope soap: >
< soap: Body >
< soap: Fault >
Client: soap < faultcode > < / faultcode >
entry processing < faultstring > error < / faultstring >
< detail >
< OracleErrors > < / OracleErrors >
< / details >
< / soap fault: >
< / soap: Body >
< / envelope soap: >
-- -------------------------------------------------------------------------------------------------------------
If I comment the function call in the package declaration I get a "correct": wsdl
-- -------------------------------------------------------------------------------------------------------------
" < name definitions = targetNamespace"GET_ROWS"=" http://xmlns.Oracle.com/orawsv/test/TEST_PKG/GET_ROWS "xmlns =" http://schemas.xmlsoap.org/wsdl/ "xmlns:tns =" http://xmlns.Oracle.com/orawsv/test/TEST_PKG/GET_ROWS "container =" http://www.w3.org/2001/XMLSchema "xmlns:soap =" http://schemas.xmlsoap.org/wsdl/SOAP/ "> " ""
< types >
" < xsd: Schema targetNamespace = ' http://xmlns.Oracle.com/orawsv/test/TEST_PKG/GET_ROWS "elementFormDefault ="qualified"> "
< xsd: element name = "GET_ROWSInput" >
< xsd: complexType >
< / xsd: complexType >
< / xsd: element >
< xsd: element name = "GET_ROWSOutput" >
< xsd: complexType >
< / xsd: complexType >
< / xsd: element >
< / xsd: Schema >
< / types >
< name of message = "GET_ROWSInputMessage" >
< name of part = "parameters" element = "tns:GET_ROWSInput" / >
< / message >
< name of message = "GET_ROWSOutputMessage" >
< name of part = "parameters" element = "tns:GET_ROWSOutput" / >
< / message >
< portType name = "GET_ROWSPortType" >
< operation name = "GET_ROWS" >
< input message = "tns:GET_ROWSInputMessage" / >
< output message = "tns:GET_ROWSOutputMessage" / >
< / operation >
< / portType >
< connection name = "GET_ROWSBinding" type = "tns:GET_ROWSPortType" >
" < style: soap = transport = 'document' binding ' http://schemas.xmlsoap.org/SOAP/HTTP "/>
< operation name = "GET_ROWS" >
< soap: operation soapAction = "GET_ROWS" / >
< input >
< soap body parts: = 'settings' use = "literal" / >
< / Entry >
< output >
< soap body parts: = 'settings' use = "literal" / >
< / output >
< / operation >
< / binding >
< service name = "GET_ROWSService" >
< documentation > Oracle Web Service < / documentation >
< name of port = "GET_ROWSPort" binding = "tns:GET_ROWSBinding" >
" < soap: address location = ' http://server.domain.ch:8080 / orawsv/TEST/TEST_PKG/GET_ROWS "/>
< / port >
< / service >
< / definitions >
-- -------------------------------------------------------------------------------------------------------------
Any suspicion that how create and access pl sql web service returning multiple lines?
I use java not and do not have access to tools such as JDeveloper.
Thank you!
The real problem is that collection types are not supported for the return parameters.
The solution is to wrap the collection into another object.
Here is an example of work based on your settings:
CREATE OR REPLACE TYPE test_rec is OBJECT ( empno number(4) , ename varchar2(10) , hiredate date ); / CREATE OR REPLACE TYPE test_array AS TABLE OF test_rec; / CREATE OR REPLACE TYPE test_array_wrapper is OBJECT ( arr test_array ); / CREATE OR REPLACE PACKAGE test_pkg AS function get_rows(p_deptno in number) return test_array_wrapper; END; / CREATE OR REPLACE PACKAGE BODY test_pkg AS function get_rows(p_deptno in number) return test_array_wrapper is results test_array; begin select test_rec(empno, ename, hiredate) bulk collect into results from scott.emp where deptno = p_deptno; return test_array_wrapper(results); end; END; /
The wsdl is then generated correctly:
SQL> select httpuritype('http://DEV:dev@localhost:8080/orawsv/DEV/TEST_PKG/GET_ROWS?wsdl').getxml() from dual; HTTPURITYPE('HTTP://DEV:DEV@LOCALHOST:8080/ORAWSV/DEV/TEST_PKG/GET_ROWS?WSDL').GETXML() --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Oracle Web Service -
I called the procedure as belowcreate procedure emp_p ( v_r OUT emp%rowtype ) AS Begin select * into v_r from emp; end;
Errordeclare v_x emp%rowtype; Begin emp_p(v_x); end;
declare
*
ERROR on line 1:
ORA-01422: exact fetch returns more than number of lines
ORA-06512: at "SYS." EMP_P', line 4
ORA-06512: at line 4 level
Thank you
REDAinfant_raj wrote:
create procedure emp_p ( v_r OUT emp%rowtype ) AS Begin select * into v_r from emp; end;
OUT parametere v_r could contain data for one line only, so if your query
Select * into v_r from emp
returns multiple rows, you're bound to get "ORA-01422: exact fetch returns more than number of lines.
You can use SYS_REFCURSOR or Collections instead.
Vivek L
-
How to load a multiple column table in the coherence of caches?
How to load a multiple column table in the coherence of caches?
I want to load a multi-column (about 20 columns) table in cache coherence. How to change the following code (spatially how to change the SQL SELECT statement)?
Is the following select statement enough: Select the key, the value of EMPLOYEES ?
public static void bulkLoad(NamedCache cache, Connection conn) { Statement s; ResultSet rs; try { s = conn.createStatement(); rs = s.executeQuery("select key, value from table"); while (rs.next()) { Integer key = new Integer(rs.getInt(1)); String value = rs.getString(2); cache.put(key, value); } ... } catch (SQLException e) {...} }
First of all, you need a class to hold your 20 fields:
public class Data { private String field1; private String field2; private String field3; private String field4; private String field5; private String field6; private String field7; private String field8; private String field9; private String field10; private String field11; private String field12; private String field13; private String field14; private String field15; private String field16; private String field17; private String field18; private String field19; private String field20; public Data() { } public String getField1() { return field1; } public void setField1(String field1) { this.field1 = field1; } public String getField2() { return field2; } public void setField2(String field2) { this.field2 = field2; } public String getField3() { return field3; } public void setField3(String field3) { this.field3 = field3; } public String getField4() { return field4; } public void setField4(String field4) { this.field4 = field4; } public String getField5() { return field5; } public void setField5(String field5) { this.field5 = field5; } public String getField6() { return field6; } public void setField6(String field6) { this.field6 = field6; } public String getField7() { return field7; } public void setField7(String field7) { this.field7 = field7; } public String getField8() { return field8; } public void setField8(String field8) { this.field8 = field8; } public String getField9() { return field9; } public void setField9(String field9) { this.field9 = field9; } public String getField10() { return field10; } public void setField10(String field10) { this.field10 = field10; } public String getField11() { return field11; } public void setField11(String field11) { this.field11 = field11; } public String getField12() { return field12; } public void setField12(String field12) { this.field12 = field12; } public String getField13() { return field13; } public void setField13(String field13) { this.field13 = field13; } public String getField14() { return field14; } public void setField14(String field14) { this.field14 = field14; } public String getField15() { return field15; } public void setField15(String field15) { this.field15 = field15; } public String getField16() { return field16; } public void setField16(String field16) { this.field16 = field16; } public String getField17() { return field17; } public void setField17(String field17) { this.field17 = field17; } public String getField18() { return field18; } public void setField18(String field18) { this.field18 = field18; } public String getField19() { return field19; } public void setField19(String field19) { this.field19 = field19; } public String getField20() { return field20; } public void setField20(String field20) { this.field20 = field20; } }
Then you can use it to store data in you original code
public static void bulkLoad(NamedCache cache, Connection conn) { Statement s; ResultSet rs; try { s = conn.createStatement(); String sql = "select key, value, value2, " + "value3, value4, value5, value6, " + "value7, value8, value9, value10 " + "value11, value12, value13, value14, " + "value15, value16, value17, value18, " + "value19, value120 from table"; rs = s.executeQuery(sql); while (rs.next()) { Integer key = new Integer(rs.getInt(1)); Data data = new Data(); data.setField1(rs.getString(2)); data.setField2(rs.getString(3)); data.setField3(rs.getString(4)); data.setField4(rs.getString(5)); data.setField5(rs.getString(6)); data.setField6(rs.getString(7)); data.setField7(rs.getString(8)); data.setField8(rs.getString(9)); data.setField9(rs.getString(10)); data.setField10(rs.getString(11)); data.setField11(rs.getString(12)); data.setField12(rs.getString(13)); data.setField13(rs.getString(14)); data.setField14(rs.getString(15)); data.setField15(rs.getString(16)); data.setField16(rs.getString(17)); data.setField17(rs.getString(18)); data.setField18(rs.getString(19)); data.setField19(rs.getString(20)); data.setField20(rs.getString(21)); cache.put(key, data); } ... } catch (SQLException e) {...} }
Of course your data object would need the appropriate field names and you will have no channels for all types. It must also implement equals and hashCode and ideally PortableObject.
JK
-
Merge multiple columns into a single column?
Hello
I need to perform queries dynamically and the return values. I need to retrieve the values of the queries in a single column only by concatenating multiple columns. I can't use the PL/SQL in my scenario.
is it possible to run a query and the result will be extracted in a single column (multiple column values must be concatenated)?
Thank you
Raja.SELECT rtrim(extract(xmltype(REPLACE(column_value,''',',')),'/ROW/*/text()'),',') col FROM TABLE (SELECT xmlsequence(dbms_xmlgen.getxmltype('select * from employees').extract('ROWSET/ROW')) FROM dual );
Check this box... Copy it directly to this
Ravi Kumar
-
Hi all. I'm doing a script that selects the NAME of a table and order the result by CLASS, by using cursors. The cursor 1, is to select CLASS NAME, where CLASS = '1'; While the 2nd cursor's SELECT CLASS NAME where CLASS = '2'; and after that, you use the LOOP, the script does the job, but I have to write the same code for 2 sliders as follows:
If I have a table named LIMBAFK with the NAME and the CLASS in the form of columns and data as follows:
NAME CLASS
JULIAN 1
Michale 1
2 George
DECLARE
CURSOR C1 IS SELECT NAME FROM LIMBAFK WHERE CLASS = '1';
CURSOR C2 IS SELECT NAME FROM LIMBAFK WHERE CLASS = '2';
MYD C1% ROWTYPE;
MY2D C2% ROWTYPE;
BEGIN
OPEN C1;
DBMS_OUTPUT. PUT_LINE('1');
LOOP
FETCH C1 INTO MYD;
WHEN EXIT C1% NOTFOUND;
DBMS_OUTPUT. PUT_LINE (MYD.NAME);
END LOOP;
CLOSE C1;
OPEN C2;
DBMS_OUTPUT. PUT_LINE('2');
LOOP
EXTRACT THE C2 IN MY2D;
WHEN THE EXIT C2% NOTFOUND;
DBMS_OUTPUT. PUT_LINE (MY2D.NAME);
END LOOP;
CLOSE C2;
END;
Then, using this script, the result would be:
1
Julian
Michale
2
George
It's good and it works, but I don't want to write the same code for the two sliders, so I had in mind that the first cursor selects CLASS DISTINCTE of the table, and the 2nd cursor NAME, CLASS, of the same table, and then a comparison between the sliders using, do the same thing. I wrote the code, but it doesn't work at all, so I hope someone can help me.
Here's what I've done so far, but it is not at all finished:
DECLARE
CURSOR C1 IS SELECT CLASS OF LIMBAFK;
CURSOR C2 IS SELECT NAME, CLASS OF LIMBAFK;
MYD C1% ROWTYPE;
MY2D C2% ROWTYPE;
BEGIN
OPEN C1;
LOOP
WHEN EXIT C1% NOTFOUND;
FETCH C1 INTO MYD;
DBMS_OUTPUT. PUT_LINE (MYD. CLASS);
OPEN C2;
LOOP
WHEN THE EXIT C2% NOTFOUND;
EXTRACT THE C2 IN MY2D;
IF C2. CLASS = C1. CLASS
DBMS_OUTPUT. PUT_LINE (MYD. CLASS);
END LOOP;
CLOSE C1;
END;declare cursor c1 is select CLASS,NAME, lag(class, 1) over (order by class) prev_class from LIMBAFK; l_var C1%ROWTYPE; begin open c1; loop fetch c1 into l_var; exit when c1%notfound; if (l_var.prev_class != l_var.class or l_var.prev_class is null) then dbms_output.put_line(l_var.class); end if; dbms_output.put_line(l_var.name) ; end loop; end;
http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/functions070.htm#SQLRF00652
-
Gears - error when you try to insert values into a table with multiple columns
Hello
I started playing with the gears and SQlLite today and I get an error when I try to insert values into a table with multiple columns.
I have:
var db = google.gears.factory.create('beta.database'); db.open('developerSet'); db.execute('create table if not exists Developers (DeveloperName text, DeveloperAge int)'); var devName = "Davy" var devAge = 32; try { db.execute('insert into Developers values (?, ?)', [devName, devAge]); alert('success'); } catch (e) { alert(e); }
I get the error:
net.rim.device.api.database.DatabaseException; insert into developers values (?,?): SQL logic error or missing database.
I use this reference: http://code.google.com/apis/gears/api_database.html
Everything works if I have only one field as:
var db = google.gears.factory.create('beta.database'); db.open('developerSet'); db.execute('create table if not exists Developers (DeveloperName text)'); var devName = "Davy" var devAge = 32; try { db.execute('insert into Developers values (?)', [devName]); alert('success'); } catch (e) { alert(e); }
I use the plug-in Visual Studio 2.0 for 2008 that are running Windows XP SP and Simulator 2.13.0.56
Thank you
Davy
Yes, a SQLite database will persist between battery pulls. The database is registered either to internal MEM or removable media (not the device memory), depending on which is available on your device.
In general, its not considered a best practice to remove your table as soon as it is empty and re - create it again when you want to add data. This adds extra overhead fresh for the final, delete and insert first for a given table. Instead, define and finalize your drawing before you create your table. Once created, review the static schema.
That being said, for development purposes, it may be easier to provide an easy way to drop your tables while you develop your schema.
See you soon,.
Adam
-
using outer joins if the two column is null? Use only (+)
Hi all
create the table xxc_tr_num (tl_number number, tr_no number tl_no_id);
insert into xxc_tr_num values (123,100,222);
insert into xxc_tr_num values (124,100,333);
create the table xxc_od_tab (tl_number number, tl_id number);
insert into xxc_od_tab values (123,001);
insert into xxc_od_tab values (null, null);
create table xxc_oth_tab (name varchar2 (10), number of tl_id);
insert into xxc_oth_tab values('abc',,001);
insert into xxc_oth_tab values (null, null);
Wait it out put
tr_no tl_no_id name
100 222 abc
100 333
using outer joins if the two column is null? use only please of outer joins
And I tried to use outer joins on both tl_id column but not get values and I use have County (tr_no ) > 1
Rajesh123 wrote:
Thank you Kiss it is not possible to use having clause?
You need to understand the functioning of the group. If you will not be asked this question.
Check this box
SQL> select tr_no, 2 tl_no_id, 3 count(*) 4 from xxc_tr_num a, 5 xxc_od_tab b, 6 xxc_oth_tab c 7 where a.tl_number = b.tl_number(+) 8 and b.tl_id = c.tl_id(+) 9 group 10 by tr_no 11 , tl_no_id; TR_NO TL_NO_ID COUNT(*) ---------- ---------- ---------- 100 333 1 100 222 1
See what returns the count? You have grouped according to TR_NO and TL_NO_ID. You must take into consideration the TL_NO_ID just put COUNT (TR_NO) does not increase the NUMBER of the whole group. To get the NUMBER on the whole group, I used the analytical function and did. Like this, see the number of the analytical function here
SQL> select tr_no, 2 tl_no_id, 3 count(*), 4 count(*) over(partition by tr_no) 5 from xxc_tr_num a, 6 xxc_od_tab b, 7 xxc_oth_tab c 8 where a.tl_number = b.tl_number(+) 9 and b.tl_id = c.tl_id(+) 10 group 11 by tr_no 12 , tl_no_id; TR_NO TL_NO_ID COUNT(*) COUNT(*)OVER(PARTITIONBYTR_NO) ---------- ---------- ---------- ------------------------------ 100 222 1 2 100 333 1 2
So to answer your question, yes you can't do in the HAVING clause...
-
What subprogramme should we prefer to return multiple values with OUT parameter?
Hello
I worked on the procedures and functions, and aware of their differences. Today I have an interview question that - suppose I don't have return multiple values through a subroutine and I want nor run any what DML within this subprogramme and I want to use this subprogramme in the SQL query. What subprogramme I would prefer - "Operating Mode" or "Function" and why?
In my view, both can be used in this case, but want to see your views and opinions.
Kind regards
Sachin jerbi
In terms of software engineering, if you claim something that you expect to "return" something (a value or values) then you use a function. If you call something to "do" something, and then you use a procedure.
THE settings are not good practices in many cases and should not strictly considered "return" of values. Instead, they are assigned values in the code and generally act as pointers to the original variable/structure that was passed as a parameter (the actual internals of Oracle don't quite do it, but in principle this is what they do).
A return value (or structure) of a function is basically push in the battery to the point that the RETURN statement is issued, and then the code calling the stack appears to assign it to a variable or placeholder, it should go in.
If it seems a little difference between procedures and functions to some people, it is recommended to use functions for obtaining values and procedures to do things, in most cases. It is not just "syntactic sugar", as mentioned above.
-
Plugin to point that returns multiple values
When you create an APEX element that can return multiple values, such as a checkbox, APEX uses the settings of varchar2 p_v01 - p_v200 instead of the p_t01 table settings - p_t200.
I would like to create a plugin item type that can return multiple values in the same way, so that the session recorded for the item state contains a delimited string of values. I realize, I could achieve with Javascript and a hidden item, but I really want to a non-Javascript solution. Is this possible? If this isn't the case, it would be a nice improvement!
Hi Tony,.
Take a look at the level of the parameter p_is_multi_value of the APEX_PLUGIN. GET_INPUT_NAME_FOR_PAGE_ITEM api (http://docs.oracle.com/cd/E37097_01/doc.42/e35127/apex_plugin.htm#AEAPI1254). If you set it to TRUE, you will get one of the p_v01 - p_v200 table settings. It's the same what our box element type calls.
Concerning
Patrick
Member of the APEX development team
My Blog: http://www.inside-oracle-apex.com
APEX Plug-Ins: http://apex.oracle.com/plugins
Twitter: http://www.twitter.com/patrickwolf
-
Update multiple columns from multiple tables in a single UPDATE request
Hello
I'm trying to figure if I'm heading in the right direction.
I want to update multiple columns from multiple tables in a single UPDATE request. Also, I would like to update multiple columns in a table from the tables.
Scenario 1
UPDATE Table2, Table 3 SET T2.Column1 = T1.Column1 ,T2.Column2 = T1.Column2 ,T3.Column2 = T1.Column2 FROM Table1 T1, Table2 T2, Table3 T3 WHERE T1.id = T2.id and T1.id = T3.id
Scenario 2
UPDATE Table3 SET T3.Column1 = T1.Column1 T3.Column2 = T1.Column2 ,T3.Column3 = T2.Column3 ,T3.Column4 = T2.Column4 FROM Table1 T1, Table2 T2, Table3 T3 WHERE T3.id = T1.id and T3.id = T2.id
Hello
For scenario 1, you must write separate instructions UPDATE table2 and table3.
To guard against someone else change one of these tables while you act so you can copy all relevant data in a global temporary table and update this global temporary table table3.
ENGAGE only when two tables have been changed.
You can write a procedure or an INSTEAD OF trigger to do all this.
For scenario 2, you can reference many tables that you need when new table3. It might be more efficient and simpler to use the MERGER rather than UPDATED. For example:
MERGE INTO table3 dst
WITH THE HELP OF)
SELECT t1.id
t1.column1
t1.column2
t2.column3
t2.column4
FROM table1 t1
JOIN table2 t2 ON t1.id = t2.id
) src
WE (dst.id = src_id
WHEN MATCHED THEN UPDATE
SET dst.column1 = src.column1
dst.column2 = src.column2,
dst.column3 = src.column3,
dst.column4 = src.column4,
;
Maybe you are looking for
-
Mirar toolbar problems and recovery disk?
My kids accidentally downloaded the Mirar Toolbar, and it has really raised heck with my count. I'm not knowledgeable enough to go into the registry and fix everything, but managed to slow it down a bit. I get pop up Windows I am in another site, and
-
phishing scam? I receive e-mail from hotmail telling me that my credit card has expired. they are capable of the id of the card with the last 4 digits showing. I checked and the card does not expire for another year. I need to get direct support to v
-
Windows password/Safe Mode
Hello I was wondering if someone could help me start my computer in normal mode. In a simple world, it would be quite easy, but here is the story/catch. I usually access my account from windows via the fingerprint on my laptop reader and so never h
-
Dear customer,Accounts from Windows Live Hotmail® has grown very rapidly. Our records indicate that your account has not been updated as part of our regular account maintenance. Due to the anonymous registration of free account we have seen mixes acc