SQL Issue in FROM CLAUSE
It is possible changed the SQL statement below to repeat only once USUARIO table in the FROM clause ?
SELECT U_PEND.NOME AS USUARIO_PEND
, U_DECLINADO.NOME AS USUARIO_DECLINADO
, U_REVISADO.NOME AS USUARIO_REENVIADO
, U_EMITIDO.NOME AS USUARIO_EMITIDO
, U_CANCELADO.NOME AS USUARIO_CANCELADO
, U_RECEBIDO.NOME AS USUARIO_RECEBIDO
, PP.NUMERO AS NUMERO_PROPOSTA
, C.CODIGO AS COOPERATIVA
, S.NOME AS SEGURADORA
, P.NOME AS PRODUTO_NOME
, GL.DATA_ENVIO AS DATA_ENVIO
, PP.OID_MOTIVO_DECLINIO AS OID_MOTIVO_DECLINIO
, MD.DESCRICAO AS DESCRICAO_MOTIVO_DECLINIO
, SUBSTR(PA.CODIGO, 6, 2) AS CODIGO_PONTO_ATENDIMENTO
, PD.NOME_DOCUMENTO
, PS.OID
FROM SIS_OWNER.SEGURADORA S
, PRODUTO P
, PRODUTO_SEGURADORA PS
, USUARIO U_PEND
, USUARIO U_DECLINADO
, USUARIO U_REVISADO
, USUARIO U_EMITIDO
, USUARIO U_CANCELADO
, USUARIO U_RECEBIDO
, GERACAO_LOTE GL
, COOPERATIVA C
, MOTIVO_DECLINIO MD
, PONTO_ATENDIMENTO PA
, PROTOCOLO_DOCUMENTO PD
, PROTOCOLO_PROPOSTA PP
WHERE PP.OID_PRODUTO_SEGURADORA = PS.OID
AND PS.OID_SEGURADORA = S.OID
AND PS.OID_PRODUTO = P.OID
AND PP.OID_USUARIO_MOV_PEND = U_PEND.OID(+)
AND PP.OID_USUARIO_MOV_DECLINADO = U_DECLINADO.OID(+)
AND PP.OID_USUARIO_MOV_REENVIADO = U_REVISADO.OID(+)
AND PP.OID_USUARIO_MOV_EMITIDO = U_EMITIDO.OID(+)
AND PP.OID_USUARIO_MOV_CANCELADO = U_CANCELADO.OID(+)
AND PP.OID_USUARIO_MOV_RECEBIDO = U_RECEBIDO.OID(+)
AND PP.OID_GERACAO_LOTE = GL.OID(+)
AND PP.OID_COOPERATIVA = C.OID(+)
AND PP.OID_MOTIVO_DECLINIO = MD.OID(+)
AND PP.OID_PONTO_ATENDIMENTO = PA.OID(+)
AND PP.OID_PROTOCOLO_DOCUMENTO = PD.OID(+)
AND PP.OID = 1704719 ;Edited by: Luciana T. Angeli on Jul 16, 2010 9:58 AM
Edited by: Luciana T. Angeli on Jul 16, 2010 10:02 AM
Hi,
Yes, you can do that, but I'm not sure it will be any more efficient, or otherwise better, than what you're doing now.
Since you didn't post CREATE TABLE and INSERT statements for sample data, I'll use tables in the scott schema to illustrate.
The following uses 3 copies of the empgrade table, similar to the way you use several copies of the usario table:
SELECT e.empno, eg.grade AS empno_g
, e.sal, sg.grade AS sal_g
, e.mgr, mg.grade AS mgr_g
, d.dname
FROM scott.emp e
JOIN scott.salgrade eg ON e.empno BETWEEN eg.losal AND eg.hisal
JOIN scott.salgrade sg ON e.sal BETWEEN sg.losal AND sg.hisal
LEFT OUTER JOIN scott.salgrade mg ON e.mgr BETWEEN mg.losal AND mg.hisal
JOIN scott.dept d ON e.deptno = d.deptno
ORDER BY e.empno
;Output:
EMPNO EMPNO_G SAL SAL_G MGR MGR_G DNAME
7369 5 800 1 7902 5 RESEARCH
7499 5 1600 3 7698 5 SALES
7521 5 1250 2 7698 5 SALES
7566 5 2975 4 7839 5 RESEARCH
7654 5 1250 2 7698 5 SALES
7698 5 2850 4 7839 5 SALES
7782 5 2450 4 7839 5 ACCOUNTING
7788 5 3000 4 7566 5 RESEARCH
7839 5 5000 5 ACCOUNTING
7844 5 1500 3 7698 5 SALES
7876 5 1100 1 7788 5 RESEARCH
7900 5 950 1 7698 5 SALES
7902 5 3000 4 7566 5 RESEARCH
7934 5 1300 2 7782 5 ACCOUNTINGThe problem is that you may need 3 different values of the grade column, from 3 different rows of salgrade, for each row of emp.
You can get all 3 grades at once as separate rows, then pivot the results to make them 3 different columns:
WITH all_grades AS
SELECT e.empno, e.sal, e.mgr, e.deptno
, MIN (CASE WHEN e.empno BETWEEN g.losal AND g.hisal THEN grade END) AS empno_g
, MIN (CASE WHEN e.sal BETWEEN g.losal AND g.hisal THEN grade END) AS sal_g
, MIN (CASE WHEN e.mgr BETWEEN g.losal AND g.hisal THEN grade END) AS mgr_g
FROM scott.emp e
JOIN scott.salgrade g ON e.empno BETWEEN g.losal AND g.hisal
OR e.sal BETWEEN g.losal AND g.hisal
OR e.mgr BETWEEN g.losal AND g.hisal
GROUP BY e.empno, e.sal, e.mgr, e.deptno
SELECT a.empno
, a.empno_g
, a.sal
, a.sal_g
, a.mgr
, a.mgr_g
, d.dname
FROM all_grades a
JOIN scott.dept d ON a.deptno = d.deptno
ORDER BY a.empno
;
Similar Messages
-
Hi,
some of my complex extractions that I am currently working on require nested SELECT statements. As far as I can see OpenSQL only supports subqueries in the WHERE clause, not in the FROM clause. Is this assumptions correct or is there a way around it? I have managed to use Native SQL for these nested expressions but the preference of the client is to use OpenSQL.
Any ideas?
Thanks,
TobiasHi
In from clause you can use join.
You can read data from more than one database table in a single SELECT statement by using inner or left outer joins in the FROM clause.
The disadvantage of using joins is that redundant data is read from the hierarchically-superior table if there is a 1:N relationship between the outer and inner tables. This can considerably increase the amount of data transferred from the database to the application server. Therefore, when you program a join, you should ensure that the SELECT clause contains a list of only the columns that you really need. Furthermore, joins bypass the table buffer and read directly from the database. For this reason, you should use an ABAP Dictionary view instead of a join if you only want to read the data.
The runtime of a join statement is heavily dependent on the database optimizer, especially when it contains more than two database tables. However, joins are nearly always quicker than using nested SELECT statements.
thanks
jagan -
SQL Dev Child Reports - Dynamic From Clause Possible?
Hi All,
Trying to figure out this problem:
Master Report SQL:
select TABLE_NAME from USER_TAB_COLS where COLUMN_NAME = 'CREATION_DATE'
Results with some table names. Now I want to use the table name to formulate my child query
Child SQL:
select * from :TABLE_NAME where CREATION_DATE >= SYSDATE-7
or whatever.....but I want to somehow use the table_name dynamically.
Thanks!
-BrentI doubt that you can get dynamic from clause for Child Report if its style is table.
But you can get dynamic one in child with style script:
Say you have :
Master report for list tables which select owner and table name by some condition (I omit this):
SQL : select owner, table_name from all_tables ..So Child Report
SQL is follow:
COLUMN TN NEW_VALUE TNAME ;
select :OWNER||'.'||:TABLE_NAME as TN from dual;
select '&&TNAME' as tab_NAME, count(1) from &&TNAME;Hope it help.
Edited by: K_Serge on Jan 5, 2013 5:10 AM
Edited by: K_Serge on Jan 5, 2013 5:20 AM -
Is it possible to pass a variable in FROM clause in SQL?
Hi Experts,
<i><b>loop at it_db_table.
select field1 from it_db_table-table_name into my_it.
endloop.</b></i>
I mean, Is it pass a variable value to FROM clause in SQL?
I got the info from SAP as,
<i><b>Works like variants 1-3, provided the source_text varialb contains the table name or a join expression as ABAP source text.
Examples
Output of a list of all customers:
DATA tabname(10).
DATA: BEGIN OF wa,
id TYPE scustom-id,
name TYPE scustom-name,
END OF wa.
tabname = 'SCUSTOM'.
SELECT id name INTO CORRESPONDING FIELDS OF wa FROM (tabname).
WRITE: / wa-id, wa-name.
ENDSELECT.</b></i>
thanq.Here is a short sample of a dynamic select statement.
Enter your table name in the parameter on selection screen. Enter you where clause in the select-option on selection screen.
I used.....
MARA
MTART = 'HALB'
report zrich_0004 .
data: xwhere(30) type c.
data: iwhere(30) type c occurs 0.
data:itab(1000) type c occurs 0 with header line.
parameters: p_table(30) type c.
select-options: s_where for xwhere.
loop at s_where.
clear iwhere.
xwhere = s_where-low.
append xwhere to iwhere.
endloop.
select * up to 100 rows into table itab
from (p_table)
where (iwhere).
loop at itab.
write:/ itab.
endloop.
Regards
vasu -
Nested query in FROM clause causes 'SQL Command not properly ended' error
SELECT sj.job_id AS job_id, 'STATUS_AWAITING_PREPARATION' AS job_status, sjr.email_sys_attach_filename AS attach_filename, sje.emailaddr as emailaddr_lastsentto
FROM arsnd_jobs sj, (SELECT emailaddr from ARSND_JOB_EMAILS where job_id=sj.job_id AND ROW_NUM=1) as SJE, ARSND_JOB_QUEUE sjq,ARSND_JOB_RECIPIENTS sjr
WHERE sj.job_id=sjq.job_id and sj.job_id=sjr.job_id
AND sjq.PROCESSING_STATE=0
ORDER BY sj.created
I don't see anything wrong with the above query, it fails with 'SQL Command not properly ended'.
If I remove the usage of the nested query in the FROM clause, then it doesn't give that error. Please advice what I'm doing wrong.Pls try
SELECT sj.job_id AS job_id, 'STATUS_AWAITING_PREPARATION' AS job_status, sjr.email_sys_attach_filename AS attach_filename, sje.emailaddr as emailaddr_lastsentto
FROM arsnd_jobs sj, (SELECT emailaddr from ARSND_JOB_EMAILS where job_id=sj.job_id AND ROW_NUM=1) SJE, ARSND_JOB_QUEUE sjq,ARSND_JOB_RECIPIENTS sjr
WHERE sj.job_id=sjq.job_id and sj.job_id=sjr.job_id
AND sjq.PROCESSING_STATE=0
ORDER BY sj.created
I have removed the 'as' clause you used for alias of the subquery. It should work fine now..... -
How to issue a SQL*Plus command from PL/SQL program?
Thanks.
You can't issue a SQL*PLus command from a PL/SQL program. If you can tell us more about what you are trying to do, perhaps we can offer a substitute.
-
Curious about this From clause in Oracle XE
SQL view of query Builder gives the following:
select "EMPLOYEES"."EMPLOYEE_ID" as "EMPLOYEE_ID",
"EMPLOYEES"."FIRST_NAME" as "FIRST_NAME",
"EMPLOYEES"."LAST_NAME" as "LAST_NAME"
from "EMPLOYEES" "EMPLOYEES"
Why does the from clause showing "EMPLOYEES" "EMPLOYEES"?
In the SQL Commands of the SQL the folowing query
select "EMPLOYEES"."EMPLOYEE_ID" as "EMPLOYEE_ID",
"EMPLOYEES"."FIRST_NAME" as "FIRST_NAME",
"EMPLOYEES"."LAST_NAME" as "LAST_NAME"
from "EMPLOYEES
gives the same result and so does
select "EMPLOYEES"."EMPLOYEE_ID" as "EMPLOYEE_ID",
"EMPLOYEES"."FIRST_NAME" as "FIRST_NAME",
"EMPLOYEES"."LAST_NAME" as "LAST_NAME"
from "EMPLOYEES" "EMPLOYEES"
What is the significence of the second "Employees" in the FROM clause.Other interesting feature is the double quotes
although the one above works as well.
Why is this?Habit.
Some developers come from environments that support mixed case identifiers (table and column names). These developers sometimes go out of their way to force Oracle to use mixed case identifiers, and that requires double quotes.
So Oracle seems to have gotten into the habit of surrounding all identifiers (coming from generated code) with double quotes to keep these developers (who usually have other porting issues anyway) from having to trace those identifier issues. -
Stupid question: whats wrong here? -- Syntax Error in FROM clause
i keep getting the error: Syntax Error in FROM clause.
here is the code:
<%@ page import="java.sql.*" %>
<HTML>
<HEAD>
<TITLE>User Application Area</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:fypproject","","");
Statement st = con.createStatement();
String email = (String)session.getAttribute("email");
String levelStatus = (String)session.getAttribute("levelStatus");
String details = "SELECT PD.Forename, PD.Surname, L.Level_Name FROM PD Personal_Details AND LD Login_Details AND L Level WHERE PD.Email_Address = LD.Email_Address AND LD.Level_ID = L.Level_ID AND Level_ID = '" + levelStatus + "'";
ResultSet rsDet = st.executeQuery(details);
if(rsDet.next()) {
String forename = rsDet.getString("Forename");
String surname = rsDet.getString("Surname");
String level_name = rsDet.getString("Level_Name");
%>
<DIV ALIGN="center"><H1>User Application Arena</H1></DIV>
<BR>
<H4>Welcome back <% out.println(forename + " " + surname); %> </H4>
<BR>
<%
out.println(level_name);
else {
out.println("NOT FOUND ANYTHING");
st.close();
con.close();
%>
</BODY>
</HTML>
the strange thing is when i write a query that doesn't involve the 'Level' table it works fine.
for example if i just want to display the forename and surname from 'Personal_Details' where the Email_Address = email it works fine...as soon as i involve the 'Level' table i get this error.
i basically have 'Level_ID' in the 'Login_Details' table which is found out in the preceding jsp and passed through to this page and i can print out the Level_ID
but....what i want to do is use this Level_ID and find the respective Level_Name in the Level table.
my Level table looks like this:
Level_ID Level_Name
0 Pending
1 Interview
2 Rejection
Thanks :o)Perhaps this is your issue ...
The column Level_ID is in both the Login_Details and Level tables. Therefore, in your WHERE clause, you must specify a table alias for each reference to Level_ID
WHERE PD.Email_Address = LD.Email_Address AND LD.Level_ID = L.Level_ID AND Level_ID = '" + levelStatus + "'";
should be
WHERE PD.Email_Address = LD.Email_Address AND LD.Level_ID = L.Level_ID AND L.Level_ID = '" + levelStatus + "'"; //ADDED "L." before Level_ID
Level_ID would have been unique until you added the Level table.
Good luck.
-Mark -
Construct a Sql block using With Clause to improve the performance
I have got four diff parametrized cursor in my Pl/Sql Procedure. As the performance of the Procedure is very pathetic,so i have been asked to tune the Select statements used in those cursors.
So I am trying to use the With Clause in order to club all those four Select Statements.
I would appreciate if anybody can help me to construct the Sql Block using With Clause.
My DB version is..
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
Four Diff cursors are defined below.
CURSOR all_iss (
b_batch_end_date IN TIMESTAMP,
IS
SELECT isb.*
FROM IMPLMN_STEP_BREKPN isb
, ISSUE iss
WHERE isb.issue_id = iss.issue_id
AND iss.issue_status_id = 50738
AND ewo_no IN
(SELECT TO_CHAR(wo_no)
FROM MGO_PLANT_AUDIT
WHERE dml_status = 'U' OR dml_status = 'I')
UNION ALL
SELECT isb.*
FROM IMPLMN_STEP_BREKPN isb
, ISSUE iss
WHERE isb.issue_id = iss.issue_id
AND iss.issue_status_id = 50738
AND CAST (isb.last_updt_timstm AS TIMESTAMP) >=
b_batch_end_date;
CURSOR ewo_plant ( p_ewo_no IN IMPLMN_STEP_BREKPN.ewo_no%TYPE)
IS
SELECT DISTINCT wo_no ,
plant_code
FROM MGO_PLANT
WHERE TO_CHAR(wo_no) = p_ewo_no;
CURSOR iss_ewo_plnt (
p_issue_id IN IMPLMN_STEP_BREKPN.issue_id%TYPE ,
p_ewo_no IN IMPLMN_STEP_BREKPN.EWO_NO%TYPE,
p_plnt_code IN IMPLMN_STEP_BREKPN.PLT_FACLTY_ID%TYPE)
IS
SELECT *
FROM IMPLMN_STEP_BREKPN
WHERE issue_id = p_issue_id
AND ewo_no = p_ewo_no
AND
(plt_faclty_id = p_plnt_code
OR
plt_faclty_id IS NULL);
CURSOR iss_ewo_plnt_count (
p_issue_id IN IMPLMN_STEP_BREKPN.issue_id%TYPE ,
p_ewo_no IN IMPLMN_STEP_BREKPN.EWO_NO%TYPE,
p_plnt_code IN IMPLMN_STEP_BREKPN.PLT_FACLTY_ID%TYPE)
IS
SELECT COUNT(*)
FROM IMPLMN_STEP_BREKPN
WHERE issue_id = p_issue_id
AND ewo_no = p_ewo_no
AND
(plt_faclty_id = p_plnt_code
OR
plt_faclty_id IS NULL);Not tested. Some thing like below. i just made the queries as tables and given name as a,b,c and substituted columns for the parameters used in the 2nd cursor and third cursor. Try like this.
CURSOR all_iss (
b_batch_end_date IN TIMESTAMP,
IS
select a.*,b.*,c.* from
( SELECT isb.*
FROM IMPLMN_STEP_BREKPN isb
, ISSUE iss
WHERE isb.issue_id = iss.issue_id
AND iss.issue_status_id = 50738
AND ewo_no IN
(SELECT TO_CHAR(wo_no)
FROM MGO_PLANT_AUDIT
WHERE dml_status = 'U' OR dml_status = 'I')
UNION ALL
SELECT isb.*
FROM IMPLMN_STEP_BREKPN isb
, ISSUE iss
WHERE isb.issue_id = iss.issue_id
AND iss.issue_status_id = 50738
AND CAST (isb.last_updt_timstm AS TIMESTAMP) >=
b_batch_end_date) a,
( SELECT DISTINCT wo_no ,
plant_code
FROM MGO_PLANT
WHERE TO_CHAR(wo_no) = p_ewo_no) b,
( SELECT *
FROM IMPLMN_STEP_BREKPN
WHERE issue_id = p_issue_id
AND ewo_no = p_ewo_no
plt_faclty_id IS NULL) c
where b.wo_no = c.ewo_no and
c.issue_id = a.issue_id ;
vinodh
Edited by: Vinodh2 on Jul 11, 2010 12:03 PM -
Is there a way to use dynamic built string in the "from" clause
Hi all, im having one problem and now, im not sure how to solve it easily at all... :) Is there someone that would be so kind and put a eye on it? ..thx
I have plsql proc, in which i have a list of table_names. For each of that table i need to run a query that will retrieve me a list of values and for each of that value i need to do something.
If i can be more specific about the problem -> each of that table is built as key_column, value_columns, day,starttime. For a key per table there are 4 records per hour - every quarter. Im truncating those quarters to full-quarter (minutes => 0->14 = 0min; 15->29 = 15min, 30->44 = 30, 45->59=45)
example
i get for one key and specific hour four records at 15:01;15:16;15:31;15:46 => i truncate em to 15:00;15:15;15:30;15:45..Sometimes there is a problem with the tool that is generating those data for me, and one quarter could be moved a little - so i get data like 15:01;15:16;15:29;15:46 => after i truncate the times i get duplicates in second quarter. It also can happen like this : 23:00; 23:14; 23:29; 23:44; 23:59 => totaly bad => cos the last one supposed to be as 0:00 next day, ..and 23:14 as 23:15...So...that was a problem - and solution -> i wanted to create plsql that will find those hours in each table i ve defined, and for each problem hour i make some fixes - update the bad time ...
..and i have problem - can i put an dynamic built table_name in the "from" clause?
example how i wanted to do that:
declare
type t_objectName is table of varchar2(030) index by pls_integer;
l_tableName t_objectName;
begin
l_tableName(1) := 'tmphlrgl';
l_tableName(2) := 'tmprcfgl';
l_tableName(3) := 'tmprcfbs';
l_tableName(4) := 'tmpvlrgl';
for i in (select evtime from (select day,trunc_quarter(evtime) evtime,m_id from l_tableName(i) group by day,trunc_quarter(evtime),m_id having count(*)>1) order by evtime) loop
--some other conditions and the update...
end loop;
end;
/I cannot use the l_tableName(i) for FROM ...get an error...I was thinking to build it as dynamic sql and execute immediate into some kind of object that can store mutliple lines, from which i would in the FOR cycle get the data...But im not sure if this could be done in plsql...
thanks for your time and help..
d.declare
c sys_refcursor;
begin
for i in 1..4 loop
open c for 'day,trunc_quarter(evtime) evtime,m_id
from ' || l_tableName(i) ||
'group by day,trunc_quarter(evtime),m_id having
count(*)>1) order by evtime';Just to high light SELECT is missing that all
OPEN c FOR ' SELECT day,trunc_quarter(evtime) evtime,m_id
FROM' || l_tableName(i) ||
'GROUP BY day,trunc_quarter(evtime),m_id HAVING count(*)>1) ORDER BY evtime'; -
I have an Script mostly that is generated by SSMS which works with-out issue on SQL Server 2008, but when I attempt to run it on a new fresh install of SQL Server 2012 I get an Msg 8631. Internal error: Server stack limit has been reached. Please look for
potentially deep nesting in your query, and try to simplify it.
The script itself doesn't seem to be all that deep or nested. The script is large 2600 lines and when I remove the bulk of the 2600 lines, it does run on SQL Server 2012. I'm just really baffled why something that SQL Server generated with very
few additions/changes AND that WORKS without issue in SQL Server 2008 R2 would suddenly be invalid in SQL Server 2012
I need to know why my script which is working great on our current SQL Server 2008 R2 servers suddenly fails and won't run on an new SQL Server 2012 server. This script is used to create 'bulk' Replications on a large number of DBs saving a tremendous
amount of our time doing it the manual way.
Below is an 'condensed' version of the script which fails. I have removed around 2550 lines of specific sp_addarticle statements which are mostly just copy and pasted from what SQL Management Studio 'scripted' for me went I when through the Replication
Wizard and told it to save to script.
declare @dbname varchar(MAX), @SQL nvarchar(MAX)
declare c_dblist cursor for
select name from sys.databases WHERE name like 'dbone[_]%' order by name;
open c_dblist
fetch next from c_dblist into @dbname
while @@fetch_status = 0
begin
print @dbname
SET @SQL = 'DECLARE @dbname NVARCHAR(MAX); SET @dbname = ''' + @dbname + ''';
use ['+@dbname+']
exec sp_replicationdboption @dbname = N'''+@dbname+''', @optname = N''publish'', @value = N''true''
use ['+@dbname+']
exec ['+@dbname+'].sys.sp_addlogreader_agent @job_login = N''DOMAIN\DBServiceAccount'', @job_password = N''secret'', @publisher_security_mode = 1, @job_name = null
-- Adding the transactional publication
use ['+@dbname+']
exec sp_addpublication @publication = N'''+@dbname+' Replication'', @description = N''Transactional publication of database
'''''+@dbname+''''' from Publisher ''''MSSQLSRV\INSTANCE''''.'', @sync_method = N''concurrent'', @retention = 0, @allow_push = N''true'', @allow_pull = N''true'', @allow_anonymous = N''false'', @enabled_for_internet
= N''false'', @snapshot_in_defaultfolder = N''true'', @compress_snapshot = N''false'', @ftp_port = 21, @allow_subscription_copy = N''false'', @add_to_active_directory = N''false'', @repl_freq = N''continuous'', @status = N''active'', @independent_agent = N''true'',
@immediate_sync = N''true'', @allow_sync_tran = N''false'', @allow_queued_tran = N''false'', @allow_dts = N''false'', @replicate_ddl = 1, @allow_initialize_from_backup = N''true'', @enabled_for_p2p = N''false'', @enabled_for_het_sub = N''false''
exec sp_addpublication_snapshot @publication = N'''+@dbname+' Replication'', @frequency_type = 1, @frequency_interval = 1, @frequency_relative_interval = 1, @frequency_recurrence_factor = 0, @frequency_subday = 8,
@frequency_subday_interval = 1, @active_start_time_of_day = 0, @active_end_time_of_day = 235959, @active_start_date = 0, @active_end_date = 0, @job_login = N''DOMAIN\DBServiceAccount'', @job_password = N''secret'', @publisher_security_mode = 1
-- There are around 2400 lines roughly the same as this only difference is the tablename repeated below this one
use ['+@dbname+']
exec sp_addarticle @publication = N'''+@dbname+' Replication'', @article = N''TABLE_ONE'', @source_owner = N''dbo'', @source_object = N''TABLE_ONE'', @type = N''logbased'', @description = null, @creation_script =
null, @pre_creation_cmd = N''drop'', @schema_option = 0x000000000803509F, @identityrangemanagementoption = N''manual'', @destination_table = N''TABLE_ONE'', @destination_owner = N''dbo'', @vertical_partition = N''false'', @ins_cmd = N''CALL sp_MSins_dboTABLE_ONE'',
@del_cmd = N''CALL sp_MSdel_dboTABLE_ONE'', @upd_cmd = N''SCALL sp_MSupd_dboTABLE_ONE''
EXEC sp_executesql @SQL
SET @dbname = REPLACE(@dbname, 'dbone_', 'dbtwo_');
print @dbname
SET @SQL = 'DECLARE @dbname NVARCHAR(MAX); SET @dbname = ''' + @dbname + ''';
use ['+@dbname+']
exec sp_replicationdboption @dbname = N'''+@dbname+''', @optname = N''publish'', @value = N''true''
use ['+@dbname+']
exec ['+@dbname+'].sys.sp_addlogreader_agent @job_login = N''DOMAIN\DBServiceAccount'', @job_password = N''secret'', @publisher_security_mode = 1, @job_name = null
-- Adding the transactional publication
use ['+@dbname+']
exec sp_addpublication @publication = N'''+@dbname+' Replication'', @description = N''Transactional publication of database
'''''+@dbname+''''' from Publisher ''''MSSQLSRV\INSTANCE''''.'', @sync_method = N''concurrent'', @retention = 0, @allow_push = N''true'', @allow_pull = N''true'', @allow_anonymous = N''false'', @enabled_for_internet
= N''false'', @snapshot_in_defaultfolder = N''true'', @compress_snapshot = N''false'', @ftp_port = 21, @allow_subscription_copy = N''false'', @add_to_active_directory = N''false'', @repl_freq = N''continuous'', @status = N''active'', @independent_agent = N''true'',
@immediate_sync = N''true'', @allow_sync_tran = N''false'', @allow_queued_tran = N''false'', @allow_dts = N''false'', @replicate_ddl = 1, @allow_initialize_from_backup = N''true'', @enabled_for_p2p = N''false'', @enabled_for_het_sub = N''false''
exec sp_addpublication_snapshot @publication = N'''+@dbname+' Replication'', @frequency_type = 1, @frequency_interval = 1, @frequency_relative_interval = 1, @frequency_recurrence_factor = 0, @frequency_subday = 8,
@frequency_subday_interval = 1, @active_start_time_of_day = 0, @active_end_time_of_day = 235959, @active_start_date = 0, @active_end_date = 0, @job_login = N''DOMAIN\DBServiceAccount'', @job_password = N''secret'', @publisher_security_mode = 1
-- There are around 140 lines roughly the same as this only difference is the tablename repeated below this one
use ['+@dbname+']
exec sp_addarticle @publication = N'''+@dbname+' Replication'', @article = N''DB_TWO_TABLE_ONE'', @source_owner = N''dbo'', @source_object = N''DB_TWO_TABLE_ONE'', @type = N''logbased'', @description = null, @creation_script
= null, @pre_creation_cmd = N''drop'', @schema_option = 0x000000000803509D, @identityrangemanagementoption = N''manual'', @destination_table = N''DB_TWO_TABLE_ONE'', @destination_owner = N''dbo'', @vertical_partition = N''false''
EXEC sp_executesql @SQL
fetch next from c_dblist into @dbname
end
close c_dblist
deallocate c_dblist
George P Botuwell, ProgrammerHi George,
Thank you for your question.
I am trying to involve someone more familiar with this topic for a further look at this issue. Sometime delay might be expected from the job transferring. Your patience is greatly appreciated.
Thank you for your understanding and support.
If you have any feedback on our support, please click
here.
Allen Li
TechNet Community Support -
Difference in behavior of sql and pl/sql after migrating from 9i to 11g
after migrating our database from oracle 9i to oracle11g, the developpers are worry that the behavior of the queries and pl/sql procedures/functions will change
example :
in 9i, select salary,count(*) from emp group by salary, it will display the rows sorted by salary
in 11gi, select salary,count(*) from emp group by salary, it will display the rows not sorted by default, we have to add the clause order by salary.
somebody could give the list of other difference in behavior (SQL and PL/SQL) agter migrating from 9i to 11g
Thanks a lot.Tell your developers: garbage in - garbage out. In relational databases only ORDER BY ensures row order. If your developers relied on GROUP BY implemented by SORT and therefore returning ordered rows they had to realize code they wrote is Oracle release dependent and sooner or later code would require changes. And that "sooner or later" is now reality. In newer versions ORACLE can do GROUP BY via SORT or via HASH. And if it is done via HASH - don't expect ordered results. So tell your developers "payback time".
SY. -
This is a noob question, though I do use SQL Server databases all the time with Entity Framework when I code in C# using Visual Studio 2013. The development environment is found below at [A]. I am trying to make a clone of a SQL Server 2008 R2
database (.mdf) that exists online. I can read, connect and work with this database in Visual Studio 2013, but I wish to make a local copy of the database, as an .MDF file. Somewhere in my notes I have a way of creating a local copy from
an online database when using Visual Studio but I forgot how (it seems, reviewing my notes, that it deals with ADO.NET which is deprecated in Visual Studio 2013 these days, or so it seems). So I'm looking for another way. What I did was create
(or export) a "Data-Tier Application File" from the online SQL Server database, with data, and it seems to have worked in that this Data-Tier Application file exists on my hard drive and seems to have data in it ("SQL Server Replication Snapshot"
is the format it seems). It contains skeleton code to create a database, but when I tried to execute it with SQL Server 2014 Management Studio, I got a bunch of errors.
So my question is:
1) Can I somehow create a .MDF SQL Server Database from an Data-Tier Application file that has data? What tool do I use? I saw this link, http://social.technet.microsoft.com/wiki/contents/articles/2639.how-to-use-data-tier-application-import-and-export-with-a-windows-azure-sql-database.aspx
and it relates to Azure, but is there a tool for C#Visual Studio 2013, standalone?
2) If there's an easy way to create a .mdf SQL Server Database file from an online file, within SQL Server Management Studio? I don't think so, since it would require Administrator permissions on the online server, which I don't have. I have permission
to read, update, delete the online database file, but strangely not to download it (the service I use has a tool for backup, but not for download).
3) same question as 2), but for Visual Studio 2013? I don't think so, since I notice none of the templates even mentions ADO.NET anymore, but instead they go with Entity Framework. Using EF I can of course do anything I want with the online database
(CRUD), but it remains online. Maybe there's a switch to make a local copy? I guess I could write a short program to suck all the data out of the online database and put it into a new, duplicate database having the same tables, that I create on
my localhost, but my question here is if there's an easier way than this, maybe a tool or command I can run from inside Visual Studio?
Any advice on any of the above questions is appreciated.
Thank you,
Paul
[A] Microsoft Visual Studio Professional 2013
Version 12.0.21005.1 REL
Microsoft .NET Framework
Version 4.5.51641
Microsoft Web Developer Tools 2013 2.0.40926.0
SQL Server Data Tools 12.0.30919.1
Microsoft SQL Server Data Tools
Windows Azure Mobile Services Tools 1.0
Windows Azure Mobile Services ToolsThanks but these links are too general to help.
"2. what do you mean by online file?" - I mean the SQL Server database file is on a remote web server that I rent from, but I am not the administrator of. I can access my database using SQL Server Authentication, but nothing more.
Paul
What do you mean by too general? It explains on how you can use data tier application to create and deploy databases
May be this will help you to understand better
http://www.databasejournal.com/features/mssql/article.php/3911041/Creating-Data-Tier-Applications--in-SQL-Server-2008-R2.htm
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
CAN I PASS A TABLE NAME AS A VARIABLE IN THE FROM CLAUSE?
For some reason, I am trying to use a variable name containing the actual table name in the from clause and it won't allow me. I keep getting the error saying I need to declare the variable I'm using eventhough I've used it in another statement that is not the FROM clause.
Example
SELECT count(col1), sum(col2)
FROM v_table_name;
v_table_name was declared as:
v_tablename VARCHAR2(20);
v_tablename := real_table_name;
Is it not allowed to use variables in the FROM clause or am I missing something here?You can use the Forms "From Clause Query" as the datasource for the data block. Then you can change the QUERY_DATA_SOURCE_NAME using set_block_property, so you can use any SQL statement you like. Of course you must name/alias the columns in a consistent manner so that the number of database items on the block matches those being queried.
-
Unable to connect to SQL Server 2008 from OBIEE 11G(on 64 bit Linux box)
We are unable to connect to connect to SQL Server 2008 from OBIEE 11G which is on 64 bit Red Hat Enterprise Linux.
Infrastructure: OBIEE 11.1.1.5 64bit, on 64 bit Red Hat Linux Enterprise Linux 5.6 , MS SQL Server 2008 on 64 bit Microsoft Windows Server
Issue Description: Unable to connect to SQL Server 2008 from OBIEE11G RPD
Details: We are unable to connect to SQL Server 2008 from OBIEE which is on a 64 bit Linux box. We created the ODBC connection on Linux box to the SQL server. Whenever we try to import metadata it throws an error that says ‘Connection Failed’.
Here are the steps we followed to setup the ODBC connection on Linux box.
1) We updated the user.sh file with the LD_LIBRARY_PATH and LD_LIBRARY_PATH_64 values that point to $ORACLE_HOME/bifoundation/odbc/lib
This is where we found the driver for SQL server SEmsss23.so.
2) We updated the odbc.ini file with the entry for SQL server with the connection details
SI_SQL_Server_DEV = SQL Server
[SI_SQL_Server_DEV]
Driver=/u001_OAS/Oracle/Middleware/Oracle_BI1/bifoundation/odbc/lib/SEmsss23.so
Description=DataDirect 5.1 SQL Server Wire Protocol
Address=10.230.216.52,54970
AlternateServers=
AnsiNPW=Yes
ConnectionRetryCount=0
ConnectionRetryDelay=3
Database=SVBDW_NEW
LoadBalancing=0
LogonID=SIDatavalidation
Password=~~~Password123
QuoteID=No
ReportCodePageConversionErrors=0
3) We updated the IDENTIFIER_QUOTE_CHAR with single quotes instead of double quotes in the DB features of the RPD
4) We updated the bash_profile file to point the ODBCINI variable to the path where the OBIEE odbc.ini file is present.
Export ODBCINI=/u001_OAS/Oracle/Middleware/instances/instance1/bifoundation/OracleBIApplication/coreapplication/setup/odbc.ini
The error in nqsserver.log file says “[nQSError: 16001] ODBC error state: IM002 code: 0 message: [DataDirect][ODBC lib] Data source name not found and no default driver specified.”Hi,
Make sure SQL Configuration Manager make sure the TCP/IP enabled. please try below method
Method 1
Re Create a new ODBC & Oracle Bi Server DSN Configuration test it and use it in the connection pools.
define your ODBC data source in your server where the BI Server is installed. Check your DB connections in your physical layer and make they are defined on your BI Server as well.
Method 2:
try using the complete TNS in below format in the datasource name section:
(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (HOST =DB IP)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = ORCL) ) and provide the credentials.
Method 3:
To use the OCI call interface you need to have oracle client DB to be installed so that you can establish a connection using that DB credentials and connect to the remote dB and then import the tables.....this is the rule of thumb.
hope helps you.
Thanks
Deva
Maybe you are looking for
-
Km component portal runtime error
hi i am creating a simple km application to create a folder using km api when i run the application it is displaying runtime error in the portal any help on this here is the trace . [EXCEPTION] #1#com.sapportals.portal.prt.component.PortalComponent
-
Re:Software Connection abort:software write error.
Hi Guys, I am developing a chess game portal in which a client and remote can play the chess game.while connecting the server and getting the values from the server After writing the data i am getting this error Software Connection abort:software wri
-
Stock transfer to physical bins from 998 storage type
Dear Experts, As part of data conversion,After loading huge stock into SAP 998 st type into INITIAL bin,I want to move the stock into physical bins.I have SU management activated. 1)During the initial upload to 998 , I have taken Material slip field
-
FOR UPDATE OF table.field
Why does the following not work create table division (code varchar2(2) primary key, div_desc varchar2(20)); insert into division values ('01', 'Ninja assassins'); insert into division values ('02', 'Working for the man'); create table employees (tk
-
In New GL we have " define document types for entry view in a ledger" and " define document types for a general ledger view in a ledger". It says, we have define different document types if the fiscal year variant is different for a non leading ledge