Fetching data through a python application from a table throws me this error:
cx_Oracle.DatabaseError: ORA-00942: table or view does not exist. I have verified the schema and table name.
cur = cursor.execute('SELECT * FROM SYS.STUDENT_RECORDS')
However, the application fetches data from the system table.
cur = cursor.execute("SELECT * FROM TAB_STATS$ WHERE ROWNUM <= 10")
Here is the connection string:
dsn_tns = cx_Oracle.makedsn(ip, port, SID)
connection = cx_Oracle.connect(user='username', password='****',dsn=dsn_tns)
I am assuming it has got to do something with the user permission, but not quite getting it right. I don't have much experience with Oracle DB. Any help would be highly appreciated.
#kaushik #krokodilko, your guidance helped me arrive at the following solution:
Created new user and granted privileges.
Changed connection string to use service name instead of SID.(don't know why SID didn't work though)
dsn_tns = cx_Oracle.makedsn(ip, port, service_name=service_name)
cur = cursor.execute("SELECT * FROM user1.STUDENT_PROFILES WHERE ROWNUM <= 10")
Related
My script on SQL dev:
**CREATE USER C##DG IDENTIFIED BY abc123;**
**CREATE VIEW DG1_VIEW**
AS SELECT m_pms.MaPMS, m_pms.MaDG, m_pms.SoLuong, m_s.MaSach, m_s.TenSach, m_ctpm.SL
FROM PhieuMuonSach m_pms, ChiTietPhieuMuon m_ctpm, Sach m_s
WHERE m_pms.MaDG = 1 AND m_pms.MaPMS = m_ctpm.Ma_PMS AND m_ctpm.Ma_Sach = m_s.MaSach**;**
**GRANT CREATE SESSION TO C##DG;
GRANT SELECT ON DG1_VIEW TO C##DG;**
On Sql Plus, i logged in as C##DG, typed '''SQL> SELECT * FROM DG1_VIEW;'''
and received 'ORA-00942: table or view does not exists'. But this view already had data.
What is my problem and how to fix it? I'd love to hear from you guys.
You need to either specify schema this view has been created in
select * from system.dg1_view;
or you may login as system again and create a public synonym for that view in order to make it available without specifying schema
This is an oracle system. I have a client table (one) and an account table (many). Frankly, I really just want to query the client table but due to poor design, there is a data element that I need for the client table that is only present on the account table - it will be the same value for all accounts for that client so I really just need to return one account row but I'm having problems accomplishing this. Here is the query I tried:
Select
c.client_num,
c.client_name,
a.agency_value
from client c
inner join account a on c.client_num = a.client_num
where a.account_num in (select a2.account_num from account a2 where rownum = 1)
You need to explicitly designate how to pick one record out of many. Here's one method - use MAX
Select
c.client_num,
c.client_name,
(SELECT
MAX(a.agency_value) agency_value
FROM account a
where c.client_num = a.client_num
-- not sure if this line is required - if not please remove
and a.account_num in (select a2.account_num from account a2 where rownum = 1)
) agency_value
from client c
Keep in mind that by implementing this you are "cementing" your bad table design.
Are you absolutely certain that there is only ever one agency_value? use query to find any clients that have more than one agency:
SELECT
a.client_num,
COUNT(DISTINCT a.agency_value) CountOfAgencyValues,
MAX(a.agency_value) max_agency_value,
MIN(a.agency_value) max_agency_value
FROM account a
GROUP BY a.client_num
HAVING COUNT(DISTINCT a.agency_value) > 1
With your input and doing some playing around on my own, here is the code that ultimately addressed my need:
select
c. client_num,
(select a.agency_value
from account a
where a.client_num = c.client_num
and rownum = 1)
from client c
I have a 'customer' table and I am trying to get a record using Laravel Eloquent using the customer's id:
Customer::where('customer_id', '=', $customer_id)->get();
However, when this gets executed I check the MySQL logs and I get:
Prepare select `kanji_name` from `customer` where `customer_id` = ?
Close stmt
Quit
As you can see, there is no 'Execute ...' log which should be present of the query was executed after preparing it.
I also tried:
Customer::find($customer_id);
with the same result.
Does anyone know the reason why?
can you do this
$cust = Customer::where('customer_id', '=', $customer_id)->get();
dd($cust);
Sorry, not enugh reps to comment. What's DD output?
It seems there is some form of caching that is happening either on the Eloquent side or MySQL side (possibly on MySQL side).
I restarted my MySQL server and found that on my first try, I get
Prepare select * from `customer` where `customer_id` = ?
Execute select * from `customer` where `customer_id` = '4058'
Close stmt
Quit
While on succeeding tries, I get:
Prepare select * from `customer` where `customer_id` = ?
Close stmt
Quit
only.
I have weird problem with my sql azure database on the live server. The MVC controller is returning an errors as "The wait operation timed out" and Sqlexpection (0x80131904): Timeout expired".
This is happening particularly on a single a sql stored procedure. The program is that if run the stored procedure with same parameter against the database using SMSS 2012 it runs fine and returns returns in less 2 seconds.
This lets me that there is nothing wrong with my stored procedure.
I am calling the stored procedure as below.
List<FileFolderItem> folders = new List<FileFolderItem>();
using (DFModel db = new DFModel())
{
folders.AddRange(
db.GetFolderStructure(companyId, (clientid ?? companyId), folderId, currentUser.df_userId).Select(x => new FileFolderItem
{
Name = x.name,
Id = x.id,
Flags = "USER_FOLDER",
TotalFiles = x.Files.Value,
TotalSize = x.Size.Value
}).ToList<FileFolderItem>()
);
return folders;
}
I have done further test by taking a backup of the database and restore on the same sql azure instance as seperate new database and pointing my application connection to the backup db and the application works.
I don't understand how should I troubleshoot this problem, there no way to restart the sql azure instance.
Any help will be highly appreciated.
Thanks
Edited on 13/03/2013
After further investigation - the problem seems to be with Table-Valued function (getfilesbyclaims) called from sub-procedure GetFolderTotalSize. Is this functions are not fully supported. The strange thing is that the application did go live about 4 weeks ago and this problem suddenly started yesterday # 4pm.
CREATE PROCEDURE [dbo].[GetFolderStructure]
#companyid int,
#clientid int,
#folderid int,
#personid int
AS
SELECT
fd.id,
fd.name,
dbo.getfoldertotalfiles(#companyid, #clientid, fd.id, #personid) AS Files,
--0 as Files,
dbo.getfoldertotalsize(#companyid, #clientid, fd.id, #personid) as Size
--0 as Size
FROM folders fd
WHERE fd.companyid = #companyid
AND fd.root_id = #folderid
AND (fd.hidden IS NULL OR fd.hidden = 0)
Sub-Procedure - GetFolderTotalFiles
ALTER FUNCTION [dbo].[GetFolderTotalSize]
(
#companyid int,
#clientid int,
#folderid int,
#personid int
)
RETURNS INT
AS
BEGIN
DECLARE #size int;
DECLARE #tblFiles TABLE (
Id uniqueidentifier not null,
CompanyId int,
folderid int,
contentLength bigint
);
INSERT INTO #tblFiles(id, companyid, folderid, contentlength)
SELECT * FROM dbo.getfilesbyclaims(#clientid, #personid);
WITH Folder_CTE as (
select fs.* FROM folders AS fs
where companyid = #companyid
AND id = #folderid
UNION ALL
SELECT f.* FROM folders f
INNER JOIN Folder_CTE fcte ON fcte.id = f.root_id)
SELECT #size = ISNULL(SUM(f.contentlength), 0) FROM folder_cte fd
INNER JOIN #tblFiles f ON f.folderid = fd.id
where f.companyid = #clientid
return #size;
END
GO
I am reading data from Oracle database by using ODP.Net with the follwing code
OracleConnection con = new OracleConnection(connectionString);
OracleCommand cmd = new OracleCommand( SELECT ID,RECORD(XMLType) FROM tbl_Name, con);
con.Open();
OracleDataReader _dataReader = cmd.ExecuteReader();
while (_dataReader.Read())
{
string rowId = _dataReader[0].ToString();
string xmlString = _dataReader[1].ToString();
adding this data into Queue for further processing
}
It working fine but in a minute it's reading only 10000 record. If I use SqlServer database it's reading 500000 record in minute having table with same schema.
Please help me if I am missing something to read data faster using ODP.NET
Thank you.
**
ANSWER:
**
I have tried with GetClobVal() and GetString Val() functions, now it is working fine.
select t.RECID, t.XMLRECORD.GetClobVal() from tableName t"
select x.RECID,x.XMLRECORD.getStringVal() from tableName x"
If we use these queries with oracle command it will run fast, but not as fast as sql server query.