Impossible to connect to sql State = s1000
Impossible to connect to sql State = s1000Ora Oracle - odbc - 28000: account is locked
This happened when a user connecting to test the connection.
can anyone solve this problem?
Question: The user accordingly entered wrong password for the maximum number of times specified by the parameter of the FAILED_LOGIN_ATTEMPTS user profile, or the ADMINISTRATOR has blocked the account
Action: Wait at PASSWORD_LOCK_TIME or contact DBA
http://www.DBA-Oracle.com/sf_ora_28000_the_account_is_locked.htm
or
If you have sysdba privileges: -.
connect sysdba virtue
change the user name user account unlock;
where username is the user name that was trying to connect for test.
Published by: varun4dba on January 10, 2011 18:53
Tags: Database
Similar Questions
-
Wandering SQL Native Client Datasource - apparently, it's a pretty common problem and I see several resolutions to it. This problem started for our long company until I started working here. We do not allow remote connections. JDE Enterprise Server and SQL server are on the same subnet. Users are on a different subnet. SQL Server gets this message tries to connect to the Server Enterprise JDE:
Connection failed: State 08001 ' SQL': SQL Server Error 10061: Microsoft SQL Native Client TCP provider: no connection could be made because the target machine actively refused it.
I tried several suggested solutions and do not get the case. Any help is appreciated. Thank you, Sophie
Hello
The issue of Windows XP, you have posted is better suited for the IT Pro TechNet public. Please ask your question in the SQL Serversupport for assistance.
Hope the helps of information.
Concerning
Joel S
Microsoft Answers Support Engineer
Visit our Microsoft answers feedback Forum and let us know what you think. -
KB2760411, KB2760588, but now "can NOT CONNECT to" SQL Server!
Today I faced with the same Windows Update problems as many people - with KB2760411 and KB2760588 constantly reinstall - and try to resolve which included several reboots - system
())BUT now... a serious problem on one of these machines: cannot access SQL Server!
Fortunately, I did not run these updates on any * production * machines (I do updates on development machines, first) - this is a development machine - but I still need to get working SQL Server of this machine!I tried to use a Windows login to connect and tried to use a SQL Server to connect user, and what it in either, looks like the same message:
"Cannot connect to."
A network-related or instance-specific error all by establishing a connection to SQL Server. The server is not found or inaccessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - could not open a connection to SQL Server) (Microsoft SQL Server, error: 2)Note that for windows, this server running Server 2003 (this is why I chose the value of the drop down menu 'windows xp', below).
and for sql server, run SQL Server 2005.Help!?
ALSO NOTE: I KNOW THIS ISN'T A "NETWORK ERROR."
because I get the same message when I remote desktop on the server and try it.
I did try to look in the windows Server 2003 event viewer, but saw nothing relevant under the security, system or Application.When I tried it with a sql server login, I clicked on "Show technical details" and got the below (blank lines removed and replaced with
the name of the server): ===================================
Unable to connect to.
===================================
A network-related or instance-specific error all by establishing a connection to SQL Server. The server is not found or inaccessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - could not open a connection to SQL Server) (.Net SqlClient data provider)
------------------------------
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=2&LinkId=20476
------------------------------
Error number: 2
Severity: 20
State: 0
------------------------------
Location of the program:
at System.Data.SqlClient.SqlInternalConnection.OnError (SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning (TdsParserStateObject stateObj)
to System.Data.SqlClient.TdsParser.Connect (ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Int64 timerExpire, Boolean ignoreSniOpenTimeout, encrypt Boolean trustServerCert, Boolean, Boolean integratedSecurity, SqlConnection owningObject)
to System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin (ServerInfo serverInfo, String newPassword, ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject, Boolean)
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover (String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist (SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
to System.Data.SqlClient.SqlInternalConnectionTds... ctor (DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection (DbConnectionOptions options Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection (DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection (DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection (DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open)
to Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.ObjectExplorer.ValidateConnection (UIConnectionInfo above, IServerType server)
at Microsoft.SqlServer.Management.UI.ConnectionDlg.Connector.ConnectionThreadUser)Thanks Nirmal for the acknowledgement of receipt.
As you can see, we ended up find us the answer.
(BOWL is not same document how to grant "Log on as a service", under Server 2008 R2, WHEN ON THE DOMAIN CONTROLLER.) BOWL documents which fully Server 2003, but only partially for Server 2008 R2.)But we are not given the opportunity to "mark as answer" on our own solution.
If YOU think that the INFORMATION we posted had value, YOU may mark as answer.The TechNet link:
Unable to connect to SQL Server... (includes advice in response: measures to grant permissions in Active Directory, the domain server * RUNNING SERVER 2008 R2 *).Thanks again.
-
'Impossible to connect with the activation server' while trying to activate Windows 7
Stater of the i run windows 7 on a laptop dell inspiron N5050 32-bit, windows asks me to re-enter my product key each tome I get it it displays after loading: impossible to connect with the activation server, see other ways to activate windows, pls make serious saying my trial period has expired why it cannot connect to the server to check the product key? Help, please
Original title: activate windows
Have you tried to restart by phone?
How to activate Windows 7 manually (activate by phone)
1) click Start and in the search for box type: slui.exe 4
(2) press the ENTER"" key.
(3) select your "country" in the list.
(4) choose the option "activate phone".
(5) stay on the phone (do not select/press all options) and wait for a person to help you with the activation.
(6) explain your problem clearly to the support person.
http://support.Microsoft.com/kb/950929/en-usPlease run the Microsoft Genuine Diagnostics Tool then copy and paste the results into an answer here for further analysis:
http://go.Microsoft.com/fwlink/?LinkId=52012 -
Failed to connect to the user when it connects to SQL Server 2008 R2 gateway
Hi - This is my first post!
I have problems to connect to a SQL Server 2008 R2 to Oracle database 11 g R2 database, use the product of the gateway.
Previously, he has worked, but we moved the database SQL 2005 to 2008 (R2).
We receive this error while trying to query through the link (Select * FROM DUAL@ADSRD)
ORA-01017: name of user and password invalid. connection refused
[Oracle] [ODBC SQL Server driver] [SQL Server] Failed to connect to the user 'SQLUSER '. {NativeErr 28000, = 18456} [Oracle] [ODBC SQL Server driver] Invalid connection string attribute {01 S 00}
ORA-02063: preceding 2 lines of ADSRD
01017 00000 - "invalid username/password; connection refused '.
* Cause:
* Action:
Error on line: 1 column: 35
The DG4MSQL configuration is here:
HS_FDS_CONNECT_INFO = //SSU_PRD_APP/IntegrationStagingDb [BSYS-sql2]
HS_FDS_TRACE_LEVEL = OFF
HD_TRANSACTION_MODEL = READ_ONLY
#HS_FDS_DELAYED_OPEN = FALSE
HS_FDS_FETCH_ROWS = 100
HS_OPEN_CURSORS = 50
The database is hosted in its own instance on the sql2-BSYS Server
Then... on the SQL Server event logs returns this:
Failed to connect to the user 'SQLUSER '. Reason: Failed to try to connect using SQL authentication. Server is configured for Windows authentication only. [CLIENT: 192.168.10.179]
However, the SQL Instance IS configured to enable mixed mode authentication.
I can't work on what I missed, and I can confirm if I'm actually to a compatibility issue between the gateway and the version of SQL server, that we are now trying to connect.
Help please!
Is the user name in your SQL Server database in the capital, mixed mode letters or small letters?
Currently, you have created a database link that tries to authenticate on the server SQL using SQLUSER in capital letters. If you use mixed or small letters, so be sure to write the user name (and password) as it is in the create database link statement and surround it with double quotes.
If you have created the link of database correctly, try an ODBC connection for example from your client and add the user name and password. Does it work?
-Klaus
-
Try to run a SQL statement through the window of OEM 12 c run SQL. Statement fails
All,
I have a 11g database. When it is initially installed, I installed it in $ORACLE_BASE = / orabin/app/oracle/product and $ORACLE_HOME = $ORACLE_BASE/11gDB_R2. This is the version 11.2.0.1 to give birth to 11.2.0.3.
Recently, I installed 11.2.0.4 in $ORACLE_BASE/11.2.0.4. Then, I upgraded my database at 11.2.0.4. Everything works fine.
All my scripts on the linux host logon changed to point my environment at $ORACLE_BASE/11.2.0.4 House and my $PATH when I connect to the linux host is: /orabin/app/oracle/product/11.2.0.4/bin:/orabin/app/oracle/product/11.2.0.4/OPatch:/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/oracle/bin
On my OEM Console, the database appears as 11.2.0.4 and me can manage very well.
However, when I try to use the window of the OEM Console to execute SQL to execute any type of SQL statement, it fails.
The failure error is:
Could not launch/orabin/app/oracle/product/11gDB_R2/bin/sqlplus-s/nolog: no such file or directory
It would be a mistake since the 11gDB_R2 directory tree (the 11.2.0.3 software) has been removed from the host, now that the database is set to level and working as 11.2.0.4.
I wonder if somewhere in the OEM software, there is always a pointer to the old ORACLE_HOME? I can't find anything in the .bashrc or other shell scripts that are executed when a Shell session on the host computer which were still the reference to the old directory of 11gDB_R2 so I'm a bit puzzled.
I have 8 guests, and all have been improved in the same way at 11.2.0.4. For some databases, the OEM window run SQL is executing the SQL code.
Someone has some ideas on this?
Go to the Configuration of the analysis of the database (when you set the password) and update of the Oracle home. Also do this for all targets listener on this host as well.
-
SQL * PLUS connects with SQL >; question
People,
I'm confused on the command. / sqlplus with Oracle database.
According to my understanding,. / sqlplus connected with SQL > using option 3: sysdba, sysoper, sysasm.
I connect with SQL > to run the rel853.sql script to create a table PSOPRDEFN but a field "OPERPSWDSALT" did not appear in the table PSOPRDEFN although it is in the Create Table statement.
I connect with SQL * in the directory/home/user/OracleDB_Home/bin as below:
$ export SYSTEM_PASS = AccessId/mypass$ export ORACLE_HOME = / home/user/OracleDB_Home
$ export ORACLE_SID = HRCS90
$. / lsnrctl start LISTENER
$. / AccessId/mypass sqlplus as sysdba
SQL > startup
SQL > @/opt/PT8.53/scripts/rel853.sql
SQL > select OPERPSWDSALT in the AccessId.PSOPRDEFN;
It returns: "OPERPSWDSALT": invalid identifier.
I checked the table PSOPRDEFN that the OPERPSWDSALT field did not appear in the table PSOPRDEFN.I tried the sysoper option as below:
$. / sqlplus AccessId/mypass as sysoper
SQL > startup
SQL > @/opt/PT8.53/scripts/rel853.sql
SQL > select OPERPSWDSALT in the AccessId.PSOPRDEFN;
It returns: "OPERPSWDSALT": invalid identifier.
The sysoper error is the same thing with sysdba error.
I tried the sysasm option as below:
$. / sqlplus AccessId/mypass as sysasm
He returned: connection refused.
Someone told me this connection as SYS causes this error. If not a sysdba, sysoper, or sysasm, use the command. / sqlplus AccessId/mypass cannot connect with SQL >.
My question is:
First of all, why is what OPERPSWDSALT did not appear in the PSOPRDEFN table while it is in the CREATE TABLE statement?
Seocond, if not use SYS which is one of the 3 options, how to run the command. / sqlplus AccessId/mypass to connect with SQL > so that CREATE TABLE PSOPRDEFN correctly?Thank you.
user8860348 wrote:
People,
Hello. Thanks much for the reply. I just do the commands below:
$ export SYSTEM_PASS = AccessId/mypass
$ export ORACLE_HOME = / home/user/OracleDB_Home
$ export ORACLE_SID = HRCS90
$. / lsnrctl start LISTENER
$. / AccessId/mypass sqlplus as sysdba
SQL > show user;
Its release: the USER is "SYS".
SQL > connect AccessId/mypass
Its output:
Error: ORA - 01034:ORACLE not available
ORA-27101: shared memory realm does not exist
64 - Linux_x86 error: no such file or directory.
As we see above, unable to connect to the Oracle database AccessId.
My question is:
What to do on AccessId, so that it can connect to the Oracle database?
Thank you.
so much for the use that you refuse to actually use COPY it PASTE & so that we can see the whole session.
In the past, you did
> SQL > startup
Maybe the database is out of order & must be started.
do exactly as below (line by line)
ID
sqlplus
/ as sysdba
startup
connect AccessId/mypass
COPY the results from above then PASTE all back here
-
How to 'show' a static pseudo index using SQL statement select?
Hello again,
I have to post a time of 24 hours as an index. (00:00 - 23:00)
It's easy, if data are available.
But, if the data are not regularly exist on specific time (the time is not regular, IE: 00:00, 01:00, 05:00, 08:00, 10:00, 11:00, 23:00), then it of OK for a TABLE, but not for a CHART.
Here is the story:
I've written a SQL statement that can 'choose' what to display respectively the time available. The result will appear on the map: days or the time is used for the x-axis and the respective value on axis y.
Example:
+ If the data consists of 'days' (ie: the last 5 days from now on, 16/07/2012, 17/07/2012, 18/07/2012, 19/07/2012, 20/07/2012), the chart will display these dates on the x-axis.
+ If the data consists of 'hours' (ie: only 1 day, hour 00:00 - 23:00), then the chart shows the hours on the x-axis.
If the 'hours' are not regular, means: there is no data on the specific hours, the result of the query is not as regular, average: the value of X - axis "jumps" irregularly.
Question:
Is it possible to interrogate our own static value?
for example:
Select 'Hello' from dual-> result: 'Hello', 1 column, 1 line
But how to display it into several lines, i.e.:
Time
*****
0
1
2
3
4
5
...
...
23
Note:
the x-axis on the graph model can be customized only for 1 single mode, example: 'Days',
but of course it will not appear correctly if the result of the query are "hours."
This means: I have to find the workaround on the SQL query.
DB: ORA 11
Thank you and best regards.You can generate mulltiple rows if you use LEVEL and CONNECT BY:
SQL> select level 2 from dual 3 connect by level <= 10; LEVEL ---------- 1 2 3 4 5 6 7 8 9 10 10 rows selected. SQL> select sysdate+level-1 2 from dual 3 connect by level <= 10; SYSDATE+LEVEL-1 ------------------- 20-07-2012 12:48:26 21-07-2012 12:48:26 22-07-2012 12:48:26 23-07-2012 12:48:26 24-07-2012 12:48:26 25-07-2012 12:48:26 26-07-2012 12:48:26 27-07-2012 12:48:26 28-07-2012 12:48:26 29-07-2012 12:48:26 10 rows selected. SQL> select to_char(trunc(sysdate), 'hh24')+level-1 2 from dual 3 connect by level <= 24; TO_CHAR(TRUNC(SYSDATE),'HH24')+LEVEL-1 -------------------------------------- 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 rows selected.
-
11g connects to SQL server... character display problems
Hi gurus,
DB: 11.2
OS: redhat 5.5
There is a problem during display of character with sqlplus and even worse on TOAD, SQL Developer tool.
There is a heterogeneous connection between 11g and ms sql serever. I use freedts, unixodbc and dg4odbc to connect.
using tool isql... the select statement has been well formatted... See example || USIM sales |
| Charge accrued on debt RespriseBUT when I use sqlplus some characters are broken... Please see sample
in other client tool for example, TOAD, the output is worse just see the only the first character of each line for example
COST_NAME
V e n s e t U S I M
R e s p r e s i d e c h a r g e p r o v I s I o e n s e n s u r v e r
a, c e nV
I tried the value for nls_language in french and English but do not solve the problem.
R
anyone with a clue of what is wrong or a bug?... 1 million .thanksPL do not post duplicate topics - character display problems... 11g connects to SQL server
-
I am trying to get into the application of SQL/Plus and it is not letting me using my old user id and the password I created when I was installing the 10 g and create the database. I use my e-mail address and password and it does not.
Use the password "MANAGER"? I don't know which username to use. Thank you893027 wrote:
So you're saying that I should not use the SYSTEM as my username?It's exactly what I'm saying.
This is purely for my class and I am learning to create the Oracle database.
So what? You develop bad habits now, you will continue to propegate poor procedures in the future.
How can we establish a different username next to the SYSTEM?
Find it in the documentation.
Go to tahiti.oracle.com
Explore your selected product and version.
You can find full documentation for the product and version.
Because your product is the RDBMS, one of the manuals of the primaries in this documentation set will be titled (drum roll, please)... SQL reference guide.
You will find useful SQL statements like CREATE USEROK, now for some lights.
In the world of Oracle all objects must be owned by a user. A common practice in the real world is to create a specificallly to the user in order to have the objects that are required by an application. Let's say I develop application of purchase orders. I would create a user - call PURORD - specifically to own all the tables, indexes, procedures, etc., necessary for the application of the purchase order. And let's say I have a buyer in the Department of the purchaseing from my company (a user of the application of purchase order) named Joe Snuffy. For him, I'll create a user named JOESNUFFY. Oracle is concerned, there is no fundamental difference between PURORD and JOESNUFFY. It's all in the privileges I have as a dba to grant these user accounts. My PURORD user might not get privileges at all - not even CREATE SESSION (you can look upward in the game of the doc I mentioned you). Or I can give him CREATE TABLE, etc., but few things. User JOESNUFFY will get CREATE SESSION and SELECT, UPDATE, DELETE, INSERT on the tables belonging to PURORD, but will not get object privileges CREATE. Joe will connect to the database (through the application) with its JOESNUFFY account.It is also a common practice to give human DBA user accounts, real on their part with the role DBA who they are conferred. In this way, they work under their own name. They can be checked. They don't accidentally create objects in the SYSTEM tablespace.
This may seem excessive for a class situation, but if you don't develop good habits now, you carry bad habits in the workplace and he don't even know until you have opened the way to hell of DBA.
-
How to run multiple sql statements
Hi all
I wonder if I can run multiple sql statements in one shot with > >, immediate run
for example:
I set the variable as X: = sql statement
Y: = sql statement
z: = sql statement
can I execute immediate (X, Y, Z);
If yes how? and if not what other possible
Thank youBeginning with the codes of Ganesh
DECLARE l_statement VARCHAR2 (2000); v_passwd VARCHAR2 (200); v_username VARCHAR2 (200) := 'test'; v_pwd_key VARCHAR2 (200) := 'lwty23'; v_dblink_name VARCHAR2 (2000); v_dblink_drop VARCHAR2 (2000); v_dblink_create VARCHAR2 (2000); v_dblink_check_connection VARCHAR2 (2000); l_number NUMBER; BEGIN --<
> FOR c_instance IN (SELECT * FROM v_oracle_instances WHERE environment = 'Developement') LOOP SELECT encpwd_owner.display_db_encpwd (v_username, c_instance.host_name, c_instance.instance_name, v_pwd_key) INTO v_passwd FROM DUAL; v_dblink_name := c_instance.host_name || '_' || c_instance.instance_name; v_dblink_create := ' CREATE DATABASE LINK ' || v_dblink_name || ' CONNECT TO ' || v_username || ' ' || 'IDENTIFIED BY ' || v_passwd || ' USING' || ' ''(DESCRIPTION= (ADDRESS=(PROTOCOL=TCP)(HOST= ' || c_instance.host_name || ')(PORT=' || c_instance.LISTENER_PORT || '))(CONNECT_DATA=(SID=' || c_instance.instance_name || ')))'''; v_dblink_check_connection := 'select 1 from global_name@' || v_dblink_name || '.QCM'; --- Notice this change. I am simply selecting 1. That should be enough to test the database link. v_dblink_drop := 'drop database link ' || v_dblink_name || '.QCMTLAF'; -- l_statement := 'BEGIN ' || v_dblink_create ';' || v_dblink_check_connection ';' || v_dblink_drop '; END ;' BEGIN EXECUTE IMMEDIATE (v_dblink_create); DBMS_OUTPUT.PUT_LINE ('DB Link ' || v_dblink_name || ' Created'); EXCEPTION WHEN others THEN dbms_output.put_line( 'Failed to create the database link ' || v_dblink_name ); dbms_output.put_line( dbms_utility.format_error_backtrace() ); INSERT INTO error_table( column_list ) VALUES( < - > );
END;
EXECUTE IMMEDIATE (v_dblink_check_connection) INTO l_number; --- Notice this.
DBMS_OUTPUT.PUT_LINE ('DB Link ' || v_dblink_name || ' Tested');
BEGIN
EXECUTE IMMEDIATE (v_dblink_drop);
DBMS_OUTPUT.PUT_LINE ('DB Link ' || v_dblink_name || ' Dropped');
EXCEPTION
WHEN others THEN
dbms_output.put_line( 'Failed to drop the database link ' || v_dblink_name );
dbms_output.put_line( dbms_utility.format_error_backtrace() );
INSERT INTO error_table( column_list )
VALUES( <
- > );
END;
END LOOP;
END;
But I agree with the comment that others have grown up is not really wise to create and drop a database like that link.
Justin
-
Help with a SQL statement...
Hello...
I have tried to find a way to write a SQL statement and may not seem to produce something that works. What I need is a set of results that returns each month that a given task is in an open State. The only columns that I have in my work table with are TASK_NM, OPEN_DT and CLOSED_DT.
So if I have a line containing the following: TASK_NM = 'task one', OPEN_DT = April 18, 10 ' and CLOSED_DT = 14 October 10 '... I would like to see as a result set that looks like:
TASK_NM YEAR JAN FEB MAR APR MAY JUNE JULY AUG SEP OCT NOV DEC
the task of a 2010 0 0 0 1 1 1 1 1 1 1 0 0
Is it still possible?
Thanks in advance,
David.
Published by: user13027968 on March 10, 2011 14:19
Published by: user13027968 on March 10, 2011 15:13Hello
Welcome to the Forum!
Whenever you have a question. Please post a small example of data (CREATE TABLE and INSERT statements) and the results desired from these data.
For example, the sample data may be:CREATE TABLE table_x ( task_nm VARCHAR2 (10) , open_dt DATE , closed_dt DATE ); INSERT INTO table_x (task_nm, open_dt, closed_dt) VALUES ('task a', DATE '2010-04-18', DATE '2010-10-14'); INSERT INTO table_x (task_nm, open_dt, closed_dt) VALUES ('foo', DATE '2010-10-31', DATE '2011-01-01'); INSERT INTO table_x (task_nm, open_dt, closed_dt) VALUES ('foo', DATE '2010-12-01', DATE '2011-02-21'); INSERT INTO table_x (task_nm, open_dt, closed_dt) VALUES ('foo', DATE '2011-04-01', DATE '2011-04-30'); INSERT INTO table_x (task_nm, open_dt, closed_dt) VALUES ('bar', DATE '2010-01-01', DATE '2010-01-01');
From this data, you may want these results:
TASK_NM YEAR JAN FEB MAR APR MAY JUN JUL AUG SEP OVT NOV DEC ---------- ----- --- --- --- --- --- --- --- --- --- --- --- --- bar 2010 1 0 0 0 0 0 0 0 0 0 0 0 foo 2010 0 0 0 0 0 0 0 0 0 1 1 1 foo 2011 1 1 0 1 0 0 0 0 0 0 0 0 task a 2010 0 0 0 1 1 1 1 1 1 1 0 0
I'm not sure eactly how you plan to use it. Are there lines that overlap for the name of the task? You always want the same number of columns? What version of Oracle are you using?
I think you want something like this:WITH got_month_cnt AS ( SELECT task_nm , TRUNC (open_dt, 'MONTH') AS first_month , 1 + MONTHS_BETWEEN ( TRUNC (closed_dt, 'MONTH') , TRUNC (open_dt, 'MONTH') ) AS month_cnt FROM table_x -- WHERE ... -- If you want any filtering, put it here ) , cntr AS ( SELECT LEVEL AS n FROM ( SELECT MAX (month_cnt) AS max_month_cnt FROM got_month_cnt ) CONNECT BY LEVEL <= max_month_cnt ) , all_months AS ( SELECT m.task_nm , ADD_MONTHS ( m.first_month , c.n - 1 ) AS open_month FROM got_month_cnt m JOIN cntr c ON c.n <= m.month_cnt ) SELECT task_nm , EXTRACT (YEAR FROM open_month) AS year , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Jan' THEN 1 ELSE 0 END) AS jan , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Feb' THEN 1 ELSE 0 END) AS feb , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Mar' THEN 1 ELSE 0 END) AS mar , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Apr' THEN 1 ELSE 0 END) AS apr , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'May' THEN 1 ELSE 0 END) AS may , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Jun' THEN 1 ELSE 0 END) AS jun , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Jul' THEN 1 ELSE 0 END) AS jul , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Aug' THEN 1 ELSE 0 END) AS aug , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Sep' THEN 1 ELSE 0 END) AS sep , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Oct' THEN 1 ELSE 0 END) AS ovt , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Nov' THEN 1 ELSE 0 END) AS nov , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Dec' THEN 1 ELSE 0 END) AS dec FROM all_months GROUP BY task_nm , EXTRACT (YEAR FROM open_month) ORDER BY task_nm , year ;
This will work in Orfacle 9 (and), but from Oracle 11, you could simplify it a little bit by using SELECT... Function PIVOT.
Published by: Frank Kulash, March 10, 2011 16:51
-
FIFO in the sql statement...
Hello
Suppose we have two tables:
(1) deliveries of items according to a contract
create the table contracted_dlv
(item_id number (2),)
date of contracted_date,
number of contracted_qty);
(2) actual delivery of items in the warehouses of the customer
create the table real_dlv
(item_id number (2),)
date of dlv_date,
number of dlv_qty);
As the two tables can be connected to each other completely... because there is not
the information in the real_dlv table that delivery of X in the warehouse takes place in
conformity of the delivery as contracted, the FIFO algorithm must be used as:
The first quantity delivered (table real_dlv) is made in order to accomplish the first
quantity (table contracted_dlv) required / contract, until the first contracted
amount would come true. Then the second contract qty... etc
For example: item_id: 10
insert into contracted_dlv (item_id, contracted_date, contracted_qty)
values(10,'03/01/2011',6);
insert into contracted_dlv (item_id, contracted_date, contracted_qty)
values(10,'03/02/2011',15);
insert into real_dlv (item_id, dlv_date, dlv_qty)
values(10,'7/01/2011',3);
insert into real_dlv (item_id, dlv_date, dlv_qty)
values(10,'17/01/2011',2);
insert into real_dlv (item_id, dlv_date, dlv_qty)
values(10,'23/01/2011',5);
insert into real_dlv (item_id, dlv_date, dlv_qty)
values(10,'23/02/2011',4);
insert into real_dlv (item_id, dlv_date, dlv_qty)
values(10,'27/02/2011',6);
insert into real_dlv (item_id, dlv_date, dlv_qty)
values(10,'02/03/2011',5);
Now I want in sql statement (even using a pl/sql function that can be used in sql)
an output such as:
item_id contracted_date contracted_qty dlv_qty
03/01/2011 10, 6 6 (1 *)
03/02/2011 10, 15 19 (2 *)
(1 *) the dlv_qty arises as the result of what follows (3 + 2 + (5-4)) to fill the 6pieces of
the first delivery as contracted.
(2 *) the dlv_qty arises as the result of what follows (4 + 4 + 6 + 5) to fill the 15pieces of
the second delivery under contracted (note that for this second contract delivery the 4pieces)
the issue of the third actual delivery is used).
How I write a sql stmt to achieve the above...?
Notes:
(1) for simplicity, I wrote only two main tables and columns in them.
(2) if the sum (contracted_qty) < sum (dlv_qty) then you should consider that deliveries carry out
then contracted quantity (as has happened in some examples of data that I posted above).
(3) it must be by point so many records there are in the contracted_dlv table.
(4) I use DB 10 g v.2
Thank you
SIMHello
That's what you asked for:
WITH contracted_rt AS ( SELECT item_id, contracted_date, contracted_qty , SUM (contracted_qty) OVER ( PARTITION BY item_id ORDER BY contracted_date ) AS total_qty FROM contracted_dlv ) , real_rt AS ( SELECT item_id, dlv_date, dlv_qty , SUM (dlv_qty) OVER ( PARTITION BY item_id ORDER BY dlv_date ) AS total_qty FROM real_dlv ) , real_final AS ( SELECT item_id , SUM (dlv_qty) AS total_qty , MAX (dlv_date) AS dlv_date FROM real_dlv GROUP BY item_id ) SELECT c.item_id , c.contracted_date , c.contracted_qty , CASE WHEN f.total_qty IS NULL THEN 0 WHEN c.total_qty <= r.total_qty THEN c.contracted_qty ELSE GREATEST ( f.total_qty - (c.total_qty - c.contracted_qty) , 0 ) END AS dlv_qty , CASE WHEN c.total_qty < r.total_qty THEN ( SELECT MIN (dlv_date) FROM real_rt WHERE item_id = c.item_id AND total_qty > c.total_qty - c.contracted_qty ) WHEN c.total_qty = r.total_qty THEN r.dlv_date WHEN f.total_qty > c.total_qty - c.contracted_qty THEN f.dlv_date END AS dlv_date FROM contracted_rt c LEFT OUTER JOIN real_rt r ON c.item_id = r.item_id AND c.total_qty BETWEEN r.total_qty - r.dlv_qty AND r.total_qty LEFT OUTER JOIN real_final f ON c.item_id = f.item_id ORDER BY c.item_id , c.contracted_date ;
Sorry, I don't have time for an explanation now. I'll post one tomorrow, if I can.
-
Auto-relation (Simple query) SQL statement
Hello
I just want to know is the following: auto-relation SQL statement
If not pls I want to create aSELECT ROWID,ACCOUNT_ID,ACCOUNT_NAME,IS_CLOSED,TYPE_ID,ACCOUNT_ID_PARENT FROM GL_ACCOUNTS WHERE GL_ACCOUNTS.TYPE_ID = GL_ACCOUNTS_PARENT.TYPE_ID AND GL_ACCOUNTS.ACCOUNT_ID_PARENT = GL_ACCOUNTS_PARENT.ACCOUNT_ID
Thanks in advance,
Kind regards
Abdetu...Abdetu wrote:
HelloI just want to know is the following: auto-relation SQL statement
SELECT ROWID,ACCOUNT_ID,ACCOUNT_NAME,IS_CLOSED,TYPE_ID,ACCOUNT_ID_PARENT FROM GL_ACCOUNTS WHERE GL_ACCOUNTS.TYPE_ID = GL_ACCOUNTS_PARENT.TYPE_ID AND GL_ACCOUNTS.ACCOUNT_ID_PARENT = GL_ACCOUNTS_PARENT.ACCOUNT_ID
If not pls I want to create a
Thanks in advance,
Kind regards
Abdetu...
Do you want a self-join or query CONNECT BY (a particular type of self-join that runs recursively).
Both are described in the documentation
-
application of SQL statement tuning
Application of SQL statement tuning
1 SQL: Code that never ends. 11 hours running, but nothing get inserted into tables
2. database version:
3.SELECT * FROM V$VERSION; BANNER Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi PL/SQL Release 10.2.0.4.0 - Production CORE 10.2.0.4.0 Production TNS for Solaris: Version 10.2.0.4.0 - Production NLSRTL Version 10.2.0.4.0 - Production
(i)
BIFSQL> SHOW PARAMETER OPTIMIZER NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ optimizer_dynamic_sampling integer 2 optimizer_features_enable string 10.2.0.4 optimizer_index_caching integer 0 optimizer_index_cost_adj integer 100 optimizer_mode string ALL_ROWS optimizer_secure_view_merging boolean TRUE SQL>
(III)SQL> SHOW PARAMETER DB_FILE_MULTI NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ db_file_multiblock_read_count integer 16 SQL>
(IV)SQL> SHOW PARAMETER DB_BLOCK_SIZE NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ db_block_size integer 8192 SQL>
4 calendar and Autotrace outputSQL> SHOW PARAMETER CURSOR_SHARING NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ cursor_sharing string EXACT SQL>
one)
(b)SQL> SQL> SET AUTOTRACE TRACEONLY SQL> Query; 99999 rows selected. Execution Plan ---------------------------------------------------------- Plan hash value: 888060805 -------------------------------------------------------------------------------- ------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------- ------ | 0 | SELECT STATEMENT | | 99999 | 171M| 6452 (1)| 00:0 1:18 | |* 1 | COUNT STOPKEY | | | | | | | 2 | TABLE ACCESS FULL| STGING| 99999 | 171M| 6452 (1)| 00:0 1:18 | -------------------------------------------------------------------------------- ------ Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter(ROWNUM<100000) Statistics ---------------------------------------------------------- 8 recursive calls 0 db block gets 33379 consistent gets 24108 physical reads 0 redo size 177773283 bytes sent via SQL*Net to client 46901 bytes received via SQL*Net from client 6668 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 99999 rows processed
6. explain Plan outputSQL> SET AUTOTRACE TRACEONLY EXPLAIN rem Could't do SET AUTOTRACE TRACEONLY as query takes a long time. SQL> Query; Execution Plan ---------------------------------------------------------- Plan hash value: 696991379 -------------------------------------------------------------------------------- ------------------------- | Id | Operation | Name | Rows | Bytes |TempSpc | Cost (%CPU)| Time | -------------------------------------------------------------------------------- ------------------------- | 0 | SELECT STATEMENT | | 99999 | 171M| | 77733 (1)| 00:15:33 | | 1 | HASH UNIQUE | | 99999 | 171M| 390M | 77733 (1)| 00:15:33 | |* 2 | CONNECT BY WITHOUT FILTERING| | | | | | | | 3 | VIEW | | 99999 | 171M| | 40120 (1)| 00:08:02 | |* 4 | COUNT STOPKEY | | | | | | | | 5 | TABLE ACCESS FULL | STG_OLD_RUBRIC1 | 621K| 1066M| | 40120 (1)| 00:08:02 | -------------------------------------------------------------------------------- ------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - filter(LEVEL<=(LENGTH("STRING")-LENGTH(REPLACE("STRING",' Criterion:')))/10 ) 4 - filter(ROWNUM<100000) SQL>
7. from TKPROF outputSQL> ed Wrote file afiedt.buf 1 EXPLAIN PLAN SET STATEMENT_ID = 'A' FOR 2 QUERY; 3 / Explained. SQL> SELECT * FROM TABLE (DBMS_XPLAN.DISPLAY); PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------- Plan hash value: 696991379 -------------------------------------------------------------------------------- ------------------------- | Id | Operation | Name | Rows | Bytes |TempSpc | Cost (%CPU)| Time | -------------------------------------------------------------------------------- ------------------------- PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 99999 | 171M| | 77733 (1)| 00:15:33 | | 1 | HASH UNIQUE | | 99999 | 171M| 390M | 77733 (1)| 00:15:33 | |* 2 | CONNECT BY WITHOUT FILTERING| | | | | | | | 3 | VIEW | | 99999 | 171M| | 40120 (1)| 00:08:02 | PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------- |* 4 | COUNT STOPKEY | | | | | | | | 5 | TABLE ACCESS FULL | STGING| 621K| 1066M| | 40120 (1)| 00:08:02 | -------------------------------------------------------------------------------- ------------------------- PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - filter(LEVEL<=(LENGTH("STRING")-LENGTH(REPLACE("STRING",' Criterion:')))/10 ) 4 - filter(ROWNUM<100000) 19 rows selected. SQL>
Any advice. Why the request is not able to generate a trace file and take so long?SQL> alter session set timed_statistics = TRUE; Session altered. SQL> alter session set sql_trace = TRUE; Session altered. SQL> query; rem it is still running, no idea what is going on.
Let me know, if needed further information.
Thank you.Something like that...?
WITH T AS (SELECT 'Criterion: Crit1.
Proficient (points 2): Crit1 text.Criterion: Crit2.
Basic (points 1): Crit2 text.Criterion: Crit3.
Proficient (points 2): Crit3 text.Criterion: Crit4.
Basic (points 1): Crit4 text.Criterion: Crit5.
Proficient (points 2): Crit5 text.
Proficient (points 2): Crit5 text.' latest_comment FROM DUAL union all SELECT 'Criterion: Crit1.
Proficient (points 2): Crit1 text.Criterion: Crit2.
Basic (points 1): Crit2 text.Criterion: Crit3.
Proficient (points 2): Crit3 text.Criterion: Crit4.
Basic (points 1): Crit4 text.Criterion: Crit5.
Proficient (points 2): Crit5 text.
Proficient (points 2): Crit5 text.' latest_comment FROM DUAL union all SELECT 'Criterion: Crit1.
Proficient (points 2): Crit1 text.Criterion: Crit2.
Basic (points 1): Crit2 text.Criterion: Crit3.
Proficient (points 2): Crit3 text.Criterion: Crit4.
Basic (points 1): Crit4 text.Criterion: Crit5.
Proficient (points 2): Crit5 text.
Proficient (points 2): Crit5 text.' latest_comment FROM DUAL ) SELECT SUBSTR(REGEXP_SUBSTR(latest_comment,'Criterion:[^<]+', 1, n.column_value), 20) column1, SUBSTR(REGEXP_SUBSTR(latest_comment,'points [^\)]+', 1, n.column_value), 8) column2, SUBSTR(REGEXP_SUBSTR(latest_comment,'\):[^<]+', 1, n.column_value), 3) column3, SUBSTR(REGEXP_SUBSTR(latest_comment,'blockquote>[^<]+', 1, n.column_value), 12) column4, SUBSTR(latest_comment, INSTR(latest_comment, '>', -1) + 1) column5 ,n.column_value FROM t,table(cast(multiset(select level from dual CONNECT BY LEVEL <= (LENGTH(latest_comment) - LENGTH(REPLACE(latest_comment, 'Criterion:')))/10) as sys.OdciNumberList)) n ;Kind regards
Bob
Maybe you are looking for
-
Someone at - it files of Lenovo Ideapad Yoga 11 Windows RT Recovey USB, my SSD got corupted. If not, anyone can create a USB stick recovery and send me the links where you downloaded... Please, I need it desperately. Thank you
-
I can't download the pictures because of "fakepath". I have gmail and IE
I could download images until today. I have Gmail and IE8. I was download more than 5 meg of images per day without problem. Now I have "fakekpath" whenever I try to attach a photo. Flash player would be involved? I've updated this morning.
-
Original title: get rid of a software box that says (Arcsoft Connect Daemon has stopped working). Keep on appearing__on from my laptop. ___ My laptop, age 6 to 7 months running Windows 7, it came with Arcsoft requests to make greeting cards, albums S
-
Notification of change of time system - BB 10
Hello Is there any event/signal that is emitted when the user tries to change the time (or time zone), on the device. Older version of Blackberry 5/6/7, I used to get DateTimeUtilities.GUID_TIMEZONE_CHANGED and DateTimeUtilities.GUID_DATE_CHANGED. Th
-
Cannot open the fonts folder in Windows
I can't access my fonts in the Windows/Fonts folder. When I opened, it leaves just a blank window and unresponsive. I tried to access them through the fonts in the Control Panel, but yet cannot access.