UNION statement in ABAP SQL
Hi,
How to achieve the UNION SQL operation results in ABAP? To be specific, I want to retrieve STCD1 field value from vendor master table (LFA1) for all vendors (LIFNR) that exist in table BSIK or BSAK.
And I want to achieve the results in single SQL statement. So in essence, the resultant SQL would be something like:
SELECT STCD1
INTO TABLE my_internal_table
FROM LFA1
WHERE LIFNR IN (SELECT DISTINCT LIFNR
FROM BSIK
UNION
SELECT DISTINCT LIFNR
FROM BSAK)
But the UNION is not a valid keyword in ABAP. Any idea how to achieve this?
Regards,
Chetan
hi chetan,
do you have any where condition to filter the records from bsak and bsik?
your requirement cannot be realized in a single statement.
you have to use two separate selects from bsak and bsik, then, collect all the vendors in one internal table and at last you have to use this table to get the vendor info from lfa1.
regards,
ravi
Similar Messages
-
SQL Statements in ABAP and meaning
Hello Friends,
Please, can anybody provide me a documentation on the different ABAP SQL statements and there usage/meanings.
Thanks,
Shreekanthi,
goto abapdocu->abap Database access->open Sql you will get examples.
for documnetation got se38->specify the command and press F1.
SELECT:
Put the curson on that word and press F1 . You can see the whole documentation for select statements.
SELECT result
FROM source
INTO|APPENDING target
[[FOR ALL ENTRIES IN itab] WHERE sql_cond]
Effect
SELECT is an Open-SQL-statement for reading data from one or several database tables into data objects.
The select statement reads a result set (whose structure is determined in result ) from the database tables specified in source, and assigns the data from the result set to the data objects specified in target. You can restrict the result set using the WHERE addition. The addition GROUP BY compresses several database rows into a single row of the result set. The addition HAVING restricts the compressed rows. The addition ORDER BY sorts the result set.
The data objects specified in target must match the result set result. This means that the result set is either assigned to the data objects in one step, or by row, or by packets of rows. In the second and third case, the SELECT statement opens a loop, which which must be closed using ENDSELECT. For every loop pass, the SELECT-statement assigns a row or a packet of rows to the data objects specified in target. If the last row was assigned or if the result set is empty, then SELECT branches to ENDSELECT . A database cursor is opened implicitly to process a SELECT-loop, and is closed again when the loop is ended. You can end the loop using the statements from section leave loops.
Up to the INTO resp. APPENDING addition, the entries in the SELECTstatement define which data should be read by the database in which form. This requirement is translated in the database interface for the database system´s programming interface and is then passed to the database system. The data are read in packets by the database and are transported to the application server by the database server. On the application server, the data are transferred to the ABAP program´s data objects in accordance with the data specified in the INTO and APPENDING additions.
System Fields
The SELECT statement sets the values of the system fields sy-subrc and sy-dbcnt.
sy-subrc Relevance
0 The SELECT statement sets sy-subrc to 0 for every pass by value to an ABAP data object. The ENDSELECT statement sets sy-subrc to 0 if at least one row was transferred in the SELECT loop.
4 The SELECT statement sets sy-subrc to 4 if the result set is empty, that is, if no data was found in the database.
8 The SELECT statement sets sy-subrc to 8 if the FOR UPDATE addition is used in result, without the primary key being specified fully after WHERE.
After every value that is transferred to an ABAP data object, the SELECT statement sets sy-dbcnt to the number of rows that were transferred. If the result set is empty, sy-dbcnt is set to 0.
Notes
Outside classes, you do not need to specify the target area with INTO or APPENDING if a single database table or a single view is specified statically after FROM, and a table work area dbtab was declared with the TABLES statement for the corresponding database table or view. In this case, the system supplements the SELECT-statement implicitly with the addition INTO dbtab.
Although the WHERE-condition is optional, you should always specify it for performance reasons, and the result set should not be restricted on the application server.
SELECT-loops can be nested. For performance reasons, you should check whether a join or a sub-query would be more effective.
Within a SELECT-loop you cannot execute any statements that lead to a database commit and consequently cause the corresponding database cursor to close.
SELECT - result
Syntax
... lines columns ... .
Effect The data in result defines whether the resulting set consists of multiple rows (table-like structure) or a single row ( flat structure). It specifies the columns to be read and defines their names in the resulting set. Note that column names from the database table can be changed. For single columns, aggregate expressions can be used to specify aggregates. Identical rows in the resulting set can be excluded, and individual rows can be protected from parallel changes by another program.
The data in result consists of data for the rows lines and for the columns columns.
SELECT - lines
Syntax
... { SINGLE }
| { { } } ... .
Alternatives:
1. ... SINGLE
2. ... { }
Effect
The data in lines specifies that the resulting set has either multiple lines or a single line.
Alternative 1
... SINGLE
Effect
If SINGLE is specified, the resulting set has a single line. If the remaining additions to the SELECT command select more than one line from the database, the first line that is found is entered into the resulting set. The data objects specified after INTO may not be internal tables, and the APPENDING addition may not be used.
An exclusive lock can be set for this line using the FOR UPDATE addition when a single line is being read with SINGLE. The SELECT command is used in this case only if all primary key fields in logical expressions linked by AND are checked to make sure they are the same in the WHERE condition. Otherwise, the resulting set is empty and sy-subrc is set to 8. If the lock causes a deadlock, an exception occurs. If the FOR UPDATE addition is used, the SELECT command circumvents SAP buffering.
Note
When SINGLE is being specified, the lines to be read should be clearly specified in the WHERE condition, for the sake of efficiency. When the data is read from a database table, the system does this by specifying comparison values for the primary key.
Alternative 2
Effect
If SINGLE is not specified and if columns does not contain only aggregate expressions, the resulting set has multiple lines. All database lines that are selected by the remaining additions of the SELECT command are included in the resulting list. If the ORDER BY addition is not used, the order of the lines in the resulting list is not defined and, if the same SELECT command is executed multiple times, the order may be different each time. A data object specified after INTO can be an internal table and the APPENDING addition can be used. If no internal table is specified after INTO or APPENDING, the SELECT command triggers a loop that has to be closed using ENDSELECT.
If multiple lines are read without SINGLE, the DISTINCT addition can be used to exclude duplicate lines from the resulting list. If DISTINCT is used, the SELECT command circumvents SAP buffering. DISTINCT cannot be used in the following situations:
If a column specified in columns has the type STRING, RAWSTRING, LCHAR or LRAW
If the system tries to access pool or cluster tables and single columns are specified in columns.
Note
When specifying DISTINCT, note that you have to carry out sort operations in the database system for this.
SELECT - columns
Syntax
| { {col1|aggregate( col1 )}
{col2|aggregate( col2 )} ... }
| (column_syntax) ... .
Alternatives:
1. ... *
2. ... {col1|aggregate( col1 )}
{col2|aggregate( col2 )} ...
3. ... (column_syntax)
Effect
The input in columns determines which columns are used to build the resulting set.
Alternative 1
Effect
If * is specified, the resulting set is built based on all columns in the database tables or views specified after FROM, in the order given there. The columns in the resulting set take on the name and data type from the database tables or views. Only one data object can be specified after INTO.
Note
If multiple database tables are specified after FROM, you cannot prevent multiple columns from getting the same name when you specify *.
Alternative 2
... {col1|aggregate( col1 )}
{col2|aggregate( col2 )} ...
Effect
A list of column labels col1 col2 ... is specified in order to build the resulting list from individual columns. An individual column can be specified directly or as an argument of an aggregate function aggregate. The order in which the column labels are specified is up to you and defines the order of the columns in the resulting list. Only if a column of the type LCHAR or LRAW is listed does the corresponding length field also have to be specified directly before it. An individual column can be specified multiple times.
The addition AS can be used to define an alternative column name a1 a2 ... with a maximum of fourteen digits in the resulting set for every column label col1 col2 .... The system uses the alternative column name in the additions INTO|APPENDING CORRESPONDING FIELDS and ORDER BY. .
http://help.sap.com/saphelp_nw04/helpdata/en/62/10a423384746e8bf5f15ccdd36e8b1/content.htm -
Where to do the abap sql statement in sapscript (PO)
Hi, all.
Hope anybody can guide me to find a solution.
My situation now is i have to do a purchase order in SAPSCRIPT starting from a standard po. I already found out all the related details as below:
Program SAPFM06P
FORM routine ENTRY_NEU
Form MEDRUCK
So, now the problem now is I have to add some more data on my print out PO. After figure out for some time, I don't know where to do my abap sql statement. Like example, I want to retriece some data from the ADRC table. I opened the standard program SAPFM06P to add in the some sql statement, but i dun know where should i add in. Bcz if we straight away put the related ADRC field in our sapscript, it is useless, right?
Thanks in advance.Thanks a lot.
So, how should i add in code in order to fetch the data frm ADRC by using that routine. Because i only the codes like below. I don't where should i start add in.
Form entry_neu using ent_retco ent_screen.
data: l_druvo like t166k-druvo,
l_nast like nast,
l_from_memory,
l_doc type meein_purchase_doc_print.
clear ent_retco.
if nast-aende eq space.
l_druvo = '1'.
else.
l_druvo = '2'.
endif.
call function 'ME_READ_PO_FOR_PRINTING'
exporting
ix_nast = nast
ix_screen = ent_screen
importing
ex_retco = ent_retco
ex_nast = l_nast
doc = l_doc
changing
cx_druvo = l_druvo
cx_from_memory = l_from_memory.
check ent_retco eq 0.
call function 'ME_PRINT_PO'
exporting
ix_nast = l_nast
ix_druvo = l_druvo
doc = l_doc
ix_screen = ent_screen
ix_from_memory = l_from_memory
ix_toa_dara = toa_dara
ix_arc_params = arc_params
ix_fonam = tnapr-fonam "HW 214570
importing
ex_retco = ent_retco.
endform.
Or i come wrong place to add in any coding. Plz guide me.
Thanks in advance. -
Who to use Native SQL statements in ABAP
hi all,
who to use native sql staements in abap bypassing Application server.
with regards,
suresh babu aluri.Hi
Native SQL statements define an area in an ABAP program in which one or more Native SQL statements are to be carried out. The area between EXEC and ENDEXEC is not completely checked by the syntax check. The statements entered there are passed to the Native SQL interface and processed there as follows:
Almost all SQL statements that are valid for the addressed database system can be included between EXEC and ENDEXEC, in particular the DDL statements. These SQL statements are passed from the Native SQL interface to the database system largely unchanged. The syntax rules are specified by the database system, in particular the case sensitivity rules for database objects. If the syntax allows a separator character between individual statements, you can include several Native SQL statements between EXEC and ENDEXEC. Generally, the semicolon ( is used as the separator character.
You can also include SAP-specific Native SQL language elements between EXEC and ENDEXEC. These statements are not passed directly from the Native SQL interface to the database, but are converted appropriately.
All Native SQL statements bypass SAP buffering.
The ENDEXEC statement sets sy-dbcnt to the number of table rows processed in the last Native SQL statement. After implicit cursor processing with PERFORMING, sy-dbcnt contains the total number of lines read.
Programs with Native SQL statements are generally dependent on the database system used, so that they cannot be executed in all ABAP systems. This is especially true for the examples in this section, which was written for Informix database systems.
Example
Inserting two rows in the database table SCARR. If neither of these rows exists, sy-subrc is set to 0 by ENDEXEC and sy-dbcnt to 1. Otherwise, an exception is raised and handled.
DATA: exc_ref TYPE REF TO cx_sy_native_sql_error,
error_text TYPE string.
TRY.
EXEC SQL.
INSERT INTO scarr
(MANDT, CARRID, CARRNAME, CURRCODE, URL)
VALUES ('000', 'FF', 'Funny Flyers', 'EUR',
'http://www.ff.com');
INSERT INTO scarr
(MANDT, CARRID, CARRNAME, CURRCODE, URL)
VALUES ('000', 'EF', 'Easy Flyers', 'EUR',
'http://www.ef.com');
ENDEXEC.
CATCH cx_sy_native_sql_error INTO exc_ref.
error_text = exc_ref->get_text( ).
MESSAGE error_text TYPE 'I'.
ENDTRY.
Reward points if useful
Regards
Anji -
Dear Gurrus,
i am having a trouble in using oracle merge statement in abap, the moment i use where clause in the bottom it gives me an oracle error
EXEC SQL.
MERGE INTO SAP_GL_ACCOUNT@GETZDB a
USING SKA1 b
ON (A.gl_code= B.SAKNR)
WHEN MATCHED THEN
UPDATE SET a.posting_block = B.XSPEB,
a.locked = B.XSPEA,
A.BALANCE_SHEET = B.XBILK
WHEN NOT MATCHED THEN
insert (gl_code,
DESCRIPTION,
posting_block,
locked,
balance_sheet)
VALUES (b.SAKNR,'shadab',B.XSPEB,B.XSPEA,B.XBILK)
where b. mandt = 950 I am talking about this line
ENDEXEC.
the Moment i include WHERE clause in the botton before ENDEXEC it generates as error
" Database error text........: "ORA-00904: "A3"."MANDT": invalid identifier#ORA-02063: preceding line from GETZDB".
although its a basic feature of Oracle to inclue where clauses in insert or update in merge, but here it is generating an error.Hello Shadab,
As per my understanding of this oracle native sql code.
everything is fine except the use of direct value i.e 950 .
System is not able to process this value .
This normally happens even in normal abap sql statements also.
The better solution could be to declare a variable with the
same data type as "mandt" and then pass this "950" value into that
variable and then use this variable in the where clause instead of directly
passing the value.
i.e data:l_var type mandt vlaue '950'.
The other option could be to use the same hard coded
value but use this value in the where clause in quotations i.e.,
'950' instead of 950.
I hope this would solve your purpose, If not please reply me back.
thanks,
M.Naveen Kumar. -
How to use union statement with declare & set function?
Hi Experts,
i have small query about how to use union statement with declare & set function?
Example as below :
DECLARE @name AS date
Declare @name2 AS date
/* SELECT FROM [2013].[dbo].[OINV] T0 */
/* WHERE */
SET @name = /* T0.DocDate */ '[%1]'
SET @name2 = /* T0.DocDate */ '[%2]'
select '2013',t5.U_salmannm,t1.CardName,t2.sumapplied as CollectionAmount,t2.DcntSum ,t3.DocTotal as InvoiceTotal,
datediff(dd,t3.DocDate,t1.Docdate) as Days
from 2013.dbo.orct t1
inner join 2013.dbo.RCT2 t2 on t1.DocNum = t2.DocNum
left join 2013.dbo.oinv t3 on
t3.docentry = t2.baseAbs
inner join 2013.dbo.ocrd t4 on t1.Cardcode = t4.CardCode
inner join [2013].[dbo].[@CQ_RTSM] t5 on t4.U_BeatCode = t5.U_RoutCode
where t2.DcntSum <> 0.000000 and t3.DocDate between [%1] and [%2]
Union
/* SELECT FROM [2014].[dbo].[OINV] T0 */
/* WHERE */
SET @name = /* T0.DocDate */ '[%1]'
SET @name2 = /* T0.DocDate */ '[%2]'
select '2014',t5.U_salmannm,t1.CardName,t2.sumapplied as CollectionAmount,t2.DcntSum ,t3.DocTotal as InvoiceTotal,
datediff(dd,t3.DocDate,t1.Docdate) as Days
from 2014.dbo.orct t1
inner join 2014.dbo.RCT2 t2 on t1.DocNum = t2.DocNum
left join 2014.dbo.oinv t3 on
t3.docentry = t2.baseAbs
inner join 2014.dbo.ocrd t4 on t1.Cardcode = t4.CardCode
inner join [2014].[dbo].[@CQ_RTSM] t5 on t4.U_BeatCode = t5.U_RoutCode
where t2.DcntSum <> 0.000000 and t3.DocDate between [%1] and [%2]You have to create stored procedure in SQL only .
Like u must have create for Crystal .
You can execute procedure in query manager but you have to enter parameter manually..
example
Exec @Test '20140101' '20140501'
Every time user has to enter it manually in yyyymmdd format in case of date parameters.
Example
Create Proc [@Test]
as begin
DECLARE @name AS date
Declare @name2 AS date
/* SELECT FROM [2013].[dbo].[OINV] T0 */
/* WHERE */
select '2013',t5.U_salmannm,t1.CardName,t2.sumapplied as CollectionAmount,t2.DcntSum ,t3.DocTotal as InvoiceTotal,
datediff(dd,t3.DocDate,t1.Docdate) as Days
from 2013.dbo.orct t1
inner join 2013.dbo.RCT2 t2 on t1.DocNum = t2.DocNum
left join 2013.dbo.oinv t3 on
t3.docentry = t2.baseAbs
inner join 2013.dbo.ocrd t4 on t1.Cardcode = t4.CardCode
inner join [2013].[dbo].[@CQ_RTSM] t5 on t4.U_BeatCode = t5.U_RoutCode
where t2.DcntSum <> 0.000000 and t3.DocDate between @Name and @Name2
Union
/* SELECT FROM [2014].[dbo].[OINV] T0 */
/* WHERE */
select '2014',t5.U_salmannm,t1.CardName,t2.sumapplied as CollectionAmount,t2.DcntSum ,t3.DocTotal as InvoiceTotal,
datediff(dd,t3.DocDate,t1.Docdate) as Days
from 2014.dbo.orct t1
inner join 2014.dbo.RCT2 t2 on t1.DocNum = t2.DocNum
left join 2014.dbo.oinv t3 on
t3.docentry = t2.baseAbs
inner join 2014.dbo.ocrd t4 on t1.Cardcode = t4.CardCode
inner join [2014].[dbo].[@CQ_RTSM] t5 on t4.U_BeatCode = t5.U_RoutCode
where t2.DcntSum <> 0.000000 and t3.DocDate between
between @Name and @Name2
end -
Hi,
I'm writing an application with jdbc. I'm using Oracle Release 8.0.5.0.0, j2re 1.4.2_06.
The query with UNION produces a resultSet with no record while if I execute the same query with Oracle SQL Worksheet I've one record.
This is the code with a sample query:
Class.forName(jdbcDriver).newInstance();
Connection c = DriverManager.getConnection(dbUrl, "**", "**");
Statement st = c.createStatement();
String query = "(select fam from people where id=1711) union (select fam from family where fam=397)";
ResultSet rs = st.executeQuery(query);
if(rs!=null){
while(rs.next()){...}
rs.next is false but I know It's not correct!
I dont get any exception and until I didn't use the UNION statement all worked fine!
Please help me, thanksok... I'm replying to myself:
It works if I write the query as follow:
"select fam from people where id=1711 union select fam from family where fam=397"
without '( ... )' !
bye -
Case statement in advanced sql
how to use case statement in advanced sql.Example if quarter=1 i need to select jan,fev,and march months from table
this is the case statement i am using :
case when 1=@{quarter} then substring(cast((etxnmis.month_year) as char) from 5 for 2) IN ('03', '04', '05') else null end
and i get the below error
: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 27002] Near <IN>: Syntax error [nQSError: 26012] . (HY000) -
Multiple select statements in PL/SQL
Hi All
I am new to PL/SQL and my experience is in writing TSQL. There we can write a SQL statement like this to return 3 result set
SELECT empname FROM Employee
SELECT authname FROM Author
SELECT athname FROM sport
how can we write the same 3 statements in PL/SQL and attain the 3 resultsets.
I tried to implement the same using PL/SQL anonymous blocks. But it didn't worked.
DECLARE
P_RECORDSET OUT SYS_REFCURSOR
BEGIN
OPEN P_RECORDSET FOR
SELECT empname FROM Employee;
SELECT authname FROM Author;
SELECT athname FROM sport;
END;
can anybody show how it can be done.
Thanks in advance
George
Edited by: user6290570 on Sep 16, 2009 11:23 PMgeorge2009 wrote:
No i just want to select 3 result sets from 3 select statements, so that it is helpful to compare the resultsets. Compare? How? This is done using the SQL language. Not PL/SQL. Not Java. Not VB. Not anything else.
You would use these other language for flow control and certain forms of conditional logic - but the actual comparison of data sets is done in SQL.
Of course, that is if you do want to do it the most optimal way, that will perform well, and scale well.
SQL is not an I/O API layer - to be used to read() a record and write() a record as if the RDBMS is an ISAM file. That form of row-by-row and slow-by-slow processing dates back to the 80's when we used Cobol.. (or at least for those old farts like me that can actually remember coding in Cobol in the 80's ;-) ).
You want to design and code database applications that are fast, robust, and can scale? Then learn how to use SQL correctly. -
Abap sql convert to native sql fuction
hi expert!
exist a function can do follow things:
convert selection-screen's select-options which user key in
to oracle where condition expression
or exist one function can convert abap sql to oracle sql
thank you very muchexample:
EXEC SQL.
CONNECT TO :'DATA BASE NAME'
ENDEXEC.
IF sy-subrc EQ 0 .
TRY.
EXEC SQL .
SELECT COUNT(*) FROM <TABLE NAME>
INTO :recount
WHERE code = :itab-<FIELD>
ENDEXEC .
CATCH cx_sy_native_sql_error INTO exc_ref.
error_text = exc_ref->get_text( ).
MESSAGE error_text TYPE 'I'.
ENDTRY. -
Run sql statements in PL/Sql Developer without installing Oracle database?
Hi all,
I wish to ask is there any possibility to run Run sql statements in PL/Sql Developer without installing Oracle database?
Regards.Hello Jimmy,
this is the forum for the tool SQL Developer and, as the title says, *(Not for general SQL/PLSQL questions)*.
PL/Sql Developer is not an Oracle tool, but from allound allroundautomations.
And you need access to a database to run SQL statements. This does not need to be one installed by yourself.
Regards
Marcus -
Hi ABAP Gurus,
Please help me in solving following ABAP SQL doubt.
In the table Zonfig there are two fields: FNAME and REQFLAG
FNAME.....REQFLAG
S1...........X
S2...........X
S3..........._
S4...........X
Other table T_Zconfig has one field : XNAME
XNAME
S1
S3
Now I have to select REQFLAG from Zconfig table for the values of field XNAME in T_Zconfig table.
That is in this case for FNAME S1 and S2 in Zonfig I need to fetch REQFLAG since in XNAME in T_Zonfig we just have S1 and S2.
Points will be surly awarded...
Thanks.Hi ABAP Gurus,
Please help me in solving following ABAP SQL doubt.
In the table Zonfig there are two fields: FNAME and REQFLAG
FNAME.....REQFLAG
S1...........X
S2...........X
S3..........._
S4...........X
Other table T_Zconfig has one field : XNAME
XNAME
S1
S3
Now I have to select REQFLAG from Zconfig table for the values of field XNAME in T_Zconfig table.
That is in this case for FNAME S1 and S3 in Zonfig I need to fetch REQFLAG since in XNAME in T_Zonfig we just have S1 and S3.
Points will be surly awarded...
Thanks. -
How to create nested CASE statements in PL/SQL
Can anyone please tell how to create Nested CASE statements in PL/SQL with proper syntax?
It would be better if you can help with an example.
Thank you!Something like this:
SQL> set serveroutput on
SQL> declare
2 v1 number := 2;
3 v2 varchar2(1) := 'C';
4 begin
5 case v1
6 when 1 then dbms_output.put_line('First');
7 when 2 then begin
8 case v2
9 when 'A' then dbms_output.put_line('Found A');
10 when 'B' then dbms_output.put_line('Found B');
11 when 'C' then dbms_output.put_line('Found C');
12 else dbms_output.put_line('NONE');
13 end case;
14 end;
15 else dbms_output.put_line('Else');
16 end case;
17 end;
18 /
Found C
PL/SQL procedure successfully completed
SQL> If you have further doubts regarding syntax you can read the docs on the Case statement here:
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/case_statement.htm -
Multiple SQL statements in Init SQL in WLS 8.1
How to seperate multiple SQL statements in Init SQL text box ?
For example, I want to enter following two SQL statements. How do I seperate them.
I tested with / and ; as seperator, but did not worked..
alter session set nls_date_format = 'MM/DD/YYYY'
set role xxx_role identified by xxxxMahendra wrote:
Thanks Joe.
Following worked for Oracle 8.1.7Good news.
but did not for 8.0.6
SQL BEGIN EXECUTE IMMEDIATE 'ALTER SESSION SET nls_date_format = ''MM/DD/YYYY''';
EXECUTE IMMEDIATE 'SET ROLE xxx identified xxx'; end;
Do you know 8.0.6 syntax ?You might try asking oracle, but note that no one is supporting that old version
of Oracle any longer...
Joe
>
Mahendra
Joe Weinstein <[email protected]> wrote:
Hi.
I found the syntax, I think. Try this:
BEGIN EXECUTE IMMEDIATE 'ALTER SESSION SET nls_date_format = 'MM/DD/YYYY'';
EXECUTE IMMEDIATE 'SET ROLE <<role name>> identified
by <<pwd>>';END;
Joe
Mahendra wrote:
Still getting following exception.
<Feb 19, 2004 1:47:58 PM EST>
<Warning>
<JDBC> <BEA-001164>
<Unable to initialize connection in pool "XXXX".
Initialization
SQL = "BEGIN alter session set nls_date_format = 'MM/DD/YYYY'; setrole xxxx_role
identified by
xxxx; END;".
Received exception: "java.sql.SQLException: ORA-06550: line 1,column7:
PLS-00103: Encountered the symbol "ALTER" when expecting one of thefollowing:
begin declare exit for goto if loop mod null pragma raise
return select update while <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql commit <a single-quoted SQL string>
The symbol "update was inserted before "ALTER" to continue.
ORA-06550: line 1, column 61:
PLS-00103: Encountered the symbol "ROLE" when expecting one of thefollowing:
transaction
".>
<Feb 19, 2004 1:47:59 PM EST> <Notice> <WebLogicServer> <BEA-000355><Thread "Li
Joe Weinstein <[email protected]> wrote:
Mahendra wrote:
Thanks for reply, but that did not worked.
Get following exception
Unable to initialize connection pool "POOL_NAME".
Initialization SQL = "Select count(*) from ""SQL BEGIN alter sessionset nls_date_format
= 'MM/DD/YYYY'; set role xxx_role identified by xxxx; END;"". Receivedexception:
"java.sql.SQLException: ORA-00972: identifier is too long
Since we have not given SQL before that statement, BEA is treating
statment "SQL Begin ....." as a table name.
Then I tried by putting SQL out side quotes, like SQL "Begin .....end;" but the
same error.
Is there any way around it ?
MahendraHi. The full string you should enter into the console when you define
the
initSQL parameter is:
SQL BEGIN alter session set nls_date_format = 'MM/DD/YYYY'; set role
xxx_role identified by xxxx; END;
Let me know...
Joe
Joe Weinstein <[email protected]> wrote:
Mahendra wrote:
How to seperate multiple SQL statements in Init SQL text box ?
For example, I want to enter following two SQL statements. How do
I
seperate them.
I tested with / and ; as seperator, but did not worked..
alter session set nls_date_format = 'MM/DD/YYYY'
set role xxx_role identified by xxxxThis will always be DBMS-specific. If this is for oracle, you can
try:
"SQL BEGIN alter session set nls_date_format = 'MM/DD/YYYY'; setrole
xxx_role identified by xxxx; END;"
Joe -
Select extra row without using UNION ALL in pl/sql
Hi,
Can anyone tell me how to select extra row without using UNION or UNION ALL in pl/sql. Actually I want to have my o/p of query as partitioned by designation and ordered by salary and than one extra row which will contain the highest salary in a particular salary. My table has first_name,emp_id,designation and salary column. And I wnt the o/p as.
Mohinish,12212,SI,46000
Ram,11212,SSI,47000
Shyam,12133,SI,48000
Rick,9898,SI,46000
Rocky,12312,SSI,56000
Sariq,23948,SI,43000
Suman,12789,HR,49000
Sampy,12780,SI,46000
Parna,11111,HR,50000
Now the o/p should be.
Mohinish,12212,SI,46000
Rick,9898,SI,46000
Sariq,23948,SI,43000
Shyam,12133,SI,48000
Shyam,12133,SI,48000
Ram,11212,SSI,47000
Rocky,12312,SSI,56000
Rocky,12312,SSI,56000
Suman,12789,HR,49000
Parna,11111,HR,50000
Parna,11111,HR,50000
Thanks in AdvanceYou don't have to do a UNION or UNION ALL in PL/SQL but you would need to in SQL to get the desired output:
with data_recs
as (select 'Mohinish' first_name,12212 emp_id,'SI' designation,46000 salary from dual union
select 'Ram',11212,'SSI',47000 from dual union
select 'Shyam',12133,'SI',48000 from dual union
select 'Rick',9898,'SI',46000 from dual union
select 'Rocky',12312,'SSI',56000 from dual union
select 'Sariq',23948,'SI',43000 from dual union
select 'Suman',12789,'HR',49000 from dual union
select 'Sampy',12780,'SI',46000 from dual union
select 'Parna',11111,'HR',50000 from dual)
select first_name, emp_id, designation, salary from data_recs union all
select s.first_name, s.emp_id, s.designation, s.salary
from (select first_name,
emp_id,
designation,
salary,
row_number() over (partition by designation order by salary desc) high_salary
from data_recs
order by designation, salary) s
where s.high_salary = 1
order by designation, salary;
FIRST_NAME EMP_ID DESIGNATION SALARY
Suman 12789 HR 49000
Parna 11111 HR 50000
Parna 11111 HR 50000
Sariq 23948 SI 43000
Rick 9898 SI 46000
Mohinish 12212 SI 46000
Sampy 12780 SI 46000
Shyam 12133 SI 48000
Shyam 12133 SI 48000
Ram 11212 SSI 47000
Rocky 12312 SSI 56000
Rocky 12312 SSI 56000
Maybe you are looking for
-
How to open a html file in a region on same page
Hi, I am trying to create a page where I have 2 regions. The left region,"lef_reg" has been created using HTML contains some text values. The right region, "rig_reg" is blank. I want that if a user clicks on a link on the left region (lef_reg) then a
-
Table move after data deletion in oracle 11g
Hi, Our previous system was in oracle 9i, And we used to archive our data in every 1 year which caused a huged number of DML operation our database. After that,we used to move our table and rebuild indexes to releases spaces. After Upgradation ,our p
-
Macbook Pro WD Firewire 800 issues possible work around
I have been having issues with my Western Digital My Passport Studio and the Firewire 800 connection. The drive would mount and was completly readable however copying to the drive would result in a stall. The USB connection worked perfect. I have fou
-
ODS Capability of 2LIS_02_SCL
All, I am having an issue with the 2LIS_02_SCL (Purchasing Schedule lines extractor) that I just cannot figure out. Here is the situation.... I have created an ODS layer in front of a set of data targets...one data target is a cube that is modeled fr
-
Hi, I am trying to use Lightroom in conjunction with ImagePrint 7/Print Through Application. I'd like to be able to use my media profiles from inside Lightroom. Per the online docs, I have copied the profiles to the /Library/ColorSync/Profiles direct