SQLServer 7 sp_executesql equivalent in Oracle 8
Hi!
Looking for an example or a code equivalent for the system
procedure "sp_executesql" in SQLServer 7 for Oracle 8... If you
have any information of this kind, please send me a message.
Thanks!
null
Pierre,
The facilities for dynamic sql from plsql are:
dbms_sql
and (new in 8( or 8i?))
execute immediate
see pl/sql documentation for details.
simplest example:
execute immediate 'select * from emp';
calling procedures with bind variables is a little more
complicated.
the following gives some simple examples:
convienience function for dbms_sql:
CREATE OR REPLACE PROCEDURE EXEC_SQL(STRING
IN VARCHAR2) AS
CURSOR_NAME INTEGER;
RET INTEGER;
BEGIN
CURSOR_NAME := DBMS_SQL.OPEN_CURSOR;
BEGIN
DBMS_SQL.PARSE(CURSOR_NAME, STRING, DBMS_SQL.native);
RET := DBMS_SQL.EXECUTE(CURSOR_NAME);
EXCEPTION
WHEN OTHERS THEN
DBMS_SQL.CLOSE_CURSOR(CURSOR_NAME);
RAISE;
END;
DBMS_SQL.CLOSE_CURSOR(CURSOR_NAME);
END;
procedure that does something;
CREATE OR REPLACE PROCEDURE usefunc AS
CURSOR_NAME INTEGER;
RET INTEGER;
BEGIN
EXEC_SQL('insert into tt values (''fred'')');
END;
procedure to do something dynamically using execute immediate;
CREATE OR REPLACE PROCEDURE usevar(STRING
IN VARCHAR2) AS
CURSOR_NAME INTEGER;
RET INTEGER;
BEGIN
execute immediate STRING;
END;
SQL> execute usevar('begin usefunc ; end;')
PL/SQL procedure successfully completed.
SQL> select * from tt;
CHARS
fred
procedure to do something dynamically using dbms_sql;
CREATE OR REPLACE PROCEDURE usevar(STRING
IN VARCHAR2) AS
CURSOR_NAME INTEGER;
RET INTEGER;
BEGIN
EXEC_SQL(STRING);
END;
SQL> execute usevar('begin usefunc ; end;')
PL/SQL procedure successfully completed.
SQL> select * from tt;
CHARS
fred
fred
Pierre Lessard (guest) wrote:
: Hi!
: Looking for an example or a code equivalent for the system
: procedure "sp_executesql" in SQLServer 7 for Oracle 8... If you
: have any information of this kind, please send me a message.
: Thanks!
Turloch
Oracle Migration Workbench team
Oracle Technology Network
http://technet.oracle.com
null
Similar Messages
-
DMBS_SQL.to_refcursor equivalent in Oracle 10g
Hello,
Is there any other way to get result as a refcursor in Oracle 10g with DBMS_SQL? I have the function that function generate dynamic query and execute with DBMS_SQL. This function called by java code for viewing result as report. How can I do this, is there equivalent in Oracle 10g for DMBS_SQL.to_refcursor? Please help.
Thanks,ilkinesrefli wrote:
Is it difficult to understand my answers?Yes, because they are not accurate. You keep saying you can't use ref cursors and must use DBMS_SQL, but you have failed to show us why that is so.
It is impossible because there is dynamic where clause in my query. Show us why it's impossible.
BluShadow please solve this one:
p_sql := 'select empno, ename, deptno from emp where deptno=:pdeptno';
if ... then
p_sql := p_sql || ' AND empno=:pempno';
end if;
...Is it possible by your way?Yes, ref cursors can be used for dynamic queries. basic example...
SQL> ed
Wrote file afiedt.buf
1 create or replace function get_refcursor(p_sql in varchar2
2 ,p_whereclause in varchar2 := null
3 ,p_whereval in number := null) return sys_refcursor is
4 v_rc sys_refcursor;
5 begin
6 if p_whereval is not null then
7 open v_rc for p_sql||' where '||p_whereclause using p_whereval;
8 else
9 open v_rc for p_sql;
10 end if;
11 return v_rc;
12* end;
SQL> /
Function created.
SQL> var rc refcursor;
SQL> exec :rc := get_refcursor('select empno, ename, deptno from emp');
PL/SQL procedure successfully completed.
SQL> print rc;
EMPNO ENAME DEPTNO
7369 SMITH 20
7499 ALLEN 30
7521 WARD 30
7566 JONES 20
7654 MARTIN 30
7698 BLAKE 30
7782 CLARK 10
7788 SCOTT 20
7839 KING 10
7844 TURNER 30
7876 ADAMS 20
7900 JAMES 30
7902 FORD 20
7934 MILLER 10
14 rows selected.
SQL> exec :rc := get_refcursor('select empno, ename, deptno from emp', 'deptno = :1', 20);
PL/SQL procedure successfully completed.
SQL> print rc;
EMPNO ENAME DEPTNO
7369 SMITH 20
7566 JONES 20
7788 SCOTT 20
7876 ADAMS 20
7902 FORD 20
SQL>So, please explain to us again why ref cursors are impossible to use and you have to use DBMS_SQL? -
SQL XMLExplicit equivalent in oracle
Hi
Is there any equivalent in oracle for SQL XMLExplicit?
In SQL the XMLExplicit will add all the retunded nodes under the single root node like that any equivalent is available in oracle.
Thanks
SurendraI hope you will get better answers if you post this in Sql/Plsql Forum ..
PL/SQL
This one is one of the genuine and active forums .. :) -
HANA equivalent of oracle's sql%rowcount to get affected rows.
I want to get the number of rows affected from an insert or update statement inside a stored procedure.
Is there any equivalent to oracle's sql%rowcount that can be called after the query.
For example:
create procedure procedure_name
begin
declare l_c integer;
insert into table values ('somevalue');
l_c := sql%rowcount; -- This would return 1 for the row inserted.
end;Yes, after the INSERT statement....
SELECT ::ROWCOUNT into L_C FROM DUMMY;
Cheers,
Rich Heilman -
TIBCO Businessworks equivalent in Oracle SOA Suite
Hello Experts,
What is the equivalent of TIBCO Business works in Oracle SOA world??
I guess Oracle Service Bus. Am I right??
Thanks
Rgds
NatrajanNatrajan,
For process orchestration, ACTIVEMATRIX BusinessWorks is equivalent to Oracle BPEL (which is part of Oracle SOA Suite). ACTIVEMATRIX Service Bus is equivalent to Oracle Service Bus.
Regards,
Anuj -
Does SQL Server has an equivalent to Oracle's OEM?
I am not sure if this is the correct area to ask my question. My manager asked me if SQL Server has an equivalent to Oracle's OEM. Does it? I mean OEM is not like Microsoft SQL Server Management Studio.
lcerniHello,
You can use SQL Server Management Studio to manage SQL Server instances as you do with Oracle Enterprise Manager, and you can have a management and performance
data warehouse using SQL Server Management Data Warehouse (MDW) as explained on the following article:
http://msdn.microsoft.com/en-us/library/dd939169(v=SQL.100).aspx
MDW data collection can be customized.
Hope this helps.
Regards,
Alberto Morillo
SQLCoffee.com -
10g Express Edition equivalent for Oracle 8.1.7?
Hi all,
Exist any Oracle 10g Express Edition equivalent (free edition) for Oracle 8.1.7?
Many thanks in advance.user5880436 wrote:
Hi all,
Exist any Oracle 10g Express Edition equivalent (free edition) for Oracle 8.1.7?
Many thanks in advance.Express edition was started from 10G onwards. So there is no equivalent in 8 i.
Regards
Rajesh -
WITH clause equivalent in oracle 8i
Hi friends,
The "WITH" clause is very well supported in Oracle 9i. Is there any equivalent ways to use it in Oracle 8i?
Regards
J.BDear J. B.!
No, there isn't an equivalent for WITH in Oracle 8i. The only workaround for you is to build inline views in the FROM-Clause of your statements. Please have a look at the following link. It shows some example using a WITH-Clause and the equivalent SQL-Statements with an inline view.
[http://www.oracle-base.com/articles/misc/WithClause.php]
Yours sincerely
Florian W. -
Hi,
I am having trouble understanding equivalent data types in my conversion from SQL Server to Oracle.
Let's say I have this statement in SQL Server, where the string being "passed in" is a uniqueidentifier:
select cast(substring('EFDA8997-63AA-4F33-96CF-29BFC2CE252E',8,1) as binary(1));
The tool I've used to convert this to Oracle says the equivalent statement to this is (where the string being "passed in" is a char:
select cast((substr('EFDA8997-63AA-4F33-96CF-29BFC2CE252E',8,1)) as raw(1)) from dual;
However, I get different results when testing these two statements:
SQL Server: 0x37
Oracle: 07
What is the correct what to convert this statement to Oracle?
Thank you!
MimiI should add that this an n-tier application, where data is passed across multiple tiers, so the client UI has no connection to the database.
I'm assuming this means that select..for update is not suitable, as that would require a connection to the database to be held open for a specific user in the middle-tier. Not suitable for a scalable, n-tier scenario. -
Hello,
What is the equivalent of "WIN_API_SESSION.Timeout_Get_Inactive_Time" in oracle 10G developer suite using webutil.
I want to exit the form if the session is inactive for a set period of time calculated as above in earlier versions.
Thanks and Regards
MohanDo you have any other solution on this?
Regards,
MKBH -
PROMPT Command equivalent in Oracle 7
Hi All,
I am working on a database Health check script . I Have to implement this on a Oracle7 server running on OS HP-unix. I have done with this health check script on all the 9i servers. The same script i have to modify and implement in Oracle7 database also. To print Headings or titles in Oracle 9i i used PROMPT command. So which is the equivalent command that can be used in Oracle7. I want to print the headings. Kindly assist me.877920 wrote:
Same error. Unable to login.
SQL> connect / as sysdba
ERROR: ORA-01017: invalid username/password; logon deniedAs far as I recall, sqlplus back then did not support this specific logon syntax. Qualify the connection string using username and password. e.g.
sqlplus sys/mysecretpassword
The sysdba role will likely not be enabled - but that should not be an issue for running a bunch SQL selects.
Also reconsider using the sys schema for logging on. The only time this schema should be used is for actual database maintenance - like doing a shutdown, changing initialisation settings, doing an upgrade and so on.
Using it as your personal superuser logon is not a good idea and one that you will be nailed for (and very hard) in any security review or audit.
Rather create a new schema and grant it the minimal rights needed to do perform the required job.
PS. Cannot recall if connect internal also worked in sqlplus back then - but that can be tried if you want a sysdba connection from sqlplus itself. -
Hi,
In SQL Server, there is a function datediff with datepart 'q'/quarter which behaves as follows :--
select datediff(q,'03-30-2005','04-01-2005') will return 1
datediff(q,start date,end date)
i.e it takes the quarter in which the start date exists and subtracts it from the quarter in which the end date exists.
I need the equivalent for the above in Oracle.
I found the below in OMWB document :--
Equivalent as : round(months_between(date2, date1)/3)
But this will not work for particular data, since the logic in which SQL Server executes the DATEDIFF is different as I have explained above. Please can anyone give the exact equivalent if any available.
Thanks,
SamTom Kyte has written a datediff function for Oracle here:
http://osi.oracle.com/~tkyte/Misc/DateDiff.html
You could modify it to include quarters like so:
scott@ORA92> create or replace function datediff
2 (p_what in varchar2,
3 p_d1 in date,
4 p_d2 in date)
5 return number
6 as
7 l_result number;
8 begin
9 if upper (p_what) = 'Q' then
10 l_result := ((to_char (p_d2, 'yyyy') - to_char (p_d1, 'yyyy')) * 4)
11 + (to_char (p_d2, 'q') - to_char (p_d1, 'q'));
12 else
13 select (p_d2-p_d1) *
14 decode (upper (p_what),
15 'SS', 24*60*60,
16 'MI', 24*60,
17 'HH', 24,
18 NULL)
19 into l_result
20 from dual;
21 end if;
22 return l_result;
23 end datediff;
24 /
Function created.
scott@ORA92> show errors
No errors.
scott@ORA92> alter session set nls_date_format = 'mm-dd-yyyy'
2 /
Session altered.
scott@ORA92> select datediff ('q', '03-30-2005', '04-01-2005') from dual
2 /
DATEDIFF('Q','03-30-2005','04-01-2005')
1
scott@ORA92> select datediff ('q', '03-30-2005', '04-01-2006') from dual
2 /
DATEDIFF('Q','03-30-2005','04-01-2006')
5
scott@ORA92> select datediff ('q', '04-01-2005', '03-30-2006') from dual
2 /
DATEDIFF('Q','04-01-2005','03-30-2006')
3
scott@ORA92> -
MySQL LIMIT clause equivalent in ORACLE statement
Is there an Oracle SQL statement that would be equivalent to the MySQL LIMIT clause used to return only part of a result set?
The preferred solution is to make use of the analytic function ROW_NUMBER. There is a description in the Oracle documentation. The final example shown returns only the fifty-first through one-hundredth row of the EMPLOYEES table:
SELECT last_name FROM
(SELECT last_name, ROW_NUMBER() OVER (ORDER BY last_name) R FROM employees)
WHERE R BETWEEN 51 and 100;An alternative is to use:
select *
from ( select a.*, rownum rnum
from ( YOUR_QUERY_GOES_HERE -- including the order by ) a
where rownum <= MAX_ROWS )
where rnum >= MIN_ROWS;which is discussed on asktom.oracle.com. This works from Oracle 8.1 onwards.
-- cj -
Datepart equivalent in oracle for date function
I was trying to convert the sqlserver query to oracle and found a function which is not available in ora, could you plz help me in converting this
select top 5 ssm.maturity,datepart(mm, dateadd(mm, -3, ssm.maturity)) from sec_ind_ss ssm;
2014-10-23 00:00:00.0 7
9999-12-31 00:00:00.0 9
2021-01-02 00:00:00.0 10
2022-07-31 00:00:00.0 4
2019-07-31 00:00:00.0 4
I tried this but no result
SELECT ssm.maturity ,CAST(EXTRACT(MONTH FROM ssm.maturity - NUMTOYMINTERVAL(3,'month')) AS VARCHAR2(30))
from sec_ind_ss ssm WHERE ROWNUM<=5;Really? Here's what I get:
alter session set nls_date_format = 'RRRR-MM-DD';
col date_minus3 format a11
with sec_ind_ss as
( select date '2014-01-31' maturity from dual union all
select date '2014-10-23' from dual union all
select date '9999-12-31' from dual union all
select date '2021-01-02' from dual union all
select date '2022-07-31' from dual union all
select date '2019-07-31' from dual )
select maturity
, add_months(maturity,-3) as date_minus3
, to_number(to_char(add_months(maturity,-3),'fmMM')) as month_minus3
from sec_ind_ss;
MATURITY DATE_MINUS3 MONTH_MINUS3
2014-01-31 2013-10-31 10
2014-10-23 2014-07-23 7
9999-12-31 9999-09-30 9
2021-01-02 2020-10-02 10
2022-07-31 2022-04-30 4
2019-07-31 2019-04-30 4 -
Implementing work queues? (or, "readpast equivalent in oracle?")
Without going to Advanced Queuing, is there a
more straightforward way to implement a work
queue?
As an example of what I'd like to do,
I have a table with rows, each row identifying some
work that has to be done.
I would like to have multiple processes pick up the
first available "unlocked" row, and select it for update.
When the work is done the process would update the row and
mark it done, and commit it, etc. If the process fails,
it would rollback and that will be the right behaviour
for my needs.
I think a SQL-server equivalent of the READPAST hint
to ignore row-locked entries would work nicely for what
I want to do, but I'm interested in other solutions, etc
for this problem?
Thanks,
-kbHello,
Two thoughts come to mind. You could have a Java Message Listener listening on a queue for an event and then do whatever you need to do after it has received that event.
The other option is to use the external procedure mechanism to invoke a bit of c code to start you Java code. A bit convoluted compared to the first option.
Thanks
Peter
Maybe you are looking for
-
Why do I have two iPhoto Libraries on two different disks?
I have two external hard drives. At one time in the past I created an iPhoto Library on disk one, and then later I created a new library on disk two since it was larger, and that became my primary library. Now I notice using Finder after several mont
-
I want to change the user details to my wife how is it done please
I have a first generation Ipad which is registered to me, i want to give it to my wife and register it to her can you tell me how I do this please. Also when I try to download her Iphone games and apps from back up it just syncs all my stuff from itu
-
All_mview_comments - Permission problem or bug?
Hi folks. I have some materialized views with comments on them. As a DBA or the schema user, I can do a SELECT * FROM all_mview_comments and see all the materialized views and comments. I have a regular user account which belongs to my user role. The
-
Calling Bex Workbooks from the Web Dynpro
Hi All, I'm calling Bex Workbooks from my dynpro using the following code: create reentrance ticket call function 'CREATE_RFC_REENTRANCE_TICKET' importing ticket = l_ticket exceptions ticket_logon_disabled = 1
-
Best Way to Sync Iphone with Outlook - Parallels, Google Cal or Mobile Me?
I just bought a macbook pro. I must sync with outlook because the software I use in my business syncs its calendar and contacts with outlook and then I sync my iphone to outlook. It seems there are three options. I am interested in feedback on these