<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1745253669180017969</id><updated>2012-02-16T03:07:58.734-08:00</updated><category term='Funciones de Texto'/><category term='Funciones'/><category term='Auditoria'/><category term='Consultas útiles'/><category term='Diccionario'/><category term='Fechas'/><title type='text'>DataAge - Oracle</title><subtitle type='html'>Técnicas de procesamiento de datos, tunning, consultas útiles  y uso de funciones en Oracle</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://daoracle.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1745253669180017969/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://daoracle.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>ElData</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>8</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1745253669180017969.post-5016980953747039580</id><published>2009-03-10T18:12:00.000-07:00</published><updated>2009-03-10T18:39:30.032-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Funciones'/><category scheme='http://www.blogger.com/atom/ns#' term='Funciones de Texto'/><title type='text'>Que hace y como utilizar la función INSTR de Oracle</title><content type='html'>&lt;div align="justify"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;/span&gt; &lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;La &lt;strong&gt;función INSTR de Oracle&lt;/strong&gt; busca una sub-cadena de caracteres dentro de una cadena de caracteres, retornando la posición de la primer ocurrencia de la misma.&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;div align="justify"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;em&gt;&lt;br /&gt;Su sintaxis es:&lt;/em&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;strong&gt;&lt;div align="left"&gt;&lt;br /&gt;INSTR( cadena , sub_cadena [, posicion_desde [ , ocurrencias_numero ] ] )&lt;br /&gt;&lt;/div&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;em&gt;&lt;div align="justify"&gt;&lt;br /&gt;Sus parámetros son:&lt;/em&gt;&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;div align="justify"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;strong&gt;&lt;br /&gt;cadena:&lt;/strong&gt; Cadena de caracteres donde se buscará la sub-cadena.&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;strong&gt;sub_cadena:&lt;/strong&gt; Sub-cadena que se desea buscar.&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;strong&gt;posicion_desde:&lt;/strong&gt; Posición a partir de donde se quiere buscar.&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;strong&gt;ocurrencias_numero:&lt;/strong&gt; Número de ocurrencia que se desea encontrar su posición.&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;div align="justify"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;br /&gt;Su valor de retorno es: Número entero que contiene la posición de la primer ocurrencia de la sub-cadena dentro de la cadena, si no la encuentra retorna cero.&lt;/span&gt;&lt;/div&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;div align="justify"&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;Ejemplos que muestra Oracle en sus manuales:&lt;/strong&gt;&lt;/em&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;SELECT INSTR('CORPORATE FLOOR','OR', 3, 2) "Instring" &lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:courier new;"&gt;FROM DUAL;&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;&lt;br /&gt;El resultado obtenido es 14, busca la segunda ocurrencia de la cadena OR a partir de la tercer posición (R), si hubiese omitido el cuarto parámetro o introducido 1 en el mismo el resultado sería 5.&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;&lt;br /&gt;Otro ejemplo es introducir la posición a buscar en negativo, lo que hace es buscar de atrás para adelante:&lt;/div&gt;&lt;div align="left"&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;SELECT INSTR('CORPORATE FLOOR','OR', -3, 2) "Reversed Instring" &lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:courier new;"&gt;FROM DUAL;&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;div align="justify"&gt;&lt;br /&gt;En este caso retorna 2, ya que comienza a buscar desde la primer O de FLOOR.&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;Si no se le pasa ningún parámetro opcional el resultado es 2:&lt;br /&gt;&lt;/div&gt;&lt;span style="font-family:courier new;"&gt;&lt;div align="left"&gt;&lt;br /&gt;SELECT INSTR('CORPORATE FLOOR','OR') "Normal" &lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:courier new;"&gt;FROM DUAL;&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;div align="justify"&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;&lt;br /&gt;Otra forma de utilizarlo es como un reemplazo, no muy bueno, de la operación IN. Tiene la ventaja de que puede ser utilizado en las columnas resultantes de un SELECT, y en condiciones mediante el uso de variables.&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;Por ejemplo de una lista de pedidos interesa separar los productos ARROZ, AZUCAR y HARINA del resto. La manera tradicional de hacerlo es utilizando un IN:&lt;/div&gt;&lt;div align="left"&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;select *&lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:courier new;"&gt;from pedidos&lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:courier new;"&gt;where PRODUCTO IN ('ARROZ', 'AZUCAR', 'HARINA');&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;div align="justify"&gt;&lt;br /&gt;Y como alternativa:&lt;/div&gt;&lt;div align="left"&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;select *&lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:courier new;"&gt;from pedidos&lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:courier new;"&gt;where INSTR('ARROZ-AZUCAR-HARINA', PRODUCTO) &gt; 0;&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;Si el resultado de la función INSTR es mayor que 0 quiere decir que se encuentra. Las líneas divisorias son para separar de manea confundirse entre los productos, aunque es mas seguro también ponerle al dato a buscar …&lt;/div&gt;&lt;div align="left"&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;select * &lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:courier new;"&gt;from pedidos&lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:courier new;"&gt;where INSTR('-ARROZ-AZUCAR-HARINA-', '-' PRODUCTO '-') &gt; 0;&lt;/span&gt;&lt;/div&gt;&lt;span style="font-family:courier new;"&gt;&lt;div align="justify"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;div align="justify"&gt;… en el caso de que existan productos donde su nombre esté contenido en otro producto.&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Si se trata de números con largos diferentes se deberá normalizar todos valores rellenando con ceros a la izquierda:&lt;/div&gt;&lt;div align="left"&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;select *&lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:courier new;"&gt;from pedidos&lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:courier new;"&gt;where INSTR('#00011#00120#15020#', '#' LPAD(codigo, 5, '0') '#') &gt; 0;&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;div align="justify"&gt;&lt;br /&gt;No cabe dudas que es mejor y mas claro utilizar en la cláusula WHERE la operación IN, pero por ejemplo cuando la lista se necesita manejar en forma variable podría ser útil (alternativa a SQL dinámicos).&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;La razón por la que forma no es buena es por que en el caso existir un índice por el campo a buscar, Oracle no lo tomaría en cuenta y accedería a la tabla en forma secuencial (FULL), aun si no se concatenaran los separadores. &lt;/div&gt;&lt;div align="justify"&gt;Utilizando la operación IN si utilizaría el índice.&lt;/div&gt;&lt;div align="justify"&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;Sí se puede utilizar cuando no se requiere acceder a la tabla por el campo a comparar, por ejemplo si existiese una índice por número de cliente y se desea saber los pedidos de estos productos realizados por el cliente 123.&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;select *&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:courier new;"&gt;from pedidos&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:courier new;"&gt;where INSTR('ARROZ-AZUCAR-HARINA', PRODUCTO) &gt; 0 and codigo_cliente = 123;&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;Es más útil utilizarla en las columnas de un SELECT o asignaciones de un UPDATE combinándolo con la función DECODE (condicional).&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;select &lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:courier new;"&gt;SUM(DECODE(INSTR('ARROZ-AZUCAR-HARINA', PRODUCTO), 0, &lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:courier new;"&gt;0, IMPORTE_PEDIDO)) importe_que_interesa, &lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:courier new;"&gt;SUM(DECODE(INSTR('ARROZ-AZUCAR-HARINA', PRODUCTO), 0, &lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:courier new;"&gt;IMPORTE_PEDIDO, 0)) importe_que_no_interesa,&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:courier new;"&gt;SUM(DECODE(INSTR('ARROZ-AZUCAR-HARINA', PRODUCTO), 0, &lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:courier new;"&gt;0, 1)) cantidad_que_interesa,&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:courier new;"&gt;SUM(DECODE(INSTR('ARROZ-AZUCAR-HARINA', PRODUCTO), 0,&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:courier new;"&gt;1, 0)) cantidad_que_no_interesa&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:courier new;"&gt;from pedidos;&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;En este ejemplo primero se pregunta si el resultado de INSTR es cero (no existe) se retorna cero, de lo contrario el importe del pedido para totalizar el importe que interesa, para el que no interesa se hace lo contrario. &lt;/div&gt;&lt;div align="justify"&gt;Si en lugar de sumar el dato del importe se suma 1, se logra contar por un lado los datos que interesan y por otro lado los demás.&lt;/div&gt;&lt;div align="justify"&gt;Como resultado final se suman todas las filas para obtener un resumen. &lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;En este otro ejemplo se actualiza a la tabla pedidos un campo indicando si el producto forma o no parte de los que interesan:&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;update pedidos&lt;/div&gt;&lt;div align="justify"&gt;set producto_que_interesa = DECODE(INSTR('ARROZ-AZUCAR-HARINA', PRODUCTO), 0, 'No', 'Si');&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1745253669180017969-5016980953747039580?l=daoracle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://daoracle.blogspot.com/feeds/5016980953747039580/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://daoracle.blogspot.com/2009/03/que-hace-y-como-utilizar-la-funcion.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1745253669180017969/posts/default/5016980953747039580'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1745253669180017969/posts/default/5016980953747039580'/><link rel='alternate' type='text/html' href='http://daoracle.blogspot.com/2009/03/que-hace-y-como-utilizar-la-funcion.html' title='Que hace y como utilizar la función INSTR de Oracle'/><author><name>ElData</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1745253669180017969.post-1675523421875958633</id><published>2009-03-06T09:44:00.000-08:00</published><updated>2009-03-06T09:47:55.231-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Consultas útiles'/><category scheme='http://www.blogger.com/atom/ns#' term='Auditoria'/><title type='text'>Auditoria sobre conexiones de usuarios</title><content type='html'>&lt;div align="justify"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;Mediante la vista propia de Oracle &lt;strong&gt;dba_audit_trail&lt;/strong&gt; (acceder con system o usuario con permiso de lectura en todas las vistas del sistema) se puede conocer la información sobre las conexiones realizadas a la base de datos. Muy útil para realizar auditorías e investigaciones. &lt;br /&gt;&lt;br /&gt;Esta consulta extrae las conexiones que realizó el usuario 'nombre_usuario' en la fecha indicada.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;select a.os_username, &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;a.username, a.terminal, &lt;/span&gt;&lt;/div&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;       a.timestamp, a.logoff_time, a.comment_text&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;from dba_audit_trail a&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;where a.username = 'nombre_usuario' &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;   and trunc(a.timestamp) = '20080124';&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;div align="justify"&gt;&lt;br /&gt;Retorna el usuario del sistema operativo con que se conectó, el usuario de Oracle, la máquina utilizada para la conexión, fecha y hora en que se conectó, fecha y hora en que se desconectó, e infrormación sobre la conexión.&lt;br /&gt;&lt;br /&gt;Por ejemlpo si se sabe que un determinado usuario realizó una determinada operación en el sistema y se conoce la fecha y hora de la misma, mediante esta vista se puede complementar la información de la máquina con que se conectó, usuario utilizado, etc.&lt;br /&gt;&lt;br /&gt;Con la siguiente consulta se obtienen estadísticas del uso de la base de datos por cada usuario:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;select a.username,       &lt;/span&gt;&lt;/div&gt;&lt;span style="font-family:courier new;"&gt;         count(*) cantidad_de_conexiones,       &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;         max(a.timestamp) fecha_utima_conexion,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;         count(distinct a.os_username) cantidad_de_usuarios,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;         count(distinct a.terminal) cantidad_de_maquinas,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;         count(distinct trunc(a.timestamp)) cantidad_de_dias&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;from dba_audit_trail a&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;where a.timestamp &gt;= '20090101'&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;group by a.username;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1745253669180017969-1675523421875958633?l=daoracle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://daoracle.blogspot.com/feeds/1675523421875958633/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://daoracle.blogspot.com/2009/03/auditoria-sobre-conexiones-de-usuarios.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1745253669180017969/posts/default/1675523421875958633'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1745253669180017969/posts/default/1675523421875958633'/><link rel='alternate' type='text/html' href='http://daoracle.blogspot.com/2009/03/auditoria-sobre-conexiones-de-usuarios.html' title='Auditoria sobre conexiones de usuarios'/><author><name>ElData</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1745253669180017969.post-6934051528930665257</id><published>2009-03-03T13:07:00.000-08:00</published><updated>2009-03-04T17:24:08.779-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Fechas'/><category scheme='http://www.blogger.com/atom/ns#' term='Consultas útiles'/><title type='text'>Calcular primer y último día del mes</title><content type='html'>&lt;div align="justify"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;Para calcular el primer día del mes respecto a una fecha dada, o del día, en Oracle se obtiene truncando la fecha a nivel del mes. Y para calcular el último día del mes se dispone de la función last_day que entrega el último día del mes correspondiente a la fecha que se pasa por parámetros.&lt;br /&gt;&lt;/div&gt;&lt;p&gt;&lt;/span&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;select trunc(sysdate, 'mm') primer_dia_del_mes,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;trunc(last_day(sysdate)) ultimo_dia_del_mes &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;from dual;&lt;/span&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-size:85%;"&gt;Para el caso del último día se trunca el resultado para quitarle las horas.&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://dataage.blogspot.com/2009/01/calcular-primer-y-ultimo-da-hbil-del.html"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;Consulta aquí como calcular el primer y último día laborable del mes.&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1745253669180017969-6934051528930665257?l=daoracle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://daoracle.blogspot.com/feeds/6934051528930665257/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://daoracle.blogspot.com/2009/02/para-calcular-el-primer-dia-del-mes.html#comment-form' title='9 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1745253669180017969/posts/default/6934051528930665257'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1745253669180017969/posts/default/6934051528930665257'/><link rel='alternate' type='text/html' href='http://daoracle.blogspot.com/2009/02/para-calcular-el-primer-dia-del-mes.html' title='Calcular primer y último día del mes'/><author><name>ElData</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1745253669180017969.post-4603057030882446040</id><published>2009-02-28T09:48:00.000-08:00</published><updated>2009-02-28T09:52:42.457-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Consultas útiles'/><title type='text'>Escribir un nùmero con letras en Oracle</title><content type='html'>&lt;div align="justify"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;Aquí se muestra una interesante manera de &lt;a href="http://dataage.blogspot.com/2009/02/escribir-numeros-con-letras-con-oracle.html"&gt;cómo escribir un número con letras&lt;/a&gt; sin desarrollar una función para esto. Si bien no es una solución “tradicional” es bueno para ver se puede hacer en una sentencia SELECT.&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;Como ejemplo para un número 1234 retorna "un mil doscientes treinta y cuatro".&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1745253669180017969-4603057030882446040?l=daoracle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://daoracle.blogspot.com/feeds/4603057030882446040/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://daoracle.blogspot.com/2009/02/escribir-un-numero-con-letras-en-oracle.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1745253669180017969/posts/default/4603057030882446040'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1745253669180017969/posts/default/4603057030882446040'/><link rel='alternate' type='text/html' href='http://daoracle.blogspot.com/2009/02/escribir-un-numero-con-letras-en-oracle.html' title='Escribir un nùmero con letras en Oracle'/><author><name>ElData</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1745253669180017969.post-205933499034849480</id><published>2009-02-25T16:44:00.000-08:00</published><updated>2009-02-25T16:49:21.612-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Diccionario'/><category scheme='http://www.blogger.com/atom/ns#' term='Consultas útiles'/><title type='text'>Buscar tablas que contengan un campo determinado</title><content type='html'>&lt;div align="justify"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;La siguinete consulta puede ser utilizada para encontrar las tablas que contienen determinado campo al que se le conoce parcial o totalmente su nombre.&lt;/span&gt;&lt;/div&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;select owner, &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;table_name,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;column_name Nombre,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;substr(data_type decode(char_col_decl_length, null, &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;decode(data_precision, null, null,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;'('data_precision&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;decode(data_scale,0,')',','data_scale')')),&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;'('char_col_decl_length')'),1,20) Tipo&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;from all_tab_columns&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;where column_name like upper( 'nombre_campo_o_parte') '%'&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;order by owner, table_name, column_name;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div align="justify"&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;Esta consulta es util por ejemplo para realizar conversiones de datos, saber tablas relacionadas cuando no existen claves foráneas, o encontrar el nombre de una tabla cuando se conoce solamente un campo de la misma.&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1745253669180017969-205933499034849480?l=daoracle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://daoracle.blogspot.com/feeds/205933499034849480/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://daoracle.blogspot.com/2009/02/buscar-tablas-que-contengan-un-campo.html#comment-form' title='2 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1745253669180017969/posts/default/205933499034849480'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1745253669180017969/posts/default/205933499034849480'/><link rel='alternate' type='text/html' href='http://daoracle.blogspot.com/2009/02/buscar-tablas-que-contengan-un-campo.html' title='Buscar tablas que contengan un campo determinado'/><author><name>ElData</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1745253669180017969.post-6946020039509777029</id><published>2009-02-25T16:42:00.000-08:00</published><updated>2009-02-25T16:49:34.903-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Diccionario'/><category scheme='http://www.blogger.com/atom/ns#' term='Consultas útiles'/><title type='text'>Buscar tablas por parte de su nombre</title><content type='html'>&lt;span style="font-family:verdana;font-size:85%;"&gt;Cuando no se conoce exactamente el nombre de una tabla &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_0"&gt;Oracle&lt;/span&gt;, con la siguiente consulta se la puede encontrar. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_1"&gt;select&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_2"&gt;owner&lt;/span&gt;, &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_3"&gt;table&lt;/span&gt;_&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_4"&gt;name&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_5"&gt;from&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_6"&gt;all&lt;/span&gt;_&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_7"&gt;tables&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_8"&gt;where&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_9"&gt;table&lt;/span&gt;_&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_10"&gt;name&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_11"&gt;like&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_12"&gt;upper&lt;/span&gt;('parte_de_nombre_tabla' '%')&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_13"&gt;order&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_14"&gt;by&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_15"&gt;owner&lt;/span&gt;, &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_16"&gt;table&lt;/span&gt;_&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_17"&gt;name&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1745253669180017969-6946020039509777029?l=daoracle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://daoracle.blogspot.com/feeds/6946020039509777029/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://daoracle.blogspot.com/2009/02/buscar-tablas-por-parte-de-su-nombre.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1745253669180017969/posts/default/6946020039509777029'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1745253669180017969/posts/default/6946020039509777029'/><link rel='alternate' type='text/html' href='http://daoracle.blogspot.com/2009/02/buscar-tablas-por-parte-de-su-nombre.html' title='Buscar tablas por parte de su nombre'/><author><name>ElData</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1745253669180017969.post-5259920751357212422</id><published>2009-02-25T16:26:00.000-08:00</published><updated>2009-02-25T16:49:43.257-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Diccionario'/><category scheme='http://www.blogger.com/atom/ns#' term='Consultas útiles'/><title type='text'>Consultar los índices de una tabla</title><content type='html'>&lt;span style="font-family:verdana;font-size:85%;"&gt;Con la siguiente consulta se obtienen los índices de una tabla Oracle, incluye las columnas de los mismos.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_0"&gt;select&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_1"&gt;table&lt;/span&gt;_&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_2"&gt;owner&lt;/span&gt;,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_3"&gt;index&lt;/span&gt;_&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_4"&gt;name&lt;/span&gt;,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_5"&gt;column&lt;/span&gt;_&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_6"&gt;position&lt;/span&gt; pos,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_7"&gt;substr&lt;/span&gt;(&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_8"&gt;column&lt;/span&gt;_&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_9"&gt;name&lt;/span&gt;, 1, 30) &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_10"&gt;column&lt;/span&gt;_&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_11"&gt;name&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_12"&gt;from&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_13"&gt;all&lt;/span&gt;_&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_14"&gt;ind&lt;/span&gt;_&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_15"&gt;columns&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_16"&gt;where&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_17"&gt;table&lt;/span&gt;_&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_18"&gt;name&lt;/span&gt; = &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_19"&gt;upper&lt;/span&gt;('nombre_de_tabla')&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_20"&gt;order&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_21"&gt;by&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_22"&gt;table&lt;/span&gt;_&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_23"&gt;owner&lt;/span&gt;, &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_24"&gt;index&lt;/span&gt;_&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_25"&gt;name&lt;/span&gt;, pos;&lt;/span&gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;En caso de tener varios esquemas, incluir el nombre de esquema en la condición: &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_26"&gt;and&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_27"&gt;table&lt;/span&gt;_&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_28"&gt;owner&lt;/span&gt; = 'nombre_esquema'&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1745253669180017969-5259920751357212422?l=daoracle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://daoracle.blogspot.com/feeds/5259920751357212422/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://daoracle.blogspot.com/2009/02/lista-de-indices-de-una-tabla.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1745253669180017969/posts/default/5259920751357212422'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1745253669180017969/posts/default/5259920751357212422'/><link rel='alternate' type='text/html' href='http://daoracle.blogspot.com/2009/02/lista-de-indices-de-una-tabla.html' title='Consultar los índices de una tabla'/><author><name>ElData</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1745253669180017969.post-8784611499145100629</id><published>2009-02-25T15:34:00.000-08:00</published><updated>2009-02-25T16:49:52.551-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Diccionario'/><category scheme='http://www.blogger.com/atom/ns#' term='Consultas útiles'/><title type='text'>Consultar los campos de una tabla</title><content type='html'>&lt;span style="font-family:verdana;font-size:85%;"&gt;Con la siguiente consulta se obtienen los campos y sus caracteríasticas de una tabla o vista de Oracle, el resultado es igual al comando DESC.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;select owner, &lt;/span&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;column_id Id,&lt;/span&gt; &lt;span style="font-family:courier new;font-size:85%;"&gt;column_name Nombre,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;decode(nullable, 'N','NOT NULL') Nulo,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;substr(data_type decode(char_col_decl_length, null, &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;decode(data_precision, null, null, &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;'(' data_precisiondecode(data_scale,0,')',',' &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;data_scale')')), '('char_col_decl_length')'),1,20) Tipo&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;from all_tab_columns&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;where table_name = upper('nombre_de_tabla') &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;order by owner, column_id; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;font-size:85%;"&gt;Cambiar 'nombre_de_tabla' por el nombre de la tabla a consultar. Si en la base de datos se manejan varios esquemas se puede agregar al where el dueño de la tabla: "and owner = 'nombre_esquema'".&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1745253669180017969-8784611499145100629?l=daoracle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://daoracle.blogspot.com/feeds/8784611499145100629/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://daoracle.blogspot.com/2009/02/consultar-los-campos-de-una-tabla.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1745253669180017969/posts/default/8784611499145100629'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1745253669180017969/posts/default/8784611499145100629'/><link rel='alternate' type='text/html' href='http://daoracle.blogspot.com/2009/02/consultar-los-campos-de-una-tabla.html' title='Consultar los campos de una tabla'/><author><name>ElData</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
