简体   繁体   English

使用SQL从数据库表中提取所有链接?

[英]Extract all links from a database table using SQL?

I need to extarct all links from a database so I can create a URL rewrite. 我需要从数据库中提取所有链接,以便创建URL重写。 Using a SQL statement, how can I extract just links from a table? 使用SQL语句,如何仅从表中提取链接? Sometimes there is more than one link within a cell which further complicates it. 有时,一个单元中存在多个链接,这使链接更加复杂。 Any idea on how to achieve this? 关于如何实现这一点的任何想法?

EDIT An example of this would be: SELECT myval FROM htmlcontrols. 编辑这样的一个例子是:从htmlcontrols中选择myval。 "myval" has an HTML string such as " <div>Hi this is a test. <a href="somewhere.htm">Click here</a> or <a href="http://somewhereelse.com/testarea">here</a></div> ". “ myval”具有HTML字符串,例如“ <div>Hi this is a test. <a href="somewhere.htm">Click here</a> or <a href="http://somewhereelse.com/testarea">here</a></div> “。 I want an extract like this: 我想要这样的摘录:

LINKS
-----
somewhere.htm
http://somewhereelse.com/testarea

You are probably better off either handling this on the client side, iterating through the fields and parsing the HTML to then re-insert them on whatever table/columns you need to; 您可能最好在客户端进行处理,遍历字段并解析HTML,然后将它们重新插入到需要的任何表/列中; or at least, creating a UDF that can do the parsing efficiently. 或者至少创建一个可以高效进行解析的UDF

Note that the link I posted above is an implementation of a UDF RegEx function but I am not suggesting necessarily that you should use a RegEx to parse HTML as this is almost always a bad idea . 请注意,我在上面发布的链接是UDF RegEx函数的实现,但是我并不建议您应该使用RegEx来解析HTML,因为这几乎总是一个坏主意

If you go with the CLR function, take a look at HTMLAgilityPack 如果您使用CLR功能,请看一下HTMLAgilityPack

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM